Search in sources :

Example 1 with Metrics

use of org.apache.heron.proto.system.Metrics in project heron by twitter.

the class MetricsManagerServer method handlePublisherPublishMessage.

private void handlePublisherPublishMessage(Metrics.MetricPublisher request, Metrics.MetricPublisherPublishMessage message) {
    if (message.getMetricsCount() <= 0 && message.getExceptionsCount() <= 0) {
        LOG.log(Level.SEVERE, "Publish message has no metrics nor exceptions for message from hostname: {0}," + " component_name: {1}, port: {2}, instance_id: {3}, instance_index: {4}", new Object[] { request.getHostname(), request.getComponentName(), request.getPort(), request.getInstanceId(), request.getInstanceIndex() });
        return;
    }
    // Convert the message to MetricsRecord
    String source = MetricsUtil.createSource(request.getHostname(), request.getPort(), request.getComponentName(), request.getInstanceId());
    List<MetricsInfo> metricsInfos = new ArrayList<MetricsInfo>(message.getMetricsCount());
    for (Metrics.MetricDatum metricDatum : message.getMetricsList()) {
        MetricsInfo info = new MetricsInfo(metricDatum.getName(), metricDatum.getValue());
        metricsInfos.add(info);
    }
    List<ExceptionInfo> exceptionInfos = new ArrayList<ExceptionInfo>(message.getExceptionsCount());
    for (Metrics.ExceptionData exceptionData : message.getExceptionsList()) {
        ExceptionInfo exceptionInfo = new ExceptionInfo(exceptionData.getStacktrace(), exceptionData.getLasttime(), exceptionData.getFirsttime(), exceptionData.getCount(), exceptionData.getLogging());
        exceptionInfos.add(exceptionInfo);
    }
    LOG.info(String.format("%d MetricsInfo and %d ExceptionInfo to push", metricsInfos.size(), exceptionInfos.size()));
    // Update the metrics
    serverMetricsCounters.scope(SERVER_METRICS_RECEIVED).incrBy(metricsInfos.size());
    serverMetricsCounters.scope(SERVER_EXCEPTIONS_RECEIVED).incrBy(exceptionInfos.size());
    MetricsRecord record = new MetricsRecord(source, metricsInfos, exceptionInfos);
    // Push MetricsRecord to Communicator, which would wake up ExecutorLooper bind with IMetricsSink
    synchronized (metricsSinkCommunicators) {
        Iterator<String> itr = metricsSinkCommunicators.keySet().iterator();
        while (itr.hasNext()) {
            String key = itr.next();
            Communicator<MetricsRecord> c = metricsSinkCommunicators.get(key);
            c.offer(record);
            serverMetricsCounters.scope(SERVER_COMMUNICATOR_OFFER).incr();
            serverMetricsCounters.scope(SERVER_COMMUNICATOR_SIZE + "-" + key).incrBy(c.size());
        }
    }
}
Also used : MetricsInfo(org.apache.heron.spi.metricsmgr.metrics.MetricsInfo) Metrics(org.apache.heron.proto.system.Metrics) MetricsRecord(org.apache.heron.spi.metricsmgr.metrics.MetricsRecord) ArrayList(java.util.ArrayList) ExceptionInfo(org.apache.heron.spi.metricsmgr.metrics.ExceptionInfo)

Aggregations

ArrayList (java.util.ArrayList)1 Metrics (org.apache.heron.proto.system.Metrics)1 ExceptionInfo (org.apache.heron.spi.metricsmgr.metrics.ExceptionInfo)1 MetricsInfo (org.apache.heron.spi.metricsmgr.metrics.MetricsInfo)1 MetricsRecord (org.apache.heron.spi.metricsmgr.metrics.MetricsRecord)1