Tag: grafana

How to update Grafana from version 4 to version 5

Grafana is a wonderful tool to display time series ans a lot of different metrics
The project is in a very active development state , and new features are added constantly.

The version 5 is particularly desirable since a new layout engine for the dashboard has been developed, and is quite powerfull !

So to update your install of Grafana from 4 to 5 you need to launch several command with root or a privileged user.

The service should automaticly restart when the update is done , but check that it is running with :

service grafana-server status

You should see something like this

? grafana-server.service – Grafana instance
Loaded: loaded (/usr/lib/systemd/system/grafana-server.service; disabled)
Active: active (running) since ven. 2018-04-20 17:47:41 CEST; 1 day 22h ago

grafana service doesn’t auto start with the system

When installing grafana and influxDB. I encountered the folowing issue

The service of grafana and influxDB where not starting .

I checked using rcconf that my service where enabled , and they where !

I then tried sysv-rc-conf and my service where correctly configured !

the services had absolutely no issue starting when called manually and started fine !


this line was telling me that the service startup was disabled !

after seaching a bit on the web ,the solution to this issue is using systemctl to enables the services.

add custom metrics in influxDB

 

If you have a influxdb server running , there is some data collector like Collectd that can be used to automatically write data in your database.
But collectd is very difficult to personalise. and the documentation is pretty bad, (try using the curl plugin and greping data)
You can’t easily add the result of a piped bash command to the collected data for example.

in my case i’ve decided to ignore these pre made solutions that never completely satisfy my needs or write exactly the value i want in the database,

there is a simple way to use a http request to write in the influxDB database.
first before you even write something in ingluxDB, you have to create a database (you only have to launch this command once)

curl -G http://localhost:8086/query --data-urlencode "q=CREATE DATABASE metrics"

then lets say i want to log every 5min the disk usage in percent of my primary storage device. which is named /dev/mmcblk0p1

the df command is only giving me a rounded value : for example 22%

for my example i want a much more precise percentage ,  this little script does exactly that.

#!/bin/bash
#change mmc by the name of your drive , ex: sdba
df_total=$(df |grep mmc |awk -F' ' '{print $2}')
df_used=$(df |grep mmc |awk -F' ' '{print $3}')
df=$(echo "$df_used * 100 / $df_total" | bc -l | head -c 6)
curl -i -XPOST 'http://localhost:8086/write?db=metrics' --data-binary "disc_space,df=used value=$df"

this is writing in the database metrics the percentage used with 3 decimals if you are using 10% or more and 4 decimals if you use 10% or less
the changing precision is not a concern in my use case.

then if you want a value every 5min for example do a crontab -e  and add the line :

*/5 * * * * bash /root/myscript.sh

 

you can then use grafana for example to graph the data.

install Grafana 5 on a PI

If you have a OrangePi or a raspberry pi ,

there is high chance that the version of grafana package in the repositories of your distribution is outdated
in my case , i use armbian , the repo is from ubuntu xenial .

the version of Grafana in the xenial repo is antique (grafana 2.6.0) and the version is bugged if you use a Headless version of the os ,
the icon are not displayed when you are connected to the grafana interface. (because of a bug in phantomJS).

if you have already the 2.6.0 runing , remove it first

apt-get remove grafana

Then use this page to download a recent version of grafana compiled to run on a arm cpu

wget https://github.com/fg2it/grafana-on-raspberry/releases/download/v5.0.4/grafana_5.0.4_armhf.deb
then 
dpkg -i grafana_5.0.4_armhf.deb

if the grafana service is not auto starting at the system boot , you can launch that command :

systemctl enable grafana-server.service

you can check with netstat that your grafana service is running if your server is listening on the tcp port 3000

netstat -tcp -l

now start your browser and try to connect to http://ip-of-your-server:3000