Grafana Monitoring Dashboard

Monitor
Published

January 19, 2016

Modified

May 3, 2024

Grafan 1 is an open source dashboard to present monitoring metrics:

Installation

# Open source Grafana
podman run -d -p 3000:3000 --name=grafana \
           -v grafana-storage:/var/lib/grafana \
           grafana/grafana-oss

Install Grafana using the official container container:

  • Defaults to HTTP port 3000, with default user/password admin.
  • Grafana uses an embedded SQLite version 3 database to store configuration…

Environment Variables

Set an environment variable to run in debug mode:

podman run -d -p 3000:3000 --name=grafana \
           -v grafana-storage:/var/lib/grafana \
           -e "GF_LOG_LEVEL=debug" \
           grafana/grafana-oss
  • …override existing options …naming convention GF_<SectionName>_<KeyName>
  • Reference the grafana.ini
    • …section name text within the brackets
    • …all text uppercase …replace .- with underscore

Configuration File

Use a configuration file…

mkdir /etc/grafana /var/lib/grafana

# …dummy configuration file example
cat > /etc/grafana/grafana.ini <<EOF
# default section
instance_name = my-instance

[security]
admin_user = admin
admin_password = secret123 

[paths]
data = /srv/grafana
logs = /var/log/grafana
plugins = /var/lib/grafana/plugins
provisioning = /etc/grafana/provisioning
EOF

# …mount the configuration into the container
podman run -d -p 3000:3000 --name=grafana \
           -v /etc/grafana/:/etc/grafana:ro \
           -v /srv/grafana:/srv/grafana:rw,U,Z
           -v /var/lib/grafana:/var/lib/grafana:rw,U,Z \
           grafana/grafana-oss:10.2.6

Systemd Unit

Create a systemd service unit for the container:

cd /etc/systemd/system

# …generate the service unit file …name is prefixed with `container-`
podman generate systemd --files --name grafana

# …make sure to start Grafana on boot
systemctl enable --now container-grafana.service

Configuration

File Description
/etc/grafana/grafana.ini Local custom configuration file

Configure Grafana 2 using a custom configuration file:

  • …default settings in $WORKING_DIR/conf/defaults.ini
  • …default path overwritten with option --config
  • ; semicolons for comments
  • Structured into sections …for example [server] …notable sections:
    • paths …data store, log file & provisioning
    • server …ports, certificates, HTTPS, routes
    • database …for users, dashboards, etc
    • security …admins login, HTTP security, etc
    • users …sign-up, themes, language, etc
    • auth.* …external identity providers
    • log.* …all about access/error logs
    • …and more

Provisioning

Provisioning system that uses configuration files 3:

  • Configure where to find the provisioning directory with paths.provisioning
  • Add YAML configuration files to …updated during (re-)start

Assumes following directory structure:

Path Description
provisioning/datasources/ …each file can contain a list of datasources 4
provisioning/plugins/ …manage plugin applications
provisioning/dashboards/ …manage dashboards
provisioning/notifiers …alerting resources

Data Sources

Create a data source manifest:

mkdir -p /etc/grafana/provisioning/datasources
cat > /etc/grafana/provisioning/datasources/promehteus.yml <<EOF
datasources:
- name: prometheus
  type: prometheus
  url: http://localhost:9090
EOF

Dashboards

Create a dashboard manifest 5 & dashboard definition 6:

mkdir -p /etc/grafana/provisioning/dashboards
cat > /etc/grafana/provisioning/dashboards/node-exporter.yml <<EOF
apiVersion: 1
providers:
  - name: Node-Exporter
    folder: Node-Exporter
    type: file
    disableDeletion: false
    allowUiUpdates: true
    options:
      path: /var/lib/grafana/dashboards/node-exporter
EOF

mkdir -p /var/lib/grafana/dashboards/node-exporter
# download a dashboard definition for the Node-Exporter
wget -O /var/lib/grafana/dashboards/node-exporter/dashboard.json \
  https://raw.githubusercontent.com/rfmoz/grafana-dashboards/master/prometheus/node-exporter-full.json
  • …regular checks for changes to the dashboard definitions (defaults 10s)
  • …community references dashboards on a search page 7
  • allowUiUpdates …allows to make changes to the dashboard
    • …not saved back to the provisioning source!
    • …changes persist in the Grafana database
    • …changes overwritten by updated to the provisioning source
    • …use export to preserver the dashboard
  • disableDeletion …deletes dashboards from the database if provisioning source removed

Grafana CLI

# execute Grafana CLI in a container
podman exec -it grafana grafana cli --help

Grafana CLI 8 …bundled with Grafana server

# Reset the admin password…
grafana cli admin reset-admin-password secret123
  • …some basic administrative functions
  • …primarily used to manage plugins

Upgrades

Upgrade Grafana 9 …to any of the supported releases:

  • …upgrades are backward compatible between supported versions
  • Breaking changes 10 …require modifications on the user side