POSTED ON[](https://blog.ithasu.org/2019/01/monitoring-de-la-livebox-4-avec-grafana/)
# Monitoring de la Livebox 4 avec Grafana
- Se connecter à base de donnée avec le programme “influx”
- Utiliser la commande suivante : CREATE DATABASE monitoring;
```
{
"host": "192.168.1.1",
"password": "A lire sous la box ...",
"db": "http://localhost:8086"
}
```
```
SELECT -derivative(last("rx"), 1s) FROM "livebox" WHERE ("host" = '192.168.1.1') AND $timeFilter GROUP BY time($__interval) fill(linear)
SELECT derivative(last("tx"), 1s) FROM "livebox" WHERE ("host" = '192.168.1.1') AND $timeFilter GROUP BY time($__interval) fill(linear)
```
## Le script
```
#!/bin/bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
LIVEBOX_HOST=`jq -r .host ${DIR}/config.json`
LIVEBOX_PASS=`jq -r .pass ${DIR}/config.json`
INFLUX_URL=`jq -r .db ${DIR}/config.json`
TMP_DIR=/tmp/
myOutput=${TMP_DIR}/myOutput.txt
myCookies=${TMP_DIR}/myCookies.txt
########################################
# Connexion et recuperation du cookies #
########################################
curl -s -o "$myOutput" -X POST -c "$myCookies" -H 'Content-Type: application/x-sah-ws-4-call+json' -H 'Authorization: X-Sah-Login' -d "{\"service\":\"sah.Device.Information\",\"method\":\"createContext\",\"parameters\":{\"applicationName\":\"so_sdkut\",\"username\":\"admin\",\"password\":\"${LIVEBOX_PASS}\"}}" http://${LIVEBOX_HOST}/ws > /dev/null
##################################################
# Lecture du cookies pour utilisation ulterieure #
##################################################
myContextID=`jq -r .data.contextID $myOutput`
#######################################################
# Envoi des commandes pour recuperer les informations #
#######################################################
getDSLStats=`curl -s -b "$myCookies" -X POST -H 'Content-Type: application/x-sah-ws-4-call+json' -H "X-Context: $myContextID" -d "{\"service\":\"NeMo.Intf.dsl0\",\"method\":\"getDSLStats\",\"parameters\":{}}" http://${LIVEBOX_HOST}/ws`
TX=`echo $getDSLStats | jq -r .status.TransmitBlocks`
RX=`echo $getDSLStats | jq -r .status.ReceiveBlocks`
#################################
# Envoi des données à influx db #
#################################
curl -s -i -XPOST "${INFLUX_URL}/write?db=monitoring" --data-binary "livebox,host=${LIVEBOX_HOST} rx=${RX},tx=${TX}" > /dev/null
```