Search in sources :

Example 1 with MonitoringDataCollector

use of fish.payara.monitoring.collect.MonitoringDataCollector in project Payara by payara.

the class GrizzlyService method collect.

@Override
public void collect(MonitoringDataCollector collector) {
    if (!"true".equals(monitoringService.getMonitoringEnabled()) || !"HIGH".equals(monitoringService.getModuleMonitoringLevels().getHttpService())) {
        return;
    }
    MonitoringDataCollector httpCollector = collector.in("http");
    httpCollector.prefix("ThreadPool").collectObject(monitoring.getThreadPoolStatsProvider(NETWORK_CONFIG_PREFIX), MonitoringDataCollection::collectObject);
    httpCollector.prefix("ConnectionQueue").collectObject(monitoring.getConnectionQueueStatsProvider(NETWORK_CONFIG_PREFIX), MonitoringDataCollection::collectObject);
    httpCollector.prefix("FileCache").collectObject(monitoring.getFileCacheStatsProvider(NETWORK_CONFIG_PREFIX), MonitoringDataCollection::collectObject);
}
Also used : MonitoringDataCollector(fish.payara.monitoring.collect.MonitoringDataCollector) MonitoringDataCollection(fish.payara.monitoring.collect.MonitoringDataCollection)

Example 2 with MonitoringDataCollector

use of fish.payara.monitoring.collect.MonitoringDataCollector in project Payara by payara.

the class SQLTraceStoreImpl method collect.

@Override
@MonitoringData(ns = "sql")
public void collect(MonitoringDataCollector collector) {
    long now = System.currentTimeMillis();
    for (Entry<String, Queue<SQLTraceEntry>> poolEntry : uncollectedTracesByPoolName.entrySet()) {
        MonitoringDataCollector poolCollector = collector.group(poolEntry.getKey());
        int count = 0;
        long maxExecutionTime = 0L;
        long sumExecutionTime = 0L;
        Queue<SQLTraceEntry> entries = poolEntry.getValue();
        SQLTraceEntry entry = entries.poll();
        while (entry != null) {
            if (now - entry.trace.getTimeStamp() < 5000) {
                // only add trace in case it was from last 5 seconds
                count++;
                long executionTime = entry.trace.getExecutionTime();
                maxExecutionTime = Math.max(maxExecutionTime, executionTime);
                sumExecutionTime += executionTime;
                if (executionTime > entry.thresholdMillis) {
                    // 
                    poolCollector.annotate(// 
                    "MaxExecutionTime", // 
                    executionTime, // 
                    "Threshold", // 
                    "" + entry.thresholdMillis, // 
                    "Timestamp", // 
                    "" + entry.trace.getTimeStamp(), "SQL", entry.sql);
                }
            }
            entry = entries.poll();
        }
        poolCollector.collect("MaxExecutionTime", maxExecutionTime).collect("AvgExecutionTime", count == 0L ? 0L : sumExecutionTime / count);
    }
}
Also used : MonitoringDataCollector(fish.payara.monitoring.collect.MonitoringDataCollector) Queue(java.util.Queue) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) MonitoringData(fish.payara.monitoring.collect.MonitoringData)

Example 3 with MonitoringDataCollector

use of fish.payara.monitoring.collect.MonitoringDataCollector in project Payara by payara.

the class MetricsServiceImpl method processMetadataToAnnotations.

private static void processMetadataToAnnotations(MetricsContextImpl context, MonitoringDataCollector collector) {
    RegisteredMetric metric = context.pollNewlyRegistered();
    while (metric != null) {
        MetricID metricID = metric.id;
        Type scope = metric.scope;
        MetricRegistry registry = context.getRegistry(scope);
        MonitoringDataCollector metricCollector = tagCollector(context.getName(), metricID, collector);
        Metadata metadata = registry.getMetadata(metricID.getName());
        String suffix = "Count";
        String property = "Count";
        boolean isGauge = metadata.getTypeRaw() == MetricType.GAUGE;
        if (isGauge) {
            suffix = getMetricUnitSuffix(metadata.unit());
            property = "Value";
        }
        // Note that by convention an annotation with value 0 done before the series collected any value is considered permanent
        metricCollector.annotate(toName(metricID, suffix), 0, false, metadataToAnnotations(context.getName(), scope, metadata, property));
        metric = context.pollNewlyRegistered();
    }
}
Also used : MonitoringDataCollector(fish.payara.monitoring.collect.MonitoringDataCollector) MetricID(org.eclipse.microprofile.metrics.MetricID) MetricType(org.eclipse.microprofile.metrics.MetricType) Type(org.eclipse.microprofile.metrics.MetricRegistry.Type) MetricRegistry(org.eclipse.microprofile.metrics.MetricRegistry) Metadata(org.eclipse.microprofile.metrics.Metadata) MBeanMetadata(fish.payara.microprofile.metrics.jmx.MBeanMetadata)

Example 4 with MonitoringDataCollector

use of fish.payara.monitoring.collect.MonitoringDataCollector in project Payara by payara.

the class HealthCheckService method collectChecks.

private Map<String, List<HealthCheckResponse>> collectChecks(MonitoringDataCollector collector, Map<String, Set<HealthCheck>> checks, Map<String, Set<String>> collected) {
    Map<String, List<HealthCheckResponse>> statusByApp = new HashMap<>();
    for (Entry<String, Set<HealthCheck>> entry : checks.entrySet()) {
        String appName = entry.getKey();
        MonitoringDataCollector appCollector = collector.group(appName);
        for (HealthCheck check : entry.getValue()) {
            HealthCheckResponse response = performHealthCheckInApplicationContext(appName, check);
            String metric = response.getName();
            Set<String> appCollected = collected.get(appName);
            // prevent adding same check more then once, unfortunately we have to run it to find that out
            if (appCollected == null || !appCollected.contains(metric)) {
                statusByApp.computeIfAbsent(appName, key -> new ArrayList<>()).add(response);
                collectUpDown(appCollector, response);
                if (response.getStatus() == Status.DOWN && response.getData().isPresent()) {
                    appCollector.annotate(metric, 0L, createAnnotation(response.getData().get()));
                }
                collected.computeIfAbsent(appName, key -> new HashSet<>()).add(metric);
            }
        }
    }
    return statusByApp;
}
Also used : MonitoringDataCollector(fish.payara.monitoring.collect.MonitoringDataCollector) JsonWriterFactory(javax.json.JsonWriterFactory) Events(org.glassfish.api.event.Events) MonitoringWatchCollector(fish.payara.monitoring.collect.MonitoringWatchCollector) Map(java.util.Map) WebApplication(com.sun.enterprise.web.WebApplication) LIVENESS(fish.payara.microprofile.healthcheck.HealthCheckType.LIVENESS) HealthCheck(org.eclipse.microprofile.health.HealthCheck) PayaraHealthCheckServiceEvents(fish.payara.nucleus.healthcheck.events.PayaraHealthCheckServiceEvents) MonitoringDataCollector(fish.payara.monitoring.collect.MonitoringDataCollector) Collections.emptyList(java.util.Collections.emptyList) UnprocessedChangeEvents(org.jvnet.hk2.config.UnprocessedChangeEvents) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) WARNING(java.util.logging.Level.WARNING) Set(java.util.Set) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) Collectors.joining(java.util.stream.Collectors.joining) MonitoringDataSource(fish.payara.monitoring.collect.MonitoringDataSource) List(java.util.List) StartupRunLevel(org.glassfish.api.StartupRunLevel) Service(org.jvnet.hk2.annotations.Service) Entry(java.util.Map.Entry) PostConstruct(javax.annotation.PostConstruct) MicroprofileHealthCheckConfiguration(fish.payara.microprofile.healthcheck.config.MicroprofileHealthCheckConfiguration) Optional(java.util.Optional) UnprocessedChangeEvent(org.jvnet.hk2.config.UnprocessedChangeEvent) JsonObjectBuilder(javax.json.JsonObjectBuilder) Deployment(org.glassfish.internal.deployment.Deployment) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) READINESS(fish.payara.microprofile.healthcheck.HealthCheckType.READINESS) JsonGenerator(javax.json.stream.JsonGenerator) InvocationManager(org.glassfish.api.invocation.InvocationManager) JsonArrayBuilder(javax.json.JsonArrayBuilder) Globals(org.glassfish.internal.api.Globals) MonitoringData(fish.payara.monitoring.collect.MonitoringData) HashMap(java.util.HashMap) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) InvocationException(org.glassfish.api.invocation.InvocationException) HealthCheckResponse(org.eclipse.microprofile.health.HealthCheckResponse) BiConsumer(java.util.function.BiConsumer) Json(javax.json.Json) Collections.singletonMap(java.util.Collections.singletonMap) EventListener(org.glassfish.api.event.EventListener) PropertyChangeEvent(java.beans.PropertyChangeEvent) WebComponentInvocation(com.sun.enterprise.web.WebComponentInvocation) RunLevel(org.glassfish.hk2.runlevel.RunLevel) StringWriter(java.io.StringWriter) HttpServletResponse(javax.servlet.http.HttpServletResponse) WebContainer(com.sun.enterprise.web.WebContainer) IOException(java.io.IOException) Checker(fish.payara.nucleus.healthcheck.configuration.Checker) STARTUP(fish.payara.microprofile.healthcheck.HealthCheckType.STARTUP) Status(org.eclipse.microprofile.health.HealthCheckResponse.Status) MonitoringWatchSource(fish.payara.monitoring.collect.MonitoringWatchSource) JsonWriter(javax.json.JsonWriter) ApplicationInfo(org.glassfish.internal.data.ApplicationInfo) ApplicationRegistry(org.glassfish.internal.data.ApplicationRegistry) ConfigListener(org.jvnet.hk2.config.ConfigListener) PayaraHealthCheck(fish.payara.microprofile.healthcheck.checks.PayaraHealthCheck) Set(java.util.Set) HashSet(java.util.HashSet) HealthCheckResponse(org.eclipse.microprofile.health.HealthCheckResponse) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) HealthCheck(org.eclipse.microprofile.health.HealthCheck) PayaraHealthCheck(fish.payara.microprofile.healthcheck.checks.PayaraHealthCheck) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet)

Example 5 with MonitoringDataCollector

use of fish.payara.monitoring.collect.MonitoringDataCollector in project Payara by payara.

the class MetricsServiceImpl method collect.

@Override
public void collect(MonitoringDataCollector rootCollector) {
    if (!isEnabled())
        return;
    MonitoringDataCollector metricsCollector = rootCollector.in("metric");
    for (MetricsContextImpl context : contextByName.values()) {
        processMetadataToAnnotations(context, metricsCollector);
        String contextName = context.getName();
        collectRegistry(contextName, context.getBaseRegistry(), metricsCollector);
        collectRegistry(contextName, context.getVendorRegistry(), metricsCollector);
        if (!context.isServerContext()) {
            collectRegistry(contextName, context.getApplicationRegistry(), metricsCollector);
        }
    }
}
Also used : MonitoringDataCollector(fish.payara.monitoring.collect.MonitoringDataCollector)

Aggregations

MonitoringDataCollector (fish.payara.monitoring.collect.MonitoringDataCollector)9 MonitoringData (fish.payara.monitoring.collect.MonitoringData)3 MonitoringDataCollection (fish.payara.monitoring.collect.MonitoringDataCollection)2 DistributedObject (com.hazelcast.core.DistributedObject)1 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 LocalTopicStats (com.hazelcast.topic.LocalTopicStats)1 WebApplication (com.sun.enterprise.web.WebApplication)1 WebComponentInvocation (com.sun.enterprise.web.WebComponentInvocation)1 WebContainer (com.sun.enterprise.web.WebContainer)1 LIVENESS (fish.payara.microprofile.healthcheck.HealthCheckType.LIVENESS)1 READINESS (fish.payara.microprofile.healthcheck.HealthCheckType.READINESS)1 STARTUP (fish.payara.microprofile.healthcheck.HealthCheckType.STARTUP)1 PayaraHealthCheck (fish.payara.microprofile.healthcheck.checks.PayaraHealthCheck)1 MicroprofileHealthCheckConfiguration (fish.payara.microprofile.healthcheck.config.MicroprofileHealthCheckConfiguration)1 NoSuchRegistryException (fish.payara.microprofile.metrics.exception.NoSuchRegistryException)1 MBeanMetadata (fish.payara.microprofile.metrics.jmx.MBeanMetadata)1 MonitoringDataSource (fish.payara.monitoring.collect.MonitoringDataSource)1 MonitoringWatchCollector (fish.payara.monitoring.collect.MonitoringWatchCollector)1 MonitoringWatchSource (fish.payara.monitoring.collect.MonitoringWatchSource)1 Checker (fish.payara.nucleus.healthcheck.configuration.Checker)1