怎么可以做网站,骨干校建设验收网站,网页制作与网站建设的题,seo网络优化招聘背景需求很简单#xff0c;分析所有的设备的内存使用率#xff0c;看那些设备的内存不够用是否需要加内存。。。下面的脚本逻辑#xff0c;就是通过提取zabbix数据库中的hostid#xff0c;在提取itemid。。然后通过item name过滤提取趋势数据#xff0c;获取一天中最大的内… 背景需求很简单分析所有的设备的内存使用率看那些设备的内存不够用是否需要加内存。。。 下面的脚本逻辑就是通过提取zabbix数据库中的hostid在提取itemid。。 然后通过item name过滤提取趋势数据获取一天中最大的内存总数和最小可用内存 然后在计算在一天中最小内存可用率的设备 下面的是通过free来计算的当然也可以通过used来计算了...#!/usr/bin/ruby
$KCODE utf8
require mysqldb Mysql.real_connect(1.1.1.1,zabbix,abbix,zabbix,3389)
db.query(SET character_set_results utf8 ;)host db.query(select hostid,host from hosts where host like %sinanode.com%)
time Time.now - 3600*24host.each_hash do |h|items db.query(select itemid,name from items where hostid #{h[hostid]} )total 0free 0items.each_hash do |item|if item[name] ~ /内存总数/total db.query(select min(value_max) from trends_uint where itemid #{item[itemid]} and clock UNIX_TIMESTAMP(#{time.strftime(%F %X)}); ).fetch_rowputs #{h[host]} #{item[itemid]} #{item[name]} #{total}endif item[name] ~ /可用内存/free db.query(select min(value_max) from trends_uint where itemid #{item[itemid]} and clock UNIX_TIMESTAMP(#{time.strftime(%F %X)}); ).fetch_rowputs #{h[host]} #{item[itemid]} #{item[name]} #{free}endendif free ! 0usage free.to_s.to_f/total.to_s.to_f*100puts #{h[host]} 最近一天最小空闲使用率: #{format(%.2f,usage)} total: #{total} free: #{free}endend 转载于:https://blog.51cto.com/kinda22/1585410