use of org.jboss.as.controller.descriptions.DescriptionProvider in project wildfly by wildfly.
the class MetricCollector method collectResourceMetrics0.
private void collectResourceMetrics0(final Resource current, ImmutableManagementResourceRegistration managementResourceRegistration, PathAddress address, Function<PathAddress, PathAddress> resourceAddressResolver, MetricRegistration registration, boolean exposeAnySubsystem, List<String> exposedSubsystems, String prefix) {
if (!isExposingMetrics(address, exposeAnySubsystem, exposedSubsystems)) {
return;
}
Map<String, AttributeAccess> attributes = managementResourceRegistration.getAttributes(address);
if (attributes == null) {
return;
}
ModelNode resourceDescription = null;
for (Map.Entry<String, AttributeAccess> entry : attributes.entrySet()) {
String attributeName = entry.getKey();
AttributeAccess attributeAccess = entry.getValue();
if (!isCollectibleMetric(attributeAccess)) {
continue;
}
if (resourceDescription == null) {
DescriptionProvider modelDescription = managementResourceRegistration.getModelDescription(address);
resourceDescription = modelDescription.getModelDescription(Locale.getDefault());
}
PathAddress resourceAddress = resourceAddressResolver.apply(address);
MeasurementUnit unit = attributeAccess.getAttributeDefinition().getMeasurementUnit();
boolean isCounter = attributeAccess.getFlags().contains(AttributeAccess.Flag.COUNTER_METRIC);
String attributeDescription = resourceDescription.get(ATTRIBUTES, attributeName, DESCRIPTION).asStringOrNull();
WildFlyMetric metric = new WildFlyMetric(modelControllerClient, resourceAddress, attributeName);
WildFlyMetricMetadata metadata = new WildFlyMetricMetadata(attributeName, resourceAddress, prefix, attributeDescription, unit, isCounter ? COUNTER : GAUGE);
registration.addRegistrationTask(() -> registration.registerMetric(metric, metadata));
registration.addUnregistrationTask(metadata.getMetricID());
}
for (String type : current.getChildTypes()) {
for (Resource.ResourceEntry entry : current.getChildren(type)) {
final PathElement pathElement = entry.getPathElement();
final PathAddress childAddress = address.append(pathElement);
collectResourceMetrics0(entry, managementResourceRegistration, childAddress, resourceAddressResolver, registration, exposeAnySubsystem, exposedSubsystems, prefix);
}
}
}
Aggregations