Class: Visage::Collectd::RRDs

Inherits:
Object
  • Object
show all
Defined in:
lib/visage-app/collectd/rrds.rb

Class Method Summary collapse

Class Method Details

.hosts(opts = {}) ⇒ Object

Returns a list of hosts that match the supplied glob, or array of names.



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/visage-app/collectd/rrds.rb', line 17

def hosts(opts={})
  hosts = opts[:hosts]
  case hosts
  when String
    glob = "{#{hosts}}"
  when Array
    glob = "{#{opts[:hosts].join(',')}}"
  else
    glob = "*"
  end

  Dir.glob("#{rrddir}/#{glob}").map {|e| e.split('/').last }.sort.uniq
end

.metrics(opts = {}) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/visage-app/collectd/rrds.rb', line 31

def metrics(opts={})
  selected_hosts = hosts(opts)

  metrics = opts[:metrics]
  case metrics
  when String && /,/
    metric_glob = "{#{metrics}}"
  when Array
    metric_glob = "{#{opts[:metrics].join(',')}}"
  else
    metric_glob = "*/*"
  end

  dametrics = selected_hosts.map { |host|
    Dir.glob("#{rrddir}/#{host}/#{metric_glob}.rrd").map {|filename|
      filename[/#{rrddir}\/#{host}\/(.*)\.rrd/, 1]
    }
  }
  if (dametrics.length) == 1
    dametrics.first
  else
    dametrics.reduce(:&)
  end

  #else
  #  Dir.glob("#{rrddir}/#{host_glob}/#{glob}.rrd").map {|e| e.split('/')[-2..-1].join('/').gsub(/\.rrd$/, '')}.sort.uniq
  #end

end

.rrddirObject



12
13
14
# File 'lib/visage-app/collectd/rrds.rb', line 12

def rrddir
  @rrddir ||= Visage::Config.rrddir
end