Howto monitor ntp server with mrtg

I’m currently maintain several ntp servers that listed in ntppool.org.
Average of all ntp servers listed there, there must be monitoring using mrtg.
After a little searching and asking questions on the mailing list. Here’s my configuration:
———————getntp.pl———————

################################## 
#getntp.pl 
#source : http://www.satsignal.eu/ntp/NTPandMRTG.html 
#budiw 20120728
$ntp_str = `ntpq -c rv $ARGV[0]`;
$val = (split(/\\,/,$ntp_str))[20];
$val =~ s/offset=//i;
$val = int ($val + 100);
if ($val < 0) {
$val = 0;
}
print "0\\n";
print "$val\\n";
print "0\\n";
print "0\\n";

 
—————–ntppackets.pl—————————

#!/usr/bin/perl
use strict;
##################################
#ntppackets.pl
#source from ntp mailing lists
#http://lists.ntp.org/pipermail/pool/2012-July/006049.html
#### Options ####
my $uptimeprog = '/usr/bin/uptime'; # Set to program to give system uptime
my $hostnameprog = '/bin/hostname'; # Set to program to give system hostname
##### Nothing below here should have to be changed #####
# Clear path and get uptime
delete $ENV{PATH};
delete $ENV{BASH_ENV};
my $uptime = `$uptimeprog`;
chomp($uptime);
$uptime=substr($uptime,12);
my $hostname = `$hostnameprog`;
chomp($hostname);
my $received = 0;
my $sent = 0;
my $status = `/usr/bin/ntpdc -c iostats`;
if($status =~ m!received packets:\\s*(-?\\d+)!) {
$received=$1 + 2147483648;
}
if($status =~ m!packets sent:\\s*(-?\\d+)!) {
$sent=$1 + 2147483648;
}
print "$received\\n$sent\n$uptime\\n$hostname\\n";
-----------mrtg.conf---------------------------
#
# NTP Packets
#
Title[ntppackets]: XXX NTP packets
Target[ntppackets]: `/home/budiw/paket/ntp-mrtg/ntppackets.pl`
PageTop[ntppackets]: Received and sent NTP packets for yyy
MaxBytes[ntppackets]: 60000
Options[ntppackets]: growright, nopercent
YLegend[ntppackets]: #/s
ShortLegend[ntppackets]:
Legend1[ntppackets]: Received packets/s
Legend2[ntppackets]: Sent packets/s
Legend3[ntppackets]: Maximal 5 minute received packets/s
Legend4[ntppackets]: Maximal 5 minute sent packets/s
LegendI[ntppackets]:  received packets/s
LegendO[ntppackets]:  sent packets/s
WithPeak[ntppackets]: wmy
#
# NTP offsets
#
Target[xxx_ntp]: `perl /home/budiw/paket/ntp-mrtg/getntp.pl 127.0.0.1`
MaxBytes[xxx_ntp]: 100
MaxBytes2[xxx_ntp]: 200
Unscaled[xxx_ntp]: dwmy
Timezone[xxx_ntp]: GMT+7
Title[xxx_ntp]: NTP statistics for XXX - offset from NTP
Options[xxx_ntp]: integer, gauge, nopercent, growright
YLegend[xxx_ntp]: offset+100 ms
ShortLegend[xxx_ntp]: ms
LegendI[xxx_ntp]:
LegendO[xxx_ntp]: offset:
Legend1[xxx_ntp]: n/a
Legend2[xxx_ntp]: time offset in ms, with 100ms offset added to ensure it's positive!
PageTop[xxx_ntp]: NTP -- XXX

—————–
Here’s one example scripts on action:
NTP – Offsets+100ms

NTP – Received and sent NTP packets for alynne.blankon.in

How to change the directory location of the screenshots in Mac OSX Snow Leopard.

I use Macbook with MacOSX Leopard, after I upgrade to Snow Leopard, short keys to take screenshots doesn’t make any output file. After searching in google, it is advisable to change the directory location for the screenshot. Here’s how I do. Do these commands using an ordinary user (without admin rights).
 

$ defaults write com.apple.screencapture location ~ / Desktop /
$ killall SystemUIServer

Then please try again to capture the screen. To capture the entire screen display use Cmd-Shift-3, if you want to just capture some of the screen you can use Cmd-Shift-4.

Tips to delete sessions file of php in CentOS 5.5

Different from Ubuntu, in CentOS 5.5, I do not find a mechanism to delete files from the php session. Because I’m worried the sessions file is not deleted, I import the fileremoval mechanism of Ubuntu.

I copy the following files from Ubuntu.

$cat /usr/lib64/php/maxlifetime

#!/bin/sh -e
max=1440
for ini in /etc/php.ini; do
cur=$(sed -n -e ‘s/^[[:space:]]*session.gc_maxlifetime[[:space:]]*=[[:space:]]*\([0-9]\+\).*$/\1/p’ $ini 2>/dev/null || true);
[ -z “$cur” ] && cur=0
[ “$cur” -gt “$max” ] && max=$cur
done
echo $(($max/60))
exit 0

Then we create cron file to auto delete the sessions files.

$cat /etc/cron.d/php

# /etc/cron.d/php5: crontab fragment for php5
# This purges session files older than X, where X is defined in seconds
# as the largest value of session.gc_maxlifetime from all your php.ini
# files, or 24 minutes if not defined. See /usr/lib/php5/maxlifetime
# Look for and purge old sessions every 30 minutes
09,39 * * * * root [ -x /usr/lib64/php/maxlifetime ] && [ -d /var/lib/php/session ] && find /var/lib/php/session -depth -mindepth 1 -maxdepth 1 -type f -cmin +$(/usr/lib64/php/maxlifetime) -delete

That’s it.

Cara memainkan Game Android di Mac OS/X

Pertama silahkan download Sun Java for Mac OS X 10.06 Update 6 di sini[1]. Untuk instalasi tinggal di double klik file disk image, kemudian akan muncul sebuah file .pkg, file tersebut juga tinggal di double klik maka Java akan terinstall.

Selanjutnya kita install Android SDK. Download Android SDK di sini[2]. Android SDK cukup kita extract saja, misal kita extract di /Users/budiw/Downloads/android-sdk.

Setelah Android SDK terinstall, kita download terlebih dahulu image android platform. Caranya kita buka terminal/console. Kemudian kita ketik perintah-perintah dibawah ini.

$cd /Users/budiw/Downloads/android-sdk
$tools/android

Kita tinggal centang Android versi berapa yang mau diinstall. Karena game yang akan dimainkan ‘katanya’ jalan di Android 2.3.3, maka saya centang yang Android 2.3.3 (API 10).

Continue reading “Cara memainkan Game Android di Mac OS/X”

How to allow Named/bind9 to write to other directory that blocked by Apparmor

My slave dns server returned error while I tried to add another domain, below example of the error.

kernel: [1239217.411031] type=1503 audit(1309700303.423:12381):
operation="mknod" pid=1692 parent=1 profile="/usr/sbin/named"
requested_mask="c::" denied_mask="c::" fsuid=109 ouid=109
name="/etc/bind/db/in/tmp-ImzPls04Rk"

That’s because named aren’t allowed to write to directory /etc/bind/db/in. To solve this issue, open apparmor profile of named (/etc/apparmor.d/usr.sbin.named), add this line right after ‘/etc/bind/** r,‘ :

/etc/bind/db/** rw,

Restart the apparmor and then restart named.