class NewRelicOpenvpnAgent::Agent
Attributes
ident[R]
Public Instance Methods
poll_cycle()
click to toggle source
# File lib/newrelic_pivpn_agent.rb, line 20 def poll_cycle [:total_users, :total_bytes_received, :total_bytes_sent, :average_bytes_received, :average_bytes_sent].each do |_type| name, unit, _output = metric(_type) report_metric name, unit, _output.call end end
Private Instance Methods
get_columns(_output, _c_index, _uniq = true, _total = true)
click to toggle source
# File lib/newrelic_pivpn_agent.rb, line 29 def get_columns(_output, _c_index, _uniq = true, _total = true) result = _output.scan(/CLIENT_LIST[\s]+([0-9a-zA-Z]+)[\s]+((\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}):\d+)[\s]+(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})[\s]+([0-9]+)[\s]+([0-9]+)[\s]+([A-Za-z0-9]+[\s]+[a-zA-Z0-9]+[\s]+[0-9]+[\s]+[0-9:]+[\s]+[0-9]+)(\s)+([0-9]+)(\s)+([a-zA-Z]+)/).map{|_x| _x[_c_index] } result = result.uniq if _uniq result = result.length if _total result end
metric(_type)
click to toggle source
# File lib/newrelic_pivpn_agent.rb, line 36 def metric(_type) if get_columns(ovpn_cmd, 1) > 0 metrics = { :total_users => ["Total/Users", "Users", lambda{get_columns(ovpn_cmd, 1) }], :total_bytes_received => ["Total/Bytes/Received", "bytes", lambda{ get_columns(ovpn_cmd, 4, false, false).inject(0){|_t, _b| (_t + _b.to_i) } }], :total_bytes_sent => ["Total/Bytes/Sent", "bytes", lambda{ get_columns(ovpn_cmd, 5, false, false).inject(0){|_t, _b| (_t + _b.to_i) } }], :average_bytes_received => ["Average/Bytes/Received", "bytes", lambda{ x = get_columns(ovpn_cmd, 4, false, false); x.inject(0){|_t, _b| (_t + _b.to_i) } / x.length }], :average_bytes_sent => ["Average/Bytes/Sent", "bytes", lambda{ x = get_columns(ovpn_cmd, 5, false, false); x.inject(0){|_t, _b| (_t + _b.to_i) } / x.length }] } else metrics = { :total_users => ["Total/Users", "Users", lambda{0}], :total_bytes_received => ["Total/Bytes/Received", "bytes", lambda{0}], :total_bytes_sent => ["Total/Bytes/Sent", "bytes", lambda{0}], :average_bytes_received => ["Average/Bytes/Received", "bytes", lambda{0}], :average_bytes_sent => ["Average/Bytes/Sent", "bytes", lambda{0}] } end metrics[_type] end
ovpn_cmd()
click to toggle source
# File lib/newrelic_pivpn_agent.rb, line 57 def ovpn_cmd `cat #{openvpn_status_path}` end