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

相关推荐
Yupureki4 小时前
从零开始的C++学习生活 8:list的入门使用
c语言·c++·学习·visual studio
胡萝卜3.05 小时前
掌握string类:从基础到实战
c++·学习·string·string的使用
果粒chenl5 小时前
React学习(四) --- Redux
javascript·学习·react.js
im_AMBER6 小时前
CSS 01【基础语法学习】
前端·css·笔记·学习
向阳花开_miemie6 小时前
Android音频学习(二十二)——音频接口
学习·音视频
胡萝卜3.06 小时前
深入理解string底层:手写高效字符串类
开发语言·c++·学习·学习笔记·string类·string模拟实现
fanstering6 小时前
腾讯混元P3-SAM: Native 3D Part Segmentation
笔记·学习·3d·点云
im_AMBER7 小时前
数据结构 05 栈和队列
数据结构·笔记·学习
报错小能手7 小时前
linux学习笔记(31)网络编程——TCP time_wait机制
linux·笔记·学习