Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / plugins / syncthing / syncthing_ @ 09b88141

Historique | Voir | Annoter | Télécharger (4,26 ko)

1 e527db57 Pierre-Alain TORET
#!/bin/sh
2 6ee4fc8d Pierre-Alain TORET
# -*- sh -*-
3
: <<=cut
4
=head1 NAME
5 09b88141 Lars Kruse
6 6ee4fc8d Pierre-Alain TORET
syncthing_ - Plugin to monitor Syncthing server
7
8 09b88141 Lars Kruse
9 6ee4fc8d Pierre-Alain TORET
=head1 DESCRIPTION
10 09b88141 Lars Kruse
11 6ee4fc8d Pierre-Alain TORET
This plugin gathers metrics from a Syncthing server.
12
13
This plugin requires the jq utility : https://stedolan.github.io/jq/
14 99123efb Pierre-Alain TORET
This plugin requires the cURL utility : https://curl.haxx.se/
15 6ee4fc8d Pierre-Alain TORET
16 09b88141 Lars Kruse
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 6ee4fc8d Pierre-Alain TORET
33
=head1 CONFIGURATION
34 17f78427 Lars Kruse
To make the plugin connect to the Syncthing server one has to use this type of
35 09b88141 Lars Kruse
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 6ee4fc8d Pierre-Alain TORET
43
44
=head1 AUTHOR
45 09b88141 Lars Kruse
46 6ee4fc8d Pierre-Alain TORET
Pierre-Alain TORET <pierre-alain.toret@protonmail.com>
47
48 09b88141 Lars Kruse
49 6ee4fc8d Pierre-Alain TORET
=head1 LICENSE
50 09b88141 Lars Kruse
51 6ee4fc8d Pierre-Alain TORET
MIT
52 09b88141 Lars Kruse
53
SPDX-License-Identifier: MIT
54
55 6ee4fc8d Pierre-Alain TORET
=cut
56
57 e541294f Pierre-Alain TORET
syncthing_apikey=${syncthing_apikey:-}
58
syncthing_proto=${syncthing_proto:-}
59
syncthing_host=${syncthing_host:-}
60
syncthing_port=${syncthing_port:-}
61
62 e527db57 Pierre-Alain TORET
getstatus() {
63
    "$CURL" -s -X GET -H "X-API-Key: $syncthing_apikey" "$syncthing_proto://$syncthing_host:$syncthing_port/rest/system/status"
64
}
65
66 f1afd73f Pierre-Alain TORET
cpu() {
67 6ee4fc8d Pierre-Alain TORET
    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 e527db57 Pierre-Alain TORET
            STATUS=$(getstatus)
79
			CPU=$(echo "$STATUS" | "$JQ" '.cpuPercent')
80 7fed3b97 Lars Kruse
            printf 'syncthing_cpu.value %s\n' "$CPU"
81 6ee4fc8d Pierre-Alain TORET
    esac
82
}
83
84 f1afd73f Pierre-Alain TORET
mem() {
85 6ee4fc8d Pierre-Alain TORET
    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 f1afd73f Pierre-Alain TORET
	    *)
100 e527db57 Pierre-Alain TORET
            STATUS=$(getstatus)
101
            ALL=$(echo "$STATUS" | "$JQ" '.alloc')
102
            SYS=$(echo "$STATUS" | "$JQ" '.sys')
103 7fed3b97 Lars Kruse
            printf 'syncthing_mem_all.value %s\n' "$ALL"
104
            printf 'syncthing_mem_sys.value %s\n' "$SYS"
105 6ee4fc8d Pierre-Alain TORET
    esac
106
}
107
108 f1afd73f Pierre-Alain TORET
uptime() {
109 6ee4fc8d Pierre-Alain TORET
    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 e527db57 Pierre-Alain TORET
            STATUS=$(getstatus)
120
            UPTIME=$(echo "$STATUS" | "$JQ" '.uptime')
121 7fed3b97 Lars Kruse
            printf 'syncthing_uptime.value %s\n' "$UPTIME"
122 6ee4fc8d Pierre-Alain TORET
    esac
123
}
124
125 f1afd73f Pierre-Alain TORET
goroutine() {
126 6ee4fc8d Pierre-Alain TORET
    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 17f78427 Lars Kruse
syncthing_goroutine.label routines
133 6ee4fc8d Pierre-Alain TORET
EOM
134
            exit 0;;
135
        *)
136 e527db57 Pierre-Alain TORET
            STATUS=$(getstatus)
137
            GOROUTINES=$(echo "$STATUS" | "$JQ" '.goroutines')
138 7fed3b97 Lars Kruse
            printf 'syncthing_goroutine.value %s\n' "$GOROUTINES"
139 6ee4fc8d Pierre-Alain TORET
    esac
140
}
141
142 f1afd73f Pierre-Alain TORET
transfer() {
143 6ee4fc8d Pierre-Alain TORET
    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 f1afd73f Pierre-Alain TORET
	    *)
162 e527db57 Pierre-Alain TORET
            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 7fed3b97 Lars Kruse
            printf 'syncthing_transfer_up.value %s\n' "$IBT"
166
            printf 'syncthing_transfer_down.value %s\n' "$OBT"
167 6ee4fc8d Pierre-Alain TORET
    esac
168
}
169
170 f1afd73f Pierre-Alain TORET
cd "$(dirname "$0")" || exit
171 6ee4fc8d Pierre-Alain TORET
172 99123efb Pierre-Alain TORET
CURL=$(which curl)
173
JQ=$(which jq)
174
175 17f78427 Lars Kruse
case $(basename "$0") in
176 6ee4fc8d Pierre-Alain TORET
    syncthing_cpu)
177 f1afd73f Pierre-Alain TORET
	cpu "$1"
178 6ee4fc8d Pierre-Alain TORET
	exit 0;;
179
    syncthing_mem)
180 f1afd73f Pierre-Alain TORET
	mem "$1"
181 6ee4fc8d Pierre-Alain TORET
	exit 0;;
182
    syncthing_uptime)
183 f1afd73f Pierre-Alain TORET
	uptime "$1"
184 6ee4fc8d Pierre-Alain TORET
	exit 0;;
185
    syncthing_goroutine)
186 f1afd73f Pierre-Alain TORET
	goroutine "$1"
187 6ee4fc8d Pierre-Alain TORET
	exit 0;;
188
    syncthing_transfer)
189 f1afd73f Pierre-Alain TORET
	transfer "$1"
190 6ee4fc8d Pierre-Alain TORET
	exit 0;;
191
esac