prometheus+grafana监控Linux之pushgateway自定义监控(九)

prometheus+grafana监控Linux之pushgateway自定义监控(九)

一、使用场景
当某些特定数据能在linux中用命令查出来时,且没有合适的exporter软件时,可以用pushgateway来采集数据,推送到Prometheus上;比如说监控Linux下一个具体目录的大小
二、pushgateway安装(默认端口9091)
下载地址https://prometheus.io/download/
docker 版安装

#docker load -i pushgateway.tar
#docker run -d -p 9091:9091 --name=pushgateway prom/pushgateway:latest

浏览器访问http://pushgatewayIP:9091/metrics验证是否安装成功
三、监控自定义(jiankong/app)文件夹大小,并推送到prometheus中
创建一个shell脚本dir.sh

#vim dir.sh

脚本文件如下:

#!/bin/bash
#要监控的文件夹(以/ /jiankong/app为例,实际中按照需要进行修改)
dir_size=`du -shm /jiankong/app | awk '{print $1}'`
#推送到prometheus中(前提是配置好了prometheus.yml)
echo dir2 $dir_size | curl --data-binary @- http://localhost:9091/metrics/job/pushgateway

保存完脚本文件后

#chmod 777 dir.sh
#crontab -e
加入以下内容(定时任务,每分钟执行一次)
*/1 * * * * bash /jiankong/app/dir.sh
保存退出

验证:访问http://Prometheus IP:9090/ graph,输入dir2,看是否有结果,或者访问http://pushgatewayIP:9091/metrics,查看有无dir2的信息
在这里插入图片描述
在这里插入图片描述
四、脚本解释
echo dir2 $dir_size | curl --data-binary @- http://localhost:9091/metrics/job/pushgateway
中,dir2为推送到prometheus的key值,是保存到prometheus数据库的依据,value值必须为数字。http://pushgatewayIP:9091/metrics/job/job_name的,与prometheus.yml中job_name的名字保持一致

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值