DEV Community

Beyza
Beyza

Posted on

Grafana and Prometheus Setup on Ubuntu 22.04

This tutorail will show you how you can create a Grafana Server and how to download Grafana agents and Prometheus to your servers.

Start Prometheus Main server

  1. wget https://github.com/prometheus/prometheus/releases/download/v2.48.0/prometheus-2.48.0.linux-amd64.tar.gz

  2. tar xvfz prometheus-*.tar.gz

  3. cd prometheus-*-amd64/

  4. screen -S prometheus => creates a new screen in you server

  5. Update prometheus yaml file:
    nano /prometheus-2.48.0.linux-amd64/prometheus.yml

Example:

# my global config
global:
  scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
  evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
  # scrape_timeout is set to the global default (10s).

# Alertmanager configuration
alerting:
  alertmanagers:
    - static_configs:
        - targets:
          # - alertmanager:9093

# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
  # - "first_rules.yml"
  # - "second_rules.yml"

# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  - job_name: "prometheus"

    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.

    static_configs:
      - targets: ["localhost:9090"]

  # configs for scraping node exporter metrics
  - job_name: node
    static_configs:
      - targets: ['localhost:9100']
Enter fullscreen mode Exit fullscreen mode

Run ./prometheus --config.file=prometheus.yml

  • http://public ip:9090/metrics You should be able to see Prometheus metrics.

(Use Ctrl a+d = go to main screen)

Download Node exporter:

  1. screen -S node-exporter
  2. wget https://github.com/prometheus/node_exporter/releases/download/v1.5.0/node_exporter-1.5.0.linux-amd64.tar.gz
  3. tar xvfz node_exporter-*.*-amd64.tar.gz
  4. cd node_exporter-*.*-amd64
  5. ./node_exporter
  • http://<public ip>:9100/metrics Prometheus metrics

(Ctrl a+d = Go to main screen)

  1. Install Grafana sudo yum install -y https://dl.grafana.com/enterprise/release/grafana-enterprise-9.5.2-1.x86_64.rpm sudo systemctl start grafana-server.service

This is your Grafana server: http://public ip:3000/

Setup your admin name and pass

  • Username: admin
  • Password: mypass

Note: service grafana-server restart = If you make any changes to the main server's configuration, be sure to run this command afterwards.

Resources:

The upcoming tutorials will cover the topics of creating dashboards, alerting systems, and integrating with Slack.

Top comments (0)