From 109961ac84cba83826ccc1834e29e58f946ef90b Mon Sep 17 00:00:00 2001 From: Anton Lundin Date: Tue, 27 Feb 2024 12:52:14 +0100 Subject: [PATCH] Add a plain bash version of memcached helper This is for servers which don't have php installed. --- snmp/memcached.sh | 49 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100755 snmp/memcached.sh diff --git a/snmp/memcached.sh b/snmp/memcached.sh new file mode 100755 index 000000000..627a2f730 --- /dev/null +++ b/snmp/memcached.sh @@ -0,0 +1,49 @@ +#!/bin/bash + +declare -A stats + +exec 200<>/dev/tcp/localhost/11211 +echo "stats" >&200 +echo "quit" >&200 + +while read -r pre var val ; do + if [ "$pre" = "END" ] ; then + break + elif [ "$pre" = "STAT" ] ; then + val="${val/$'\r'/}" + if [ "$var" = "rusage_system" ] || [ "$var" = "rusage_user" ] ; then + val=$(bc -l <<< "scale=0 ; ($val * 1000)/1") + var+="_microseconds" + fi + stats["$var"]=$val + fi +done <&200 + +exec 200>&- + +cat </dev/null ; then + #echo -nE "s:${#var}:\"$var\";i:$val;" + echo "\"$var\": $val," + else + #echo -nE "s:${#var}:\"$var\";s:${#val}:\"$val\";" + echo "\"$var\": \"$val\"," + fi +done +echo '"dummy":"value"' + +cat <