Search in sources :

Example 1 with CustomGarbageCollectorMetricSet

use of com.linkedin.drelephant.metrics.CustomGarbageCollectorMetricSet in project dr-elephant by linkedin.

the class MetricsController method init.

/**
 * Initializer method for the metrics registry. Call this method before registering
 * new metrics with the registry.
 */
public static void init() {
    // Metrics registries will be initialized only if enabled
    if (!Configuration.root().getBoolean("metrics", false)) {
        LOGGER.debug("Metrics not enabled in the conf file.");
        return;
    }
    // Metrics & healthcheck registries will be initialized only once
    if (_metricRegistry != null) {
        LOGGER.debug("Metric registries already initialized.");
        return;
    }
    _metricRegistry = new MetricRegistry();
    String className = AnalyticJob.class.getSimpleName();
    _skippedJobs = _metricRegistry.meter(name(className, "skippedJobs", "count"));
    _processedJobs = _metricRegistry.meter(name(className, "processedJobs", "count"));
    _jobProcessingTime = _metricRegistry.histogram(name(className, "jobProcessingTime", "ms"));
    _metricRegistry.register(name(className, "jobQueue", "size"), new Gauge<Integer>() {

        @Override
        public Integer getValue() {
            return _queueSize;
        }
    });
    _metricRegistry.register(name(className, "lastDayJobs", "count"), new Gauge<Integer>() {

        private static final long DAY = 24 * 60 * 60 * 1000;

        private static final long UPDATE_DELAY = 60 * 1000;

        private long _lastUpdate = 0;

        private int _count = -1;

        @Override
        public Integer getValue() {
            long now = System.currentTimeMillis();
            if (now - _lastUpdate > UPDATE_DELAY) {
                _count = AppResult.find.where().gt(AppResult.TABLE.FINISH_TIME, now - DAY).findRowCount();
                _lastUpdate = now;
            }
            return _count;
        }
    });
    _metricRegistry.register(name(className, "retryQueue", "size"), new Gauge<Integer>() {

        @Override
        public Integer getValue() {
            return _retryQueueSize;
        }
    });
    _metricRegistry.registerAll(new CustomGarbageCollectorMetricSet());
    _metricRegistry.registerAll(new MemoryUsageGaugeSet());
    JmxReporter.forRegistry(_metricRegistry).build().start();
    _healthCheckRegistry = new HealthCheckRegistry();
    _healthCheckRegistry.register("ThreadDeadlockHealthCheck", new ThreadDeadlockHealthCheck());
}
Also used : MemoryUsageGaugeSet(com.codahale.metrics.jvm.MemoryUsageGaugeSet) MetricRegistry(com.codahale.metrics.MetricRegistry) HealthCheckRegistry(com.codahale.metrics.health.HealthCheckRegistry) ThreadDeadlockHealthCheck(com.codahale.metrics.health.jvm.ThreadDeadlockHealthCheck) CustomGarbageCollectorMetricSet(com.linkedin.drelephant.metrics.CustomGarbageCollectorMetricSet)

Aggregations

MetricRegistry (com.codahale.metrics.MetricRegistry)1 HealthCheckRegistry (com.codahale.metrics.health.HealthCheckRegistry)1 ThreadDeadlockHealthCheck (com.codahale.metrics.health.jvm.ThreadDeadlockHealthCheck)1 MemoryUsageGaugeSet (com.codahale.metrics.jvm.MemoryUsageGaugeSet)1 CustomGarbageCollectorMetricSet (com.linkedin.drelephant.metrics.CustomGarbageCollectorMetricSet)1