P   D


A   C
$ pgrep memcached
4695




$ pgrep memcached
$
$ pgrep memcached
4695
$ echo $?
0

$ pgrep memcached
$
$ echo $?
1
$ cronlog -- pgrep memcached
$

$ cronlog -- pgrep memcached
srv1 starting: pgrep memcached
command exited with code:1
MAILTO=”ops@example.com”
5 * * * * cronlog -- pgrep memcached >&1
$ nc -z -w 4 localhost 11211




$ cronlog -- nc -w 1 -z localhost 11211
srv1 starting: nc -w 1 -z localhost 11211
command...
GetOptions(
   'H=s' => my $HOST,
   'p=s' => my $PORT,
);

my $sock = IO::Socket::INET->new(
   PeerAddr => $HOST, PeerPo...
$ cronlog -- ./version.pl -H localhost -p 11211
srv1 starting: perl version.pl -H localhost -p 11211
couldnot get VERSION ...
GetOptions(
   'H=s' => my $HOST,
   'p=s' => my $PORT,
);

my $sock = IO::Socket::INET->new(
   PeerAddr => $HOST, PeerPo...
GetOptions(                                      $sock->syswrite("stats settingsrn");
    'H=s' =>   my   $HOST,
         ...
stats                         stats settings
STAT pid 4695                 STAT maxbytes 67108864
STAT uptime 84017       ...
$ cronlog -- ./memconn.pl -H localhost -p 11211 
                          -w 80 -c 90
srv1 starting: memconn.pl -H localh...
define service{
  use                     generic-service
  host_name               srv1
  service_description     Memcach...
#!/bin/sh

exec 2>&1
exec /usr/bin/memcached -c 32768 -u nobody 
              -C -m 16G -p 11211 -U 0 -v
5 min




                t


        1 sec
GetOptions(
    'H=s' => my $HOST,
    'p=s' => my $PORT,
    'c=i' => my $CRITICAL,
);

my $sock = IO::Socket::INET->new(...
define service{
   use                     generic-service
   host_name               srv1
   service_description     Memc...
Shibuya.pm#14 memcached運用監視ノウハウ
Shibuya.pm#14 memcached運用監視ノウハウ
Shibuya.pm#14 memcached運用監視ノウハウ
Shibuya.pm#14 memcached運用監視ノウハウ
Shibuya.pm#14 memcached運用監視ノウハウ
Shibuya.pm#14 memcached運用監視ノウハウ
Shibuya.pm#14 memcached運用監視ノウハウ
Shibuya.pm#14 memcached運用監視ノウハウ
Shibuya.pm#14 memcached運用監視ノウハウ
Shibuya.pm#14 memcached運用監視ノウハウ
Shibuya.pm#14 memcached運用監視ノウハウ
Shibuya.pm#14 memcached運用監視ノウハウ
Shibuya.pm#14 memcached運用監視ノウハウ
Shibuya.pm#14 memcached運用監視ノウハウ
Shibuya.pm#14 memcached運用監視ノウハウ
Shibuya.pm#14 memcached運用監視ノウハウ
Upcoming SlideShare
Loading in …5
×

Shibuya.pm#14 memcached運用監視ノウハウ

6,994 views

Published on

0 Comments
10 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
6,994
On SlideShare
0
From Embeds
0
Number of Embeds
624
Actions
Shares
0
Downloads
45
Comments
0
Likes
10
Embeds 0
No embeds

No notes for slide































  • Shibuya.pm#14 memcached運用監視ノウハウ

    1. 1. P D A C
    2. 2. $ pgrep memcached 4695 $ pgrep memcached $
    3. 3. $ pgrep memcached 4695 $ echo $? 0 $ pgrep memcached $ $ echo $? 1
    4. 4. $ cronlog -- pgrep memcached $ $ cronlog -- pgrep memcached srv1 starting: pgrep memcached command exited with code:1
    5. 5. MAILTO=”ops@example.com” 5 * * * * cronlog -- pgrep memcached >&1
    6. 6. $ nc -z -w 4 localhost 11211 $ cronlog -- nc -w 1 -z localhost 11211 srv1 starting: nc -w 1 -z localhost 11211 command exited with code:1
    7. 7. GetOptions( 'H=s' => my $HOST, 'p=s' => my $PORT, ); my $sock = IO::Socket::INET->new( PeerAddr => $HOST, PeerPort => $PORT ); if ( !$sock ) { print "couldnot connect to $HOST:$PORT: $!n"; exit(1); } $sock->syswrite("versionrn"); $sock->sysread( my $result, 16 ); if ( $result =~ m!^VERSION! ) { exit(0); } print "couldnot get VERSION from $HOST:$PORTn"; exit(1);
    8. 8. $ cronlog -- ./version.pl -H localhost -p 11211 srv1 starting: perl version.pl -H localhost -p 11211 couldnot get VERSION from localhost:11211 command exited with code:1
    9. 9. GetOptions( 'H=s' => my $HOST, 'p=s' => my $PORT, ); my $sock = IO::Socket::INET->new( PeerAddr => $HOST, PeerPort => $PORT ); if ( !$sock ) { print "couldnot connect to $HOST:$PORT: $!n"; exit(3); ##UNKNOWN } $sock->syswrite("versionrn"); $sock->sysread( my $result, 16 ); if ( $result =~ m!^VERSION! ) { exit(0); ##OK } print "couldnot get VERSION from $HOST:$PORTn"; exit(1); ##CLITICAL
    10. 10. GetOptions( $sock->syswrite("stats settingsrn"); 'H=s' => my $HOST, $sock->sysread(my $r_setting, 8192 ); 'p=s' => my $PORT, my %setting; ‘w=i' => my $WARN, foreach my $line ( split /r?n/, $r_setting ) 'c=i' => my $CRITICAL, { ); if ( $line =~ /^STATs([^ ]+)s(.+)$/ ) { $setting{$1} = $2; my $sock = IO::Socket::INET->new( } PeerAddr => $HOST, PeerPort => $PORT } ); my $rate = $stats{curr_connections} $sock->syswrite("statsrn"); / $setting{maxconns} * 100; $sock->sysread(my $r_stats, 8192 ); if ( $rate >= $CRITICAL ) { my %stats; printf "conn/max = %d%%n",$rate; foreach my $line ( split /r?n/, $r_stats ) { exit(2); #CRTICAL if ( $line =~ /^STATs([^ ]+)s(.+)$/ ) { } $stats{$1} = $2; elsif ( $rate >=$WARN ) { } printf "conn/max = %d%%n", $rate; } exit(1); #WARNING } exit(0); #OK
    11. 11. stats stats settings STAT pid 4695 STAT maxbytes 67108864 STAT uptime 84017 STAT maxconns 300000 STAT time 1285600226 STAT tcpport 11211 STAT version 1.4.2 STAT udpport 11211 STAT pointer_size 64 STAT inter NULL STAT rusage_user 0.000000 STAT verbosity 0 STAT rusage_system 0.020000 STAT oldest 0 STAT curr_connections 10 STAT evictions on STAT total_connections 16 STAT domain_socket NULL STAT cmd_get 0 STAT umask 700 ... STAT growth_factor 1.25 STAT bytes 0 STAT chunk_size 48 STAT curr_items 0 STAT num_threads 4 STAT total_items 0 .. STAT evictions 0 STAT item_size_max 1048576 END END
    12. 12. $ cronlog -- ./memconn.pl -H localhost -p 11211 -w 80 -c 90 srv1 starting: memconn.pl -H localhost -p 11211 -w 80 -c 90 conn/max = 91 command exited with code:2
    13. 13. define service{ use generic-service host_name srv1 service_description Memcached Connection check_command check_memcached_conn normal_check_interval 10 retry_check_interval 2 max_check_attempts 3 notification_options w,u,c,r } define command{ command_name check_memcached_conn command_line $USER1$/memconn.pl -H $HOSTADDRESS$ -p 11211 -c 90 -w 80 }
    14. 14. #!/bin/sh exec 2>&1 exec /usr/bin/memcached -c 32768 -u nobody -C -m 16G -p 11211 -U 0 -v
    15. 15. 5 min t 1 sec
    16. 16. GetOptions( 'H=s' => my $HOST, 'p=s' => my $PORT, 'c=i' => my $CRITICAL, ); my $sock = IO::Socket::INET->new( PeerAddr => $HOST, PeerPort => $PORT ); $sock->syswrite("statsrn"); $sock->sysread(my $r_stats, 8192 ); my %stats; foreach my $line ( split /r?n/, $r_stats ) { if ( $line =~ /^STATs([^ ]+)s(.+)$/ ) { $stats{$1} = $2; } } if ( $stat{uptime} <= $CRITICAL ) { printf "uptime: %dn", $stat{uptime}; exit(2); #CRTICAL } exit(0);
    17. 17. define service{ use generic-service host_name srv1 service_description Memcached Uptime check_command check_memcached_uptime normal_check_interval 5 retry_check_interval 5 max_check_attempts 1 notification_options c } define command{ command_name check_memcached_uptime command_line $USER1$/check_memcahced_uptime.pl -H $HOSTADDRESS$ -p 11211 -c 310 }

    ×