下载

https://github.com/prometheus/pushgateway/releases

curl https://github.com/prometheus/pushgateway/releases/download/v1.2.0/pushgateway-1.2.0.linux-amd64.tar.gz

 

 

 

https://prometheus.io/download/

 

启动Pushgateway

nohup ./pushgateway > run.log 2>&1 &

usage: pushgateway [<flags>]
Flags:
--web.listen-address=":9091" 监听Web界面,API和遥测的地址。
--web.telemetry-path="/metrics" 公开metrics的路径。
--web.external-url= 可从外部访问Pushgateway的URL.
--web.route-prefix="" Web端点内部路由的前缀。 默认为--web.external-url的路径.
--persistence.file="" 归档以保留metrics。 如果为空,则metrics仅保留在内存中.
--persistence.interval=5m 写入持久性文件的最小间隔。
--log.level="info" 仅记录具有给定严重性或更高严重性的消息。 有效级别:[debug, info, warn, error, fatal]
--log.format="logger:stderr" 设置日志目标和格式。 示例:“ logger:syslog?appname = bob&local = 7”或“ logger:stdout?json = true”
--version 显示应用程序版本。

查看是否启动成功

curl "http://localhost:9091/metrics"

把Pushgateway信息添加到Prometheus配置文件prometheus.yml中

- job_name: pushgateway
    honor_labels: true
    static_configs:
    - targets: ['localhost:9091']
      labels:
        instance: pushgateway
        service: pushgatewayservicet

 推送数据

echo "mytest_metric 2022" | curl --data-binary @- http://localhost:9091/metrics/job/mytest_job

#这里pushgateway_test就是prometheus主配置文件里job的名字,需要保持一致,这样数据就会推送给这个job。后面的instance则是指定机器名,使用的就是脚本里获取的那个变量值
echo "$label  $count" | curl --data-binary @- http://server.com:9091/metrics/job/pushgateway_test/instance/$instance_name  

  

 

curl "http://localhost:9091/metrics"|grep mytest_metric

 

 

 posted on 2023-01-10 16:21  boye169  阅读(233)  评论(0编辑  收藏  举报