Skip to content

Commit

Permalink
Merge pull request #509 from glance-/bash-memcached
Browse files Browse the repository at this point in the history
Add a plain bash version of memcached helper
  • Loading branch information
VVelox authored Mar 13, 2024
2 parents 9645624 + 109961a commit ceef8c4
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions snmp/memcached.sh
Original file line number Diff line number Diff line change
@@ -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 <<EOD
{
"data": {
"localhost:11211": {
EOD

for var in "${!stats[@]}" ; do
val=${stats["$var"]}
if [ "$val" -eq "$val" ] 2>/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 <<EOD
}
},
"error": 0,
"errorString": "SUCCESS",
"version": "1.1"
}
EOD

0 comments on commit ceef8c4

Please sign in to comment.