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);
}
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);
}
}
}
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());
}
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));
}
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));
}
Aggregations