Method: Bfire::Engine#metric

Defined in:
lib/bfire/engine.rb

#metric(name, options = {}) ⇒ Object



355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
# File 'lib/bfire/engine.rb', line 355

def metric(name, options = {})
  hosts = [options.delete(:hosts) || []].flatten.map{|h|
    [h['name'], h['id']].join("-")
  }
  @zabbix ||= Aggregator::Zabbix.new(session, experiment)

  items = @zabbix.request("item.get", {
    :filter => {
      "host" => hosts[0],
      "key_" => name.to_s
    },
    "output" => "extend"
  }).map{|i| i['itemid']}

  # Most recent last
  now = Time.now.to_i
  results = @zabbix.request("history.get", {
    "itemids" => items[0..1],
    # FIX once we can correctly specify metric type
    "history" => 1, # STRING
    "output" => "extend",
    "time_from" => now-3600,
    "time_till" => now
  })

  Metric.new(name, results, options)
end