root / plugins / syncthing / strelaysrv_ @ e527db57
Historique | Voir | Annoter | Télécharger (3,68 ko)
| 1 |
#!/bin/sh |
|---|---|
| 2 |
: <<=cut |
| 3 |
=head1 NAME |
| 4 |
strelaysrv_ - Plugin to monitor Syncthing relay server |
| 5 |
|
| 6 |
=head1 DESCRIPTION |
| 7 |
This plugin gathers metrics from a Syncthing relay server. |
| 8 |
|
| 9 |
This plugin requires the jq utility : https://stedolan.github.io/jq/ |
| 10 |
This plugin requires the curl utility : https://curl.haxx.se/ |
| 11 |
|
| 12 |
Available plugins : |
| 13 |
strelaysrv_goroutine # |
| 14 |
strelaysrv_num # |
| 15 |
strelaysrv_proxied # |
| 16 |
strelaysrv_transfer # |
| 17 |
strelaysrv_uptime # |
| 18 |
|
| 19 |
=head1 CONFIGURATION |
| 20 |
To make the plugin connect to the Syncthing relay server one has to use this type of |
| 21 |
configuration |
| 22 |
[strelaysrv_*] |
| 23 |
|
| 24 |
env.syncthing_relaysrv_host 127.0.0.1 |
| 25 |
env.syncthing_relaysrv_port 22070 |
| 26 |
|
| 27 |
=head1 AUTHOR |
| 28 |
Pierre-Alain TORET <pierre-alain.toret@protonmail.com> |
| 29 |
|
| 30 |
=head1 LICENSE |
| 31 |
MIT |
| 32 |
=cut |
| 33 |
|
| 34 |
getstatus() {
|
| 35 |
"$CURL" -s "http://$syncthing_relaysrv_host:$syncthing_relaysrv_port/status" |
| 36 |
} |
| 37 |
|
| 38 |
num() {
|
| 39 |
case $1 in |
| 40 |
config) |
| 41 |
cat <<'EOM' |
| 42 |
graph_title Syncthing relay numbers |
| 43 |
graph_category network |
| 44 |
graph_vlabel numbers |
| 45 |
strelaysrv_num_sessions.label sessions |
| 46 |
strelaysrv_num_connections.label connections |
| 47 |
strelaysrv_num_pending.label pending session keys |
| 48 |
strelaysrv_num_proxies.label proxies |
| 49 |
EOM |
| 50 |
exit 0;; |
| 51 |
*) |
| 52 |
STATUS=$(getstatus) |
| 53 |
NS=$(echo "$STATUS" | $JQ '.numActiveSessions ') |
| 54 |
NC=$(echo "$STATUS" | $JQ '.numConnections ') |
| 55 |
NK=$(echo "$STATUS" | $JQ '.numPendingSessionKeys ') |
| 56 |
NP=$(echo "$STATUS" | $JQ '.numProxies ') |
| 57 |
printf "strelaysrv_num_sessions.value %s\n" "$NS" |
| 58 |
printf "strelaysrv_num_connections.value %s\n" "$NC" |
| 59 |
printf "strelaysrv_num_pending.value %s\n" "$NK" |
| 60 |
printf "strelaysrv_num_proxies.value %s\n" "$NP" |
| 61 |
esac |
| 62 |
} |
| 63 |
|
| 64 |
uptime() {
|
| 65 |
case $1 in |
| 66 |
config) |
| 67 |
cat <<'EOM' |
| 68 |
graph_title Syncthing relay uptime |
| 69 |
graph_vlabel uptime in seconds |
| 70 |
graph_category network |
| 71 |
strelaysrv_uptime.label uptime |
| 72 |
EOM |
| 73 |
exit 0;; |
| 74 |
*) |
| 75 |
STATUS=$(getstatus) |
| 76 |
UPTIME=$(echo "$STATUS" | "$JQ" '.uptimeSeconds') |
| 77 |
printf "strelaysrv_uptime.value %s\n" "$UPTIME" |
| 78 |
esac |
| 79 |
} |
| 80 |
|
| 81 |
goroutine() {
|
| 82 |
case $1 in |
| 83 |
config) |
| 84 |
cat <<'EOM' |
| 85 |
graph_title Syncthing relay go routines |
| 86 |
graph_vlabel number of go routines |
| 87 |
graph_category network |
| 88 |
strelaysrv_goroutine.label routines |
| 89 |
EOM |
| 90 |
exit 0;; |
| 91 |
*) |
| 92 |
STATUS=$(getstatus) |
| 93 |
GOROUTINE=$(echo "$STATUS" | "$JQ" '.goNumRoutine') |
| 94 |
printf "strelaysrv_goroutine.value %s\n" "$GOROUTINE" |
| 95 |
esac |
| 96 |
} |
| 97 |
|
| 98 |
proxied() {
|
| 99 |
case $1 in |
| 100 |
config) |
| 101 |
cat <<'EOM' |
| 102 |
graph_title Syncthing relay total proxied bits |
| 103 |
graph_category network |
| 104 |
graph_vlabel bits |
| 105 |
graph_args --base 1000 |
| 106 |
strelaysrv_proxied.label bits |
| 107 |
strelaysrv_proxied.cdef strelaysrv_proxied,8,* |
| 108 |
EOM |
| 109 |
exit 0;; |
| 110 |
*) |
| 111 |
STATUS=$(getstatus) |
| 112 |
BP=$(echo "$STATUS" | "$JQ" '.bytesProxied ') |
| 113 |
printf "strelaysrv_proxied.value %s\n" "$BP" |
| 114 |
esac |
| 115 |
} |
| 116 |
|
| 117 |
transfer() {
|
| 118 |
case $1 in |
| 119 |
config) |
| 120 |
cat <<'EOM' |
| 121 |
graph_title Syncthing relay transfer rate |
| 122 |
graph_category network |
| 123 |
graph_vlabel bps |
| 124 |
graph_args --base 1000 |
| 125 |
strelaysrv_transfer.label bps |
| 126 |
strelaysrv_transfer.cdef strelaysrv_transfer,1000,* |
| 127 |
EOM |
| 128 |
exit 0;; |
| 129 |
*) |
| 130 |
STATUS=$(getstatus) |
| 131 |
TRANSFER=$(echo "$STATUS" | "$JQ" '.kbps10s1m5m15m30m60m[2] ') |
| 132 |
printf "strelaysrv_transfer.value %s\n" "$TRANSFER" |
| 133 |
esac |
| 134 |
} |
| 135 |
|
| 136 |
cd "$(dirname "$0")" || exit |
| 137 |
|
| 138 |
CURL=$(which curl) |
| 139 |
JQ=$(which jq) |
| 140 |
|
| 141 |
case $(basename "$0") in |
| 142 |
strelaysrv_num) |
| 143 |
num "$1" |
| 144 |
exit 0;; |
| 145 |
strelaysrv_uptime) |
| 146 |
uptime "$1" |
| 147 |
exit 0;; |
| 148 |
strelaysrv_goroutine) |
| 149 |
goroutine "$1" |
| 150 |
exit 0;; |
| 151 |
strelaysrv_proxied) |
| 152 |
proxied "$1" |
| 153 |
exit 0;; |
| 154 |
strelaysrv_transfer) |
| 155 |
transfer "$1" |
| 156 |
exit 0;; |
| 157 |
esac |
