macOS - Log & track historical CPU, RAM usage
Tags: devops, macbook, python
Published: 2024-06-22 13:16:11

---
title: macOS - Log & track historical CPU, RAM usage
published: true
date: 2024-05-31 20:18:02 UTC
tags: devops,macbook,python
canonical_url: https://avilpage.com/2024/06/macos-log-track-cpu-ram-usage.html
---

![macOS - Log CPU & RAM history](https://avilpage.com/images/mac-log-cpu-ram-grafana.png)

In macOS, we can use inbuilt `Activity Monitor` or third party apps like `Stats` to check the live CPU/RAM usage. But, we can't track the historical CPU & memory usage. `sar`, `atop` can track the historical CPU & memory usage. But, they are not available for macOS.

#### Netdata

Netdata<sup id="fnref:Netdata"><a href="https://avilpage.com/2024/06/macos-log-track-cpu-ram-usage.html#fn:Netdata">1</a></sup> is an open source observability tool that can monitor CPU, RAM, network, disk usage. It can also track the historical data.

Unfortunately, it is not stable on macOS. I tried installing it on multiple macbooks, but it didn't work. I raised an issue<sup id="fnref:netdata_issue"><a href="https://avilpage.com/2024/06/macos-log-track-cpu-ram-usage.html#fn:netdata_issue">2</a></sup> on their GitHub repository and the team mentioned that macOS is a low priority for them.

#### Glances

Glances<sup id="fnref:Glances"><a href="https://avilpage.com/2024/06/macos-log-track-cpu-ram-usage.html#fn:Glances">3</a></sup> is a cross-platform monitoring tool that can monitor CPU, RAM, network, disk usage. It can also track the historical data.

We can install it using Brew or pip.

```
$ brew install glances

$ pip install glances

```

Once it is installed, we can monitor the resource usage using the below command.

```
$ glances

```

![macOS - Log CPU & RAM history](https://avilpage.com/images/mac-log-cpu-ram-glances.png)

Glances can log historical data to a file using the below command.

```
$ glances --export-csv /tmp/glances.csv

```

In addition to that, it can log data to services like influxdb, prometheus, etc.

Let's install influxdb and export stats to it.

```
$ brew install influxdb
$ brew services start influxdb
$ influx setup

$ python -m pip install influxdb-client

$ cat glances.conf
[influxdb]
host=localhost
port=8086
protocol=http
org=avilpage
bucket=glances
token=secret_token

$ glances --export-influxdb -C glances.conf

```

We can view stats in the influxdb from Data Explorer web UI at [http://localhost:8086](http://localhost:8086).

![macOS - Log CPU & RAM history](https://avilpage.com/images/mac-log-cpu-ram-influxdb.png)

Glances provides a prebuilt Grafana dashboard<sup id="fnref:grafana_dashboard"><a href="https://avilpage.com/2024/06/macos-log-track-cpu-ram-usage.html#fn:grafana_dashboard">4</a></sup> that we can import to visualize the stats.

From Grafana -> Dashboard -> Import, we can import the dashboard using the above URL.

![macOS - Log CPU & RAM history](https://avilpage.com/images/mac-log-cpu-ram-grafana.png)

#### Conclusion

In addition to InfluxDB, Glances can export data to ~20 services. So far, it is the best tool to log, track and view historical CPU, RAM, network and disk usage in macOS. The same method works for Linux and Windows as well.

* * *

1. [https://github.com/netdata/netdata](https://github.com/netdata/netdata) [↩](https://avilpage.com/2024/06/macos-log-track-cpu-ram-usage.html#fnref:Netdata "Jump back to footnote 1 in the text")

2. [https://github.com/netdata/netdata/issues/16696](https://github.com/netdata/netdata/issues/16696) [↩](https://avilpage.com/2024/06/macos-log-track-cpu-ram-usage.html#fnref:netdata_issue "Jump back to footnote 2 in the text")

3. [https://github.com/niolargo/glances](https://github.com/nicolargo/glances) [↩](https://avilpage.com/2024/06/macos-log-track-cpu-ram-usage.html#fnref:Glances "Jump back to footnote 3 in the text")

4. [https://glances.readthedocs.io/en/latest/gw/influxdb.html#grafana](https://glances.readthedocs.io/en/latest/gw/influxdb.html#grafana) [↩](https://avilpage.com/2024/06/macos-log-track-cpu-ram-usage.html#fnref:grafana_dashboard "Jump back to footnote 4 in the text")