Search in sources :

Example 1 with MetricData

use of com.ctrip.xpipe.metric.MetricData in project x-pipe by ctripcorp.

the class HickwallMetric method log.

@Override
public void log(String desc, String metricSub, long delayNanos) {
    MetricData metricData = new MetricData(desc, clusterKey, metricSub);
    metricData.setTimestampMilli(System.currentTimeMillis());
    metricData.setValue(delayNanos);
    try {
        metricProxy.writeBinMultiDataPoint(Lists.newArrayList(metricData));
    } catch (MetricProxyException e) {
        logger.error("[log]", e);
    }
}
Also used : MetricData(com.ctrip.xpipe.metric.MetricData) MetricProxyException(com.ctrip.xpipe.metric.MetricProxyException)

Example 2 with MetricData

use of com.ctrip.xpipe.metric.MetricData in project x-pipe by ctripcorp.

the class MetricDelayCollector method getPoint.

private MetricData getPoint(HostPort hostPort, long value, DelaySampleResult result) {
    MetricData data = new MetricData(TYPE, result.getClusterId(), result.getShardId());
    data.setValue(value / 1000);
    data.setTimestampMilli(System.currentTimeMillis());
    data.setHostPort(hostPort);
    return data;
}
Also used : MetricData(com.ctrip.xpipe.metric.MetricData)

Example 3 with MetricData

use of com.ctrip.xpipe.metric.MetricData in project x-pipe by ctripcorp.

the class MetricDelayCollector method collect.

@Override
public void collect(DelaySampleResult result) {
    try {
        List<MetricData> data = new LinkedList<>();
        for (Entry<HostPort, Long> entry : result.getSlaveHostPort2Delay().entrySet()) {
            MetricData point = getPoint(entry.getKey(), entry.getValue(), result);
            data.add(point);
        }
        HostPort masterHostPort = result.getMasterHostPort();
        if (masterHostPort != null) {
            MetricData point = getPoint(masterHostPort, result.getMasterDelayNanos(), result);
            data.add(point);
        }
        proxy.writeBinMultiDataPoint(data);
    } catch (Exception e) {
        log.error("Error send metrics to metric", e);
    }
}
Also used : HostPort(com.ctrip.xpipe.endpoint.HostPort) LinkedList(java.util.LinkedList) MetricData(com.ctrip.xpipe.metric.MetricData)

Example 4 with MetricData

use of com.ctrip.xpipe.metric.MetricData in project x-pipe by ctripcorp.

the class HickwallMetricTest method testHickWall.

@Test
public void testHickWall() throws MetricProxyException, IOException {
    int port = 11111;
    logger.info("[testHickWall]{}", port);
    scheduled.scheduleAtFixedRate(new AbstractExceptionLogTask() {

        @Override
        protected void doRun() throws Exception {
            List<MetricData> data = new LinkedList<>();
            HostPort hostPort = new HostPort("127.0.0.1", port);
            MetricData metricData = new MetricData("delay", "cluster", "shard");
            metricData.setValue(1000);
            metricData.setHostPort(hostPort);
            metricData.setTimestampMilli(System.currentTimeMillis());
            data.add(metricData);
            hickwallMetricProxy.writeBinMultiDataPoint(data);
        }
    }, 0, 2, TimeUnit.SECONDS);
    waitForAnyKeyToExit();
}
Also used : HostPort(com.ctrip.xpipe.endpoint.HostPort) AbstractExceptionLogTask(com.ctrip.xpipe.concurrent.AbstractExceptionLogTask) List(java.util.List) LinkedList(java.util.LinkedList) IOException(java.io.IOException) MetricProxyException(com.ctrip.xpipe.metric.MetricProxyException) MetricData(com.ctrip.xpipe.metric.MetricData) Test(org.junit.Test) AbstractServiceTest(com.ctrip.xpipe.AbstractServiceTest)

Aggregations

MetricData (com.ctrip.xpipe.metric.MetricData)4 HostPort (com.ctrip.xpipe.endpoint.HostPort)2 MetricProxyException (com.ctrip.xpipe.metric.MetricProxyException)2 LinkedList (java.util.LinkedList)2 AbstractServiceTest (com.ctrip.xpipe.AbstractServiceTest)1 AbstractExceptionLogTask (com.ctrip.xpipe.concurrent.AbstractExceptionLogTask)1 IOException (java.io.IOException)1 List (java.util.List)1 Test (org.junit.Test)1