Search in sources :

Example 1 with MeasurementUnit

use of org.jboss.as.controller.client.helpers.MeasurementUnit 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)

Example 2 with MeasurementUnit

use of org.jboss.as.controller.client.helpers.MeasurementUnit in project wildfly by wildfly.

the class JmxMetricCollector method metadataOf.

private JmxMetricMetadata metadataOf(Map.Entry<String, List<MetricProperty>> metadataEntry) {
    String name = metadataEntry.getKey();
    Map<String, String> entryProperties = new HashMap<>();
    metadataEntry.getValue().forEach(prop -> entryProperties.put(prop.propertyKey, prop.propertyValue));
    List<String> tagsToFill = new ArrayList<>();
    if (entryProperties.containsKey("tagsToFill")) {
        tagsToFill = Arrays.asList(entryProperties.get("tagsToFill").split(","));
    }
    final MeasurementUnit unit = (entryProperties.get("unit") == null) ? NONE : MeasurementUnit.valueOf(entryProperties.get("unit").toUpperCase());
    JmxMetricMetadata metadata = new JmxMetricMetadata(name, entryProperties.get("description"), unit, MetricMetadata.Type.valueOf(entryProperties.get("type").toUpperCase()), entryProperties.get("mbean"), tagsToFill, Collections.emptyList());
    return metadata;
}
Also used : MeasurementUnit(org.jboss.as.controller.client.helpers.MeasurementUnit) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList)

Aggregations

MeasurementUnit (org.jboss.as.controller.client.helpers.MeasurementUnit)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 PathAddress (org.jboss.as.controller.PathAddress)1 PathElement (org.jboss.as.controller.PathElement)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