Search in sources :

Example 1 with DescriptionProvider

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);
        }
    }
}
Also used : MeasurementUnit(org.jboss.as.controller.client.helpers.MeasurementUnit) Resource(org.jboss.as.controller.registry.Resource) AttributeAccess(org.jboss.as.controller.registry.AttributeAccess) PathElement(org.jboss.as.controller.PathElement) PathAddress(org.jboss.as.controller.PathAddress) ModelNode(org.jboss.dmr.ModelNode) DescriptionProvider(org.jboss.as.controller.descriptions.DescriptionProvider) Map(java.util.Map)

Aggregations

Map (java.util.Map)1 PathAddress (org.jboss.as.controller.PathAddress)1 PathElement (org.jboss.as.controller.PathElement)1 MeasurementUnit (org.jboss.as.controller.client.helpers.MeasurementUnit)1 DescriptionProvider (org.jboss.as.controller.descriptions.DescriptionProvider)1 AttributeAccess (org.jboss.as.controller.registry.AttributeAccess)1 Resource (org.jboss.as.controller.registry.Resource)1 ModelNode (org.jboss.dmr.ModelNode)1