use of io.vertigo.commons.analytics.metric.Metrics in project vertigo by KleeGroup.
the class MetricAnalyticsUtil method createMetricDefinitions.
/**
* Registers all methods annotated with @Metrics
*/
public static List<MetricDefinition> createMetricDefinitions(final String componentId, final Component component, final AopPlugin aopPlugin) {
Assertion.checkNotNull(component);
// -- we construct a map of feature by componentId
final Map<String, String> featureByComponentId = new HashMap<>();
Home.getApp().getConfig().getModuleConfigs().forEach(moduleConfig -> moduleConfig.getComponentConfigs().forEach(componentConfig -> featureByComponentId.put(componentConfig.getId(), moduleConfig.getName())));
// 1. search all methods
return Stream.of(aopPlugin.unwrap(component).getClass().getMethods()).filter(method -> method.isAnnotationPresent(Metrics.class)).map(method -> {
Assertion.checkArgument(List.class.isAssignableFrom(method.getReturnType()), "metrics supplier methods of class {0} must return a List of Metric instead of {1}", component.getClass(), method.getReturnType());
Assertion.checkArgument(method.getParameterTypes().length == 0, "metrics supplier methods of class {0} must not have any parameter", component.getClass());
// -----
// 2. For each method register a listener
// we remove # because it doesn't comply with definition naming rule
final String metricDefinitionName = "MET_" + StringUtil.camelToConstCase(componentId.replaceAll("#", "")) + "$" + StringUtil.camelToConstCase(method.getName());
return new MetricDefinition(metricDefinitionName, () -> (List<Metric>) ClassUtil.invoke(component, method));
}).collect(Collectors.toList());
}
use of io.vertigo.commons.analytics.metric.Metrics in project vertigo by KleeGroup.
the class SystemMetricsProvider method getSystemMetrics.
@Metrics
public List<Metric> getSystemMetrics() {
final OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();
final Runtime runtime = Runtime.getRuntime();
// ---
final Metric memoryUsed = buildMetric("memoryUsed", () -> Long.valueOf(runtime.totalMemory() / 1024 / 1024).doubleValue());
final Metric memoryUsedPercent = buildMetric("memoryUsedPercent", () -> Long.valueOf(runtime.totalMemory()).doubleValue() / runtime.maxMemory() * 100);
final Metric cpuUsage = buildMetric("cpuUsage", () -> operatingSystemMXBean.getSystemLoadAverage());
// ---
return Arrays.asList(memoryUsed, memoryUsedPercent, cpuUsage);
}
Aggregations