Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'rubygems'
- require 'open-uri'
- require 'time'
- $config = {
- "-ip" => "168.198.1.213"
- }
- $maxitem = 10
- $pollseries = []
- #---------------------
- def poll( ip )
- puts "#{ip}"
- url="http://#{ip}:9100/metrics"
- puts $url
- cpu_idle_val = {}
- open($url).read.split("\n").each {|line|
- if line[/^node_cpu_seconds_total/] && line[/idle/]
- tokens = line.split(" ")
- txt = tokens[0]
- match = txt.match(/(?<cpu>cpu=\".\")/)
- cpu_id = match.captures[0].gsub("\"","").split("=")[1].to_i
- val = tokens[1].to_f
- cpu_idle_val[cpu_id] = val
- end
- }
- pollitem = {}
- pollitem[:time] = Time.now.to_i
- pollitem[:idle] = cpu_idle_val
- $pollseries << pollitem
- $pollseries.shift if $pollseries.count > $maxitem
- end
- #-----------------------------
- def report
- if $pollseries.count >= 2
- n = $pollseries.count
- last_0 = $pollseries[n-1]
- last_1 = $pollseries[n-2]
- irates = {}
- last_0[:idle].keys.each { |cpu_id|
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement