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