| 121 | } |
| 122 | |
| 123 | CheckableCheckStatistics CIB::CalculateServiceCheckStats() |
| 124 | { |
| 125 | double min_latency = -1, max_latency = 0, sum_latency = 0; |
| 126 | int count_latency = 0; |
| 127 | double min_execution_time = -1, max_execution_time = 0, sum_execution_time = 0; |
| 128 | int count_execution_time = 0; |
| 129 | bool checkresult = false; |
| 130 | |
| 131 | for (const Service::Ptr& service : ConfigType::GetObjectsByType<Service>()) { |
| 132 | ObjectLock olock(service); |
| 133 | |
| 134 | CheckResult::Ptr cr = service->GetLastCheckResult(); |
| 135 | |
| 136 | if (!cr) |
| 137 | continue; |
| 138 | |
| 139 | /* set to true, we have a checkresult */ |
| 140 | checkresult = true; |
| 141 | |
| 142 | /* latency */ |
| 143 | double latency = cr->CalculateLatency(); |
| 144 | |
| 145 | if (min_latency == -1 || latency < min_latency) |
| 146 | min_latency = latency; |
| 147 | |
| 148 | if (latency > max_latency) |
| 149 | max_latency = latency; |
| 150 | |
| 151 | sum_latency += latency; |
| 152 | count_latency++; |
| 153 | |
| 154 | /* execution_time */ |
| 155 | double execution_time = cr->CalculateExecutionTime(); |
| 156 | |
| 157 | if (min_execution_time == -1 || execution_time < min_execution_time) |
| 158 | min_execution_time = execution_time; |
| 159 | |
| 160 | if (execution_time > max_execution_time) |
| 161 | max_execution_time = execution_time; |
| 162 | |
| 163 | sum_execution_time += execution_time; |
| 164 | count_execution_time++; |
| 165 | } |
| 166 | |
| 167 | if (!checkresult) { |
| 168 | min_latency = 0; |
| 169 | min_execution_time = 0; |
| 170 | } |
| 171 | |
| 172 | CheckableCheckStatistics ccs; |
| 173 | |
| 174 | ccs.min_latency = min_latency; |
| 175 | ccs.max_latency = max_latency; |
| 176 | ccs.avg_latency = sum_latency / count_latency; |
| 177 | ccs.min_execution_time = min_execution_time; |
| 178 | ccs.max_execution_time = max_execution_time; |
| 179 | ccs.avg_execution_time = sum_execution_time / count_execution_time; |
| 180 |
nothing calls this directly
no test coverage detected