forked from bpineau/redis-munin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
redis_
executable file
·290 lines (249 loc) · 8.56 KB
/
redis_
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
#!/bin/bash
#
# The following code is released in public domain (where applicable).
# http://creativecommons.org/publicdomain/zero/1.0/
#%# family=auto
#%# capabilities=autoconf suggest
ip_socket=$(echo $0 | awk -F_ '{ print $2 }')
if [ $ip_socket = "socket" ]; then
tmp_var=$(echo $0 | awk -F_ '{ s = ""; for (i = 3; i <= NF; i++) s = s $i "/"; print s }')
port_path=$(echo "/${tmp_var}" | sed 's,/$,,')
else
port_path=$(echo $0 | awk -F_ '{ print $3 }')
fi
if [ "$ip_socket" = "socket" ]; then
ip_socket="-s";
else
if [ -z $ip_socket ] ; then
ip_socket="-h 127.0.0.1"
else
ip_socket="-h $ip_socket"
fi
fi
if [ -z "$port_path" ]; then
port_path="-p 6379"
elif [ "$ip_socket" = "-s" ]; then
port_path="$port_path"
else
port_path="-p $port_path"
fi
# add the ability to set a password in a respective config file
if [ -z "$password" ]; then
passwd='' # no password was configured
else
passwd="-a $password"
fi
if [ "$1" = "autoconf" ]; then
redis-cli $ip_socket $port_path $passwd info >/dev/null 2>&1 && echo yes && exit 0
echo no
exit 0
fi
if [ "$1" = "suggest" ]; then
redis-cli $ip_socket $port_path $passwd info >/dev/null 2>&1 && echo ${ip_socket}_${port_path}
exit 0
fi
if [ "$ip_socket" = "-s" ]; then
tmp_muninport=$(echo "$port_path" | tr '/' '_')
muninport=$(echo "${tmp_muninport:1}" | tr '.' '_')
else
muninport=$(echo "$port_path" | awk '{ print $2 }')
fi
if [ "$1" = "config" ]; then
# Expose all possibles graphes according to server's capabilities
redis-cli $ip_socket $port_path $passwd info | awk -v port=${muninport} -F: '
/^changes_since_last_save:|^rdb_changes_since_last_save:/ {
print "multigraph redis_changes_since_last_save_"port;
print "graph_title Redis changes since last save Port: "port ;
print "graph_info Number of write operations since last SAVE or BGSAVE";
print "graph_category redis";
print "changes.label changes";
};
/^keyspace_hits:/ {
print "multigraph redis_commands_"port;
print "graph_order commands hits misses";
print "graph_title Redis commands rate Port: "port;
print "graph_category redis";
print "graph_vlabel commands/s";
print "graph_info Redis commands per second";
print "commands.label commands/s";
print "commands.type COUNTER";
print "commands.min 0";
print "hits.label key hits";
print "hits.type COUNTER";
print "hits.min 0";
print "misses.label key misses";
print "misses.type COUNTER";
print "misses.min 0";
};
/^total_connections_received:/ {
print "multigraph redis_total_connections_"port;
print "graph_title Redis connections rate Port: "port;
print "graph_category redis";
print "graph_vlabel connections/s";
print "graph_info Connections per second to the Redis server";
print "connections.label connections";
print "connections.info connections per second";
print "connections.type COUNTER";
print "connections.min 0";
};
/^used_memory:/ {
print "multigraph redis_memory_"port;
print "graph_title Redis memory usage "port;
print "graph_category redis";
print "graph_vlabel mem used";
print "graph_info Memory allocated by Redis";
print "graph_args --base 1024 -l 0";
print "memory.label memory";
print "memory.info Amount of mem used by Redis";
print "memory.type GAUGE";
print "memory.min 0";
};
/^connected_clients:/ {
print "multigraph redis_clients_"port;
print "graph_title Redis connected clients port: "port;
print "graph_category redis";
print "graph_vlabel clients";
print "graph_info Number of currently connected clients";
print "clients.label clients";
print "clients.type GAUGE";
print "clients.min 0";
};
/^mem_fragmentation_ratio:/ {
print "multigraph redis_fragmentation_"port;
print "graph_title Redis memory fragmentation Port: "port;
print "graph_category redis";
print "graph_vlabel fragmentation ratio";
print "graph_info Ratio between Redis RSS usage and allocated memory";
print "frag.label fragmentation ratio";
print "frag.type GAUGE";
print "frag.min 0";
};
/^expired_keys:/ {
print "multigraph redis_expired_keys_"port;
print "graph_title Redis expired keys rate Port: "port;
print "graph_category redis";
print "graph_vlabel expired keys/s";
print "graph_info Expired Redis keys per second";
print "expired.label expired keys";
print "expired.info expired keys per second";
print "expired.type COUNTER";
print "expired.min 0";
};
/^evicted_keys:/ {
print "multigraph redis_evicted_keys_"port;
print "graph_title Redis evicted keys rate Port: "port;
print "graph_category redis";
print "graph_vlabel evicted keys/s";
print "graph_info Evicted Redis keys per second";
print "evicted.label evicted keys";
print "evicted.info evicted keys per second";
print "evicted.type COUNTER";
print "evicted.min 0";
};
/^pubsub_channels:/ {
print "multigraph redis_pubsub_channels_"port;
print "graph_title Redis pubsub channels Port: "port;
print "graph_category redis";
print "graph_vlabel channels";
print "graph_info Number of pubsub channels";
print "channels.label channels";
print "channels.type GAUGE";
print "channels.min 0";
};
/^blocked_clients:/ {
print "multigraph redis_blocked_clients_"port;
print "graph_title Redis blocked clients Port: "port;
print "graph_category redis";
print "graph_vlabel clients";
print "graph_info Number of blocked clients";
print "blocked.label clients";
print "blocked.type GAUGE";
print "blocked.min 0";
print "blocked.warning 1";
};
/^db/ {
split($2, where, "=|,");
dbskeys[$1] = where[2];
dbsexpires[$1] = where[4];
};
END {
print "multigraph redis_dbs_"port;
print "graph_title Redis dbs Port: "port;
print "graph_category redis";
print "graph_vlabel keys";
print "graph_info Number of keys per dbs";
for (i in dbskeys)
print i "keys.label " i " keys"
print i "keys.type GAUGE"
print i "keys.min 0"
for (i in dbsexpires)
print i "expires.label " i " keys with TTL"
print i "expires.type GAUGE"
print i "expires.min 0";
};
'
exit $?
fi
redis-cli $ip_socket $port_path $passwd info | awk -v port=${muninport} -F: '
/^changes_since_last_save:|^rdb_changes_since_last_save:/ {
print "multigraph redis_changes_since_last_save_"port;
print "changes.value " $2 ;
};
/^total_connections_received:/ {
print "multigraph redis_total_connections_"port;
print "connections.value " $2 ;
};
/^used_memory:/ {
print "multigraph redis_memory_"port;
print "memory.value " $2 ;
};
/^connected_clients:/ {
print "multigraph redis_clients_"port;
print "clients.value " $2 ;
};
/^mem_fragmentation_ratio:/ {
print "multigraph redis_fragmentation_"port;
print "frag.value " $2 ;
};
/^expired_keys:/ {
print "multigraph redis_expired_keys_"port;
print "expired.value " $2 ;
};
/^evicted_keys:/ {
print "multigraph redis_evicted_keys_"port;
print "evicted.value " $2 ;
};
/^pubsub_channels:/ {
print "multigraph redis_pubsub_channels_"port;
print "channels.value " $2 ;
};
/^blocked_clients:/ {
print "multigraph redis_blocked_clients_"port;
print "blocked.value " $2 ;
};
/^total_commands_processed:/ {
commands=$2
};
/^keyspace_hits:/ {
hits=$2
};
/^keyspace_misses:/ {
misses=$2
};
/^db/ {
split($2, where, "=|,");
dbskeys[$1] = where[2];
dbsexpires[$1] = where[4];
};
END {
print "multigraph redis_commands_"port;
print "commands.value " commands;
print "hits.value " hits;
print "misses.value " misses;
print "multigraph redis_dbs_"port;
for (i in dbskeys)
print i "keys.value " dbskeys[i];
for (i in dbsexpires)
print i "expires.value " dbsexpires[i];
};
'