@Override
  public void start(long period, TimeUnit unit) {
    // Create metrics directory if it is not present
    if (!metricsDir.toFile().exists()) {
      LOG.warn("Metrics directory {} does not exist, creating one", metricsDir);
      try {
        // createDirectories creates all non-existent parent directories
        Files.createDirectories(metricsDir, DIR_ATTRS);
      } catch (IOException e) {
        LOG.warn("Failed to initialize JSON reporter: failed to create directory {}: {}", metricsDir, e.getMessage());
        return;
      }
    }
    jsonWriter = new ObjectMapper().registerModule(
            new MapCapableJsonMetricsModule(TimeUnit.MILLISECONDS, TimeUnit.MILLISECONDS, false))
        .writerWithDefaultPrettyPrinter();
    super.start(period, unit);
  }
A metrics reporter for Metrics that dumps metrics periodically into
a file in JSON format.
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/metrics/JsonReporter.java