Try   HackMD

Monitoring CPU & Memory Using Glances & Grafana

This page describes the steps for setting up a Grafana dashboard to monitor system CPU & Memory over time, using data collected from Glances.

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Set up Glances Grafana Dashboard

Install and start InfluxDB

InfluxDB is used to store timeseries data exported from Glances.

brew install influxdb
influxd

Go to http://localhost:8086 and do the following via the InfluxDB UI:

  • Create a bucket and name it glances
  • Create an API token

Install and start Glances

pip3 install glances==3.2.7
pip3 install bottle
pip3 install influxdb-client

Note: I was getting a TypeError on latest version of glances (3.3.1), and installing 3.2.7 fixed the issue.

Create a glances config file (MacOS example below). For config file paths on other operating systems, see documentation.

# Create directory
mkdir "$HOME/Library/Application Support/glances"

# Create config file
cat > "$HOME/Library/Application Support/glances/glances.conf" << EOF
[influxdb2]
host=localhost
port=8086
protocol=http
org=<enter your org name>
bucket=glances
token=TsAfocp8ynW3idpvavB4l3ld6h9KzTPvhLobv2qpBeCk4VO3Gqk-EqLNilmyRaWIscbdcbmxjvyqbH_d20m5cA==
EOF

Start Glances and export to InfluxDB:

glances -t 5 --export influxdb2

Install and start Grafana

brew install grafana
brew services start grafana

Go to http://localhost:3000 to view the Grafana UI, and do the following:

  1. Add Data Source: go to configuration and add a InfluxDB data source, and enter the following:
    • HTTP URL: http://localhost:8086
    • InfluxDB Details / Organization
    • InfluxDB Details / Token
    • then click [Save & Test]
  2. Import this dashboard by ID: 2387

Shutting down the services

glances and influxd can be stopped by sending the SIGINT signal to terminal (Ctrl + C)

To stop Grafana:

brew services stop grafana

Reference: https://grafana.com/grafana/dashboards/2387-glances-for-flux/