xcirel / prometheus-grafana

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Start a container with Prometheus

docker run \
    --name prometheus \
    -d \
    -v prometheus:/prometheus \
    -v $(pwd)/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml \
    -p 9090:9090 \
    prom/prometheus

Monitoring an Application with Prometheus

In this example we work with a node application, see on app folder.

Added a Gauge Metric

Can increase or decrease arbitrarily

const gauge = new promClient.Gauge({
    name: 'class_free_bytes',
    help: 'Example of gauge'
});

gauge.set(100*Math.random());

Added a Histogram Metric

Used to measure the distribution

const histogram = new promClient.Histogram({
    name: 'class_request_time_seconds',
    help: 'Time to response from API',
    buckets: [0.1, 0.2, 0.3, 0.4, 0.5],
});

histogram.observe(Math.random()); // Observe value in histogram

Added a Summary Metric

Used to measure the distribution with percentiles

const summary = new promClient.Summary({
    name: 'class_summary_request_time_seconds',
    help: 'Time to response from API',
    percentiles: [0.01, 0.1, 0.5, 0.9, 0.99] // percentiles 1%, 10%, 50%, 90%, 99%
});

summary.observe(time);

Links https://prometheus.io/docs/instrumenting/clientlibs/ https://github.com/siimon/prom-client#labels

Monitoring Servers with Prometheus

Install node_exporter on server for registrer metrics

version: '3.8'

services:
  node_exporter:
    image: quay.io/prometheus/node-exporter:latest
    container_name: node_exporter
    command:
      - '--path.rootfs=/host'
    network_mode: bridge
    restart: unless-stopped
    volumes:
      - '/:/host:ro,rslave'     
    ports:
      - 9100:9100

Add a new target on prometheus.yml

- job_name: server-001
  static_configs:
  - targets:
    - 3.87.217.36:9100    

Restart de container to update de configuration

docker container restart prometheus

Done! Now you can see the metrics on http://<IP_ADDRESS>:9100/metrics

Links https://prometheus.io/docs/instrumenting/exporters/

About


Languages

Language:JavaScript 100.0%