Search in sources :

Example 86 with Histogram

use of com.codahale.metrics.Histogram in project engineblock by engineblock.

the class MetricsIntegrationTest method testHistogramLogger.

@Test
public void testHistogramLogger() {
    ActivityDef ad = ActivityDef.parseActivityDef("alias=foo;type=diag");
    Histogram testhistogram = ActivityMetrics.histogram(ad, "testhistogram");
    ActivityMetrics.addHistoLogger("testsession", ".*", "testhisto.log", "1s");
    testhistogram.update(400);
    testhistogram.getSnapshot();
    File logfile = new File("testhisto.log");
    assertThat(logfile).exists();
    assertThat(logfile.lastModified()).isGreaterThan(System.currentTimeMillis() - 10000);
}
Also used : Histogram(com.codahale.metrics.Histogram) ActivityDef(io.engineblock.activityimpl.ActivityDef) File(java.io.File) Test(org.testng.annotations.Test)

Example 87 with Histogram

use of com.codahale.metrics.Histogram in project ambry by linkedin.

the class MySqlReportAggregatorTask method run.

@Override
public TaskResult run() {
    Exception exception = null;
    Histogram fetchTimeMs = statsReportType == StatsReportType.ACCOUNT_REPORT ? metrics.accountStatsFetchTimeMs : metrics.partitionClassStatsFetchTimeMs;
    Histogram aggregationTimeMs = statsReportType == StatsReportType.ACCOUNT_REPORT ? metrics.accountStatsAggregationTimeMs : metrics.partitionClassStatsAggregationTimeMs;
    long startTimeMs = System.currentTimeMillis();
    StatsSnapshot accountPhysicalStorageSnapshot = null;
    try {
        List<String> instanceNames = manager.getClusterManagmentTool().getInstancesInCluster(manager.getClusterName());
        if (statsReportType == StatsReportType.ACCOUNT_REPORT) {
            Map<String, HostAccountStorageStatsWrapper> accountStatsWrappers = fetchAccountStorageStatsWrapperForInstances(instanceNames);
            fetchTimeMs.update(System.currentTimeMillis() - startTimeMs);
            logger.info("Aggregating stats from " + accountStatsWrappers.size() + " hosts");
            Pair<AggregatedAccountStorageStats, AggregatedAccountStorageStats> results = clusterAggregator.aggregateHostAccountStorageStatsWrappers(accountStatsWrappers);
            if (clusterMapConfig.clustermapEnableDeleteInvalidDataInMysqlAggregationTask) {
                removeInvalidAggregatedAccountAndContainerStats(results.getSecond());
            }
            accountStatsStore.storeAggregatedAccountStorageStats(results.getSecond());
            accountPhysicalStorageSnapshot = StorageStatsUtil.convertAggregatedAccountStorageStatsToStatsSnapshot(results.getFirst(), true);
        } else if (statsReportType == StatsReportType.PARTITION_CLASS_REPORT) {
            Map<String, HostPartitionClassStorageStatsWrapper> statsWrappers = fetchPartitionClassStorageStatsWrapperForInstances(instanceNames);
            fetchTimeMs.update(System.currentTimeMillis() - startTimeMs);
            logger.info("Aggregating stats from " + statsWrappers.size() + " hosts");
            Pair<AggregatedPartitionClassStorageStats, AggregatedPartitionClassStorageStats> results = clusterAggregator.aggregateHostPartitionClassStorageStatsWrappers(statsWrappers);
            if (clusterMapConfig.clustermapEnableDeleteInvalidDataInMysqlAggregationTask) {
                removeInvalidAggregatedPartitionClassStats(results.getSecond());
            }
            accountStatsStore.storeAggregatedPartitionClassStorageStats(results.getSecond());
        }
        // Check if there is a base report for this month or not.
        if (clusterMapConfig.clustermapEnableAggregatedMonthlyAccountReport && statsReportType == StatsReportType.ACCOUNT_REPORT) {
            // Get the month, if not the same month, then copy the aggregated stats and update the month
            String currentMonthValue = LocalDateTime.ofEpochSecond(time.seconds(), 0, ZONE_OFFSET).format(TIMESTAMP_FORMATTER);
            String recordedMonthValue = accountStatsStore.queryRecordedMonth();
            if (recordedMonthValue == null || recordedMonthValue.isEmpty() || !currentMonthValue.equals(recordedMonthValue)) {
                if (clusterMapConfig.clustermapEnableDeleteInvalidDataInMysqlAggregationTask) {
                    accountStatsStore.deleteSnapshotOfAggregatedAccountStats();
                }
                logger.info("Taking snapshot of aggregated stats for month " + currentMonthValue);
                accountStatsStore.takeSnapshotOfAggregatedAccountStatsAndUpdateMonth(currentMonthValue);
            }
        }
        aggregationTimeMs.update(System.currentTimeMillis() - startTimeMs);
        return new TaskResult(TaskResult.Status.COMPLETED, "Aggregation success");
    } catch (Exception e) {
        logger.error("Exception thrown while aggregating stats from container stats reports across all nodes ", e);
        exception = e;
        return new TaskResult(TaskResult.Status.FAILED, "Exception thrown");
    } finally {
        if (clusterMapConfig.clustermapEnableContainerDeletionAggregation && callback != null && accountPhysicalStorageSnapshot != null && statsReportType.equals(StatsReportType.ACCOUNT_REPORT)) {
            callback.onCompletion(accountPhysicalStorageSnapshot, exception);
        }
    }
}
Also used : Histogram(com.codahale.metrics.Histogram) HostAccountStorageStatsWrapper(com.github.ambry.server.HostAccountStorageStatsWrapper) AggregatedAccountStorageStats(com.github.ambry.server.storagestats.AggregatedAccountStorageStats) TaskResult(org.apache.helix.task.TaskResult) HashMap(java.util.HashMap) Map(java.util.Map) StatsSnapshot(com.github.ambry.server.StatsSnapshot) Pair(com.github.ambry.utils.Pair)

Example 88 with Histogram

use of com.codahale.metrics.Histogram in project ambry by linkedin.

the class GetBlobOperationTest method testRouterRequestTimeoutAllFailure.

/**
 * Test the case where all requests time out within the GetOperation.
 * @throws Exception
 */
@Test
public void testRouterRequestTimeoutAllFailure() throws Exception {
    doPut();
    GetBlobOperation op = createOperation(routerConfig, null);
    op.poll(requestRegistrationCallback);
    while (!op.isOperationComplete()) {
        time.sleep(routerConfig.routerRequestTimeoutMs + 1);
        op.poll(requestRegistrationCallback);
    }
    // At this time requests would have been created for all replicas, as none of them were delivered,
    // and cross-colo proxying is enabled by default.
    Assert.assertEquals("Must have attempted sending requests to all replicas", replicasCount, correlationIdToGetOperation.size());
    assertFailureAndCheckErrorCode(op, RouterErrorCode.OperationTimedOut);
    // test that timed out response won't update latency histogram if exclude timeout is enabled.
    assumeTrue(operationTrackerType.equals(AdaptiveOperationTracker.class.getSimpleName()));
    AdaptiveOperationTracker tracker = (AdaptiveOperationTracker) op.getFirstChunkOperationTrackerInUse();
    Histogram localColoTracker = tracker.getLatencyHistogram(RouterTestHelpers.getAnyReplica(blobId, true, localDcName));
    Histogram crossColoTracker = tracker.getLatencyHistogram(RouterTestHelpers.getAnyReplica(blobId, false, localDcName));
    Assert.assertEquals("Timed-out response shouldn't be counted into local colo latency histogram", 0, localColoTracker.getCount());
    Assert.assertEquals("Timed-out response shouldn't be counted into cross colo latency histogram", 0, crossColoTracker.getCount());
}
Also used : Histogram(com.codahale.metrics.Histogram) PutManagerTest(com.github.ambry.router.PutManagerTest) Test(org.junit.Test)

Example 89 with Histogram

use of com.codahale.metrics.Histogram in project ambry by linkedin.

the class AmbryServerRequests method handleAdminRequest.

/**
 * Handles an administration request. These requests can query for or change the internal state of the server.
 * @param request the request that needs to be handled.
 * @throws InterruptedException if response sending is interrupted.
 * @throws IOException if there are I/O errors carrying our the required operation.
 */
@Override
public void handleAdminRequest(NetworkRequest request) throws InterruptedException, IOException {
    long requestQueueTime = SystemTime.getInstance().milliseconds() - request.getStartTimeInMs();
    long totalTimeSpent = requestQueueTime;
    long startTime = SystemTime.getInstance().milliseconds();
    DataInputStream requestStream = new DataInputStream(request.getInputStream());
    AdminRequest adminRequest = AdminRequest.readFrom(requestStream, clusterMap);
    Histogram processingTimeHistogram = null;
    Histogram responseQueueTimeHistogram = null;
    Histogram responseSendTimeHistogram = null;
    Histogram requestTotalTimeHistogram = null;
    AdminResponse response = null;
    try {
        switch(adminRequest.getType()) {
            case TriggerCompaction:
                metrics.triggerCompactionRequestQueueTimeInMs.update(requestQueueTime);
                metrics.triggerCompactionRequestRate.mark();
                processingTimeHistogram = metrics.triggerCompactionResponseQueueTimeInMs;
                responseQueueTimeHistogram = metrics.triggerCompactionResponseQueueTimeInMs;
                responseSendTimeHistogram = metrics.triggerCompactionResponseSendTimeInMs;
                requestTotalTimeHistogram = metrics.triggerCompactionRequestTotalTimeInMs;
                response = handleTriggerCompactionRequest(adminRequest);
                break;
            case RequestControl:
                metrics.requestControlRequestQueueTimeInMs.update(requestQueueTime);
                metrics.requestControlRequestRate.mark();
                processingTimeHistogram = metrics.requestControlResponseQueueTimeInMs;
                responseQueueTimeHistogram = metrics.requestControlResponseQueueTimeInMs;
                responseSendTimeHistogram = metrics.requestControlResponseSendTimeInMs;
                requestTotalTimeHistogram = metrics.requestControlRequestTotalTimeInMs;
                response = handleRequestControlRequest(requestStream, adminRequest);
                break;
            case ReplicationControl:
                metrics.replicationControlRequestQueueTimeInMs.update(requestQueueTime);
                metrics.replicationControlRequestRate.mark();
                processingTimeHistogram = metrics.replicationControlResponseQueueTimeInMs;
                responseQueueTimeHistogram = metrics.replicationControlResponseQueueTimeInMs;
                responseSendTimeHistogram = metrics.replicationControlResponseSendTimeInMs;
                requestTotalTimeHistogram = metrics.replicationControlRequestTotalTimeInMs;
                response = handleReplicationControlRequest(requestStream, adminRequest);
                break;
            case CatchupStatus:
                metrics.catchupStatusRequestQueueTimeInMs.update(requestQueueTime);
                metrics.catchupStatusRequestRate.mark();
                processingTimeHistogram = metrics.catchupStatusResponseQueueTimeInMs;
                responseQueueTimeHistogram = metrics.catchupStatusResponseQueueTimeInMs;
                responseSendTimeHistogram = metrics.catchupStatusResponseSendTimeInMs;
                requestTotalTimeHistogram = metrics.catchupStatusRequestTotalTimeInMs;
                response = handleCatchupStatusRequest(requestStream, adminRequest);
                break;
            case BlobStoreControl:
                metrics.blobStoreControlRequestQueueTimeInMs.update(requestQueueTime);
                metrics.blobStoreControlRequestRate.mark();
                processingTimeHistogram = metrics.blobStoreControlRequestQueueTimeInMs;
                responseQueueTimeHistogram = metrics.blobStoreControlRequestQueueTimeInMs;
                responseSendTimeHistogram = metrics.blobStoreControlResponseSendTimeInMs;
                requestTotalTimeHistogram = metrics.blobStoreControlRequestTotalTimeInMs;
                response = handleBlobStoreControlRequest(requestStream, adminRequest);
                break;
        }
    } catch (Exception e) {
        logger.error("Unknown exception for admin request {}", adminRequest, e);
        metrics.unExpectedAdminOperationError.inc();
        response = new AdminResponse(adminRequest.getCorrelationId(), adminRequest.getClientId(), ServerErrorCode.Unknown_Error);
        switch(adminRequest.getType()) {
            case CatchupStatus:
                response = new CatchupStatusAdminResponse(false, response);
                break;
        }
    } finally {
        long processingTime = SystemTime.getInstance().milliseconds() - startTime;
        totalTimeSpent += processingTime;
        publicAccessLogger.info("{} {} processingTime {}", adminRequest, response, processingTime);
        processingTimeHistogram.update(processingTime);
    }
    requestResponseChannel.sendResponse(response, request, new ServerNetworkResponseMetrics(responseQueueTimeHistogram, responseSendTimeHistogram, requestTotalTimeHistogram, null, null, totalTimeSpent));
}
Also used : CatchupStatusAdminRequest(com.github.ambry.protocol.CatchupStatusAdminRequest) AdminRequest(com.github.ambry.protocol.AdminRequest) ReplicationControlAdminRequest(com.github.ambry.protocol.ReplicationControlAdminRequest) RequestControlAdminRequest(com.github.ambry.protocol.RequestControlAdminRequest) BlobStoreControlAdminRequest(com.github.ambry.protocol.BlobStoreControlAdminRequest) ServerNetworkResponseMetrics(com.github.ambry.network.ServerNetworkResponseMetrics) AdminResponse(com.github.ambry.protocol.AdminResponse) CatchupStatusAdminResponse(com.github.ambry.protocol.CatchupStatusAdminResponse) Histogram(com.codahale.metrics.Histogram) CatchupStatusAdminResponse(com.github.ambry.protocol.CatchupStatusAdminResponse) DataInputStream(java.io.DataInputStream) StoreException(com.github.ambry.store.StoreException) IOException(java.io.IOException)

Example 90 with Histogram

use of com.codahale.metrics.Histogram in project cassandra by apache.

the class TableMetrics method createTableHistogram.

protected TableHistogram createTableHistogram(String name, String alias, Histogram keyspaceHistogram, boolean considerZeroes) {
    Histogram cfHistogram = Metrics.histogram(factory.createMetricName(name), aliasFactory.createMetricName(alias), considerZeroes);
    register(name, alias, cfHistogram);
    return new TableHistogram(cfHistogram, keyspaceHistogram, Metrics.histogram(GLOBAL_FACTORY.createMetricName(name), GLOBAL_ALIAS_FACTORY.createMetricName(alias), considerZeroes));
}
Also used : Histogram(com.codahale.metrics.Histogram) EstimatedHistogram(org.apache.cassandra.utils.EstimatedHistogram)

Aggregations

Histogram (com.codahale.metrics.Histogram)97 Test (org.junit.Test)39 Timer (com.codahale.metrics.Timer)34 Counter (com.codahale.metrics.Counter)30 Meter (com.codahale.metrics.Meter)29 Gauge (com.codahale.metrics.Gauge)17 Snapshot (com.codahale.metrics.Snapshot)12 Map (java.util.Map)11 Test (org.testng.annotations.Test)11 MetricRegistry (com.codahale.metrics.MetricRegistry)9 DataProvider (com.tngtech.java.junit.dataprovider.DataProvider)8 IOException (java.io.IOException)8 HashMap (java.util.HashMap)8 Metric (com.codahale.metrics.Metric)6 Reservoir (com.codahale.metrics.Reservoir)6 ZonedDateTime (java.time.ZonedDateTime)6 Properties (java.util.Properties)6 SortedMap (java.util.SortedMap)6 DateTime (org.joda.time.DateTime)6 UniformReservoir (com.codahale.metrics.UniformReservoir)5