Search in sources :

Example 1 with WorkerMetricList

use of org.apache.storm.generated.WorkerMetricList in project storm by apache.

the class Container method processMetrics.

/**
 * Send worker metrics to Nimbus.
 */
void processMetrics(OnlyLatestExecutor<Integer> exec, WorkerMetricsProcessor processor) {
    try {
        Optional<Long> usedMemoryForPort = containerMemoryTracker.getUsedMemoryMb(port);
        if (usedMemoryForPort.isPresent()) {
            // Make sure we don't process too frequently.
            long nextMetricProcessTime = this.lastMetricProcessTime + 60L * 1000L;
            long currentTimeMsec = System.currentTimeMillis();
            if (currentTimeMsec < nextMetricProcessTime) {
                return;
            }
            String hostname = Utils.hostname();
            // create metric for memory
            long timestamp = System.currentTimeMillis();
            WorkerMetricPoint workerMetric = new WorkerMetricPoint(MEMORY_USED_METRIC, timestamp, usedMemoryForPort.get(), SYSTEM_COMPONENT_ID, INVALID_EXECUTOR_ID, INVALID_STREAM_ID);
            WorkerMetricList metricList = new WorkerMetricList();
            metricList.add_to_metrics(workerMetric);
            WorkerMetrics metrics = new WorkerMetrics(topologyId, port, hostname, metricList);
            exec.execute(port, () -> {
                try {
                    processor.processWorkerMetrics(conf, metrics);
                } catch (MetricException e) {
                    LOG.error("Failed to process metrics", e);
                }
            });
        }
    } catch (Exception e) {
        LOG.error("Failed to process metrics", e);
    } finally {
        this.lastMetricProcessTime = System.currentTimeMillis();
    }
}
Also used : WorkerMetricPoint(org.apache.storm.generated.WorkerMetricPoint) WorkerMetricList(org.apache.storm.generated.WorkerMetricList) WorkerMetrics(org.apache.storm.generated.WorkerMetrics) MetricException(org.apache.storm.metricstore.MetricException) IOException(java.io.IOException) MetricException(org.apache.storm.metricstore.MetricException)

Aggregations

IOException (java.io.IOException)1 WorkerMetricList (org.apache.storm.generated.WorkerMetricList)1 WorkerMetricPoint (org.apache.storm.generated.WorkerMetricPoint)1 WorkerMetrics (org.apache.storm.generated.WorkerMetrics)1 MetricException (org.apache.storm.metricstore.MetricException)1