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

156 lines
4.0 KiB
Plaintext
Raw Normal View History

#!/usr/bin/env bash
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/
This plugin requires the cURL utility : https://curl.haxx.se/
2017-11-15 13:54:43 +01:00
Available plugins :
syncthing_cpu #
syncthing_mem #
syncthing_goroutine #
syncthing_transfer #
syncthing_uptime #
=head1 CONFIGURATION
To make the plugin connect to the Syncthing server one has to use this type of
configuration
[syncthing_*]
env.ST_APIKEY myapikey0123456789
env.ST_HOST 127.0.0.1
env.ST_PORT 8384
env.ST_PROTO http
=head1 AUTHOR
Pierre-Alain TORET <pierre-alain.toret@protonmail.com>
=head1 LICENSE
MIT
=cut
function cpu {
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;;
*)
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'
2017-11-15 13:54:43 +01:00
esac
}
function mem {
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;;
*)
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')
2017-11-15 13:54:43 +01:00
printf "syncthing_mem_all.value $ALL\nsyncthing_mem_sys.value $SYS\n"
esac
}
function uptime {
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;;
*)
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'
2017-11-15 13:54:43 +01:00
esac
}
function goroutine {
case $1 in
config)
cat <<'EOM'
graph_title Syncthing server go routines
graph_vlabel number of go routines
graph_category network
syncthing_goroutine.label routines
EOM
exit 0;;
*)
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'
2017-11-15 13:54:43 +01:00
esac
}
function transfer {
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;;
*)
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')
2017-11-15 13:54:43 +01:00
printf "syncthing_transfer_up.value $IBT\nsyncthing_transfer_down.value $OBT\n"
esac
}
cd $(dirname $0)
CURL=$(which curl)
JQ=$(which jq)
2017-11-15 13:54:43 +01:00
case $(basename $0) in
syncthing_cpu)
cpu $1
exit 0;;
syncthing_mem)
mem $1
exit 0;;
syncthing_uptime)
uptime $1
exit 0;;
syncthing_goroutine)
goroutine $1
exit 0;;
syncthing_transfer)
transfer $1
exit 0;;
esac