Prometheus & Grafana를 사용해 보았습니다.

시작



docker-compose로 간단 실행.
docker-compose up

docker-compose.yml
version: '3.1'

services:
  prometheus:
    image: prom/prometheus
    container_name: prometheus
    ports:
      - 9090:9090
    networks:
      - public
    volumes:
      - ./prometheus/prometheus.yml:/etc/prometheus/prometheus.yml

  pushgateway:
    image: prom/pushgateway
    container_name: pushgateway
    ports:
      - 9091:9091
    networks:
      - public

  grafana:
    image: kannkyo/grafana
    container_name: grafana
    ports:
      - 3000:3000
    networks:
      - public

networks:
  public:

./prometheus/prometheus.yml
scrape_configs:
  - job_name: 'pushgateway'
    scrape_interval: 1s
    static_configs:
      - targets: ['pushgateway:9091']
        labels:
          environment: "hoge"
          category: "pushgateway"

표시



prometheus





pushgateway





grafana





지표 작업



docker-compose.yml의 networks 설정을 통해 pushgateway -> prometheus -> grafana에 메트릭을 보낼 수 있습니다.

다음 스크립트에서 메트릭을 푸시하거나 지울 수 있습니다.

지표 푸시



push.sh
#!/bin/bash

JOB=pushgateway

MAX_VAL=100
DATA=$(($RANDOM % $MAX_VAL))
METRICS="some_metric $DATA"

echo $METRICS
echo $METRICS | curl --data-binary @- http://localhost:9091/metrics/job/$JOB

지표 지우기



clear.sh
#!/bin/bash

JOB=pushgateway
curl -X DELETE http://localhost:9091/metrics/job/$JOB

좋은 웹페이지 즐겨찾기