2018-03-27 18:04:29 +02:00
|
|
|
#!/bin/sh
|
2017-11-15 13:54:43 +01:00
|
|
|
# -*- sh -*-
|
|
|
|
: <<=cut
|
|
|
|
=head1 NAME
|
|
|
|
syncthing_ - Plugin to monitor Syncthing server
|
|
|
|
|
|
|
|
=head1 DESCRIPTION
|
|
|
|
This plugin gathers metrics from a Syncthing server.
|
|
|
|
|
|
|
|
This plugin requires the jq utility : https://stedolan.github.io/jq/
|
2017-12-13 19:46:47 +01:00
|
|
|
This plugin requires the cURL utility : https://curl.haxx.se/
|
2017-11-15 13:54:43 +01:00
|
|
|
|
|
|
|
Available plugins :
|
2018-08-02 02:03:42 +02:00
|
|
|
syncthing_cpu #
|
2017-11-15 13:54:43 +01:00
|
|
|
syncthing_mem #
|
|
|
|
syncthing_goroutine #
|
|
|
|
syncthing_transfer #
|
|
|
|
syncthing_uptime #
|
|
|
|
|
|
|
|
=head1 CONFIGURATION
|
2018-08-02 02:03:42 +02:00
|
|
|
To make the plugin connect to the Syncthing server one has to use this type of
|
2017-11-15 13:54:43 +01:00
|
|
|
configuration
|
|
|
|
[syncthing_*]
|
|
|
|
|
2018-03-24 18:43:32 +01:00
|
|
|
env.syncthing_apikey myapikey0123456789
|
|
|
|
env.syncthing_host 127.0.0.1
|
|
|
|
env.syncthing_port 8384
|
|
|
|
env.syncthing_proto http
|
2017-11-15 13:54:43 +01:00
|
|
|
|
|
|
|
=head1 AUTHOR
|
|
|
|
Pierre-Alain TORET <pierre-alain.toret@protonmail.com>
|
|
|
|
|
|
|
|
=head1 LICENSE
|
|
|
|
MIT
|
|
|
|
=cut
|
|
|
|
|
2018-03-29 13:15:44 +02:00
|
|
|
syncthing_apikey=${syncthing_apikey:-}
|
|
|
|
syncthing_proto=${syncthing_proto:-}
|
|
|
|
syncthing_host=${syncthing_host:-}
|
|
|
|
syncthing_port=${syncthing_port:-}
|
|
|
|
|
2018-03-27 18:04:29 +02:00
|
|
|
getstatus() {
|
|
|
|
"$CURL" -s -X GET -H "X-API-Key: $syncthing_apikey" "$syncthing_proto://$syncthing_host:$syncthing_port/rest/system/status"
|
|
|
|
}
|
|
|
|
|
2018-03-24 19:16:03 +01:00
|
|
|
cpu() {
|
2017-11-15 13:54:43 +01:00
|
|
|
case $1 in
|
|
|
|
config)
|
|
|
|
cat <<'EOM'
|
|
|
|
graph_title Syncthing server cpu usage
|
|
|
|
graph_args -u 100
|
|
|
|
graph_vlabel %
|
|
|
|
graph_category network
|
|
|
|
syncthing_cpu.label cpu
|
|
|
|
EOM
|
|
|
|
exit 0;;
|
|
|
|
*)
|
2018-03-27 18:04:29 +02:00
|
|
|
STATUS=$(getstatus)
|
|
|
|
CPU=$(echo "$STATUS" | "$JQ" '.cpuPercent')
|
|
|
|
printf "syncthing_cpu.value %s\n" "$CPU"
|
2017-11-15 13:54:43 +01:00
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2018-03-24 19:16:03 +01:00
|
|
|
mem() {
|
2017-11-15 13:54:43 +01:00
|
|
|
case $1 in
|
|
|
|
config)
|
|
|
|
cat <<'EOM'
|
|
|
|
graph_title Syncthing server memory
|
|
|
|
graph_category network
|
|
|
|
graph_order syncthing_mem_all syncthing_mem_sys
|
|
|
|
graph_args --base 1000
|
|
|
|
graph_vlabel bits
|
|
|
|
syncthing_mem_all.label allocated
|
|
|
|
syncthing_mem_all.cdef syncthing_mem_all,8,*
|
|
|
|
syncthing_mem_sys.label obtained
|
|
|
|
syncthing_mem_sys.cdef syncthing_mem_sys,8,*
|
|
|
|
EOM
|
|
|
|
exit 0;;
|
2018-03-24 19:16:03 +01:00
|
|
|
*)
|
2018-03-27 18:04:29 +02:00
|
|
|
STATUS=$(getstatus)
|
|
|
|
ALL=$(echo "$STATUS" | "$JQ" '.alloc')
|
|
|
|
SYS=$(echo "$STATUS" | "$JQ" '.sys')
|
|
|
|
printf "syncthing_mem_all.value %s\n" "$ALL"
|
|
|
|
printf "syncthing_mem_sys.value %s\n" "$SYS"
|
2017-11-15 13:54:43 +01:00
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2018-03-24 19:16:03 +01:00
|
|
|
uptime() {
|
2017-11-15 13:54:43 +01:00
|
|
|
case $1 in
|
|
|
|
config)
|
|
|
|
cat <<'EOM'
|
|
|
|
graph_title Syncthing server uptime
|
|
|
|
graph_vlabel uptime in seconds
|
|
|
|
graph_category network
|
|
|
|
syncthing_uptime.label uptime
|
|
|
|
EOM
|
|
|
|
exit 0;;
|
|
|
|
*)
|
2018-03-27 18:04:29 +02:00
|
|
|
STATUS=$(getstatus)
|
|
|
|
UPTIME=$(echo "$STATUS" | "$JQ" '.uptime')
|
|
|
|
printf "syncthing_uptime.value %s\n" "$UPTIME"
|
2017-11-15 13:54:43 +01:00
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2018-03-24 19:16:03 +01:00
|
|
|
goroutine() {
|
2017-11-15 13:54:43 +01:00
|
|
|
case $1 in
|
|
|
|
config)
|
|
|
|
cat <<'EOM'
|
|
|
|
graph_title Syncthing server go routines
|
|
|
|
graph_vlabel number of go routines
|
|
|
|
graph_category network
|
2018-08-02 02:03:42 +02:00
|
|
|
syncthing_goroutine.label routines
|
2017-11-15 13:54:43 +01:00
|
|
|
EOM
|
|
|
|
exit 0;;
|
|
|
|
*)
|
2018-03-27 18:04:29 +02:00
|
|
|
STATUS=$(getstatus)
|
|
|
|
GOROUTINES=$(echo "$STATUS" | "$JQ" '.goroutines')
|
|
|
|
printf "syncthing_goroutine.value %s\n" "$GOROUTINES"
|
2017-11-15 13:54:43 +01:00
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2018-03-24 19:16:03 +01:00
|
|
|
transfer() {
|
2017-11-15 13:54:43 +01:00
|
|
|
case $1 in
|
|
|
|
config)
|
|
|
|
cat <<'EOM'
|
|
|
|
graph_title Syncthing server total transfer
|
|
|
|
graph_category network
|
|
|
|
graph_order syncthing_transfer_down syncthing_transfer_up
|
|
|
|
graph_args --base 1000
|
|
|
|
graph_vlabel bits in (-) / out (+) per ${graph_period}
|
|
|
|
syncthing_transfer_down.label received
|
|
|
|
syncthing_transfer_down.type COUNTER
|
|
|
|
syncthing_transfer_down.graph no
|
|
|
|
syncthing_transfer_down.cdef syncthing_transfer_down,8,*
|
|
|
|
syncthing_transfer_up.label bps
|
|
|
|
syncthing_transfer_up.type COUNTER
|
|
|
|
syncthing_transfer_up.negative syncthing_transfer_down
|
|
|
|
syncthing_transfer_up.cdef syncthing_transfer_up,8,*
|
|
|
|
EOM
|
|
|
|
exit 0;;
|
2018-03-24 19:16:03 +01:00
|
|
|
*)
|
2018-03-27 18:04:29 +02:00
|
|
|
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')
|
|
|
|
OBT=$(echo "$CONNECTIONS" | "$JQ" '.total | .outBytesTotal')
|
2018-03-28 10:56:34 +02:00
|
|
|
printf "syncthing_transfer_up.value %s\n" "$IBT"
|
|
|
|
printf "syncthing_transfer_down.value %s\n" "$OBT"
|
2017-11-15 13:54:43 +01:00
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2018-03-24 19:16:03 +01:00
|
|
|
cd "$(dirname "$0")" || exit
|
2017-11-15 13:54:43 +01:00
|
|
|
|
2017-12-13 19:46:47 +01:00
|
|
|
CURL=$(which curl)
|
|
|
|
JQ=$(which jq)
|
|
|
|
|
2018-08-02 02:03:42 +02:00
|
|
|
case $(basename "$0") in
|
2017-11-15 13:54:43 +01:00
|
|
|
syncthing_cpu)
|
2018-03-24 19:16:03 +01:00
|
|
|
cpu "$1"
|
2017-11-15 13:54:43 +01:00
|
|
|
exit 0;;
|
|
|
|
syncthing_mem)
|
2018-03-24 19:16:03 +01:00
|
|
|
mem "$1"
|
2017-11-15 13:54:43 +01:00
|
|
|
exit 0;;
|
|
|
|
syncthing_uptime)
|
2018-03-24 19:16:03 +01:00
|
|
|
uptime "$1"
|
2017-11-15 13:54:43 +01:00
|
|
|
exit 0;;
|
|
|
|
syncthing_goroutine)
|
2018-03-24 19:16:03 +01:00
|
|
|
goroutine "$1"
|
2017-11-15 13:54:43 +01:00
|
|
|
exit 0;;
|
|
|
|
syncthing_transfer)
|
2018-03-24 19:16:03 +01:00
|
|
|
transfer "$1"
|
2017-11-15 13:54:43 +01:00
|
|
|
exit 0;;
|
|
|
|
esac
|