We recommend you follow this tutorial using a
Production-Optimized Instance.
Configuring a Prometheus monitoring Instance with a Grafana dasard
- monitoring
- Grafana
- Prometheus
Prometheus is a flexible monitoring solution developed since 2012. It stores all data in a time series database, offering a multi-dimensional data model and a powerful query language to generate reports of the monitored resources.
In this tutorial, you will learn how to use a Prometheus Monitoring Instance with a Grafana dasard.
Before you startLink to this anchor
To complete the actions presented below, you must have:
- A Scaleway account logged into theconsole
- Owner status orIAM permissions allowing you to perform actions in the intended Organization
- AnSSH key
- AnInstance running on Ubuntu Jammy Jellyfish (22.04 LTS) or later
Preparing your environmentLink to this anchor
Create users for Prometheus and Node Exporter:
useradd --no-create-home --shell /usr/sbin/nologin prometheususeradd --no-create-home --shell /bin/false node_exporterCreate necessary directories:
mkdir /etc/prometheusmkdir /var/lib/prometheusSet ownership of directories:
chown prometheus:prometheus /etc/prometheuschown prometheus:prometheus /var/lib/prometheus
Downloading and installing Node ExporterLink to this anchor
Download Node Exporter:
wget https://.com/prometheus/node_exporter/releases/download/v1.8.2/node_exporter-1.8.2.linux-amd64.tar.gzUnpack the archive:
tar xvf node_exporter-1.8.2.linux-amd64.tar.gzCopy the binary and set ownership:
cp node_exporter-1.8.2.linux-amd64/node_exporter /usr/local/binchown node_exporter:node_exporter /usr/local/bin/node_exporterRemove unnecessary files to avoid clutter in your system:
rm -rf node_exporter-1.8.2.linux-amd64.tar.gz node_exporter-1.8.2.linux-amd64Create systemd service file:
nano /etc/systemd/system/node_exporter.serviceAdd the following content to the
node_exporter.service
file:[Unit]Description=Node ExporterWants=network-online.targetAfter=network-online.target[Service]User=node_exporterGroup=node_exporterType=simpleExecStart=/usr/local/bin/node_exporter[Install]WantedBy=multi-user.targetReload systemd and start Node Exporter:
systemctl daemon-reloadsystemctl start node_exporter.serviceVerify Node Exporter status:
systemctl status node_exporter.serviceEnable Node Exporter at boot:
systemctl enable node_exporter.service
Downloading and installing PrometheusLink to this anchor
Download and unpack Prometheus:
apt-get update && apt-get upgradewget https://.com/prometheus/prometheus/releases/download/v3.1.0/prometheus-3.1.0.linux-amd64.tar.gztar xfz prometheus-3.1.0.linux-amd64.tar.gzcd prometheus-3.1.0.linux-amd64/Copy binaries and set ownership:
cp ./prometheus /usr/local/bin/cp ./promtool /usr/local/bin/chown prometheus:prometheus /usr/local/bin/prometheuschown prometheus:prometheus /usr/local/bin/promtoolCopy console libraries and set ownership:
cp -r ./consoles /etc/prometheuscp -r ./console_libraries /etc/prometheuschown -R prometheus:prometheus /etc/prometheus/consoleschown -R prometheus:prometheus /etc/prometheus/console_librariesRemove source files:
cd .. && rm -rf prometheus-\*
Configuring PrometheusLink to this anchor
Create a configuration file:
nano /etc/prometheus/prometheus.ymlAdd the following configuration:
global:scrape_interval: 15sevaluation_interval: 15srule_files:# - "first.rules"# - "second.rules"scrape_configs:- job_name: 'prometheus'scrape_interval: 5sstatic_configs:- targets: ['localhost:9090']- job_name: 'node_exporter'scrape_interval: 5sstatic_configs:- targets: ['localhost:9100']Set ownership of configuration file:
chown prometheus:prometheus /etc/prometheus/prometheus.yml
Running PrometheusLink to this anchor
Start Prometheus from the command line:
sudo -u prometheus /usr/local/bin/prometheus --config.file /etc/prometheus/prometheus.yml --storage.tsdb.path /var/lib/prometheus/ --web.console.templates=/etc/prometheus/consoles --web.console.libraries=/etc/prometheus/console_librariesAccess Prometheus web interface: Open
http://IP.OF.YOUR.SERVER:9090
in your browser.Create systemd service file for Prometheus:
nano /etc/systemd/system/prometheus.serviceAdd the following content:
[Unit]Description=Prometheus MonitoringWants=network-online.targetAfter=network-online.target[Service]User=prometheusGroup=prometheusType=simpleExecStart=/usr/local/bin/prometheus \--config.file /etc/prometheus/prometheus.yml \--storage.tsdb.path /var/lib/prometheus/ \--web.console.templates=/etc/prometheus/consoles \--web.console.libraries=/etc/prometheus/console_librariesExecReload=/bin/kill -HUP $MAINPID[Install]WantedBy=multi-user.targetReload systemd and enable Prometheus service:
systemctl daemon-reloadsystemctl enable prometheus.serviceStart Prometheus:
systemctl start prometheus.service
Prometheus web interfaceLink to this anchor
Prometheus provides a basic web interface running on http://your.instance.ip:9090
that provides access to the collected data. You can perform queries and verify the status of your Prometheus instance.
Installing GrafanaLink to this anchor
Install Grafana:
apt-get install -y adduser libfontconfig1wget https://dl.grafana.com/oss/release/grafana_9.3.6_amd64.debdpkg -i grafana_11.2.4_amd64.debEnable and start Grafana service:
systemctl daemon-reload && systemctl enable grafana-server.service && systemctl start grafana-server.service
Grafana is now running and can be accessed at http://your.instance.ip:3000
. The default username and password is admin
/ admin
.
Configuring GrafanaLink to this anchor
- Add Prometheus data source:
- Click the settings icon (cogwheel) on the sidebar
- Click Data Sources
- Choose Add data source
- Select Prometheus as the data source
- Set the Prometheus instance URL to
http://localhost:9090/
- Click Save & test to test the connection and save the new data source
You are now ready to create your first dasard from the information collected by Prometheus. You can also import some dasards from a collection of
shared dasards.Below is an example of a dasard that uses the CPU usage of our node and presents it in Grafana: