private List<SingleMetric> getEvents() {
    List<SingleMetric> metrics = new ArrayList<>();
    Long totalEventsCounter = 0L;
    synchronized (events) {
      for (Map.Entry<STOMPEvent.Type, Long> event : events.entrySet()) {
        totalEventsCounter += event.getValue();
        metrics.add(new SingleMetric(event.getKey().getMetricName(), event.getValue(), System.currentTimeMillis()));

        String averageMetricName = event.getKey().getMetricName() + AVERAGE_METRIC_SUFFIX;
        Double eventsPerSecond = event.getValue() == 0 ? -1 : (double) interval / (double) event.getValue();
        metrics.add(new SingleMetric(averageMetricName,
                eventsPerSecond, System.currentTimeMillis()));
        events.put(event.getKey(), 0L);
      }
      metrics.add(new SingleMetric(EVENTS_TOTAL_METRIC, totalEventsCounter, System.currentTimeMillis()));

      String totalAverageMetricName = EVENTS_TOTAL_METRIC + AVERAGE_METRIC_SUFFIX;
      Double eventsPerSecond = totalEventsCounter == 0 ? -1 : (double) interval / (double) totalEventsCounter;
      metrics.add(new SingleMetric(totalAverageMetricName,
              eventsPerSecond, System.currentTimeMillis()));
    }
    return metrics;
  }
Collects metrics about number of events by types and publishes to configured Metric Sink.
ambari-server/src/main/java/org/apache/ambari/server/metrics/system/impl/StompEventsMetricsSource.java