Standaard configuratie voor Prometheus:

$ mkdir ~/prometheus

$ cat >> prometheus/prometheus.yml << EOF

global:

  scrape_interval: 15s

  evaluation_interval: 30s

EOF

Docker image van Prometheus:

$ sudo docker run -d -p 9090:9090 -v /home/pi/prometheus:/etc/prometheus --restart unless-stopped --name prometheus prom/prometheus

 

Script read_p1.sh:

#!/bin/bash




stty -F /dev/ttyUSB0 raw speed 115200 > /dev/null




while true

do

                seconds=$(date +%S)

                until (( 10#$seconds % 15 == 0 ))

                do

                               sleep 1

                               seconds=$(date +%S)

                done




                echo -e "$(date +%s) \c"

                data=$(head -22 /dev/ttyUSB0 | strings)

                net_afname=$(echo "$data" | awk -F'(' '/1-0:1.7.0/ {print $2}' | awk -F'*' '{print $1}')

                net_injectie=$(echo "$data" | awk -F'(' '/1-0:2.7.0/ {print $2}' | awk -F'*' '{print $1}')

                echo "$net_afname $net_injectie"

done

 

Configuratiebestand ~/mtail/read_p1.mtail:

gauge net_afname

gauge net_injectie




/^/ +

/(?P<timestamp>\d*) / + # eerste veld: tijdstip

/(?P<afname>[0-9\.]*) / + # tweede veld: afname

/(?P<injectie>[0-9\.]*)/ + # derde veld: injectie

/$/ {

                net_afname = $afname

                net_injectie = $injectie

}

 

Installatie Grafana:

$ mkdir ~/grafana

$ sudo docker run -d --user $(id -u) -p 3000:3000 -v /home/pi/grafana:/var/lib/grafana --restart unless-stopped --name grafana grafana/grafana