Prometheus pushgateway学习

Prometheus pushgateway学习

    • [1. Pushgateway 介绍](#1. Pushgateway 介绍)
    • [2. prometheus和pushgateway安装](#2. prometheus和pushgateway安装)
    • [3. 创建自定义监控指标](#3. 创建自定义监控指标)

1. Pushgateway 介绍

Pushgateway是Prometheus 提供的一个自定义监控指标的工具,主要是创建自定义监控指标然后推送给pushgateway,Prometheus从pushgateway中获取数据

2. prometheus和pushgateway安装

通过docker安装

复制代码
 docker pull prom/pushgateway
 docker pull prom/prometheus

创建配置文件:
prometheus.yml:

clike 复制代码
global:
alerting:
  alertmanagers:
    - static_configs:
        - targets:
rule_files:
scrape_configs:
  - job_name: "prometheus"
    static_configs:
      - targets: ["localhost:9090"]
        labels:
          app: "prometheus"
  # pushgateway配置
  - job_name: "pushgateway"
    honor_labels: true
    static_configs:
    - targets:
      - 192.168.25.250:9091
  • honor_labels: true :当配置中的指标与抓取目标中的指标冲突优先使用目标指标

启动prometheus:

复制代码
docker run -d --name prometheus --net host  -v ./prometheus.yml:/etc/prometheus/prometheus.yml:ro prom/prometheus

启动pushgateway :

复制代码
docker run -d --name pushgateway --net host  prom/pushgateway

访问prometheus和pushgateway web ui:

3. 创建自定义监控指标

指标值必须是数值型

推送格式:curl --data-binary @- "http://IP:9091/metrics/job/${JOB_NAME}/instance/${INSTANCE_NAME}"

复制代码
echo "docker_live_info{status=\"running\"} $(ps -ef | grep -v grep | grep docker | wc -l)" | curl --data-binary @- "http://192.168.25.250:9091/metrics/job/test/instance/192.168.25.250"

指标格式:指标名{key} value

查看指标:

通过Prometheus抓取数据:

可以通过定时执行指标推送命令来更新指标的数据。

推送到pushgateway的指标的数据,如果没有持续更新会一直保持上次的值,并且只能手动删除指标。

相关推荐
SRETalk7 天前
Zabbix、Prometheus、Grafana、Nightingale,四个监控如何选型?
zabbix·grafana·prometheus·nightingale
虚无境14 天前
如何编写一个SpringBoot项目告警推送的Starter
java·prometheus·webhook
通信小呆呆15 天前
当算法有了“五感”:多模态数据融合如何向人体感官协同学习?
人工智能·学习·算法·机器学习·机器人
H__Rick15 天前
自动对焦学习-3
人工智能·学习·计算机视觉
Daisy Lee15 天前
量化学习-第1章-什么是量化金融
学习·金融·datawhale
Alsn8615 天前
等待学习-学习目录:Docker 容器安全攻防
学习·安全·docker
YM52e15 天前
买菜计算器小应用 - HarmonyOS ArkUI 开发实战-PC版本
学习·华为·harmonyos·鸿蒙·鸿蒙系统
小雨下雨的雨15 天前
HarmonyOS ArkUI训练营入门-组件掌握系列-Animation 动画效果实现-PC版本
学习·华为·harmonyos·鸿蒙
cqbzcsq15 天前
CellFlow虚拟细胞论文阅读
论文阅读·人工智能·笔记·学习·生物信息
YangYang9YangYan15 天前
2026初入职场学习数据分析的价值
学习·数据挖掘·数据分析