2018-03-24 20:23:40 +01:00
|
|
|
#!/usr/bin/env sh
|
2018-03-24 19:55:12 +01:00
|
|
|
: <<=cut
|
|
|
|
=head1 NAME
|
|
|
|
strelaysrv_ - Plugin to monitor Syncthing relay server
|
|
|
|
|
|
|
|
=head1 DESCRIPTION
|
|
|
|
This plugin gathers metrics from a Syncthing relay server.
|
|
|
|
|
|
|
|
This plugin requires the jq utility : https://stedolan.github.io/jq/
|
|
|
|
This plugin requires the curl utility : https://curl.haxx.se/
|
|
|
|
|
|
|
|
Available plugins :
|
|
|
|
strelaysrv_goroutine #
|
|
|
|
strelaysrv_num #
|
|
|
|
strelaysrv_proxied #
|
|
|
|
strelaysrv_transfer #
|
|
|
|
strelaysrv_uptime #
|
|
|
|
|
|
|
|
=head1 CONFIGURATION
|
|
|
|
To make the plugin connect to the Syncthing relay server one has to use this type of
|
|
|
|
configuration
|
|
|
|
[strelaysrv_*]
|
|
|
|
|
2018-03-24 19:56:32 +01:00
|
|
|
env.syncthing_relaysrv_host 127.0.0.1
|
|
|
|
env.syncthing_relaysrv_port 22070
|
2018-03-24 19:55:12 +01:00
|
|
|
|
|
|
|
=head1 AUTHOR
|
|
|
|
Pierre-Alain TORET <pierre-alain.toret@protonmail.com>
|
|
|
|
|
|
|
|
=head1 LICENSE
|
|
|
|
MIT
|
|
|
|
=cut
|
|
|
|
|
2018-03-24 20:23:40 +01:00
|
|
|
num() {
|
2018-03-24 19:55:12 +01:00
|
|
|
case $1 in
|
2018-03-24 20:23:40 +01:00
|
|
|
config)
|
2018-03-24 19:55:12 +01:00
|
|
|
cat <<'EOM'
|
|
|
|
graph_title Syncthing relay numbers
|
|
|
|
graph_category network
|
|
|
|
graph_vlabel numbers
|
|
|
|
strelaysrv_num_sessions.label sessions
|
|
|
|
strelaysrv_num_connections.label connections
|
|
|
|
strelaysrv_num_pending.label pending session keys
|
|
|
|
strelaysrv_num_proxies.label proxies
|
|
|
|
EOM
|
2018-03-24 20:23:40 +01:00
|
|
|
exit 0;;
|
2018-03-24 19:55:12 +01:00
|
|
|
*)
|
2018-03-24 20:23:40 +01:00
|
|
|
STATUS=$($CURL -s http://"$syncthing_relaysrv_host":"$syncthing_relaysrv_port"/status)
|
|
|
|
NS=$(echo "$STATUS" | $JQ '.numActiveSessions ')
|
|
|
|
NC=$(echo "$STATUS" | $JQ '.numConnections ')
|
|
|
|
NK=$(echo "$STATUS" | $JQ '.numPendingSessionKeys ')
|
|
|
|
NP=$(echo "$STATUS" | $JQ '.numProxies ')
|
|
|
|
printf "strelaysrv_num_sessions.value %s\\n" "$NS"
|
|
|
|
printf "strelaysrv_num_connections.value %s\\n" "$NC"
|
|
|
|
printf "strelaysrv_num_pending.value %s\\n" "$NK"
|
|
|
|
printf "strelaysrv_num_proxies.value %s\\n" "$NP"
|
2018-03-24 19:55:12 +01:00
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2018-03-24 20:23:40 +01:00
|
|
|
uptime() {
|
2018-03-24 19:55:12 +01:00
|
|
|
case $1 in
|
2018-03-24 20:23:40 +01:00
|
|
|
config)
|
2018-03-24 19:55:12 +01:00
|
|
|
cat <<'EOM'
|
|
|
|
graph_title Syncthing relay uptime
|
|
|
|
graph_vlabel uptime in seconds
|
|
|
|
graph_category network
|
|
|
|
strelaysrv_uptime.label uptime
|
|
|
|
EOM
|
2018-03-24 20:23:40 +01:00
|
|
|
exit 0;;
|
2018-03-24 19:55:12 +01:00
|
|
|
*)
|
2018-03-24 20:23:40 +01:00
|
|
|
UPTIME=$($CURL -s http://"$syncthing_relaysrv_host":"$syncthing_relaysrv_port"/status | $JQ '.uptimeSeconds')
|
|
|
|
printf "strelaysrv_uptime.value %s\\n" "$UPTIME"
|
2018-03-24 19:55:12 +01:00
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2018-03-24 20:23:40 +01:00
|
|
|
goroutine() {
|
2018-03-24 19:55:12 +01:00
|
|
|
case $1 in
|
2018-03-24 20:23:40 +01:00
|
|
|
config)
|
2018-03-24 19:55:12 +01:00
|
|
|
cat <<'EOM'
|
|
|
|
graph_title Syncthing relay go routines
|
|
|
|
graph_vlabel number of go routines
|
|
|
|
graph_category network
|
|
|
|
strelaysrv_goroutine.label routines
|
|
|
|
EOM
|
2018-03-24 20:23:40 +01:00
|
|
|
exit 0;;
|
2018-03-24 19:55:12 +01:00
|
|
|
*)
|
2018-03-24 20:23:40 +01:00
|
|
|
GOROUTINE=$($CURL -s http://"$syncthing_relaysrv_host":"$syncthing_relaysrv_port"/status | $JQ '.goNumRoutine')
|
|
|
|
printf "strelaysrv_goroutine.value %s\\n" "$GOROUTINE"
|
2018-03-24 19:55:12 +01:00
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2018-03-24 20:23:40 +01:00
|
|
|
proxied() {
|
2018-03-24 19:55:12 +01:00
|
|
|
case $1 in
|
2018-03-24 20:23:40 +01:00
|
|
|
config)
|
2018-03-24 19:55:12 +01:00
|
|
|
cat <<'EOM'
|
|
|
|
graph_title Syncthing relay total proxied bits
|
|
|
|
graph_category network
|
|
|
|
graph_vlabel bits
|
|
|
|
graph_args --base 1000
|
|
|
|
strelaysrv_proxied.label bits
|
|
|
|
strelaysrv_proxied.cdef strelaysrv_proxied,8,*
|
|
|
|
EOM
|
|
|
|
exit 0;;
|
2018-03-24 20:23:40 +01:00
|
|
|
*)
|
|
|
|
BP=$($CURL -s http://"$syncthing_relaysrv_host":"$syncthing_relaysrv_port"/status | $JQ '.bytesProxied ')
|
|
|
|
printf "strelaysrv_proxied.value %s\\n" "$BP"
|
2018-03-24 19:55:12 +01:00
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2018-03-24 20:23:40 +01:00
|
|
|
transfer() {
|
2018-03-24 19:55:12 +01:00
|
|
|
case $1 in
|
2018-03-24 20:23:40 +01:00
|
|
|
config)
|
2018-03-24 19:55:12 +01:00
|
|
|
cat <<'EOM'
|
|
|
|
graph_title Syncthing relay transfer rate
|
|
|
|
graph_category network
|
|
|
|
graph_vlabel bps
|
|
|
|
graph_args --base 1000
|
|
|
|
strelaysrv_transfer.label bps
|
|
|
|
strelaysrv_transfer.cdef strelaysrv_transfer,1000,*
|
|
|
|
EOM
|
|
|
|
exit 0;;
|
2018-03-24 20:23:40 +01:00
|
|
|
*)
|
|
|
|
TRANSFER=$($CURL -s http://"$syncthing_relaysrv_host":"$syncthing_relaysrv_port"/status | $JQ '.kbps10s1m5m15m30m60m[2] ')
|
|
|
|
printf "strelaysrv_transfer.value %s\\n" "$TRANSFER"
|
2018-03-24 19:55:12 +01:00
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2018-03-24 20:23:40 +01:00
|
|
|
cd "$(dirname "$0")" || exit
|
2018-03-24 19:55:12 +01:00
|
|
|
|
|
|
|
CURL=$(which curl)
|
|
|
|
JQ=$(which jq)
|
|
|
|
|
2018-03-24 20:23:40 +01:00
|
|
|
case $(basename "$0") in
|
2018-03-24 19:55:12 +01:00
|
|
|
strelaysrv_num)
|
2018-03-24 20:23:40 +01:00
|
|
|
num "$1"
|
2018-03-24 19:55:12 +01:00
|
|
|
exit 0;;
|
|
|
|
strelaysrv_uptime)
|
2018-03-24 20:23:40 +01:00
|
|
|
uptime "$1"
|
2018-03-24 19:55:12 +01:00
|
|
|
exit 0;;
|
|
|
|
strelaysrv_goroutine)
|
2018-03-24 20:23:40 +01:00
|
|
|
goroutine "$1"
|
2018-03-24 19:55:12 +01:00
|
|
|
exit 0;;
|
|
|
|
strelaysrv_proxied)
|
2018-03-24 20:23:40 +01:00
|
|
|
proxied "$1"
|
2018-03-24 19:55:12 +01:00
|
|
|
exit 0;;
|
|
|
|
strelaysrv_transfer)
|
2018-03-24 20:23:40 +01:00
|
|
|
transfer "$1"
|
2018-03-24 19:55:12 +01:00
|
|
|
exit 0;;
|
|
|
|
esac
|