Search in sources :

Example 11 with Metric

use of org.springframework.boot.actuate.metrics.Metric in project spring-boot by spring-projects.

the class PublicMetricsAutoConfigurationTests method autoCacheManager.

@Test
public void autoCacheManager() {
    load(CacheConfiguration.class);
    CachePublicMetrics bean = this.context.getBean(CachePublicMetrics.class);
    Collection<Metric<?>> metrics = bean.metrics();
    assertMetrics(metrics, "cache.books.size", "cache.speakers.size");
}
Also used : CachePublicMetrics(org.springframework.boot.actuate.endpoint.CachePublicMetrics) Metric(org.springframework.boot.actuate.metrics.Metric) Test(org.junit.Test)

Example 12 with Metric

use of org.springframework.boot.actuate.metrics.Metric in project spring-boot by spring-projects.

the class PublicMetricsAutoConfigurationTests method multipleCacheManagers.

@Test
public void multipleCacheManagers() {
    load(MultipleCacheConfiguration.class);
    CachePublicMetrics bean = this.context.getBean(CachePublicMetrics.class);
    Collection<Metric<?>> metrics = bean.metrics();
    assertMetrics(metrics, "cache.books.size", "cache.second_speakers.size", "cache.first_speakers.size", "cache.users.size");
}
Also used : CachePublicMetrics(org.springframework.boot.actuate.endpoint.CachePublicMetrics) Metric(org.springframework.boot.actuate.metrics.Metric) Test(org.junit.Test)

Example 13 with Metric

use of org.springframework.boot.actuate.metrics.Metric in project ontrack by nemerosa.

the class JobMetrics method metrics.

@Override
public Collection<Metric<?>> metrics() {
    // Gets the statuses
    Collection<JobStatus> statuses = scheduler.getJobStatuses();
    // Collects all metrics
    List<Metric<?>> metrics = new ArrayList<>();
    // Statuses
    JobMetric general = new JobMetric();
    Map<String, JobMetric> categories = new HashMap<>();
    for (JobStatus status : statuses) {
        general.count++;
        JobMetric.getCategory(categories, status).count++;
        if (status.isRunning()) {
            general.running++;
            JobMetric.getCategory(categories, status).running++;
        }
        if (status.isDisabled()) {
            general.disabled++;
            JobMetric.getCategory(categories, status).disabled++;
        }
        if (!status.isValid()) {
            general.invalid++;
            JobMetric.getCategory(categories, status).invalid++;
        }
        if (status.isPaused()) {
            general.paused++;
            JobMetric.getCategory(categories, status).paused++;
        }
        if (status.isError()) {
            general.error++;
            JobMetric.getCategory(categories, status).error++;
        }
    }
    // Collection of metrics
    metrics.add(new Metric<>("gauge.jobs", general.count));
    metrics.add(new Metric<>("gauge.jobs.running", general.running));
    metrics.add(new Metric<>("gauge.jobs.disabled", general.disabled));
    metrics.add(new Metric<>("gauge.jobs.error", general.error));
    metrics.add(new Metric<>("gauge.jobs.invalid", general.invalid));
    metrics.add(new Metric<>("gauge.jobs.paused", general.paused));
    // Per categories
    for (Map.Entry<String, JobMetric> entry : categories.entrySet()) {
        String category = entry.getKey();
        JobMetric metric = entry.getValue();
        metrics.add(new Metric<>("gauge.jobs." + category, metric.count));
        metrics.add(new Metric<>("gauge.jobs." + category + ".running", metric.running));
        metrics.add(new Metric<>("gauge.jobs." + category + ".disabled", metric.disabled));
        metrics.add(new Metric<>("gauge.jobs." + category + ".error", metric.error));
        metrics.add(new Metric<>("gauge.jobs." + category + ".invalid", metric.invalid));
        metrics.add(new Metric<>("gauge.jobs." + category + ".paused", metric.paused));
    }
    // OK
    return metrics;
}
Also used : JobStatus(net.nemerosa.ontrack.job.JobStatus) TaggedMetric(net.nemerosa.ontrack.model.metrics.TaggedMetric) Metric(org.springframework.boot.actuate.metrics.Metric)

Example 14 with Metric

use of org.springframework.boot.actuate.metrics.Metric in project ontrack by nemerosa.

the class DataSourceMetrics method metrics.

@Override
public Collection<Metric<?>> metrics() {
    List<Metric<?>> metrics = new ArrayList<>();
    dataSources.entrySet().stream().forEach(entry -> {
        String name = entry.getKey();
        String prefix = String.format("gauge.datasource.%s", name);
        DataSource dataSource = entry.getValue();
        DataSourcePoolMetadata poolMetadata = provider.getDataSourcePoolMetadata(dataSource);
        metrics.add(new Metric<>(prefix + ".active", poolMetadata.getActive()));
        metrics.add(new Metric<>(prefix + ".max", poolMetadata.getMax()));
        metrics.add(new Metric<>(prefix + ".min", poolMetadata.getMin()));
        metrics.add(new Metric<>(prefix + ".usage", poolMetadata.getUsage()));
    });
    return metrics;
}
Also used : DataSourcePoolMetadata(org.springframework.boot.autoconfigure.jdbc.metadata.DataSourcePoolMetadata) ArrayList(java.util.ArrayList) Metric(org.springframework.boot.actuate.metrics.Metric) DataSource(javax.sql.DataSource)

Example 15 with Metric

use of org.springframework.boot.actuate.metrics.Metric in project spring-boot by spring-projects.

the class PublicMetricsAutoConfigurationTests method multipleDataSourcesWithCustomPrimary.

@Test
public void multipleDataSourcesWithCustomPrimary() {
    load(MultipleDataSourcesWithCustomPrimaryConfig.class);
    PublicMetrics bean = this.context.getBean(DataSourcePublicMetrics.class);
    Collection<Metric<?>> metrics = bean.metrics();
    assertMetrics(metrics, "datasource.primary.active", "datasource.primary.usage", "datasource.dataSource.active", "datasource.dataSource.usage");
}
Also used : Metric(org.springframework.boot.actuate.metrics.Metric) RichGaugeReaderPublicMetrics(org.springframework.boot.actuate.endpoint.RichGaugeReaderPublicMetrics) MetricReaderPublicMetrics(org.springframework.boot.actuate.endpoint.MetricReaderPublicMetrics) CachePublicMetrics(org.springframework.boot.actuate.endpoint.CachePublicMetrics) DataSourcePublicMetrics(org.springframework.boot.actuate.endpoint.DataSourcePublicMetrics) TomcatPublicMetrics(org.springframework.boot.actuate.endpoint.TomcatPublicMetrics) PublicMetrics(org.springframework.boot.actuate.endpoint.PublicMetrics) SystemPublicMetrics(org.springframework.boot.actuate.endpoint.SystemPublicMetrics) Test(org.junit.Test)

Aggregations

Metric (org.springframework.boot.actuate.metrics.Metric)24 Test (org.junit.Test)11 CachePublicMetrics (org.springframework.boot.actuate.endpoint.CachePublicMetrics)7 RichGaugeReaderPublicMetrics (org.springframework.boot.actuate.endpoint.RichGaugeReaderPublicMetrics)6 LongAdder (java.util.concurrent.atomic.LongAdder)5 Theory (org.junit.experimental.theories.Theory)5 DataSourcePublicMetrics (org.springframework.boot.actuate.endpoint.DataSourcePublicMetrics)5 MetricReaderPublicMetrics (org.springframework.boot.actuate.endpoint.MetricReaderPublicMetrics)5 PublicMetrics (org.springframework.boot.actuate.endpoint.PublicMetrics)5 SystemPublicMetrics (org.springframework.boot.actuate.endpoint.SystemPublicMetrics)5 TomcatPublicMetrics (org.springframework.boot.actuate.endpoint.TomcatPublicMetrics)5 ArrayList (java.util.ArrayList)4 Date (java.util.Date)4 HashSet (java.util.HashSet)3 ExecutorService (java.util.concurrent.ExecutorService)3 Future (java.util.concurrent.Future)3 HashMap (java.util.HashMap)2 DataSource (javax.sql.DataSource)2 RichGauge (org.springframework.boot.actuate.metrics.rich.RichGauge)2 Counter (com.codahale.metrics.Counter)1