Ejemplo n.º 1
0
  private void reportToElasticsearch(
      Metric2Registry metricRegistry,
      int reportingInterval,
      final MeasurementSession measurementSession,
      CorePlugin corePlugin) {
    if (isReportToElasticsearch()) {
      elasticsearchClient.sendBulkAsync("KibanaConfig.bulk");
      logger.info(
          "Sending metrics to Elasticsearch ({}) every {}s",
          getElasticsearchUrl(),
          reportingInterval);
      final String mappingJson =
          ElasticsearchClient.requireBoxTypeHotIfHotColdAritectureActive(
              "stagemonitor-elasticsearch-metrics-index-template.json",
              corePlugin.moveToColdNodesAfterDays.getValue());
      elasticsearchClient.sendMappingTemplateAsync(mappingJson, "stagemonitor-metrics");
      final ElasticsearchReporter reporter =
          new ElasticsearchReporter(
              metricRegistry,
              Metric2Filter.ALL,
              TimeUnit.SECONDS,
              TimeUnit.MILLISECONDS,
              measurementSession.asMap(),
              new HttpClient(),
              this);

      reporter.start(reportingInterval, TimeUnit.SECONDS);
      reporters.add(reporter);
      elasticsearchClient.scheduleIndexManagement(
          ElasticsearchReporter.STAGEMONITOR_METRICS_INDEX_PREFIX,
          moveToColdNodesAfterDays.getValue(),
          deleteElasticsearchMetricsAfterDays.getValue());
    } else {
      logger.info(
          "Not sending metrics to Elasticsearch (url={}, interval={}s)",
          getElasticsearchUrl(),
          reportingInterval);
    }
  }