Class: MuninManager::Plugins::StarlingNet

Inherits:
Object
  • Object
show all
Includes:
ActsAsMuninPlugin
Defined in:
lib/munin_manager/plugins/starling_net.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ActsAsMuninPlugin

included

Constructor Details

#initialize(host, port) ⇒ StarlingNet

Returns a new instance of StarlingNet.



12
13
14
15
16
# File 'lib/munin_manager/plugins/starling_net.rb', line 12

def initialize(host, port)
  @host = "#{host}:#{port}"
  @starling = Starling.new(@host)
  @category = 'starling'
end

Class Method Details

.runObject



59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/munin_manager/plugins/starling_net.rb', line 59

def self.run
  host = ENV['HOST'] || '127.0.0.1';
  port = ENV['PORT'] || 22122;
  starling = new(host, port)


  allowed_commands = ['config']

  if cmd = ARGV[0] and allowed_commands.include? cmd then
    puts starling.send(cmd.to_sym)
  else
    puts starling.values
  end
end

Instance Method Details

#configObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/munin_manager/plugins/starling_net.rb', line 36

def config
  graph_config = <<-END.gsub(/  +/, '')
    graph_title Starling traffic
    graph_args --base 1000
    graph_vlabel bits read(-) / written(+) per second
    graph_category #{@category}
    graph_order bytes_read bytes_written
  END

  stat_config = ''
  net_stats.each do |stat,config|
    config.each do |var,value|
      stat_config << "#{stat}.#{var} #{value}\n"
    end
  end
  return graph_config + stat_config
end

#net_statsObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/munin_manager/plugins/starling_net.rb', line 18

def net_stats
  stats = {
    :bytes_read => {
      :label => 'read',
      :type => 'COUNTER',
      :graph => 'no',
      :cdef => 'bytes_read,8,*'
    },
    :bytes_written => {
      :label => 'bps',
      :type => 'COUNTER',
      :cdef => 'bytes_written,8,*',
      :negative => 'bytes_read'
    }
  }
  return stats
end

#valuesObject



54
55
56
57
# File 'lib/munin_manager/plugins/starling_net.rb', line 54

def values
  ret = "bytes_read.value #{@starling.stats[@host]['bytes_read']}\n"
  ret << "bytes_written.value #{@starling.stats[@host]['bytes_written']}\n"
end