#!/bin/bash
F5监控指标脚本
设置F5 IP地址和用户名密码
F5_IP=“192.168.1.1” F5_USER=“admin” F5_PASS=“password”
获取CPU使用率
CPU_USAGE=\((sshpass -p \)F5_PASS ssh \(F5_USER@\)F5_IP “tmsh show sys cpu | grep ‘System:’ | awk ‘{print \$2}’”)
获取内存使用率
MEM_USAGE=\((sshpass -p \)F5_PASS ssh \(F5_USER@\)F5_IP “tmsh show sys memory | grep ‘Memory usage’ | awk ‘{print \$3}’”)
获取流量数据
TRAFFIC_STATS=\((sshpass -p \)F5_PASS ssh \(F5_USER@\)F5_IP “tmsh show net interface all-properties | egrep ‘Net::Interface|ifInOctets|ifOutOctets’ | awk ‘{print \\(2,\\)3}’”) IN_BYTES=\((echo "\)TRAFFIC_STATS” | grep “^Net::Interface” | awk ‘{sum+=\(2} END {print sum}') OUT_BYTES=\)(echo “\(TRAFFIC_STATS" | grep "^Net::Interface" | awk '{sum+=\)3} END {print sum}’)
获取连接数信息
CONNECTION_STATS=\((sshpass -p \)F5_PASS ssh \(F5_USER@\)F5_IP “tmsh show ltm virtual detail | egrep ‘Virtual server|Current connections’” ) CURRENT_CONNECTIONS=\((echo "\)CONNECTION_STATS” | grep “^Current connections:”| awk ‘{print \(NF}') VIRTUAL_SERVER_COUNT=\)(echo “$CONNECTION_STATS”|grep “^Virtual server”|wc -l)
输出Prometheus Metrics格式的指标数据
cat < f5_cpu_usage{\(F5_IP} \)CPU_USAGE f5_mem_usage{\(F5_IP} \)MEM_USAGE f5_in_bytes{\(F5_IP} \)IN_BYTES f5_out_bytes{\(F5_IP} \)OUT_BYTES f5_current_connections{\(F5_IP} \)CURRENT_CONNECTIONS f_count_of_virtual_servers{\(F8_IP} \)VIRTUAL_SERVER_COUNT EOFHELP f5_cpu_usage CPU usage on F5 device
TYPE f5_cpu_usage gauge
HELP f5_mem_usage Memory usage on F5 device
TYPE f5_mem_usage gauge
HELP f5_in_bytes Inbound traffic on F5 device in bytes
TYPE f5_in_bytes counter
HELP f5_out_bytes Outbound traffic on F5 device in bytes
TYPE f5_out_bytes counter
HELP f5_current_connections Number of current connections on F5 virtual servers
TYPE f5_current_connections gauge
HELP f_count_of_virtual_servers Total number of virtual servers configured
TYPE count_of_virtual_servers gauge