Révision e527db57
Improve plugins call to status and few other fixes
Signed-off-by: Pierre-Alain TORET <pierre-alain.toret@protonmail.com>
| plugins/syncthing/strelaysrv_ | ||
|---|---|---|
| 1 |
#!/usr/bin/env sh
|
|
| 1 |
#!/bin/sh
|
|
| 2 | 2 |
: <<=cut |
| 3 | 3 |
=head1 NAME |
| 4 | 4 |
strelaysrv_ - Plugin to monitor Syncthing relay server |
| ... | ... | |
| 31 | 31 |
MIT |
| 32 | 32 |
=cut |
| 33 | 33 |
|
| 34 |
getstatus() {
|
|
| 35 |
"$CURL" -s "http://$syncthing_relaysrv_host:$syncthing_relaysrv_port/status" |
|
| 36 |
} |
|
| 37 |
|
|
| 34 | 38 |
num() {
|
| 35 | 39 |
case $1 in |
| 36 | 40 |
config) |
| ... | ... | |
| 45 | 49 |
EOM |
| 46 | 50 |
exit 0;; |
| 47 | 51 |
*) |
| 48 |
STATUS=$($CURL -s http://"$syncthing_relaysrv_host":"$syncthing_relaysrv_port"/status)
|
|
| 52 |
STATUS=$(getstatus)
|
|
| 49 | 53 |
NS=$(echo "$STATUS" | $JQ '.numActiveSessions ') |
| 50 | 54 |
NC=$(echo "$STATUS" | $JQ '.numConnections ') |
| 51 | 55 |
NK=$(echo "$STATUS" | $JQ '.numPendingSessionKeys ') |
| 52 | 56 |
NP=$(echo "$STATUS" | $JQ '.numProxies ') |
| 53 |
printf "strelaysrv_num_sessions.value %s\\n" "$NS"
|
|
| 54 |
printf "strelaysrv_num_connections.value %s\\n" "$NC"
|
|
| 55 |
printf "strelaysrv_num_pending.value %s\\n" "$NK"
|
|
| 56 |
printf "strelaysrv_num_proxies.value %s\\n" "$NP"
|
|
| 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" |
|
| 57 | 61 |
esac |
| 58 | 62 |
} |
| 59 | 63 |
|
| ... | ... | |
| 68 | 72 |
EOM |
| 69 | 73 |
exit 0;; |
| 70 | 74 |
*) |
| 71 |
UPTIME=$($CURL -s http://"$syncthing_relaysrv_host":"$syncthing_relaysrv_port"/status | $JQ '.uptimeSeconds') |
|
| 72 |
printf "strelaysrv_uptime.value %s\\n" "$UPTIME" |
|
| 75 |
STATUS=$(getstatus) |
|
| 76 |
UPTIME=$(echo "$STATUS" | "$JQ" '.uptimeSeconds') |
|
| 77 |
printf "strelaysrv_uptime.value %s\n" "$UPTIME" |
|
| 73 | 78 |
esac |
| 74 | 79 |
} |
| 75 | 80 |
|
| ... | ... | |
| 84 | 89 |
EOM |
| 85 | 90 |
exit 0;; |
| 86 | 91 |
*) |
| 87 |
GOROUTINE=$($CURL -s http://"$syncthing_relaysrv_host":"$syncthing_relaysrv_port"/status | $JQ '.goNumRoutine') |
|
| 88 |
printf "strelaysrv_goroutine.value %s\\n" "$GOROUTINE" |
|
| 92 |
STATUS=$(getstatus) |
|
| 93 |
GOROUTINE=$(echo "$STATUS" | "$JQ" '.goNumRoutine') |
|
| 94 |
printf "strelaysrv_goroutine.value %s\n" "$GOROUTINE" |
|
| 89 | 95 |
esac |
| 90 | 96 |
} |
| 91 | 97 |
|
| ... | ... | |
| 102 | 108 |
EOM |
| 103 | 109 |
exit 0;; |
| 104 | 110 |
*) |
| 105 |
BP=$($CURL -s http://"$syncthing_relaysrv_host":"$syncthing_relaysrv_port"/status | $JQ '.bytesProxied ') |
|
| 106 |
printf "strelaysrv_proxied.value %s\\n" "$BP" |
|
| 111 |
STATUS=$(getstatus) |
|
| 112 |
BP=$(echo "$STATUS" | "$JQ" '.bytesProxied ') |
|
| 113 |
printf "strelaysrv_proxied.value %s\n" "$BP" |
|
| 107 | 114 |
esac |
| 108 | 115 |
} |
| 109 | 116 |
|
| ... | ... | |
| 120 | 127 |
EOM |
| 121 | 128 |
exit 0;; |
| 122 | 129 |
*) |
| 123 |
TRANSFER=$($CURL -s http://"$syncthing_relaysrv_host":"$syncthing_relaysrv_port"/status | $JQ '.kbps10s1m5m15m30m60m[2] ') |
|
| 124 |
printf "strelaysrv_transfer.value %s\\n" "$TRANSFER" |
|
| 130 |
STATUS=$(getstatus) |
|
| 131 |
TRANSFER=$(echo "$STATUS" | "$JQ" '.kbps10s1m5m15m30m60m[2] ') |
|
| 132 |
printf "strelaysrv_transfer.value %s\n" "$TRANSFER" |
|
| 125 | 133 |
esac |
| 126 | 134 |
} |
| 127 | 135 |
|
| plugins/syncthing/syncthing_ | ||
|---|---|---|
| 1 |
#!/usr/bin/env sh
|
|
| 1 |
#!/bin/sh
|
|
| 2 | 2 |
# -*- sh -*- |
| 3 | 3 |
: <<=cut |
| 4 | 4 |
=head1 NAME |
| ... | ... | |
| 34 | 34 |
MIT |
| 35 | 35 |
=cut |
| 36 | 36 |
|
| 37 |
getstatus() {
|
|
| 38 |
"$CURL" -s -X GET -H "X-API-Key: $syncthing_apikey" "$syncthing_proto://$syncthing_host:$syncthing_port/rest/system/status" |
|
| 39 |
} |
|
| 40 |
|
|
| 37 | 41 |
cpu() {
|
| 38 | 42 |
case $1 in |
| 39 | 43 |
config) |
| ... | ... | |
| 46 | 50 |
EOM |
| 47 | 51 |
exit 0;; |
| 48 | 52 |
*) |
| 49 |
CPU=$($CURL -s -X GET -H "X-API-Key: $syncthing_apikey" "$syncthing_proto"://"$syncthing_host":"$syncthing_port"/rest/system/status | $JQ '.cpuPercent') |
|
| 50 |
printf "syncthing_cpu.value %s\\n" "$CPU" |
|
| 53 |
STATUS=$(getstatus) |
|
| 54 |
CPU=$(echo "$STATUS" | "$JQ" '.cpuPercent') |
|
| 55 |
printf "syncthing_cpu.value %s\n" "$CPU" |
|
| 51 | 56 |
esac |
| 52 | 57 |
} |
| 53 | 58 |
|
| ... | ... | |
| 67 | 72 |
EOM |
| 68 | 73 |
exit 0;; |
| 69 | 74 |
*) |
| 70 |
STATUS=$($CURL -s -X GET -H "X-API-Key: $syncthing_apikey" "$syncthing_proto"://"$syncthing_host":"$syncthing_port"/rest/system/status)
|
|
| 71 |
ALL=$(echo "$STATUS" | $JQ '.alloc')
|
|
| 72 |
SYS=$(echo "$STATUS" | $JQ '.sys')
|
|
| 73 |
printf "syncthing_mem_all.value %s\\n" "$ALL"
|
|
| 74 |
printf "syncthing_mem_sys.value %s\\n" "$SYS"
|
|
| 75 |
STATUS=$(getstatus)
|
|
| 76 |
ALL=$(echo "$STATUS" | "$JQ" '.alloc')
|
|
| 77 |
SYS=$(echo "$STATUS" | "$JQ" '.sys')
|
|
| 78 |
printf "syncthing_mem_all.value %s\n" "$ALL" |
|
| 79 |
printf "syncthing_mem_sys.value %s\n" "$SYS" |
|
| 75 | 80 |
esac |
| 76 | 81 |
} |
| 77 | 82 |
|
| ... | ... | |
| 86 | 91 |
EOM |
| 87 | 92 |
exit 0;; |
| 88 | 93 |
*) |
| 89 |
UPTIME=$($CURL -s -X GET -H "X-API-Key: $syncthing_apikey" "$syncthing_proto"://"$syncthing_host":"$syncthing_port"/rest/system/status | $JQ '.uptime') |
|
| 90 |
printf "syncthing_uptime.value %s\\n" "$UPTIME" |
|
| 94 |
STATUS=$(getstatus) |
|
| 95 |
UPTIME=$(echo "$STATUS" | "$JQ" '.uptime') |
|
| 96 |
printf "syncthing_uptime.value %s\n" "$UPTIME" |
|
| 91 | 97 |
esac |
| 92 | 98 |
} |
| 93 | 99 |
|
| ... | ... | |
| 102 | 108 |
EOM |
| 103 | 109 |
exit 0;; |
| 104 | 110 |
*) |
| 105 |
GOROUTINES=$($CURL -s -X GET -H "X-API-Key: $syncthing_apikey" "$syncthing_proto"://"$syncthing_host":"$syncthing_port"/rest/system/status | $JQ '.goroutines') |
|
| 106 |
printf "syncthing_goroutine.value %s\\n" "$GOROUTINES" |
|
| 111 |
STATUS=$(getstatus) |
|
| 112 |
GOROUTINES=$(echo "$STATUS" | "$JQ" '.goroutines') |
|
| 113 |
printf "syncthing_goroutine.value %s\n" "$GOROUTINES" |
|
| 107 | 114 |
esac |
| 108 | 115 |
} |
| 109 | 116 |
|
| ... | ... | |
| 127 | 134 |
EOM |
| 128 | 135 |
exit 0;; |
| 129 | 136 |
*) |
| 130 |
CONNECTIONS=$($CURL -s -X GET -H "X-API-Key: $syncthing_apikey" "$syncthing_proto"://"$syncthing_host":"$syncthing_port"/rest/system/connections)
|
|
| 131 |
IBT=$(echo "$CONNECTIONS" | $JQ '.total | .inBytesTotal')
|
|
| 132 |
OBT=$(echo "$CONNECTIONS" | $JQ '.total | .outBytesTotal')
|
|
| 137 |
CONNECTIONS=$("$CURL" -s -X GET -H "X-API-Key: $syncthing_apikey" "$syncthing_proto://$syncthing_host:$syncthing_port/rest/system/connections")
|
|
| 138 |
IBT=$(echo "$CONNECTIONS" | "$JQ" '.total | .inBytesTotal')
|
|
| 139 |
OBT=$(echo "$CONNECTIONS" | "$JQ" '.total | .outBytesTotal')
|
|
| 133 | 140 |
printf "syncthing_transfer_up.value %s\\n" "$IBT" |
| 134 | 141 |
printf "syncthing_transfer_down.value %s\\n" "$OBT" |
| 135 | 142 |
esac |
Formats disponibles : Unified diff