6.prometheus数据上报方式-pushgateway

6.prometheus数据上报方式-pushgateway
6.1.pushgateway下载、安装、启动
6.2.prometheus上配置target
6.3.push数据到pushgateway

6.prometheus数据上报方式-pushgateway

参考:https://www.cnblogs.com/xiaobaozi-95/p/10684524.html

客户端使用push的方式上报监控数据到pushgateway,prometheus会定期从pushgateway拉取数据。使用它的原因主要是:
Prometheus 采用 pull 模式,可能由于不在一个子网或者防火墙原因,导致Prometheus 无法直接拉取各个 target数据。
在监控业务数据的时候,需要将不同数据汇总, 由 Prometheus 统一收集。

拓扑图
在这里插入图片描述

6.1.pushgateway下载、安装、启动

软件包下载位置:https://prometheus.io/download/
在这里插入图片描述
下载包之后将包pushgateway-1.4.1.linux-amd64.tar.gz放到:cd /root/software 中。

解压、安装、启动

cd /root/software
tar -zxvf pushgateway-1.4.1.linux-amd64.tar.gz -C ../installed/

cd /root/installed/pushgateway
nohup ./pushgateway > pushgateway.file 2>&1 &

服务器上的访问地址:

http://localhost:9091

pushgateway访问地址:

http://localhost:19091 (使用docker映射后的端口进行访问)
[root@node1 node_exporter]# curl localhost:9091/metrics
# HELP go_gc_duration_seconds A summary of the pause duration of garbage collection cycles.
# TYPE go_gc_duration_seconds summary
go_gc_duration_seconds{quantile="0"} 3.7902e-05
go_gc_duration_seconds{quantile="0.25"} 3.7902e-05
go_gc_duration_seconds{quantile="0.5"} 0.000109801
go_gc_duration_seconds{quantile="0.75"} 0.000109801
go_gc_duration_seconds{quantile="1"} 0.000109801
go_gc_duration_seconds_sum 0.000147703
go_gc_duration_seconds_count 2
# HELP go_goroutines Number of goroutines that currently exist.
# TYPE go_goroutines gauge
go_goroutines 16
# HELP go_info Information about the Go environment.
# TYPE go_info gauge
go_info{version="go1.16.4"} 1
# HELP go_memstats_alloc_bytes Number of bytes allocated and still in use.
# TYPE go_memstats_alloc_bytes gauge
go_memstats_alloc_bytes 3.439648e+06
# HELP go_memstats_alloc_bytes_total Total number of bytes allocated, even if freed.
# TYPE go_memstats_alloc_bytes_total counter
go_memstats_alloc_bytes_total 4.901016e+06
# HELP go_memstats_buck_hash_sys_bytes Number of bytes used by the profiling bucket hash table.
# TYPE go_memstats_buck_hash_sys_bytes gauge

6.2.prometheus上配置target

- job_name: 'push-metrics'
  static_configs:
    - targets: ['172.17.0.2:9091']
      labels:
        instance: pushgateway

6.3.push数据到pushgateway

推送URL :pushgateway默认采用9091端口,路径:

/metrics/job/<JOBNAME>{/<LABEL_NAME>/<LABEL_VALUE>}
<JOBNAME>是job标签的值,后面跟任意数量的标签对,instance标签可以有也可以没有。

示例1(添加单条数据):
shell下执行:

echo "test_metric 2333" | curl --data-binary @- http://172.17.0.2:9091/metrics/job/test_job

执行完成之后:
A: 在http://localhost:19091/#中可以看到添加的内容。

B:在http://localhost:19090/中的输入框中输入test_metric,可以看到结果:

test_metric{exported_job="test_job", instance="pushgateway", job="push-metrics"}

示例二(从文件中写入指标数据):
/root/workspace/data.txt

http_request_total{code="200",domain="abc.cn"} 276683
http_request_total{code="400",domain="abc.cn"} 0
http_request_total{code="408",domain="abc.cn"} 7
http_request_total{code="401",domain="abc.cn"} 0
http_request_total{schema="http",domain="abc.cn"} 277725
http_request_total{schema="https",domain="abc.cn"} 0
http_request_time{code="total",domain="abc.cn"} 76335.809000
http_request_uniqip{domain="abc.cn"} 216944
http_request_maxip{clientip="172.27.0.12",domain="abc.cn"} 81

执行的命令如下:

curl -XPOST --data-binary @data.txt http://172.17.0.2:9091/metrics/job/test_job

执行完成之后,可以到prometheus中查看上面的http_request_total数据信息。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值