pushgatewayを使用したPrometheusメトリックのプッシュ

それでも、ファビコンに青い炎があるのはプッシュゲートウェイだけです







序文



このメモは一般的にプッシュゲートウェイのプッシュに関するものですが、テキストに例が含まれていることを警告し、すぐに認めます-サービスが常に機能しない場合(またはサービス/開始されたタスクの場合)にプッシュゲートウェイの使用が推奨されるため、プッシュゲートウェイのプッシュのアンチパターンインターフェースはありません)。つまり、プロメテウスは常に閉じたドアをノックし、不要な作業を行わない方がよいということです。







前書き



, pushgateway — , pull- prometheus' ( , , ). , pushgateway prometheus , , , up, prometheus , — pushgateway.







p.s. , up , , , pushgateway -.







prometheus pushgateway



, compose prometheus pushgateway:







# ....( -   ..)   
prometheus:  
    restart: always  
    image: bitnami/prometheus:latest  
    links:  
        - pushgateway  
    volumes:  
        - ./.prom.yml:/opt/bitnami/prometheus/conf/prometheus.yml  

pushgateway:  
    restart: always  
    image: bitnami/pushgateway:latest  
    ports:  
        - 9091:9091  
      
      





prom.yml - , pushgateway:







global: null
scrape_interval: 5s
scrape_timeout: 2s
evaluation_interval: 15s

scrape_configs:
  - job_name: pushgateway
    honor_labels: true
    static_configs:
      - targets:
          - 'pushgateway:9091'
      
      





, honor_lables, , , , "X" pushgateway, "X", honor_lables=false "X" pushgateway "exported_X" , pushgateway, true ( , ).







p.s. pushgateway — - , , basic_auth.









, , , , , - , service_discovery ( , , ).







, , Faust ( swarm, ), consul prometheus, docker compose scale.







, , , , :







ports:  
- "9100-9200:6066"  
      
      





prometheus .







. . , — , push_to_gateway .







async def push_metrics():  
    def auth_handler(url, method, timeout, headers, data):  
        return basic_auth_handler(url, method, timeout, headers, data, PUSHGATEWAY_USERNAME, PUSHGATEWAY_PASSWORD)  
    push_to_gateway(PUSHGATEWAY_URI, job=f"{WORKERS_APP_NAME}-{ENV}", registry=registry_metrics, handler=auth_handler)  

@app.timer(interval=PUSH_METRICS_INTERVAL)  
async def push_metrics_cron():  
    await push_metrics()  
      
      





— job name ( — prometheus'), handler registry . , pushgateway - , , prometheus.









私はメモを書くことにしました。私の仕事で同様の方法に遭遇したので、例の方法は本番環境には移行しないとすぐに言いますが、サービス検出がない場合にプッシュゲートウェイを使用するように、テストのためにそれが外れる可能性があります。








All Articles