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的指标的数据,如果没有持续更新会一直保持上次的值,并且只能手动删除指标。

相关推荐
半夏知半秋8 小时前
docker常用指令整理
运维·笔记·后端·学习·docker·容器
蒸蒸yyyyzwd9 小时前
网络编程——threadpool.h学习笔记
笔记·学习
浪子不回头4159 小时前
SGLang学习笔记
人工智能·笔记·学习
deng-c-f10 小时前
Linux C/C++ 学习日记(53):原子操作(二):实现shared_ptr
开发语言·c++·学习
旖旎夜光10 小时前
Linux(3)(下)
linux·学习
geneculture10 小时前
从智力仿真到认知协同:人机之间的价值对齐与共生框架
大数据·人工智能·学习·融智学的重要应用·信智序位
sbc-study12 小时前
comsol仿真例题学习-模块-水平集+相场法
学习·comsol·例题·水平集·相场法·电镀
EchoL、12 小时前
Obsidian使用学习
笔记·学习