Search in sources :

Example 1 with Metrics

use of com.twitter.heron.proto.system.Metrics in project heron by twitter.

the class SpoutInstanceTest method testGatherMetrics.

/**
   * Test the gathering of metrics
   */
@Test
public void testGatherMetrics() throws Exception {
    physicalPlan = UnitTestHelper.getPhysicalPlan(false, -1);
    PhysicalPlanHelper physicalPlanHelper = new PhysicalPlanHelper(physicalPlan, SPOUT_INSTANCE_ID);
    InstanceControlMsg instanceControlMsg = InstanceControlMsg.newBuilder().setNewPhysicalPlanHelper(physicalPlanHelper).build();
    inControlQueue.offer(instanceControlMsg);
    Runnable task = new Runnable() {

        @Override
        public void run() {
            for (int i = 0; i < Constants.RETRY_TIMES; i++) {
                if (!slaveMetricsOut.isEmpty()) {
                    Metrics.MetricPublisherPublishMessage msg = slaveMetricsOut.poll();
                    Set<String> metricsName = new HashSet<String>();
                    for (Metrics.MetricDatum metricDatum : msg.getMetricsList()) {
                        metricsName.add(metricDatum.getName());
                    }
                    Assert.assertTrue(metricsName.contains("__ack-count/default"));
                    Assert.assertTrue(metricsName.contains("__complete-latency/default"));
                    Assert.assertTrue(metricsName.contains("__emit-count/default"));
                    Assert.assertTrue(metricsName.contains("__next-tuple-latency"));
                    Assert.assertTrue(metricsName.contains("__next-tuple-count"));
                    testLooper.exitLoop();
                    break;
                }
                SysUtils.sleep(Constants.RETRY_INTERVAL_MS);
            }
        }
    };
    testLooper.addTasksOnWakeup(task);
    testLooper.loop();
}
Also used : Metrics(com.twitter.heron.proto.system.Metrics) PhysicalPlanHelper(com.twitter.heron.common.utils.misc.PhysicalPlanHelper) InstanceControlMsg(com.twitter.heron.instance.InstanceControlMsg) ByteString(com.google.protobuf.ByteString) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 2 with Metrics

use of com.twitter.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 = String.format("%s:%d/%s/%s", 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 SlaveLooper bind with IMetricsSink
    for (Communicator<MetricsRecord> c : metricsSinkCommunicators) {
        c.offer(record);
    }
}
Also used : MetricsInfo(com.twitter.heron.spi.metricsmgr.metrics.MetricsInfo) Metrics(com.twitter.heron.proto.system.Metrics) MetricsRecord(com.twitter.heron.spi.metricsmgr.metrics.MetricsRecord) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ExceptionInfo(com.twitter.heron.spi.metricsmgr.metrics.ExceptionInfo)

Aggregations

Metrics (com.twitter.heron.proto.system.Metrics)2 ByteString (com.google.protobuf.ByteString)1 PhysicalPlanHelper (com.twitter.heron.common.utils.misc.PhysicalPlanHelper)1 InstanceControlMsg (com.twitter.heron.instance.InstanceControlMsg)1 ExceptionInfo (com.twitter.heron.spi.metricsmgr.metrics.ExceptionInfo)1 MetricsInfo (com.twitter.heron.spi.metricsmgr.metrics.MetricsInfo)1 MetricsRecord (com.twitter.heron.spi.metricsmgr.metrics.MetricsRecord)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 Test (org.junit.Test)1