Module: Icinga2::Statistics
- Included in:
- Client
- Defined in:
- lib/icinga2/statistics.rb
Overview
namespace for icinga2 statistics
Instance Method Summary collapse
-
#average_statistics ⇒ Hash
return statistic data for latency and execution_time.
-
#host_statistics ⇒ Hash
return statistic data for hosts.
-
#interval_statistics ⇒ Hash
return statistic data for intervall data.
-
#service_statistics ⇒ Hash
return statistic data for services.
-
#work_queue_statistics ⇒ Hash
return queue statistics from the api.
Instance Method Details
#average_statistics ⇒ Hash
return statistic data for latency and execution_time
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/icinga2/statistics.rb', line 22 def average_statistics cib_data if((Time.now.to_i - @last_cib_data_called).to_i > @last_call_timeout) avg_latency = @avg_latency.nil? ? 0 : @avg_latency avg_execution_time = @avg_execution_time.nil? ? 0 : @avg_execution_time { latency: avg_latency.to_f, execution_time: avg_execution_time.to_f } end |
#host_statistics ⇒ Hash
return statistic data for hosts
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/icinga2/statistics.rb', line 124 def host_statistics cib_data if((Time.now.to_i - @last_cib_data_called).to_i > @last_call_timeout) hosts_up = @hosts_up.nil? ? 0 : @hosts_up hosts_down = @hosts_down.nil? ? 0 : @hosts_down hosts_pending = @hosts_pending.nil? ? 0 : @hosts_pending hosts_unreachable = @hosts_unreachable.nil? ? 0 : @hosts_unreachable hosts_in_downtime = @hosts_in_downtime.nil? ? 0 : @hosts_in_downtime hosts_acknowledged = @hosts_acknowledged.nil? ? 0 : @hosts_acknowledged { up: hosts_up.to_i, down: hosts_down.to_i, pending: hosts_pending.to_i, unreachable: hosts_unreachable.to_i, in_downtime: hosts_in_downtime.to_i, acknowledged: hosts_acknowledged.to_i } end |
#interval_statistics ⇒ Hash
return statistic data for intervall data
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/icinga2/statistics.rb', line 49 def interval_statistics cib_data if((Time.now.to_i - @last_cib_data_called).to_i > @last_call_timeout) # take a look into https://github.com/Icinga/pkg-icinga2-debian/blob/master/lib/icinga/cib.cpp hosts_active_checks = @hosts_active_checks_1min.nil? ? 0 : @hosts_active_checks_1min hosts_passive_checks = @hosts_passive_checks_1min.nil? ? 0 : @hosts_passive_checks_1min services_active_checks = @services_active_checks_1min.nil? ? 0 : @services_active_checks_1min services_passive_checks = @services_passive_checks_1min.nil? ? 0 : @services_passive_checks_1min { hosts_active_checks: hosts_active_checks.to_f, hosts_passive_checks: hosts_passive_checks.to_f, services_active_checks: services_active_checks.to_f, services_passive_checks: services_passive_checks.to_f } end |
#service_statistics ⇒ Hash
return statistic data for services
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/icinga2/statistics.rb', line 85 def service_statistics cib_data if((Time.now.to_i - @last_cib_data_called).to_i > @last_call_timeout) services_ok = @services_ok.nil? ? 0 : @services_ok services_warning = @services_warning.nil? ? 0 : @services_warning services_critical = @services_critical.nil? ? 0 : @services_critical services_unknown = @services_unknown.nil? ? 0 : @services_unknown services_pending = @services_pending.nil? ? 0 : @services_pending services_in_downtime = @services_in_downtime.nil? ? 0 : @services_in_downtime services_acknowledged = @services_acknowledged.nil? ? 0 : @services_acknowledged { ok: services_ok.to_i, warning: services_warning.to_i, critical: services_critical.to_i, unknown: services_unknown.to_i, pending: services_pending.to_i, in_downtime: services_in_downtime.to_i, acknowledged: services_acknowledged.to_i } end |
#work_queue_statistics ⇒ Hash
return queue statistics from the api
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
# File 'lib/icinga2/statistics.rb', line 153 def work_queue_statistics stats = {} data = api_data( url: format( '%s/status', @icinga_api_url_base ), headers: @headers, options: @options ) return stats if data.nil? if( data.is_a?(Array) ) json_rpc_data = data.find { |k| k['name'] == 'ApiListener' } graphite_data = data.find { |k| k['name'] == 'GraphiteWriter' } ido_mysql_data = data.find { |k| k['name'] == 'IdoMysqlConnection' } json_rpc_data = json_rpc_data.dig('status', 'api', 'json_rpc') unless( json_rpc_data.nil? ) graphite_data = graphite_data.dig('status', 'graphitewriter', 'graphite') unless( graphite_data.nil? ) ido_mysql_data = ido_mysql_data.dig('status', 'idomysqlconnection', 'ido-mysql') unless( ido_mysql_data.nil? ) payload = { json_rpc: json_rpc_data, graphite: graphite_data, ido_mysql: ido_mysql_data } payload.reject!{ |_k, v| v.nil? } key_list = %w[work_queue_item_rate query_queue_item_rate] payload.each do |k,v| key_list.each do |key| if( v.include?( key )) attr_name = format('%s queue rate', k) stats[attr_name] = v[key].to_f.round(3) end end end end stats end |