Projet

Général

Profil

Révision 3e56b658

ID3e56b6589b33d2953af7a1704e6a549c2e476165
Parent 84866ca6
Enfant fe49d512

Ajouté par Rafał Trójniak il y a presque 12 ans

Refactoring of fetching procedures, information about the limits, more memory statistics

Voir les différences:

plugins/redis/redis_
67 67
    }
68 68
}
69 69

  
70
print $sock "INFO\r\n";
71
my $result = <$sock> || die "can't read socket: $!";
72

  
73
my $rep;
74
read($sock, $rep, substr($result,1)) || die "can't read from socket: $!";
75

  
76
my $hash;
77
foreach (split(/\r\n/, $rep)) {
78
    my ($key,$val) = split(/:/, $_, 2);
79
    if (defined($key)) {
80
        $hash->{$key} = $val;
81
    }
82
}
83
close ($sock);
70
my $hash=&get_info();
84 71

  
85 72
$0 =~ s/(.+)redis_//g;
86 73

  
87 74
switch ($0) {
88 75
    case "connected_clients" {
89 76
        if ( $config ) {
77
            my $maxclients= get_config("maxclients")->{"maxclients"};
90 78
            print "graph_title Connected clients\n";
91 79
            print "graph_vlabel Connected clients\n";
92 80
            print "graph_category redis\n";
93 81
            print "graph_args -l 0\n";
82
            print "connected_clients.line $maxclients:ff0000:Limit\n";
94 83
            print "connected_clients.label connected clients\n";
95 84
            exit 0;
96 85
        }
......
169 158

  
170 159
    case "used_memory" {
171 160
        if ( $config ) {
161
            my $maxmemory = get_config("maxmemory")->{"maxmemory"};
172 162
            print "graph_title Used memory\n";
173 163
            print "graph_vlabel Used memory\n";
174 164
            print "graph_category redis\n";
175 165
            print "graph_args -l 0 --base 1024\n";
166
            print "used_memory.line $maxmemory:ff0000:Limit\n";
176 167
            print "used_memory.label used memory\n";
177
            print "used_memory.draw AREA\n";
168
            print "used_memory_peak.label used memory in peak\n";
169
            print "used_memory_rss.label Resident set size memory usage\n";
178 170
            exit 0;
179 171
        }
180 172

  
181 173
        print "used_memory.value ". $hash->{'used_memory'}  ."\n";
174
        print "used_memory_rss.value ". $hash->{'used_memory_rss'}  ."\n";
175
        print "used_memory_peak.value ". $hash->{'used_memory_peak'}  ."\n";
182 176
    }
183 177
    
184 178
    case "used_keys" {
......
210 204
    }
211 205
}
212 206

  
207
close ($sock);
208

  
213 209
sub get_conn {
214 210
    my $sock = IO::Socket::INET->new(
215 211
        PeerAddr => $HOST,
......
224 220
    return $sock;
225 221
}
226 222

  
223
sub get_info{
224
    print $sock "INFO\r\n";
225
    my $result = <$sock> || die "can't read socket: $!";
226

  
227
    my $rep;
228
    # +2 characters for \r\n at end of the data block
229
    read($sock, $rep, substr($result,1)+2) || die "can't read from socket: $!";
230

  
231
    my $hash;
232
    foreach (split(/\r\n/, substr($rep, 0, -2))) {
233
        my ($key,$val) = split(/:/, $_, 2);
234
        if (defined($key)) {
235
            $hash->{$key} = $val;
236
        }
237
    }
238
    return $hash;
239
}
240

  
241
# This subroutine returns configuration matched to supplied as object
242
sub get_config{
243

  
244
    print $sock "*3\r\n\$6\r\nCONFIG\r\n\$3\r\nGET\r\n\$".length($_[0])."\r\n".$_[0]."\r\n";
245
    # Response will look like like
246
    # *2\r\n$9\r\nmaxmemory\r\n$10\r\n3221225472\r\n
247

  
248
    my $type = <$sock> || die "can't read socket: $!";
249

  
250
    my $conf;
251
    if( substr($type,0,1) ne "*" ) {
252
        return $conf;
253
    }
254

  
255
    my $count=substr($type,1);
256

  
257
    my ( $namesize, $name, $valuesize, $value );
258
    while ( $count > 1 ){
259
        $count=$count-2;
260

  
261
        $namesize=<$sock>;
262
        read($sock, $name, substr($namesize,1)+2) || die "can't read from socket: $!";
263

  
264
        $valuesize=<$sock>;
265
        read($sock, $value, substr($valuesize,1)+2) || die "can't read from socket: $!";
266

  
267
        $conf->{substr($name, 0, -2)}=substr($value, 0, -2);
268
    }
269

  
270
    return $conf;
271
}
272

  
227 273
# vim: ft=perl ai ts=4 sw=4 et:

Formats disponibles : Unified diff