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

Improve plugins call to status and few other fixes

Signed-off-by: Pierre-Alain TORET <pierre-alain.toret@protonmail.com>
This commit is contained in:
Pierre-Alain TORET 2018-03-27 18:04:29 +02:00
parent c594a16484
commit e527db57a5
2 changed files with 44 additions and 29 deletions

View file

@ -1,4 +1,4 @@
#!/usr/bin/env sh #!/bin/sh
: <<=cut : <<=cut
=head1 NAME =head1 NAME
strelaysrv_ - Plugin to monitor Syncthing relay server strelaysrv_ - Plugin to monitor Syncthing relay server
@ -31,6 +31,10 @@ Pierre-Alain TORET <pierre-alain.toret@protonmail.com>
MIT MIT
=cut =cut
getstatus() {
"$CURL" -s "http://$syncthing_relaysrv_host:$syncthing_relaysrv_port/status"
}
num() { num() {
case $1 in case $1 in
config) config)
@ -45,15 +49,15 @@ strelaysrv_num_proxies.label proxies
EOM EOM
exit 0;; exit 0;;
*) *)
STATUS=$($CURL -s http://"$syncthing_relaysrv_host":"$syncthing_relaysrv_port"/status) STATUS=$(getstatus)
NS=$(echo "$STATUS" | $JQ '.numActiveSessions ') NS=$(echo "$STATUS" | $JQ '.numActiveSessions ')
NC=$(echo "$STATUS" | $JQ '.numConnections ') NC=$(echo "$STATUS" | $JQ '.numConnections ')
NK=$(echo "$STATUS" | $JQ '.numPendingSessionKeys ') NK=$(echo "$STATUS" | $JQ '.numPendingSessionKeys ')
NP=$(echo "$STATUS" | $JQ '.numProxies ') NP=$(echo "$STATUS" | $JQ '.numProxies ')
printf "strelaysrv_num_sessions.value %s\\n" "$NS" printf "strelaysrv_num_sessions.value %s\n" "$NS"
printf "strelaysrv_num_connections.value %s\\n" "$NC" printf "strelaysrv_num_connections.value %s\n" "$NC"
printf "strelaysrv_num_pending.value %s\\n" "$NK" printf "strelaysrv_num_pending.value %s\n" "$NK"
printf "strelaysrv_num_proxies.value %s\\n" "$NP" printf "strelaysrv_num_proxies.value %s\n" "$NP"
esac esac
} }
@ -68,8 +72,9 @@ strelaysrv_uptime.label uptime
EOM EOM
exit 0;; exit 0;;
*) *)
UPTIME=$($CURL -s http://"$syncthing_relaysrv_host":"$syncthing_relaysrv_port"/status | $JQ '.uptimeSeconds') STATUS=$(getstatus)
printf "strelaysrv_uptime.value %s\\n" "$UPTIME" UPTIME=$(echo "$STATUS" | "$JQ" '.uptimeSeconds')
printf "strelaysrv_uptime.value %s\n" "$UPTIME"
esac esac
} }
@ -84,8 +89,9 @@ strelaysrv_goroutine.label routines
EOM EOM
exit 0;; exit 0;;
*) *)
GOROUTINE=$($CURL -s http://"$syncthing_relaysrv_host":"$syncthing_relaysrv_port"/status | $JQ '.goNumRoutine') STATUS=$(getstatus)
printf "strelaysrv_goroutine.value %s\\n" "$GOROUTINE" GOROUTINE=$(echo "$STATUS" | "$JQ" '.goNumRoutine')
printf "strelaysrv_goroutine.value %s\n" "$GOROUTINE"
esac esac
} }
@ -102,8 +108,9 @@ strelaysrv_proxied.cdef strelaysrv_proxied,8,*
EOM EOM
exit 0;; exit 0;;
*) *)
BP=$($CURL -s http://"$syncthing_relaysrv_host":"$syncthing_relaysrv_port"/status | $JQ '.bytesProxied ') STATUS=$(getstatus)
printf "strelaysrv_proxied.value %s\\n" "$BP" BP=$(echo "$STATUS" | "$JQ" '.bytesProxied ')
printf "strelaysrv_proxied.value %s\n" "$BP"
esac esac
} }
@ -120,8 +127,9 @@ strelaysrv_transfer.cdef strelaysrv_transfer,1000,*
EOM EOM
exit 0;; exit 0;;
*) *)
TRANSFER=$($CURL -s http://"$syncthing_relaysrv_host":"$syncthing_relaysrv_port"/status | $JQ '.kbps10s1m5m15m30m60m[2] ') STATUS=$(getstatus)
printf "strelaysrv_transfer.value %s\\n" "$TRANSFER" TRANSFER=$(echo "$STATUS" | "$JQ" '.kbps10s1m5m15m30m60m[2] ')
printf "strelaysrv_transfer.value %s\n" "$TRANSFER"
esac esac
} }

View file

@ -1,4 +1,4 @@
#!/usr/bin/env sh #!/bin/sh
# -*- sh -*- # -*- sh -*-
: <<=cut : <<=cut
=head1 NAME =head1 NAME
@ -34,6 +34,10 @@ Pierre-Alain TORET <pierre-alain.toret@protonmail.com>
MIT MIT
=cut =cut
getstatus() {
"$CURL" -s -X GET -H "X-API-Key: $syncthing_apikey" "$syncthing_proto://$syncthing_host:$syncthing_port/rest/system/status"
}
cpu() { cpu() {
case $1 in case $1 in
config) config)
@ -46,8 +50,9 @@ syncthing_cpu.label cpu
EOM EOM
exit 0;; exit 0;;
*) *)
CPU=$($CURL -s -X GET -H "X-API-Key: $syncthing_apikey" "$syncthing_proto"://"$syncthing_host":"$syncthing_port"/rest/system/status | $JQ '.cpuPercent') STATUS=$(getstatus)
printf "syncthing_cpu.value %s\\n" "$CPU" CPU=$(echo "$STATUS" | "$JQ" '.cpuPercent')
printf "syncthing_cpu.value %s\n" "$CPU"
esac esac
} }
@ -67,11 +72,11 @@ syncthing_mem_sys.cdef syncthing_mem_sys,8,*
EOM EOM
exit 0;; exit 0;;
*) *)
STATUS=$($CURL -s -X GET -H "X-API-Key: $syncthing_apikey" "$syncthing_proto"://"$syncthing_host":"$syncthing_port"/rest/system/status) STATUS=$(getstatus)
ALL=$(echo "$STATUS" | $JQ '.alloc') ALL=$(echo "$STATUS" | "$JQ" '.alloc')
SYS=$(echo "$STATUS" | $JQ '.sys') SYS=$(echo "$STATUS" | "$JQ" '.sys')
printf "syncthing_mem_all.value %s\\n" "$ALL" printf "syncthing_mem_all.value %s\n" "$ALL"
printf "syncthing_mem_sys.value %s\\n" "$SYS" printf "syncthing_mem_sys.value %s\n" "$SYS"
esac esac
} }
@ -86,8 +91,9 @@ syncthing_uptime.label uptime
EOM EOM
exit 0;; exit 0;;
*) *)
UPTIME=$($CURL -s -X GET -H "X-API-Key: $syncthing_apikey" "$syncthing_proto"://"$syncthing_host":"$syncthing_port"/rest/system/status | $JQ '.uptime') STATUS=$(getstatus)
printf "syncthing_uptime.value %s\\n" "$UPTIME" UPTIME=$(echo "$STATUS" | "$JQ" '.uptime')
printf "syncthing_uptime.value %s\n" "$UPTIME"
esac esac
} }
@ -102,8 +108,9 @@ syncthing_goroutine.label routines
EOM EOM
exit 0;; exit 0;;
*) *)
GOROUTINES=$($CURL -s -X GET -H "X-API-Key: $syncthing_apikey" "$syncthing_proto"://"$syncthing_host":"$syncthing_port"/rest/system/status | $JQ '.goroutines') STATUS=$(getstatus)
printf "syncthing_goroutine.value %s\\n" "$GOROUTINES" GOROUTINES=$(echo "$STATUS" | "$JQ" '.goroutines')
printf "syncthing_goroutine.value %s\n" "$GOROUTINES"
esac esac
} }
@ -127,9 +134,9 @@ syncthing_transfer_up.cdef syncthing_transfer_up,8,*
EOM EOM
exit 0;; exit 0;;
*) *)
CONNECTIONS=$($CURL -s -X GET -H "X-API-Key: $syncthing_apikey" "$syncthing_proto"://"$syncthing_host":"$syncthing_port"/rest/system/connections) CONNECTIONS=$("$CURL" -s -X GET -H "X-API-Key: $syncthing_apikey" "$syncthing_proto://$syncthing_host:$syncthing_port/rest/system/connections")
IBT=$(echo "$CONNECTIONS" | $JQ '.total | .inBytesTotal') IBT=$(echo "$CONNECTIONS" | "$JQ" '.total | .inBytesTotal')
OBT=$(echo "$CONNECTIONS" | $JQ '.total | .outBytesTotal') OBT=$(echo "$CONNECTIONS" | "$JQ" '.total | .outBytesTotal')
printf "syncthing_transfer_up.value %s\\n" "$IBT" printf "syncthing_transfer_up.value %s\\n" "$IBT"
printf "syncthing_transfer_down.value %s\\n" "$OBT" printf "syncthing_transfer_down.value %s\\n" "$OBT"
esac esac