This guide shows the steps needed to setup Mactop for use with Grafana using Prometheus as a data source.
Mactop is a resource monitor tool for use on the terminal.
You can use it like you would use tools like top, htop, btop, asitop, etc.
One of the "extra features" you get with MacTop is a built-in Prometheus exporter. This will let you use Mactop as a datasource for Prometheus.
Prometheus is a monitor system that is capable of collecting data (scraping) from several sources, and keeping it organized in a database. It then acts as query engine and alerting source for other software. In this case we want to use it as a query engine for Grafana.
Grafana is a powerfull dashboard platform. In this case we just want to create a dashboard that shows the information exported by Mactop and collected by Prometheus.
What follows is a description of such a basic setup.
# Update brew package list
brew update
# Upgrade brew packages# Check Package Info
brew info mactop
# Install mactop
brew install mactop# Check Package Info
brew info prometheus
# Install mactop
brew install prometheus# Check Package Info
brew info grafana
# Install mactop
brew install grafanaTo edit your Prometheus configuration file:
# Use vi or your favorite editor to modify prometheus.yml
vi $(brew --prefix)/etc/prometheus.ymlThe file should look like:
global:
scrape_interval: 5s
scrape_configs:
- job_name: "prometheus"
static_configs:
- targets: ["localhost:9090"]Add the following text to it:
- job_name: "mactop"
static_configs:
- targets: ["localhost:9101"]It should end up looking like this:
global:
scrape_interval: 5s
scrape_configs:
- job_name: "prometheus"
static_configs:
- targets: ["localhost:9090"]
- job_name: "mactop"
static_configs:
- targets: ["localhost:9101"]To check brew services status:
# List brew services
brew services listStart the services:
brew services start mactop
brew services start prometheus
brew services start grafanaYou will need to access grafana using a browser. Open the following url: http://localhost:3000
You will be asked to provide an admin password. Take note of the password you used.
Go to the Connections menu item and select Add new connection.
This will normally take you to http://localhost:3000/connections/add-new-connection
Search for Prometheus and click on it (should show you a page for the Prometheus Native Plugin).
Click on the Add new data source button:
- On the
Prometheus URLfield puthttp://localhost:9090 - Click Save & Test
Go to the Dashboard menu item:
- Click
New->Import dashboarditem. - It should take you to http://localhost:3000/dashboard/import
- Search for dashboard ID 22454
- Click on the
ImportButton.
You should now be able to access de Mactop dashboard in the dashboard menu.
If you lose your Grafana password and need to reset use this:
# Stop service
brew services stop grafana
# Get --config and --homepad paths
brew info grafana
# Copy the paths shown and use them in the command below
# Change Password
grafana cli \
--config /opt/homebrew/etc/grafana/grafana.ini \
--homepath /opt/homebrew/opt/grafana/share/grafana \
admin reset-admin-password 'YourNewPassword'
# Start service again
brew services start grafana