root / plugins / syncthing / syncthing_ @ 09b88141
Historique | Voir | Annoter | Télécharger (4,26 ko)
| 1 |
#!/bin/sh |
|---|---|
| 2 |
# -*- sh -*- |
| 3 |
: <<=cut |
| 4 |
=head1 NAME |
| 5 |
|
| 6 |
syncthing_ - Plugin to monitor Syncthing server |
| 7 |
|
| 8 |
|
| 9 |
=head1 DESCRIPTION |
| 10 |
|
| 11 |
This plugin gathers metrics from a Syncthing server. |
| 12 |
|
| 13 |
This plugin requires the jq utility : https://stedolan.github.io/jq/ |
| 14 |
This plugin requires the cURL utility : https://curl.haxx.se/ |
| 15 |
|
| 16 |
Available wildcard plugin features: |
| 17 |
|
| 18 |
=over 4 |
| 19 |
|
| 20 |
=item syncthing_cpu |
| 21 |
|
| 22 |
=item syncthing_mem |
| 23 |
|
| 24 |
=item syncthing_goroutine |
| 25 |
|
| 26 |
=item syncthing_transfer |
| 27 |
|
| 28 |
=item syncthing_uptime |
| 29 |
|
| 30 |
=back |
| 31 |
|
| 32 |
|
| 33 |
=head1 CONFIGURATION |
| 34 |
To make the plugin connect to the Syncthing server one has to use this type of |
| 35 |
configuration: |
| 36 |
|
| 37 |
[syncthing_*] |
| 38 |
env.syncthing_apikey myapikey0123456789 |
| 39 |
env.syncthing_host 127.0.0.1 |
| 40 |
env.syncthing_port 8384 |
| 41 |
env.syncthing_proto http |
| 42 |
|
| 43 |
|
| 44 |
=head1 AUTHOR |
| 45 |
|
| 46 |
Pierre-Alain TORET <pierre-alain.toret@protonmail.com> |
| 47 |
|
| 48 |
|
| 49 |
=head1 LICENSE |
| 50 |
|
| 51 |
MIT |
| 52 |
|
| 53 |
SPDX-License-Identifier: MIT |
| 54 |
|
| 55 |
=cut |
| 56 |
|
| 57 |
syncthing_apikey=${syncthing_apikey:-}
|
| 58 |
syncthing_proto=${syncthing_proto:-}
|
| 59 |
syncthing_host=${syncthing_host:-}
|
| 60 |
syncthing_port=${syncthing_port:-}
|
| 61 |
|
| 62 |
getstatus() {
|
| 63 |
"$CURL" -s -X GET -H "X-API-Key: $syncthing_apikey" "$syncthing_proto://$syncthing_host:$syncthing_port/rest/system/status" |
| 64 |
} |
| 65 |
|
| 66 |
cpu() {
|
| 67 |
case $1 in |
| 68 |
config) |
| 69 |
cat <<'EOM' |
| 70 |
graph_title Syncthing server cpu usage |
| 71 |
graph_args -u 100 |
| 72 |
graph_vlabel % |
| 73 |
graph_category network |
| 74 |
syncthing_cpu.label cpu |
| 75 |
EOM |
| 76 |
exit 0;; |
| 77 |
*) |
| 78 |
STATUS=$(getstatus) |
| 79 |
CPU=$(echo "$STATUS" | "$JQ" '.cpuPercent') |
| 80 |
printf 'syncthing_cpu.value %s\n' "$CPU" |
| 81 |
esac |
| 82 |
} |
| 83 |
|
| 84 |
mem() {
|
| 85 |
case $1 in |
| 86 |
config) |
| 87 |
cat <<'EOM' |
| 88 |
graph_title Syncthing server memory |
| 89 |
graph_category network |
| 90 |
graph_order syncthing_mem_all syncthing_mem_sys |
| 91 |
graph_args --base 1000 |
| 92 |
graph_vlabel bits |
| 93 |
syncthing_mem_all.label allocated |
| 94 |
syncthing_mem_all.cdef syncthing_mem_all,8,* |
| 95 |
syncthing_mem_sys.label obtained |
| 96 |
syncthing_mem_sys.cdef syncthing_mem_sys,8,* |
| 97 |
EOM |
| 98 |
exit 0;; |
| 99 |
*) |
| 100 |
STATUS=$(getstatus) |
| 101 |
ALL=$(echo "$STATUS" | "$JQ" '.alloc') |
| 102 |
SYS=$(echo "$STATUS" | "$JQ" '.sys') |
| 103 |
printf 'syncthing_mem_all.value %s\n' "$ALL" |
| 104 |
printf 'syncthing_mem_sys.value %s\n' "$SYS" |
| 105 |
esac |
| 106 |
} |
| 107 |
|
| 108 |
uptime() {
|
| 109 |
case $1 in |
| 110 |
config) |
| 111 |
cat <<'EOM' |
| 112 |
graph_title Syncthing server uptime |
| 113 |
graph_vlabel uptime in seconds |
| 114 |
graph_category network |
| 115 |
syncthing_uptime.label uptime |
| 116 |
EOM |
| 117 |
exit 0;; |
| 118 |
*) |
| 119 |
STATUS=$(getstatus) |
| 120 |
UPTIME=$(echo "$STATUS" | "$JQ" '.uptime') |
| 121 |
printf 'syncthing_uptime.value %s\n' "$UPTIME" |
| 122 |
esac |
| 123 |
} |
| 124 |
|
| 125 |
goroutine() {
|
| 126 |
case $1 in |
| 127 |
config) |
| 128 |
cat <<'EOM' |
| 129 |
graph_title Syncthing server go routines |
| 130 |
graph_vlabel number of go routines |
| 131 |
graph_category network |
| 132 |
syncthing_goroutine.label routines |
| 133 |
EOM |
| 134 |
exit 0;; |
| 135 |
*) |
| 136 |
STATUS=$(getstatus) |
| 137 |
GOROUTINES=$(echo "$STATUS" | "$JQ" '.goroutines') |
| 138 |
printf 'syncthing_goroutine.value %s\n' "$GOROUTINES" |
| 139 |
esac |
| 140 |
} |
| 141 |
|
| 142 |
transfer() {
|
| 143 |
case $1 in |
| 144 |
config) |
| 145 |
cat <<'EOM' |
| 146 |
graph_title Syncthing server total transfer |
| 147 |
graph_category network |
| 148 |
graph_order syncthing_transfer_down syncthing_transfer_up |
| 149 |
graph_args --base 1000 |
| 150 |
graph_vlabel bits in (-) / out (+) per ${graph_period}
|
| 151 |
syncthing_transfer_down.label received |
| 152 |
syncthing_transfer_down.type COUNTER |
| 153 |
syncthing_transfer_down.graph no |
| 154 |
syncthing_transfer_down.cdef syncthing_transfer_down,8,* |
| 155 |
syncthing_transfer_up.label bps |
| 156 |
syncthing_transfer_up.type COUNTER |
| 157 |
syncthing_transfer_up.negative syncthing_transfer_down |
| 158 |
syncthing_transfer_up.cdef syncthing_transfer_up,8,* |
| 159 |
EOM |
| 160 |
exit 0;; |
| 161 |
*) |
| 162 |
CONNECTIONS=$("$CURL" -s -X GET -H "X-API-Key: $syncthing_apikey" "$syncthing_proto://$syncthing_host:$syncthing_port/rest/system/connections")
|
| 163 |
IBT=$(echo "$CONNECTIONS" | "$JQ" '.total | .inBytesTotal') |
| 164 |
OBT=$(echo "$CONNECTIONS" | "$JQ" '.total | .outBytesTotal') |
| 165 |
printf 'syncthing_transfer_up.value %s\n' "$IBT" |
| 166 |
printf 'syncthing_transfer_down.value %s\n' "$OBT" |
| 167 |
esac |
| 168 |
} |
| 169 |
|
| 170 |
cd "$(dirname "$0")" || exit |
| 171 |
|
| 172 |
CURL=$(which curl) |
| 173 |
JQ=$(which jq) |
| 174 |
|
| 175 |
case $(basename "$0") in |
| 176 |
syncthing_cpu) |
| 177 |
cpu "$1" |
| 178 |
exit 0;; |
| 179 |
syncthing_mem) |
| 180 |
mem "$1" |
| 181 |
exit 0;; |
| 182 |
syncthing_uptime) |
| 183 |
uptime "$1" |
| 184 |
exit 0;; |
| 185 |
syncthing_goroutine) |
| 186 |
goroutine "$1" |
| 187 |
exit 0;; |
| 188 |
syncthing_transfer) |
| 189 |
transfer "$1" |
| 190 |
exit 0;; |
| 191 |
esac |
