Prefácio
Esta nota é geralmente sobre pushgateway push , no entanto, vou avisá-lo e admitir imediatamente que o texto conterá um exemplo - um antipadrão de pushgateway push, uma vez que o uso de pushgateway é recomendado no caso em que o serviço não funciona constantemente (ou para um serviço / tarefa iniciada em geral não existe interface), o que significa que é melhor para o prometheus não bater constantemente a portas fechadas e não realizar trabalhos desnecessários.
Introdução
, 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 .
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.
Decidi escrever uma nota, já que encontrei um semelhante em meu trabalho, direi imediatamente que o método do exemplo não entrará em produção, porém, usando pushgateway na ausência de descoberta de serviço, para testá-lo pode sair.