Class: Netdata::Client::Helper::DataAggregator
- Inherits:
-
Object
- Object
- Netdata::Client::Helper::DataAggregator
- Defined in:
- lib/netdata/client/helper/data_aggregator.rb
Overview
Organize and parse data for certain flags
Instance Method Summary collapse
-
#get_cpu(url) ⇒ Object
…
-
#get_cpu_users(url) ⇒ Object
…
-
#initialize ⇒ DataAggregator
constructor
Initializer.
-
#parse_alarms(data) ⇒ Object
…
Constructor Details
#initialize ⇒ DataAggregator
Initializer
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/netdata/client/helper/data_aggregator.rb', line 7 def initialize @network = Network.new # CPU usage per-user request options @users_cpu_opts = { 'chart' => 'users.cpu', 'format' => 'array', 'points' => 54, 'group' => 'average', 'options' => 'absolute|jsonwrap|nonzero', 'after' => -540 } # raw CPU request options @cpu_opts = { 'chart' => 'system.cpu', 'format' => 'array', 'points' => 54, 'group' => 'average', 'options' => 'absolute|jsonwrap|nonzero', 'after' => -540 } end |
Instance Method Details
#get_cpu(url) ⇒ Object
… Params:
51 52 53 54 55 |
# File 'lib/netdata/client/helper/data_aggregator.rb', line 51 def get_cpu(url) cpu = @network.get('data', url, @cpu_opts) JSON.parse(cpu.body)['result'].first end |
#get_cpu_users(url) ⇒ Object
… Params:
59 60 61 62 63 64 65 66 67 68 |
# File 'lib/netdata/client/helper/data_aggregator.rb', line 59 def get_cpu_users(url) users_cpu = @network.get('data', url, @users_cpu_opts) users_cpu_resp = JSON.parse(users_cpu.body) users_cpu_value = users_cpu_resp['result'].first users_cpu_value_history = users_cpu_resp['result'][0..119] users_cpu_users = users_cpu_resp['dimension_names'] [users_cpu_value_history, users_cpu_value, users_cpu_users] end |
#parse_alarms(data) ⇒ Object
… Params:
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/netdata/client/helper/data_aggregator.rb', line 33 def parse_alarms(data) out = data.dup return { 'hostname' => data['hostname'] } if data['alarms'].empty? out['alarms'] = nil data['alarms'].each do |alarm| alarm_value = alarm[1] recipient = alarm_value['recipient'] out['alarms'] = alarm_value unless recipient == 'silent' end out end |