/** * * @param HostDetailDataEvent $event * @param string $domainType */ private static function getDomainDatas(HostDetailDataEvent $event, $domainType, $serviceList) { $parentDomain['name'] = $domainType; if ($domainType !== 'FileSystem') { $parentDomain = DomainRepository::getParent($domainType); } $normalizeServiceSet = array(); foreach ($serviceList as $service) { $serviceMetricList = MetricRepository::getMetricsFromService($service['service_id']); $normalizedMetrics = DomainRepository::normalizeMetrics($domainType, $service, $serviceMetricList); if ($parentDomain['name'] === 'Application') { $normalizeServiceSet[] = $normalizedMetrics; } else { $normalizeServiceSet[$service['description']] = $normalizedMetrics; } } if (count($normalizeServiceSet) > 0) { if ($parentDomain['name'] === 'Application') { $normalizeServiceSet = array($domainType => $normalizeServiceSet); } $event->addHostDetailData(strtolower($parentDomain['name']), $normalizeServiceSet); } }
/** * * @param array $metricList * @return array */ public static function normalizeMetricsForNetwork($domain, $service, $metricList) { $normalizeMetricSet = array(); $endTime = time(); $startTime = $endTime - 3600; if (isset($metricList['traffic_in'])) { $in = $metricList['traffic_in']; // unit $currentUnitExploded = explode('/', $in['unit_name']); // Get values $metricValuesForIn = MetricRepository::getMetricsValuesFromRrd($in['metric_id'], $startTime, $endTime, $currentUnitExploded[0]); $normalizeMetricSet['in'] = $metricValuesForIn['datas']; // Max if (is_null($in['max'])) { $in['max'] = $in['current_value']; } $normalizeMetricSet['in_max'] = $in['max']; // Set Unit if (!empty($metricValuesForIn['unit'])) { $in['unit_name'] = $metricValuesForIn['unit'] . '/' . $currentUnitExploded[1]; } } else { $normalizeMetricSet['in'] = array(); $normalizeMetricSet['in_max'] = 0; } if (isset($metricList['traffic_out'])) { $out = $metricList['traffic_out']; // unit $currentUnitExploded = explode('/', $out['unit_name']); // Get values $metricValuesForout = MetricRepository::getMetricsValuesFromRrd($out['metric_id'], $startTime, $endTime, $currentUnitExploded[0]); $normalizeMetricSet['out'] = $metricValuesForout['datas']; // Max if (is_null($out['max'])) { $out['max'] = $out['current_value']; } $normalizeMetricSet['out_max'] = $out['max']; // Set Unit if (!empty($metricValuesForout['unit'])) { $out['unit_name'] = $metricValuesForout['unit'] . '/' . $currentUnitExploded[1]; } $normalizeMetricSet['unit'] = $out['unit_name']; } else { $normalizeMetricSet['out'] = array(); $normalizeMetricSet['out_max'] = 0; } if (!isset($normalizeMetricSet['unit'])) { $normalizeMetricSet['unit'] = "b/s"; } $normalizeMetricSet['status'] = strtolower(StatusUtils::numToString($service['state'], StatusUtils::TYPE_SERVICE)); return $normalizeMetricSet; }