get_job.sh脚本
#!/bin/bash
#获取所有的job list,循环获取vm的job指标推送量,累加整个x月份的指标推送量#线下
#ip_port="x.x.x.x:80"
#线上
ip_port="x.x.x.x:80"get_job=`curl -sG "http://$ip_port/select/0/prometheus/api/v1/label/job/values" > /root/job_list.txt`
for job in `cat /root/job_list.txt | jq -r .data[]`
dovalue=0start_date="20220401"end_date="20220429"while [ "$start_date" -le "$end_date" ];dostat_date=`date -d "$start_date" +%Y-%m-%d`metrics_num=`curl -sG "http://$ip_port/select/0/prometheus/api/v1/status/tsdb?topN=5&extra_label=job=$job&date=$stat_date" > /root/metrics_num.txt`metrics_num=`cat /root/metrics_num.txt | jq .data.seriesCountByLabelValuePair[0].value`let value=value+$metrics_numstart_date=$(date -d "$start_date+1days" +%Y%m%d)doneecho "$job : $value"
done
bash get_job.sh > job_list.txt
筛选
cat job_list.txt | awk -F " : " '{print$2}'
cat job_list.txt | awk -F " : " '{print$1}'
步骤
- 登录堡垒机,关注线下线下机器
- 修改/root/get_job.sh脚本:
- 修改线下线上:ip_port
- 修改start_date/end_date
- 执行脚本,输出到相应文件:
bash get_job.sh > job_list.txt
- 筛选列:
cat job_list.txt | awk -F " : " '{print$2}'
cat job_list.txt | awk -F " : " '{print$1}'