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

相关推荐
世人万千丶1 天前
Flutter 框架跨平台鸿蒙开发 - 恐惧清单应用
学习·flutter·华为·开源·harmonyos·鸿蒙
yuzhuanhei1 天前
Visual Studio 配置C++opencv
c++·学习·visual studio
此刻觐神1 天前
IMX6ULL开发板学习-01(Linux文件目录和目录相关命令)
linux·服务器·学习
憧憬从前1 天前
算法学习记录DAY2
学习
babe小鑫1 天前
会计岗位学习数据分析的价值分析
学习·数据挖掘·数据分析
千枫s1 天前
电脑vm虚拟机kali linux安装shannon
学习·网络安全
zjnlswd1 天前
tkinter学习案例--笔记代码
笔记·学习
咬_咬1 天前
go语言学习(基本数据类型)
开发语言·学习·golang·数据类型
山甫aa1 天前
List 容器 -----C++的stl学习
开发语言·c++·学习
无聊大侠hello world1 天前
Yu-AI-Agent 项目(AI 恋爱大师智能体) · 学习笔记
人工智能·笔记·学习