Projet

Général

Profil

Révision 5a489679

ID5a489679c70fe6265d49b6c8fdd32fcc429e37d9
Parent d81a0f06
Enfant 567d6d9e

Ajouté par raszi il y a presque 14 ans

used keys and expires

Voir les différences:

plugins/other/redis
38 38

  
39 39
my $server = "$HOST:$PORT";
40 40
my $sock = IO::Socket::INET->new(
41
	PeerAddr => $server,
42
	Proto => 'tcp'
41
    PeerAddr => $server,
42
    Proto => 'tcp'
43 43
);
44 44

  
45 45
print $sock "INFO\r\n";
......
50 50

  
51 51
my $hash;
52 52
foreach (split(/\r\n/, $rep)) {
53
  my ($key,$val) = split(/:/, $_, 2);
54
  $hash->{$key} = $val;
53
    my ($key,$val) = split(/:/, $_, 2);
54
    $hash->{$key} = $val;
55 55
}
56 56
close ($sock);
57 57

  
58
my $config = ( defined $ARGV[0] and $ARGV[0] eq "config" );
59

  
58 60

  
59 61
$0 =~ s/(.+)redis_//g;
60 62

  
61 63
switch ($0) {
62 64
    case "connected_clients" {
63
	if ( defined $ARGV[0] and $ARGV[0] eq "config" ) {
65
        if ( $config ) {
64 66
            print "graph_title Connected clients\n";
65 67
            print "graph_vlabel Connected clients\n";
66 68
            print "connected_clients.label connected clients\n";
67 69
            print "graph_category redis\n";
68 70
            exit 0;
69
	}
70
	print "connected_clients.value " . $hash->{'connected_clients'} . "\n";
71
        }
72

  
73
        print "connected_clients.value " . $hash->{'connected_clients'} . "\n";
71 74
    }
72 75

  
73 76

  
74 77
    case "per_sec" {
75
	if ( defined $ARGV[0] and $ARGV[0] eq "config" ) {
78
        if ( $config ) {
76 79
            print "graph_title Per second\n";
77 80
            print "graph_vlabel per \${graph_period}\n";
78 81
            print "graph_category redis\n";
......
81 84
            print "connections.label connections\n";
82 85
            print "connections.type COUNTER\n";
83 86
            exit 0;
84
	}
85
	print "requests.value ". $hash->{'total_commands_processed'} ."\n";
86
	print "connections.value ". $hash->{'total_connections_received'} ."\n";
87
        }
88

  
89
        print "requests.value ". $hash->{'total_commands_processed'} ."\n";
90
        print "connections.value ". $hash->{'total_connections_received'} ."\n";
87 91
    }
88 92

  
89 93

  
90 94
    case "used_memory" {
91
	if ( defined $ARGV[0] and $ARGV[0] eq "config" ) {
95
        if ( $config ) {
92 96
            print "graph_title Used memory\n";
93 97
            print "graph_vlabel Used memory\n";
94 98
            print "used_memory.label used memory\n";
95 99
            print "graph_category redis\n";
96 100
            exit 0;
97
	}
98
	print "used_memory.value ". $hash->{'used_memory'}  ."\n";
101
        }
102

  
103
        print "used_memory.value ". $hash->{'used_memory'}  ."\n";
104
    }
105
    
106
    case "used_keys" {
107
        my $dbs;
108
        foreach my $key (keys %{$hash}) {
109
            if ( $key =~ /^db\d+$/ && $hash->{$key} =~ /keys=(\d+),expires=(\d+)/ ) {
110
                $dbs->{$key} = [ $1, $2 ];
111
            }
112
        }
113

  
114
        if ( $config ) {
115
            print "graph_title Used keys\n";
116
            print "graph_vlabel Used keys\n";
117
            print "graph_category redis\n";
118

  
119
            foreach my $db (keys %{$dbs}) {
120
                printf "%s_keys.label %s keys\n", $db, $db;
121
                printf "%s_expires.label %s expires\n", $db, $db;
122
            }
123

  
124
            exit 0;
125
        }
126

  
127
        foreach my $db (keys %{$dbs}) {
128
            printf "%s_keys.value %d\n", $db, $dbs->{$db}[0];
129
            printf "%s_expires.value %d\n", $db, $dbs->{$db}[1];
130
        }
99 131
    }
100 132
}
133

  
134
# vim: ft=perl ai ts=4 sw=4 et:

Formats disponibles : Unified diff