Installing the Prometheus

We will be installing Prometheus using Dockers, so make sure that docker is already installed and running perfectly on the machine if not then first get Docker installed on your machine.

Initially when we will take pull of our docker image then it comes with a demo prometheus.yml, for adding our prometheus.yml we need to update it

Creating a Prometheus Configuration with name prometheus.yml

$ vim ~/prometheus.yml
# my global config
  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
  - static_configs:
    - targets:
      - <your-ip>:9093

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

# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
  # 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'.

    - targets: ['localhost:9090']
  - job_name: 'node_exporter'
    - targets: ['']


 - name: example
   - alert: InstanceDown
     expr: up == 0
     for: 1m

Start the Prometheus Docker container with this external configuration file using the below mention command

$ docker run -d -p 9090:9090 -v ~/prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus

The -d option starts the Prometheus container to start in detached mode
The -p 9090:9090 option allows the Prometheus’s web port (9090) and makes it reachable via the external IP address of the host system.
The -v […] option mounts the prometheus.yml configuration file from the host file system from the location within the container where Prometheus expects it (/etc/prometheus/prometheus.yml)

Subscribe Now