Guida Grafana & MySQL su Raspberry pi

Roronoa Zoro

Utente Emerald
14 Ottobre 2016
739
95
269
525
Questa guida è stata fatta per gli utenti che, come me, hanno la necessità di installare grafera su database MySQL. Parto con il fatto che la versione di raspbian che sto usando è quella più recente (November 2018). Prima di cominciare con la guida vera e propria, andiamo a capire che cos'è Grafana:

1543315016506.png


Grafana in poche parole è un software opensource di monitoraggio e analisi dei dati, serve per avere una "dashboard" magari dei server che avete e vedere le risorse libere o occupate, anche da fuori casa per esempio...

Ma ora senza perderci in chiacchere vi dico che potete tranquillamente vedere che cosa è grafana al seguente link: https://grafana.com/

1543316982641.png
Installare grafana:

Come prima cosa dobbiamo aggiornare il nostro raspberry, digitando:

sudo apt-get update && sudo apt-get upgrade


\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Installazione di MySQL:

Ora andiamo ad installare il Database MySQL semplicemente scrivendo:

sudo apt-get install mysql-server –fix-missing

e poi

sudo apt-get install mysql-client

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Installazione di CURL

Andiamo ad installare CURL:

digitando:

sudo apt-get install apt-transport-https curl

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Update delle risorse del Rasp.

Ora andiamo ad aggiornare le risorse del raspberry digitando:

echo "deb https://dl.bintray.com/fg2it/deb jessie main" | sudo tee -a /etc/apt/sources.list.d/grafana.list

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Installazione di Grafana

Questa è l'installazione vera e propria del software Grafana, si scaricherà automaticamente l'ultima versione disponibile.

sudo apt-get update

sudo apt-get install grafana

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Avviare Grafana in http e configurazione avvio automatico al boot

Questo comando servirà per avviare il servizio di Grafana (porta 3000) e per far si che grafana si avvii ogni volta automaticamente all'avvio del raspberry, come se fosse un servizio nomalissimo di sistema.

sudo service grafana-server start

e

sudo systemctl enable grafana-server.service

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Avviamo MySQL

Per avviare MySQL digitiamo:

sudo mysql -u root -p

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Creiamo e usiamo il DB

Ora andiamo a creare ed usare il DB quindi scriviamo il seguente codice (Creiamo il database Raspberry pi e poi Usiamo il database Raspberry PI)

CREATE DATABASE RASPBERRY_PI;
use RASPBERRY_PI;


\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Creiamo la tabella con le colonne:

Ora andiamo a creare una tabella esempio con colonne a caso:

CREATE TABLE logger (DATE DATETIME, TEMPERATURE FLOAT, PRESSURE FLOAT, HUMIDITY FLOAT);

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Creiamo l'utente per Grafana

CREATE USER 'nomeutente'@'localhost' IDENTIFIED BY 'identificativo';
set password for 'nomeutente'@'localhost' = PASSWORD('metti-qui-la-password');


**ricordatevi questi parametri, vi serviranno dopo.

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Impostiamo gli accessi all'utente creato

Ora andiamo ad impostare gli accessi consentiti per l'utente che abbiamo appena creato:

GRANT ALL PRIVILEGES ON RASPBERRY_PI.* TO 'nomeutente'@'localhost';

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Aggiornamento dei Privilegi e uscita da MySQL

FLUSH PRIVILEGES;

E usciamo da MySQL digitando:

exit;

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Connettiamo Grafana a MySQL

Accedendo a Grafana (clicca QUI per accedere a Grafana se non lo hai ancora fatto) e accedendo con username : password = admin : admin.

Andiamo su "Add a new data source" e clicchiamo su MySQL e configuriamo con i seguenti dati:

Andiamo su “add a new data source”(MYSQL) e compiliamo I seguenti dati:
Name: Nome che vogliamo,
Type: MySQL
Host: localhost:3306
Database Name: Nome del database creato precedentemente
User: utente che abbiamo scelto
Password: Password che abbiamo scelto.


\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

Ottimo, ora avete Grafana collegato con il DB che avete creato, dove ora è possibile prendere i dati e rappresentarli su grafana. Per altre informazioni andate sul link che vi metto qui sotto, è la documentazione originale consiltabile gratuitamente e potete anche domandare sul forum grafera, che è pieno di sviluppatori.
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Official Grafana Documentation
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\


Guida relizzata interamente da me : M.L.. alias: Vladimir Putin.

Download
 
  • Mi piace
Reazioni: Psychonaut