ZBLOG

shell脚本编写通过snmp协议批量获取华为UPS设备性能指标,并按照Prometheus Metrics 标准格式输出

#!/bin/bash

#定义变量 IP_LIST=(“192.168.1.1” “192.168.1.2” “192.168.1.3”) COMMUNITY=“public” OUTPUT_FILE=“ups_metrics.prom”

#遍历设备列表 for IP in \({IP_LIST[@]} do #获取UPS信息 UPS_NAME=\)(snmpget -v2c -c \(COMMUNITY \)IP sysName.0 | awk ‘{print \(4}') UPS_MODEL=\)(snmpget -v2c -c \(COMMUNITY \)IP hrDeviceDescr.\((snmpwalk -v2c -c \)COMMUNITY \(IP | grep 'hrDeviceType' | awk '{print \)1}’ | cut -d ‘.’ -f 2) | awk ‘{print substr(\(0, index(\)0,\(4))}') UPS_STATUS=\)(snmpget -v2c -c \(COMMUNITY \)IP upsBasicOutputStatus.0 | awk ‘{print substr(\(4, 1, length(\)4)-1)}’) UPS_LOAD=\((snmpget -v2c -c \)COMMUNITY \(IP upsAdvBatteryCapacity.\)(snmpwalk -v2c -c \(COMMUNITY \)IP | grep ‘upsAdvBatteryCapacity’ | awk ‘{print \(1}' | cut -d '.' -f 2) | awk '{print substr(\)4, 1, length($4)-1)}’)

#输出Prometheus Metrics格式的指标数据到文件中 echo “# HELP ups_name The name of the UPS device” >>\(OUTPUT_FILE echo "# TYPE ups_name gauge" >>\)OUTPUT_FILE echo “ups_name{ip=\”\(IP\",name=\"\)UPS_NAME\“} 1” >>$OUTPUT_FILE

echo “# HELP ups_model The model of the UPS device” >>\(OUTPUT_FILE echo "# TYPE ups_model gauge" >>\)OUTPUT_FILE echo “ups_model{ip=\”\(IP\",model=\"\)UPS_MODEL\“} 1” >>$OUTPUT_FILE

echo “# HELP ups_status The status of the UPS output (1=on, 2=off, 3=rebooting)” >>\(OUTPUT_FILE echo "# TYPE ups_status gauge" >>\)OUTPUT_FILE echo “ups_status{ip=\”\(IP\",status=\"\)UPS_STATUS\“} 1” >>$OUTPUT_FILE

echo “# HELP ups_load The current load percentage of the UPS battery” >>\(OUTPUT_FILE echo "# TYPE ups_load gauge" >>\)OUTPUT_FILE echo “ups_load{ip=\”\(IP\"} \)UPS_LOAD” >>$OUTPUT_FILE

done

echo “Metrics collection completed.”

本站部分文章来源于网络,版权归原作者所有,如有侵权请联系站长删除。
转载请注明出处:https://golang.0voice.com/?id=5866

分享:
扫描分享到社交APP
上一篇
下一篇
发表列表
游客 游客
此处应有掌声~
评论列表

还没有评论,快来说点什么吧~

联系我们

在线咨询: 点击这里给我发消息

微信号:3007537140

上班时间: 10:30-22:30

关注我们
x

注册

已经有帐号?