2
0
mirror of https://github.com/munin-monitoring/contrib.git synced 2018-11-08 00:59:34 +01:00

Make syncthing_ more portable

Signed-off-by: Pierre-Alain TORET <pierre-alain.toret@protonmail.com>
This commit is contained in:
Pierre-Alain TORET 2017-12-13 19:46:47 +01:00
parent 6ee4fc8d30
commit 99123efbb8

View File

@ -1,4 +1,4 @@
#!/bin/sh #!/usr/bin/env bash
# -*- sh -*- # -*- sh -*-
: <<=cut : <<=cut
=head1 NAME =head1 NAME
@ -8,6 +8,7 @@ syncthing_ - Plugin to monitor Syncthing server
This plugin gathers metrics from a Syncthing server. This plugin gathers metrics from a Syncthing server.
This plugin requires the jq utility : https://stedolan.github.io/jq/ This plugin requires the jq utility : https://stedolan.github.io/jq/
This plugin requires the cURL utility : https://curl.haxx.se/
Available plugins : Available plugins :
syncthing_cpu # syncthing_cpu #
@ -46,7 +47,7 @@ EOM
exit 0;; exit 0;;
*) *)
printf "syncthing_cpu.value " printf "syncthing_cpu.value "
curl -s -X GET -H "X-API-Key: $ST_APIKEY" $ST_PROTO://$ST_HOST:$ST_PORT/rest/system/status | jq '.cpuPercent' $CURL -s -X GET -H "X-API-Key: $ST_APIKEY" $ST_PROTO://$ST_HOST:$ST_PORT/rest/system/status | $JQ '.cpuPercent'
esac esac
} }
@ -66,8 +67,8 @@ syncthing_mem_sys.cdef syncthing_mem_sys,8,*
EOM EOM
exit 0;; exit 0;;
*) *)
ALL=$(curl -s -X GET -H "X-API-Key: $ST_APIKEY" $ST_PROTO://$ST_HOST:$ST_PORT/rest/system/status | jq '.alloc') ALL=$($CURL -s -X GET -H "X-API-Key: $ST_APIKEY" $ST_PROTO://$ST_HOST:$ST_PORT/rest/system/status | $JQ '.alloc')
SYS=$(curl -s -X GET -H "X-API-Key: $ST_APIKEY" $ST_PROTO://$ST_HOST:$ST_PORT/rest/system/status | jq '.sys') SYS=$($CURL -s -X GET -H "X-API-Key: $ST_APIKEY" $ST_PROTO://$ST_HOST:$ST_PORT/rest/system/status | $JQ '.sys')
printf "syncthing_mem_all.value $ALL\nsyncthing_mem_sys.value $SYS\n" printf "syncthing_mem_all.value $ALL\nsyncthing_mem_sys.value $SYS\n"
esac esac
} }
@ -84,7 +85,7 @@ EOM
exit 0;; exit 0;;
*) *)
printf "syncthing_uptime.value " printf "syncthing_uptime.value "
curl -s -X GET -H "X-API-Key: $ST_APIKEY" $ST_PROTO://$ST_HOST:$ST_PORT/rest/system/status | jq '.uptime' $CURL -s -X GET -H "X-API-Key: $ST_APIKEY" $ST_PROTO://$ST_HOST:$ST_PORT/rest/system/status | $JQ '.uptime'
esac esac
} }
@ -100,7 +101,7 @@ EOM
exit 0;; exit 0;;
*) *)
printf "syncthing_goroutine.value " printf "syncthing_goroutine.value "
curl -s -X GET -H "X-API-Key: $ST_APIKEY" $ST_PROTO://$ST_HOST:$ST_PORT/rest/system/status | jq '.goroutines' $CURL -s -X GET -H "X-API-Key: $ST_APIKEY" $ST_PROTO://$ST_HOST:$ST_PORT/rest/system/status | $JQ '.goroutines'
esac esac
} }
@ -124,14 +125,17 @@ syncthing_transfer_up.cdef syncthing_transfer_up,8,*
EOM EOM
exit 0;; exit 0;;
*) *)
IBT=$(curl -s -X GET -H "X-API-Key: $ST_APIKEY" $ST_PROTO://$ST_HOST:$ST_PORT/rest/system/connections | jq '.total | .inBytesTotal') IBT=$($CURL -s -X GET -H "X-API-Key: $ST_APIKEY" $ST_PROTO://$ST_HOST:$ST_PORT/rest/system/connections | $JQ '.total | .inBytesTotal')
OBT=$(curl -s -X GET -H "X-API-Key: $ST_APIKEY" $ST_PROTO://$ST_HOST:$ST_PORT/rest/system/connections | jq '.total | .outBytesTotal') OBT=$($CURL -s -X GET -H "X-API-Key: $ST_APIKEY" $ST_PROTO://$ST_HOST:$ST_PORT/rest/system/connections | $JQ '.total | .outBytesTotal')
printf "syncthing_transfer_up.value $IBT\nsyncthing_transfer_down.value $OBT\n" printf "syncthing_transfer_up.value $IBT\nsyncthing_transfer_down.value $OBT\n"
esac esac
} }
cd $(dirname $0) cd $(dirname $0)
CURL=$(which curl)
JQ=$(which jq)
case $(basename $0) in case $(basename $0) in
syncthing_cpu) syncthing_cpu)
cpu $1 cpu $1