Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / plugins / memcached / memcached_bytes_all @ 17f78427

Historique | Voir | Annoter | Télécharger (2,32 ko)

1
#!/usr/bin/env perl
2
# ex:ts=4
3
# Copyright © Nicolas BOUTHORS / Smile <nicolas.bouthors@smile.fr>
4
#
5
# Licence GPLv2
6
#
7
# Based on a script distributed on munin-exchange.
8

    
9
use strict;
10
use warnings;
11

    
12
use Cache::Memcached;
13

    
14
my %instances = ();
15

    
16
# Will look into /etc for memcached config files and extract TCP listening port
17
# from the config file.
18
sub fetch_instances() {
19
        my @files = glob("/etc/memcached_*.conf");
20
        undef $/;
21
        for my $f (@files) {
22
                $f =~ m/.*memcached_(.*)\.conf/;
23
                my $instance_name = $1;
24

    
25
                open(CONF, $f);
26
                my $confdata = <CONF>;
27
                close(CONF);
28

    
29
                if ($confdata =~ m/-p ([0-9]+)/m) {
30
                    $instances{$instance_name}{'port'} = $1;
31
                }
32
        }
33
}
34

    
35
fetch_instances();
36

    
37
my $cmd = shift || '';
38

    
39
if ($cmd eq 'config') {
40
        print "graph_title Memcached bytes used for all instances\n";
41
        print "graph_args --base 1024 -l 0\n";
42
        print "graph_vlabel bytes\n";
43
        print "graph_category memory\n";
44
        print "graph_info This graph monitors the size of the memcached cache for every instance.\n";
45

    
46
        foreach my $instance_name (keys(%instances)) {
47
            my $pretty_name = $instance_name;
48
            $pretty_name =~ s/[^a-zA-Z0-9]/_/g;
49

    
50
            print "${pretty_name}_bytes.label $instance_name used\n";
51
            print "${pretty_name}_bytes.info Number of bytes currently used\n";
52
            print "${pretty_name}_bytes.min 0\n";
53
            print "${pretty_name}_bytes.draw LINE2\n";
54
            print "${pretty_name}_maxbytes.label $instance_name maximum\n";
55
            print "${pretty_name}_maxbytes.info The configured cache size\n";
56
            print "${pretty_name}_maxbytes.min 0\n";
57
        }
58

    
59
        exit 0;
60
}
61

    
62
foreach my $instance_name (keys(%instances)) {
63
    my $ip = "127.0.0.1";
64
    my $port = $instances{$instance_name}{'port'};
65
    my $pretty_name = $instance_name;
66
    $pretty_name =~ s/[^a-zA-Z0-9]/_/g;
67

    
68
    my $address = "$ip:$port";
69

    
70
    my $memd = new Cache::Memcached { 'servers' => [$address] };
71
    my $memstats = $memd->stats(['misc']);
72

    
73
    print "${pretty_name}_bytes.value " . $memstats->{hosts}->{$address}->{misc}->{bytes} . "\n";
74
    print "${pretty_name}_maxbytes.value " .
75
            $memstats->{hosts}->{$address}->{misc}->{limit_maxbytes} . "\n";
76
}