arrow_backAll Posts·5 Min Read·2024-11-01

Prometheus

Prometheus

Prometheus is an open-source monitoring system focused on collecting and managing application and infrastructure metrics. Metrics are numerical measurements that describe the performance or current state of a system.

  • Flexibility: Monitor a wide range of systems and services, from small workloads to large environments, and connect Prometheus to visualization and alerting tools.
  • Scalability: Handle large volumes of metrics and scale horizontally by adding Prometheus servers to a monitoring environment.
<br>
  • Download the Prometheus package.

    bash
    ~$ sudo su
    ~# wget https://github.com/prometheus/prometheus/releases/download/v2.48.1/prometheus-2.48.1.linux-amd64.tar.gz
    ~# tar -xvfz prometheus-2.48.1.linux-amd64.tar.gz
    ~# cp prometheus-2.48.1.linux-amd64/ /etc/prometheus
    
  • Edit /etc/prometheus/config.yml and define the targets Prometheus should scrape.

    yaml
    global:
      scrape_interval: 15s
      evaluation_interval: 15s
    
    scrape_configs:
      - job_name: "NAME_JOB"
        static_configs:
        - targets: ["IP_TARGET:PORT"]
    
  • Create a systemd service so Prometheus runs in the background.

    bash
    ~$ sudo nano /etc/systemd/system/prometheus_server.service
    
    bash
    [Unit]
    Description=Prometheus Server
    [Service]
    User=root
    ExecStart=/etc/prometheus/prometheus \
        --config.file=/etc/prometheus/config.yml \
        --web.external-url=http://IP_SERVER:9090/
    [Install]
    WantedBy=default.target
    
  • Reload systemd, then start and enable the Prometheus service.

    bash
    ~$ sudo systemctl daemon-reload
    ~$ sudo systemctl start prometheus_server.service
    ~$ sudo systemctl enable prometheus_server.service
    ~$ sudo systemctl status prometheus_server.service
    
"

For Prometheus TLS/SSL configuration, see Secure Prometheus.

Once Prometheus is running, you can configure Alertmanager if your environment requires alert routing. The Alertmanager post includes an example configuration and setup procedure.

If you want to visualize Prometheus data in Grafana, see the companion post on Grafana.