---
# System prepended metadata

title: Monitoring CPU & Memory Using Glances & Grafana

---

# Monitoring CPU & Memory Using Glances & Grafana

This page describes the steps for setting up a [Grafana](https://grafana.com) dashboard to monitor system CPU & Memory over time, using data collected from [Glances](https://glances.readthedocs.io/en/latest/).

![](https://i.imgur.com/OckKc8M.png)

## Set up Glances Grafana Dashboard

### Install and start InfluxDB

[InfluxDB](https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=&cad=rja&uact=8&ved=2ahUKEwiImLeqgvH8AhWzSmwGHVdSABMQFnoECAoQAQ&url=https%3A%2F%2Fwww.influxdata.com%2F&usg=AOvVaw0OrrIidHZarR-ez1tpqJ0W) 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](https://glances.readthedocs.io/en/latest/config.html).

```wrap!
# 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](https://grafana.com/grafana/dashboards/2387-glances-for-flux/)** 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/