Skip to content

Setting up Prometheus

If you want to monitor servers in the NETWAYS Cloud, this can be done, for example, with Prometheus – for instance through an integration with the Prometheus Managed Service.

Installation

Standalone Binary

The Prometheus project publishes binaries for all releases on its download page.

You can download and extract it directly on the server:

cd /tmp
curl -LO $(curl -s https://api.github.com/repos/prometheus/prometheus/releases/latest \
    | grep browser_download_url \
    | grep linux-amd64 \
    | cut -d '"' -f 4)
tar xvf prometheus-*.tar.gz
cd prometheus-*/

After that, some directories and permissions need to be created for smooth operation:

sudo mv prometheus /usr/local/bin
sudo mv promtool /usr/local/bin
sudo mkdir -p /etc/prometheus
sudo mkdir -p /var/lib/prometheus
sudo mv prometheus.yml /etc/prometheus

sudo useradd --no-create-home --shell /bin/false prometheus
sudo chown -R prometheus:prometheus /etc/prometheus /var/lib/prometheus
sudo chown prometheus:prometheus /usr/local/bin/prometheus /usr/local/bin/promtool

systemd Service

For a persistent operation, it is recommended to run Prometheus as a systemd service.

An example service definition could look like this:

# /etc/systemd/system/prometheus.service
[Unit]
Description=Prometheus
Wants=network-online.target
After=network-online.target

[Service]
User=prometheus
Group=prometheus
Type=simple
ExecStart=/usr/local/bin/prometheus \
    --config.file=/etc/prometheus/prometheus.yml \
    --storage.tsdb.path=/var/lib/prometheus \
    --web.listen-address=0.0.0.0:9090

[Install]
WantedBy=multi-user.target

Then you need to reload systemd and start Prometheus:

sudo systemctl daemon-reload
sudo systemctl enable --now prometheus

The status of the service can also be checked with systemctl:

sudo systemctl status prometheus

Installation via Docker

Alternatively to the standalone binary, you can also run Prometheus in Docker.

Docker Installation

Docker must be installed first. Depending on the operating system, this can be done in various ways.

More information can be found in the Docker documentation.

For this, it makes sense to create the directories required by Prometheus as described above:

  • /etc/prometheus/ for configuration files
  • /var/lib/prometheus/ for persistent storage of the collected metrics

Then you can start Prometheus as a container with the following command:

docker run -d --name=prometheus \
    -p 9090:9090 \
    -v /etc/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml \
    -v /var/lib/prometheus:/prometheus \
    --restart unless-stopped \
    prom/prometheus

Alternatively, you can also use Docker Compose to set up Prometheus.

Configuration

After configuration, you can configure Prometheus according to your requirements.

A minimal example configuration that only monitors Prometheus itself could look like this:

global:
  scrape_interval: 15s

scrape_configs:
- job_name: prometheus
  static_configs:
  - targets:
    - localhost:9090

More information can be found in the Prometheus documentation.

Connecting to the Prometheus Managed Service

If you operate the Prometheus Managed Service available in MyNWS, you can also store collected data centrally there.

For this, you configure the so‑called Remote Write feature in the local Prometheus on a server:

# /etc/prometheus/prometheus.yaml
remote_write:
- url: <managed-service-remote-write-url>
  remote_timeout: 30s
  name: prometheus_app
  basic_auth:
    username: <managed-service-user>
    password: <managed-service-password>

Security Groups on the Server

Depending on the server configuration, the locally running Prometheus may not be able to connect to the Prometheus Managed Service.

To fix this, you can create an additional security group that allows HTTPS egress.

Credentials for the Prometheus Managed Service

The credentials as well as the Remote Write URL for the Prometheus Managed Service can be found in the corresponding product overview in MyNWS.