Install and configure a Grafana server: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
== Install Grafana and the sqlite plugin == | |||
* Create a bare-bones nw server - no host-classes needed, just an IP address and host | * Create a bare-bones nw server - no host-classes needed, just an IP address and host | ||
Line 20: | Line 22: | ||
*(Re)tart the service: | *(Re)tart the service: | ||
<code>systemctl restart grafana-server</code> | <code>systemctl restart grafana-server</code> | ||
== Create the database == | |||
* Create schema.sql: | * Create schema.sql: | ||
Line 36: | Line 40: | ||
sqlite3 /var/lib/grafana/data.db < schema.sql | sqlite3 /var/lib/grafana/data.db < schema.sql | ||
chown grafana. /var/lib/grafana/data.db</pre> | chown grafana. /var/lib/grafana/data.db</pre> | ||
== Set up the stat-gathering == | |||
* Install snmpget: | * Install snmpget: | ||
Line 41: | Line 47: | ||
* Default snmp mibs seem to be broken out of the box; lots of errors from snmpget. | * Default snmp mibs seem to be broken out of the box; lots of errors from snmpget. | ||
* | * I had to copy some files from a working box: | ||
<pre> | <pre> | ||
scp nw-syd-monitor1:/usr/share/snmp/mibs/IANA-ADDRESS-FAMILY-NUMBERS-MIB.txt /usr/share/snmp/mibs/ | scp nw-syd-monitor1:/usr/share/snmp/mibs/IANA-ADDRESS-FAMILY-NUMBERS-MIB.txt /usr/share/snmp/mibs/ | ||
Line 47: | Line 53: | ||
mv /usr/share/snmp/mibs/UCD-SNMP-MIB.txt /usr/share/snmp/mibs/UCD-SNMP-MIB-old.txt | mv /usr/share/snmp/mibs/UCD-SNMP-MIB.txt /usr/share/snmp/mibs/UCD-SNMP-MIB-old.txt | ||
scp nw-syd-monitor1:/usr/share/snmp/mibs/UCD-SNMP-MIB.txt /usr/share/snmp/mibs/</pre> | scp nw-syd-monitor1:/usr/share/snmp/mibs/UCD-SNMP-MIB.txt /usr/share/snmp/mibs/</pre> | ||
::- I don't know why, and I don't like it. | |||
* Create script to populate the db - /usr/local/infrastructure/bin/getstats.sh (look in ~jbc/Projects/nw-k17-grafana) | * Create script to populate the db - /usr/local/infrastructure/bin/getstats.sh (look in ~jbc/Projects/nw-k17-grafana) | ||
Line 56: | Line 62: | ||
<code>scp acoustics:/import/acoustics/1/status/infoterm/nagios-stat /usr/local/infrastructure/bin</code> | <code>scp acoustics:/import/acoustics/1/status/infoterm/nagios-stat /usr/local/infrastructure/bin</code> | ||
* The need for nagios-stat will go away once everything is new-world and we can just use snmp | * The need for nagios-stat will go away once everything is new-world and we can just use snmp | ||
* add /etc/cron.d/getstats | |||
* | <code>* * * * * grafana /usr/local/infrastructure/bin/getstats.sh 2>&1 > /dev/null</code> | ||
== Configure the Grafana app == | |||
* http to port 3000 on the machine, and log in. Default password is admin:admin - you'll be prompted to change it immediately. | |||
* Create a new dashboard | |||
* In the Dashboard Settings (top right, in the new dashboard), create variables for each row you want to populate - following the hosttype values in the database. | |||
* For instance, backendhosts => <code>select distinct(hostname) from stats where hosttype="backend"</code>, ensure that Multi-value, All-option and Sort are all enabled. | |||
* In the dropdown for each variable, select 'All'. | |||
* Now create a new row, name it eg. Backend Hosts, and expand it. | |||
* Create a new panel, and drag it into the row. | |||
* Edit the panel from its little dropdown | |||
* Set the panel type to 'Stat', set its repeat value to eg. backendhosts, and max per row = 12 | |||
* Blow away the existing query, and add eg. | |||
<pre> | |||
SELECT ts, value | |||
FROM stats | |||
WHERE hostname='$backendhosts' | |||
AND metric="load" | |||
</pre> | |||
::- note the different quotes for the two fields. | |||
::- you don't need to worry about the time range, as we're already pruning the whole db to the range we want. | |||
* Pick the other options to make it look pretty - set background colour mode, create thresholds as appropriate, set Title to eg. $backendhosts | |||
* Save and return to the dashboard, *save* the dashboard, then refresh the page. The row should auto-populate with a panel for each hosts. | |||
* Drag them to a reasonable size. | |||
* Rinse and repeat for the other rows - and a panel below for metric="user" for the rows that need a user-count. Leave the title blank for that one, to save space. |
Revision as of 17:18, 19 August 2022
Install Grafana and the sqlite plugin
- Create a bare-bones nw server - no host-classes needed, just an IP address and host
- Add the Grafana repository to
/etc/apt/sources.list.d/grafana.list
:
deb https://packages.grafana.com/enterprise/deb stable main
- Grab the Grafana gpg key to allow installation from the repository:
apt install -y apt-transport-https software-properties-common wget gnupg wget -q -O - https://packages.grafana.com/gpg.key cat gpg.key | gpg --dearmor -o /etc/apt/trusted.gpg.d/grafana.gpg
- Install the Grafana package:
apt update && apt install grafana-enterprise
- Install sqlite3:
apt install sqlite3
- Install sqlite3 datasource plugin for grafana:
grafana-cli plugins install frser-sqlite-datasource
- (Re)tart the service:
systemctl restart grafana-server
Create the database
- Create schema.sql:
CREATE TABLE stats ( ts integer not null, hostname text not null, metric text not null, value real not null, hosttype text not null );
- Create grafana database:
sqlite3 /var/lib/grafana/data.db < schema.sql chown grafana. /var/lib/grafana/data.db
Set up the stat-gathering
- Install snmpget:
apt install snmp
- Default snmp mibs seem to be broken out of the box; lots of errors from snmpget.
- I had to copy some files from a working box:
scp nw-syd-monitor1:/usr/share/snmp/mibs/IANA-ADDRESS-FAMILY-NUMBERS-MIB.txt /usr/share/snmp/mibs/ scp nw-syd-monitor1:/usr/share/snmp/mibs/RFC-1215.txt /usr/share/snmp/mibs/ mv /usr/share/snmp/mibs/UCD-SNMP-MIB.txt /usr/share/snmp/mibs/UCD-SNMP-MIB-old.txt scp nw-syd-monitor1:/usr/share/snmp/mibs/UCD-SNMP-MIB.txt /usr/share/snmp/mibs/
- - I don't know why, and I don't like it.
- Create script to populate the db - /usr/local/infrastructure/bin/getstats.sh (look in ~jbc/Projects/nw-k17-grafana)
- Or roll your own. to use snmpget and/or nagios-stat to gather load / usercount and populate the table.
- Hosttype column to distinguish different classes of hosts, to populate the different rows in grafana
- Prune stats older than 60 minutes at the end of the script
- Copy in nagios-stat script from acoustics:
scp acoustics:/import/acoustics/1/status/infoterm/nagios-stat /usr/local/infrastructure/bin
- The need for nagios-stat will go away once everything is new-world and we can just use snmp
- add /etc/cron.d/getstats
* * * * * grafana /usr/local/infrastructure/bin/getstats.sh 2>&1 > /dev/null
Configure the Grafana app
- http to port 3000 on the machine, and log in. Default password is admin:admin - you'll be prompted to change it immediately.
- Create a new dashboard
- In the Dashboard Settings (top right, in the new dashboard), create variables for each row you want to populate - following the hosttype values in the database.
- For instance, backendhosts =>
select distinct(hostname) from stats where hosttype="backend"
, ensure that Multi-value, All-option and Sort are all enabled. - In the dropdown for each variable, select 'All'.
- Now create a new row, name it eg. Backend Hosts, and expand it.
- Create a new panel, and drag it into the row.
- Edit the panel from its little dropdown
- Set the panel type to 'Stat', set its repeat value to eg. backendhosts, and max per row = 12
- Blow away the existing query, and add eg.
SELECT ts, value FROM stats WHERE hostname='$backendhosts' AND metric="load"
- - note the different quotes for the two fields.
- - you don't need to worry about the time range, as we're already pruning the whole db to the range we want.
- Pick the other options to make it look pretty - set background colour mode, create thresholds as appropriate, set Title to eg. $backendhosts
- Save and return to the dashboard, *save* the dashboard, then refresh the page. The row should auto-populate with a panel for each hosts.
- Drag them to a reasonable size.
- Rinse and repeat for the other rows - and a panel below for metric="user" for the rows that need a user-count. Leave the title blank for that one, to save space.