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
23 24 25 26 27 28 29 30 31 |
# File 'lib/icinga2/statistics.rb', line 23 def average_statistics 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
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/icinga2/statistics.rb', line 121 def host_statistics 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
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/icinga2/statistics.rb', line 48 def interval_statistics # 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
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/icinga2/statistics.rb', line 83 def service_statistics 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
148 149 150 151 152 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 |
# File 'lib/icinga2/statistics.rb', line 148 def work_queue_statistics stats = {} data = Network.api_data( url: format( '%s/status', @icinga_api_url_base ), headers: @headers, options: @options ) return stats if data.nil? if( data.dig(:status).nil? ) results = data.dig('results') json_rpc_data = results.find { |k| k['name'] == 'ApiListener' } graphite_data = results.find { |k| k['name'] == 'GraphiteWriter' } ido_mysql_data = results.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? ) a = {} a['json_rpc'] = json_rpc_data if(json_rpc_data.is_a?(Hash)) a['graphite'] = graphite_data if(graphite_data.is_a?(Hash)) a['ido-mysql'] = ido_mysql_data if(ido_mysql_data.is_a?(Hash)) key_list = %w[work_queue_item_rate query_queue_item_rate] a.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 |