victoriametrics获取指标情况脚本

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[]`
do
    value=0
    start_date="20220401"
    end_date="20220429"
    while [ "$start_date" -le "$end_date" ];
    do
        stat_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_num
        start_date=$(date -d "$start_date+1days" +%Y%m%d)
    done
    echo "$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}'

步骤

  1. 登录堡垒机,关注线下线下机器
  2. 修改/root/get_job.sh脚本:
  • 修改线下线上:ip_port
  • 修改start_date/end_date
  1. 执行脚本,输出到相应文件:
bash get_job.sh > job_list.txt
  1. 筛选列:
cat job_list.txt | awk -F " : " '{print$2}'
cat job_list.txt | awk -F " : " '{print$1}'

你可能感兴趣的:(VictoriaMetrics,chrome,前端)