Difference between revisions of "Plugin:exec-redis.sh"

From collectd Wiki
Jump to: navigation, search
(Added <source /> tags.)
(Update for the new Github template.)
 
(8 intermediate revisions by 2 users not shown)
Line 1: Line 1:
[http://code.google.com/p/redis/ Redis] is a high-perf NoSQL data structure server with persistent storage.
+
{{Infobox Plugin
 +
  | Name=exec-redis.sh
 +
  | Type=read
 +
  | Callbacks=''n/a''
 +
  | Status=external
 +
  | FirstVersion=''n/a''
 +
  | Copyright=''2010'' [[User:Astro|Astro]]
 +
  | License=''unknown''
 +
  | Manpage=''n/a''
 +
}}
 +
The '''exec-redis.sh plugin''' reads statistics from ''Redis'', a high-performance NoSQL data structure server with persistent storage.
  
 
== Code ==
 
== Code ==
Line 5: Line 15:
  
 
<source lang="bash">
 
<source lang="bash">
#!/bin/bash
+
#!/bin/bash
+
 
HOSTNAME=`hostname -f`
+
HOSTNAME="${COLLECTD_HOSTNAME:-`hostname -f`}"
PORT=6379
+
INTERVAL="${COLLECTD_INTERVAL:-10}"
INTERVAL=10
+
PORT=6379
+
 
while true; do
+
while sleep "$INTERVAL"
+
do
info=$(echo info|nc -w 1 127.0.0.1 $PORT)
+
 
connected_clients=$(echo "$info"|awk -F : '$1 == "connected_clients" {print $2}')
+
info=$(echo info|nc -w 1 127.0.0.1 $PORT)
connected_slaves=$(echo "$info"|awk -F : '$1 == "connected_slaves" {print $2}')
+
connected_clients=$(echo "$info"|awk -F : '$1 == "connected_clients" {print $2}')
uptime=$(echo "$info"|awk -F : '$1 == "uptime_in_seconds" {print $2}')
+
connected_slaves=$(echo "$info"|awk -F : '$1 == "connected_slaves" {print $2}')
used_memory=$(echo "$info"|awk -F ":" '$1 == "used_memory" {print $2}'|sed -e 's/\r//')
+
uptime=$(echo "$info"|awk -F : '$1 == "uptime_in_seconds" {print $2}')
changes_since_last_save=$(echo "$info"|awk -F : '$1 == "changes_since_last_save" {print $2}')
+
used_memory=$(echo "$info"|awk -F ":" '$1 == "used_memory" {print $2}'|sed -e 's/\r//')
total_commands_processed=$(echo "$info"|awk -F : '$1 == "total_commands_processed" {print $2}')
+
changes_since_last_save=$(echo "$info"|awk -F : '$1 == "changes_since_last_save" {print $2}')
keys=$(echo "$info"|egrep -e "^db0"|sed -e 's/^.\+:keys=//'|sed -e 's/,.\+//')
+
total_commands_processed=$(echo "$info"|awk -F : '$1 == "total_commands_processed" {print $2}')
+
keys=$(echo "$info"|egrep -e "^db0"|sed -e 's/^.\+:keys=//'|sed -e 's/,.\+//')
echo "PUTVAL $HOSTNAME/redis-$PORT/memcached_connections-clients interval=$INTERVAL N:$connected_clients"
+
 
echo "PUTVAL $HOSTNAME/redis-$PORT/memcached_connections-slaves interval=$INTERVAL N:$connected_slaves"
+
echo "PUTVAL $HOSTNAME/redis-$PORT/memcached_connections-clients interval=$INTERVAL N:$connected_clients"
echo "PUTVAL $HOSTNAME/redis-$PORT/uptime interval=$INTERVAL N:$uptime"
+
echo "PUTVAL $HOSTNAME/redis-$PORT/memcached_connections-slaves interval=$INTERVAL N:$connected_slaves"
echo "PUTVAL $HOSTNAME/redis-$PORT/df-memory interval=$INTERVAL N:$used_memory:U"
+
echo "PUTVAL $HOSTNAME/redis-$PORT/uptime interval=$INTERVAL N:$uptime"
echo "PUTVAL $HOSTNAME/redis-$PORT/files-unsaved_changes interval=$INTERVAL N:$changes_since_last_save"
+
echo "PUTVAL $HOSTNAME/redis-$PORT/df-memory interval=$INTERVAL N:$used_memory:U"
echo "PUTVAL $HOSTNAME/redis-$PORT/memcached_command-total interval=$INTERVAL N:$total_commands_processed"
+
echo "PUTVAL $HOSTNAME/redis-$PORT/files-unsaved_changes interval=$INTERVAL N:$changes_since_last_save"
echo "PUTVAL $HOSTNAME/redis-$PORT/memcached_items-db0 interval=$INTERVAL N:$keys"
+
echo "PUTVAL $HOSTNAME/redis-$PORT/memcached_command-total interval=$INTERVAL N:$total_commands_processed"
+
echo "PUTVAL $HOSTNAME/redis-$PORT/memcached_items-db0 interval=$INTERVAL N:$keys"
sleep $INTERVAL
+
 
done
+
done
 
</source>
 
</source>
  
Configure the exec plugin:
+
== Configuration ==
 +
 
 +
Configure the {{Plugin|Exec}}:
 
  <Plugin exec>
 
  <Plugin exec>
 
  Exec nobody "/etc/collectd/redis.sh"
 
  Exec nobody "/etc/collectd/redis.sh"
Line 42: Line 54:
  
 
[[File:Plugin-exec-redis-commands.png]]
 
[[File:Plugin-exec-redis-commands.png]]
 +
 +
== Dependencies ==
 +
 +
* ''nc(1)'' (netcat)
 +
* ''awk(1)''
 +
 +
== See also ==
 +
 +
* http://code.google.com/p/redis/<br />Homepage of ''Redis''
 +
* {{Plugin|Python}} based implementation at {{Github | user=powdahound | repository=redis-collectd-plugin}}.
 +
* C-based implementation at [[Plugin:Redis]].
 +
 +
[[Category:Exec Plugins]]
 +
{{DEFAULTSORT:Exec-munin.px}}

Latest revision as of 11:04, 27 November 2010

exec-redis.sh plugin
Type: read
Callbacks: n/a
Status: external
First version: n/a
Copyright: 2010 Astro
License: unknown
Manpage: n/a
List of Plugins

The exec-redis.sh plugin reads statistics from Redis, a high-performance NoSQL data structure server with persistent storage.

Code

Create /etc/collectd/redis.sh and make it executable:

#!/bin/bash

HOSTNAME="${COLLECTD_HOSTNAME:-`hostname -f`}"
INTERVAL="${COLLECTD_INTERVAL:-10}"
PORT=6379

while sleep "$INTERVAL"
do

info=$(echo info|nc -w 1 127.0.0.1 $PORT)
connected_clients=$(echo "$info"|awk -F : '$1 == "connected_clients" {print $2}')
connected_slaves=$(echo "$info"|awk -F : '$1 == "connected_slaves" {print $2}')
uptime=$(echo "$info"|awk -F : '$1 == "uptime_in_seconds" {print $2}')
used_memory=$(echo "$info"|awk -F ":" '$1 == "used_memory" {print $2}'|sed -e 's/\r//')
changes_since_last_save=$(echo "$info"|awk -F : '$1 == "changes_since_last_save" {print $2}')
total_commands_processed=$(echo "$info"|awk -F : '$1 == "total_commands_processed" {print $2}')
keys=$(echo "$info"|egrep -e "^db0"|sed -e 's/^.\+:keys=//'|sed -e 's/,.\+//')

echo "PUTVAL $HOSTNAME/redis-$PORT/memcached_connections-clients interval=$INTERVAL N:$connected_clients"
echo "PUTVAL $HOSTNAME/redis-$PORT/memcached_connections-slaves interval=$INTERVAL N:$connected_slaves"
echo "PUTVAL $HOSTNAME/redis-$PORT/uptime interval=$INTERVAL N:$uptime"
echo "PUTVAL $HOSTNAME/redis-$PORT/df-memory interval=$INTERVAL N:$used_memory:U"
echo "PUTVAL $HOSTNAME/redis-$PORT/files-unsaved_changes interval=$INTERVAL N:$changes_since_last_save"
echo "PUTVAL $HOSTNAME/redis-$PORT/memcached_command-total interval=$INTERVAL N:$total_commands_processed"
echo "PUTVAL $HOSTNAME/redis-$PORT/memcached_items-db0 interval=$INTERVAL N:$keys"

done

Configuration

Configure the Exec plugin:

<Plugin exec>
	Exec nobody "/etc/collectd/redis.sh"
</Plugin>

Example graph

Plugin-exec-redis-commands.png

Dependencies

  • nc(1) (netcat)
  • awk(1)

See also