We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Metrics Exporters

Think of Prometheus as a database for metrics. But a database is only as useful as the data it contains. So where does Prometheus get its data?

Prometheus is pull-based. It scrapes data from sources, then stores that data in its database. This contrasts with push-based systems, where data sources send data directly.

Getting data into Prometheus requires two things:

  1. A data source to pull from (the host machine, a specific application like Linko, etc.)
  2. Configuring Prometheus to find and pull from that data source

Assignment

Add Node Exporter so Prometheus can scrape host-level metrics.

  1. services:
      prometheus:
        image: prom/prometheus:latest
        ports:
          - "9090:9090"
        volumes:
          - ./prometheus.yml:/etc/prometheus/prometheus.yml
      node-exporter:
        image: prom/node-exporter:latest
        ports:
          - "9100:9100"
    
  2. scrape_configs:
      - job_name: prometheus
        static_configs:
          - targets: ["localhost:9090"]
      - job_name: node_exporter
        static_configs:
          - targets: ["node-exporter:9100"]
    
  3. docker compose up
    
  4. Available Memory (in bytes):

    node_memory_MemAvailable_bytes
    

    Available Disk Space (in bytes):

    node_filesystem_avail_bytes
    

    Prometheus also lets you run functions over stored data like sums and averages. For example, average CPU Usage for the last 5 minutes (percentage):

    1 - avg(rate(node_cpu_seconds_total{mode="idle"}[5m]))
    

Aside from debugging, it's not normal to query Prometheus directly. Another tool like Grafana will typically run these queries for us and visualize the results.

Run and submit the CLI tests from the root of the Linko repo.