Search in sources :

Example 1 with Metric

use of alluxio.metrics.Metric in project alluxio by Alluxio.

the class MetricsStore method putReportedMetrics.

/**
 * Update the reported metrics received from a worker or client.
 *
 * Cluster metrics of {@link MetricType} COUNTER are directly incremented by the reported values.
 *
 * @param instanceType the instance type that reports the metrics
 * @param reportedMetrics the metrics received by the RPC handler
 */
private void putReportedMetrics(InstanceType instanceType, List<Metric> reportedMetrics) {
    for (Metric metric : reportedMetrics) {
        if (metric.getSource() == null) {
            // ignore metrics whose source is null
            continue;
        }
        // increment its value based on the received metric rather than replacing it.
        if (metric.getMetricType() == MetricType.COUNTER) {
            ClusterCounterKey key = new ClusterCounterKey(instanceType, metric.getName());
            Counter counter = mClusterCounters.get(key);
            if (counter != null) {
                counter.inc((long) metric.getValue());
                continue;
            }
            if (instanceType.equals(InstanceType.CLIENT)) {
                continue;
            }
            // and one to summarize values from all UFSes
            if (metric.getName().equals(BYTES_READ_UFS)) {
                incrementUfsRelatedCounters(metric, MetricKey.CLUSTER_BYTES_READ_UFS.getName(), MetricKey.CLUSTER_BYTES_READ_UFS_ALL.getName());
            } else if (metric.getName().equals(BYTES_WRITTEN_UFS)) {
                incrementUfsRelatedCounters(metric, MetricKey.CLUSTER_BYTES_WRITTEN_UFS.getName(), MetricKey.CLUSTER_BYTES_WRITTEN_UFS_ALL.getName());
            }
        }
    }
}
Also used : Counter(com.codahale.metrics.Counter) Metric(alluxio.metrics.Metric)

Example 2 with Metric

use of alluxio.metrics.Metric in project alluxio by Alluxio.

the class MetricsMasterTest method testThroughputGauge.

@Test
public void testThroughputGauge() throws Exception {
    String counterName = "Master.counter";
    String throughputName = "Cluster.counterThroughput";
    mMetricsMaster.registerThroughputGauge("Master.counter", "Cluster.counterThroughput");
    Metric metric = MetricsSystem.getMetricValue(throughputName);
    assertNotNull(metric);
    assertEquals(0, (long) metric.getValue());
    Counter masterCounter = MetricsSystem.counter(counterName);
    masterCounter.inc(100);
    Gauge gauge = MetricsSystem.METRIC_REGISTRY.getGauges().get(throughputName);
    assertNotNull(gauge);
    assertEquals(100, (long) gauge.getValue());
    masterCounter.inc(200);
    mClock.addTimeMs(2 * Constants.MINUTE_MS);
    System.out.println(gauge.getValue());
    assertEquals(150, (long) gauge.getValue());
}
Also used : Counter(com.codahale.metrics.Counter) Metric(alluxio.metrics.Metric) Gauge(com.codahale.metrics.Gauge) Test(org.junit.Test)

Example 3 with Metric

use of alluxio.metrics.Metric in project alluxio by Alluxio.

the class MetricsMasterTest method testRegisteredAggregator.

@Test
public void testRegisteredAggregator() throws Exception {
    String ufsOp = MetricInfo.UfsOps.values().clone()[0].toString();
    String masterUfsOpName = MetricsSystem.getMasterMetricName(ufsOp);
    String ufs = MetricsSystem.escape(new AlluxioURI("hdfs://name:9000/alluxio_storage"));
    String counterName = Metric.getMetricNameWithTags(masterUfsOpName, MetricInfo.TAG_UFS, ufs, MetricInfo.TAG_UFS_TYPE, "hdfs");
    MetricsSystem.counter(counterName).inc(2333);
    HeartbeatScheduler.execute(HeartbeatContext.MASTER_CLUSTER_METRICS_UPDATER);
    String clusterMetricName = Metric.getMetricNameWithTags(MetricInfo.UFS_OP_PREFIX + ufsOp, MetricInfo.TAG_UFS, ufs);
    Metric clusterMetric = MetricsSystem.getMetricValue(clusterMetricName);
    assertNotNull(clusterMetric);
    assertEquals(2333, (long) clusterMetric.getValue());
    String timerNameOne = Metric.getMetricNameWithTags(masterUfsOpName, MetricInfo.TAG_UFS, ufs, MetricInfo.TAG_USER, "userA");
    MetricsSystem.timer(timerNameOne).time().close();
    String timerNameTwo = Metric.getMetricNameWithTags(masterUfsOpName, MetricInfo.TAG_UFS, ufs, MetricInfo.TAG_USER, "userB");
    MetricsSystem.timer(timerNameTwo).time().close();
    HeartbeatScheduler.execute(HeartbeatContext.MASTER_CLUSTER_METRICS_UPDATER);
    clusterMetric = MetricsSystem.getMetricValue(clusterMetricName);
    assertNotNull(clusterMetric);
    assertEquals(2335, (long) clusterMetric.getValue());
}
Also used : Metric(alluxio.metrics.Metric) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

Example 4 with Metric

use of alluxio.metrics.Metric in project alluxio by Alluxio.

the class MetricsMasterTest method testMultiValueAggregator.

@Test
public void testMultiValueAggregator() throws Exception {
    // Add user tag
    String masterMetricName = "Master.TestMetric";
    String clusterMetricName = "Cluster.TestMetric";
    mMetricsMaster.addAggregator(new SingleTagValueAggregator(clusterMetricName, masterMetricName, MetricInfo.TAG_UFS));
    String ufsOne = MetricsSystem.escape(new AlluxioURI("/path/to/ufs"));
    String counterNameOne = Metric.getMetricNameWithTags(masterMetricName, MetricInfo.TAG_UFS, ufsOne);
    Counter counterOne = MetricsSystem.counter(counterNameOne);
    counterOne.inc(10);
    String clusterMetricNameOne = Metric.getMetricNameWithTags(clusterMetricName, MetricInfo.TAG_UFS, ufsOne);
    assertTrue(MetricsSystem.getMetricValue(clusterMetricNameOne) == null);
    HeartbeatScheduler.execute(HeartbeatContext.MASTER_CLUSTER_METRICS_UPDATER);
    Metric clusterMetricOne = MetricsSystem.getMetricValue(clusterMetricNameOne);
    assertNotNull(clusterMetricOne);
    assertEquals(10, (long) clusterMetricOne.getValue());
    counterOne.inc(7);
    String ufsTwo = MetricsSystem.escape(new AlluxioURI("s3://alluxio-test-metrics/metrics"));
    String counterNameTwo = Metric.getMetricNameWithTags(masterMetricName, MetricInfo.TAG_UFS, ufsTwo);
    Counter counterTwo = MetricsSystem.counter(counterNameTwo);
    counterTwo.inc(50);
    HeartbeatScheduler.execute(HeartbeatContext.MASTER_CLUSTER_METRICS_UPDATER);
    Metric clusterMetricOne2 = MetricsSystem.getMetricValue(clusterMetricNameOne);
    assertNotNull(clusterMetricOne2);
    assertEquals(17, (long) clusterMetricOne2.getValue());
    Metric clusterMetricTwo = MetricsSystem.getMetricValue(Metric.getMetricNameWithTags(clusterMetricName, MetricInfo.TAG_UFS, ufsTwo));
    assertNotNull(clusterMetricTwo);
    assertEquals(50, (long) clusterMetricTwo.getValue());
}
Also used : Counter(com.codahale.metrics.Counter) Metric(alluxio.metrics.Metric) SingleTagValueAggregator(alluxio.metrics.aggregator.SingleTagValueAggregator) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

Example 5 with Metric

use of alluxio.metrics.Metric in project alluxio by Alluxio.

the class MetricsStoreTest method putWorkerUfsMetrics.

@Test
public void putWorkerUfsMetrics() {
    String readBytes = MetricKey.WORKER_BYTES_READ_UFS.getName();
    String writtenBytes = MetricKey.WORKER_BYTES_WRITTEN_UFS.getName();
    String ufsName1 = MetricsSystem.escape(new AlluxioURI("/my/local/folder"));
    String readBytesUfs1 = Metric.getMetricNameWithTags(readBytes, MetricInfo.TAG_UFS, ufsName1);
    String writtenBytesUfs1 = Metric.getMetricNameWithTags(writtenBytes, MetricInfo.TAG_UFS, ufsName1);
    String ufsName2 = MetricsSystem.escape(new AlluxioURI("s3://my/s3/bucket/"));
    String readBytesUfs2 = Metric.getMetricNameWithTags(readBytes, MetricInfo.TAG_UFS, ufsName2);
    String writtenBytesUfs2 = Metric.getMetricNameWithTags(writtenBytes, MetricInfo.TAG_UFS, ufsName2);
    String host1 = "192_1_1_1";
    List<Metric> metrics1 = Lists.newArrayList(Metric.from(readBytesUfs1 + "." + host1, 10, MetricType.COUNTER), Metric.from(writtenBytesUfs1 + "." + host1, 20, MetricType.COUNTER), Metric.from(writtenBytesUfs2 + "." + host1, 7, MetricType.COUNTER));
    mMetricStore.putWorkerMetrics(host1, metrics1);
    String host2 = "192_1_1_2";
    List<Metric> metrics2 = Lists.newArrayList(Metric.from(readBytesUfs1 + "." + host2, 5, MetricType.COUNTER), Metric.from(writtenBytesUfs1 + "." + host2, 12, MetricType.COUNTER), Metric.from(readBytesUfs2 + "." + host2, 33, MetricType.COUNTER));
    mMetricStore.putWorkerMetrics(host2, metrics2);
    assertEquals(15, MetricsSystem.counter(Metric.getMetricNameWithTags(MetricKey.CLUSTER_BYTES_READ_UFS.getName(), MetricInfo.TAG_UFS, ufsName1)).getCount());
    assertEquals(33, MetricsSystem.counter(Metric.getMetricNameWithTags(MetricKey.CLUSTER_BYTES_READ_UFS.getName(), MetricInfo.TAG_UFS, ufsName2)).getCount());
    assertEquals(48, MetricsSystem.counter(MetricKey.CLUSTER_BYTES_READ_UFS_ALL.getName()).getCount());
    assertEquals(32, MetricsSystem.counter(Metric.getMetricNameWithTags(MetricKey.CLUSTER_BYTES_WRITTEN_UFS.getName(), MetricInfo.TAG_UFS, ufsName1)).getCount());
    assertEquals(7, MetricsSystem.counter(Metric.getMetricNameWithTags(MetricKey.CLUSTER_BYTES_WRITTEN_UFS.getName(), MetricInfo.TAG_UFS, ufsName2)).getCount());
    assertEquals(39, MetricsSystem.counter(MetricKey.CLUSTER_BYTES_WRITTEN_UFS_ALL.getName()).getCount());
}
Also used : Metric(alluxio.metrics.Metric) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

Aggregations

Metric (alluxio.metrics.Metric)6 Test (org.junit.Test)4 AlluxioURI (alluxio.AlluxioURI)3 Counter (com.codahale.metrics.Counter)3 SingleTagValueAggregator (alluxio.metrics.aggregator.SingleTagValueAggregator)1 Gauge (com.codahale.metrics.Gauge)1 HashMap (java.util.HashMap)1