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.register(name(className, "secondRetryQueue", "size"), new Gauge<Integer>() {
      @Override
      public Integer getValue() {
        return _secondRetryQueueSize;
      }
    });
    _metricRegistry.registerAll(new CustomGarbageCollectorMetricSet());
    _metricRegistry.registerAll(new MemoryUsageGaugeSet());

    JmxReporter.forRegistry(_metricRegistry).build().start();

    _healthCheckRegistry = new HealthCheckRegistry();

    _healthCheckRegistry.register("ThreadDeadlockHealthCheck",
        new ThreadDeadlockHealthCheck());
  }
Initializer method for the metrics registry. Call this method before registering
new metrics with the registry.
app/controllers/MetricsController.java