services: Add mqtt-graphite
This commit is contained in:
parent
0e75ce25c5
commit
3716997783
5 changed files with 69 additions and 0 deletions
20
roles/services/templates/mqtt-graphite.sh
Normal file
20
roles/services/templates/mqtt-graphite.sh
Normal file
|
@ -0,0 +1,20 @@
|
|||
#!/bin/bash
|
||||
|
||||
GRAPHITE_HOST="100.64.0.11"
|
||||
GRAPHITE_PORT="2003"
|
||||
|
||||
set -eu
|
||||
set -o pipefail
|
||||
|
||||
mqtt-simple -h {{ mqtt_internal_host }} -t "#" |
|
||||
while read line; do
|
||||
topic=$(echo "$line" | cut -d' ' -f1 | sed 's/\//./g' | tr '[:upper:]' '[:lower:]')
|
||||
value=$(echo "$line" | cut -s -d' ' -f2- | sed 's/closed/0/g;s/open/1/g')
|
||||
|
||||
# Only relay numeric values.
|
||||
if [[ $value =~ ^-?[0-9]+\.?[0-9]*$ ]]; then
|
||||
echo "$topic $value $(date +%s)" | nc -q0 "$GRAPHITE_HOST" "$GRAPHITE_PORT"
|
||||
echo "$topic $value $(date +%s)"
|
||||
fi
|
||||
done
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue