Révision 99123efb
Make syncthing_ more portable
Signed-off-by: Pierre-Alain TORET <pierre-alain.toret@protonmail.com>
| plugins/syncthing/syncthing_ | ||
|---|---|---|
| 1 |
#!/bin/sh
|
|
| 1 |
#!/usr/bin/env bash
|
|
| 2 | 2 |
# -*- sh -*- |
| 3 | 3 |
: <<=cut |
| 4 | 4 |
=head1 NAME |
| ... | ... | |
| 8 | 8 |
This plugin gathers metrics from a Syncthing server. |
| 9 | 9 |
|
| 10 | 10 |
This plugin requires the jq utility : https://stedolan.github.io/jq/ |
| 11 |
This plugin requires the cURL utility : https://curl.haxx.se/ |
|
| 11 | 12 |
|
| 12 | 13 |
Available plugins : |
| 13 | 14 |
syncthing_cpu # |
| ... | ... | |
| 46 | 47 |
exit 0;; |
| 47 | 48 |
*) |
| 48 | 49 |
printf "syncthing_cpu.value " |
| 49 |
curl -s -X GET -H "X-API-Key: $ST_APIKEY" $ST_PROTO://$ST_HOST:$ST_PORT/rest/system/status | jq '.cpuPercent'
|
|
| 50 |
$CURL -s -X GET -H "X-API-Key: $ST_APIKEY" $ST_PROTO://$ST_HOST:$ST_PORT/rest/system/status | $JQ '.cpuPercent'
|
|
| 50 | 51 |
esac |
| 51 | 52 |
} |
| 52 | 53 |
|
| ... | ... | |
| 66 | 67 |
EOM |
| 67 | 68 |
exit 0;; |
| 68 | 69 |
*) |
| 69 |
ALL=$(curl -s -X GET -H "X-API-Key: $ST_APIKEY" $ST_PROTO://$ST_HOST:$ST_PORT/rest/system/status | jq '.alloc')
|
|
| 70 |
SYS=$(curl -s -X GET -H "X-API-Key: $ST_APIKEY" $ST_PROTO://$ST_HOST:$ST_PORT/rest/system/status | jq '.sys')
|
|
| 70 |
ALL=$($CURL -s -X GET -H "X-API-Key: $ST_APIKEY" $ST_PROTO://$ST_HOST:$ST_PORT/rest/system/status | $JQ '.alloc')
|
|
| 71 |
SYS=$($CURL -s -X GET -H "X-API-Key: $ST_APIKEY" $ST_PROTO://$ST_HOST:$ST_PORT/rest/system/status | $JQ '.sys')
|
|
| 71 | 72 |
printf "syncthing_mem_all.value $ALL\nsyncthing_mem_sys.value $SYS\n" |
| 72 | 73 |
esac |
| 73 | 74 |
} |
| ... | ... | |
| 84 | 85 |
exit 0;; |
| 85 | 86 |
*) |
| 86 | 87 |
printf "syncthing_uptime.value " |
| 87 |
curl -s -X GET -H "X-API-Key: $ST_APIKEY" $ST_PROTO://$ST_HOST:$ST_PORT/rest/system/status | jq '.uptime'
|
|
| 88 |
$CURL -s -X GET -H "X-API-Key: $ST_APIKEY" $ST_PROTO://$ST_HOST:$ST_PORT/rest/system/status | $JQ '.uptime'
|
|
| 88 | 89 |
esac |
| 89 | 90 |
} |
| 90 | 91 |
|
| ... | ... | |
| 100 | 101 |
exit 0;; |
| 101 | 102 |
*) |
| 102 | 103 |
printf "syncthing_goroutine.value " |
| 103 |
curl -s -X GET -H "X-API-Key: $ST_APIKEY" $ST_PROTO://$ST_HOST:$ST_PORT/rest/system/status | jq '.goroutines'
|
|
| 104 |
$CURL -s -X GET -H "X-API-Key: $ST_APIKEY" $ST_PROTO://$ST_HOST:$ST_PORT/rest/system/status | $JQ '.goroutines'
|
|
| 104 | 105 |
esac |
| 105 | 106 |
} |
| 106 | 107 |
|
| ... | ... | |
| 124 | 125 |
EOM |
| 125 | 126 |
exit 0;; |
| 126 | 127 |
*) |
| 127 |
IBT=$(curl -s -X GET -H "X-API-Key: $ST_APIKEY" $ST_PROTO://$ST_HOST:$ST_PORT/rest/system/connections | jq '.total | .inBytesTotal')
|
|
| 128 |
OBT=$(curl -s -X GET -H "X-API-Key: $ST_APIKEY" $ST_PROTO://$ST_HOST:$ST_PORT/rest/system/connections | jq '.total | .outBytesTotal')
|
|
| 128 |
IBT=$($CURL -s -X GET -H "X-API-Key: $ST_APIKEY" $ST_PROTO://$ST_HOST:$ST_PORT/rest/system/connections | $JQ '.total | .inBytesTotal')
|
|
| 129 |
OBT=$($CURL -s -X GET -H "X-API-Key: $ST_APIKEY" $ST_PROTO://$ST_HOST:$ST_PORT/rest/system/connections | $JQ '.total | .outBytesTotal')
|
|
| 129 | 130 |
printf "syncthing_transfer_up.value $IBT\nsyncthing_transfer_down.value $OBT\n" |
| 130 | 131 |
esac |
| 131 | 132 |
} |
| 132 | 133 |
|
| 133 | 134 |
cd $(dirname $0) |
| 134 | 135 |
|
| 136 |
CURL=$(which curl) |
|
| 137 |
JQ=$(which jq) |
|
| 138 |
|
|
| 135 | 139 |
case $(basename $0) in |
| 136 | 140 |
syncthing_cpu) |
| 137 | 141 |
cpu $1 |
Formats disponibles : Unified diff