Monitoring a Linux host using Prometheus and node_exporter
This guide will show you how to install Prometheus and node_exporter to a Linux node and use them to push metrics to Grafana Cloud. Then it will show you how to install a preconfigured dashboard or create your own to visualize those metrics.
A Grafana Cloud account, as shown in Quickstarts.
A Grafana Cloud API key with the Admin role
A Linux machine
Command line (terminal) access to that Linux machine
Account permissions sufficient to install
wgeton the Linux machine
Install and run node_exporter on the node
Download the node_exporter compressed package.
Extract the node_exporter binary, which will collect metrics from the Linux machine, format those metrics in a Prometheus format, and provide those metrics on an internal port for Prometheus to scrape.
tar xvfz node_exporter-*.*-amd64.tar.gz
Change to the directory created during extraction.
Make the node_exporter binary executable.
chmod +x node_exporter
Run the node_exporter binary.
Test that metrics are being exported on port 9100.
If you see metrics on your screen, all is well. If not, check your steps for typos, make sure the binary is executable, and whether curl works with other URLs.
If you don’t want to start node_exporter directly from the command line, you can create a systemd service for it, similar to Creating a systemd service to manage the agent.
Install Prometheus on the node
Next, we will download and install Prometheus on the node to scrape the metrics being provided by node_exporter and send them to Grafana Cloud. Prometheus collects metrics and makes them available for searching and visualization. Typically, Prometheus pulls metrics from configured sources, but we will use the
remote_write feature which will push metrics from Prometheus to Grafana Cloud.
Download the Prometheus compressed package.
Extract the binary.
tar xvf prometheus-*.*-amd64.tar.gz
Change to the directory created during extraction.
Create a configuration file for Prometheus, so that it can scrape the metrics and to send them to Grafana Cloud. This configuration file has many options. For our example, it only needs three sections:
globalis the section into which configurations common across all Prometheus actions are placed. In this example, we set the
scrape_intervalfor checking and grabbing metrics from configured jobs to happen every 15 seconds.
scrape_configsis where we name our job; this name will be used in Grafana to help you find associated metrics. It is also where we configure Prometheus to find the metrics for that job.
remote_writeis where we instruct Prometheus to send the scraped metrics to a secondary endpoint.
Edit this file to include your Grafana Cloud username and the API key you created earlier.
To confirm your username and URL, first navigate to the Cloud Portal, then from the Prometheus box, click Send Metrics.
Create a Prometheus configuration file named
prometheus.yml in the same directory as the Prometheus binary with the following content.
global: scrape_interval: 15s scrape_configs: - job_name: node static_configs: - targets: ['localhost:9100'] remote_write: - url: "<Your Metrics instance remote_write endpoint>" basic_auth: username: "your grafana username" password: "your Grafana API key"
You can find the
/api/prom/push URL, username, and password for your metrics endpoint by clicking on Details in the Prometheus card of the Cloud Portal.
Save the file.
Run the Prometheus binary, instructing Prometheus to use the configuration file we just created.
If you don’t want to have to start Prometheus directly from the command line every time you want it to run, you can create a systemd service for it, similar to Creating a systemd service to manage the agent.
Check that metrics are being ingested into Grafana Cloud
Within minutes, metrics should begin to be available in Grafana Cloud. To test this, use the Explore feature, specifically it’s Prometheus-specific features. Click the Explore icon (looks like compass points) in the sidebar to start. This takes you to the Explore page, which looks like this.
At the top of the page, use the dropdown menu to select your Prometheus data source.
Use the Metrics dropdown to find the entry for node, which is the
job_name we created in
node is not listed, metrics are not being collected. If metrics are listed, this confirms that metrics are being received.
If metrics are not displayed after several minutes, check your steps for typos, make sure the binary is executable, and whether Prometheus is running on the Linux machine.
Configure a dashboard
Here you have two options: install a pre-made dashboard or create a dashboard from scratch.
Import a dashboard
Official and community-built dashboards are listed on the Grafana website Dashboards page.
Dashboards on this page will include information in the Overview tab about special configurations you may need to use to get the dashboard to work. For our example, we require a dashboard that is built to display Linux Node metrics using Prometheus and node_exporter, so we chose Linux Hosts Metrics | Base. Note the ID of the dashboard: 10180. We will use this ID in the next step.
In Grafana, click Dashboards in the left side menu (looks like four boxes) and from the menu that appears select Manage.
Click Import. Enter the ID number of the dashboard we selected into the box and click Load.
You will get a dashboard like this one.
See Export and import to learn more about importing Grafana dashboards.
Create a Dashboard
To create a dashboard, it is helpful to know PromQL and have a sense of the metrics and calculations based on those metrics that you want to display in your dashboard panels.
In Grafana, click Dashboards in the left side menu (looks like four boxes) and from the menu the appears select Manage.
Click New Dashboard. Your new dashboard starts out completely empty.
Click Add new panel to open the Edit Panel screen.
Complete instructions for creating a dashboard panel (indeed, multiple panels to create a dashboard) are beyond the scope of this quickstart. To learn more about creating a panel, see the Grafana Add a panel documentation.
Related Grafana Cloud resources
How to set up and visualize synthetic monitoring at scale with Grafana Cloud
Learn how to use Kubernetes, Grafana Loki, and Grafana Cloud’s synthetic monitoring feature to set up your infrastructure's checks in this GrafanaCONline session.
Using Grafana Cloud to drive manufacturing plant efficiency
This GrafanaCONline session tells how Grafana helps a 75-year-old manufacturing company with product quality and equipment maintenance.