use of org.sonatype.nexus.blobstore.api.OperationMetrics in project nexus-blobstore-google-cloud by sonatype-nexus-community.
the class ShardedCounterMetricsStore method initialize.
void initialize() throws Exception {
this.datastore = datastoreFactory.create(blobStoreConfiguration);
this.namespace = NAMESPACE_PREFIX + safe(blobStoreConfiguration.getName());
this.shardRoot = datastore.newKeyFactory().addAncestors(NXRM_ROOT).setNamespace(namespace).setKind(METRICS_STORE).newKey(1L);
for (OperationType type : OperationType.values()) {
operationMetrics.put(type, new OperationMetrics());
}
try {
getMetrics();
} catch (DatastoreException e) {
throw new GoogleCloudProjectException("Check that Firestore is configured for datastore mode, not native mode ", e);
}
try {
test();
} catch (DatastoreException e) {
throw new GoogleCloudProjectException("unable to write metrics metadata", e);
}
}
use of org.sonatype.nexus.blobstore.api.OperationMetrics in project nexus-public by sonatype.
the class BlobStoreMetricsStoreSupport method updateProperties.
private void updateProperties() {
properties.setProperty(TOTAL_SIZE_PROP_NAME, totalSize.toString());
properties.setProperty(BLOB_COUNT_PROP_NAME, blobCount.toString());
for (Entry<OperationType, OperationMetrics> operationMetricByType : operationMetrics.entrySet()) {
OperationType type = operationMetricByType.getKey();
OperationMetrics operationMetric = operationMetricByType.getValue();
properties.setProperty(type + TOTAL_SUCCESSFUL_REQUESTS_PROP_NAME, String.valueOf(operationMetric.getSuccessfulRequests()));
properties.setProperty(type + TOTAL_ERROR_REQUESTS_PROP_NAME, String.valueOf(operationMetric.getErrorRequests()));
properties.setProperty(type + TOTAL_TIME_ON_REQUEST_PROP_NAME, String.valueOf(operationMetric.getTimeOnRequests()));
properties.setProperty(type + TOTAL_SIZE_ON_REQUEST_PROP_NAME, String.valueOf(operationMetric.getBlobSize()));
}
}
use of org.sonatype.nexus.blobstore.api.OperationMetrics in project nexus-public by sonatype.
the class DatastoreBlobStoreMetricsServiceSupport method getOperationMetrics.
@Override
public Map<OperationType, OperationMetrics> getOperationMetrics() {
BlobStoreMetricsEntity metricsEntity = blobStoreMetricsStore.get(this.blobStore.getBlobStoreConfiguration().getName());
Map<OperationType, OperationMetrics> delta = getOperationMetricsDelta();
OperationMetrics uploadMetrics = new OperationMetrics();
uploadMetrics.setBlobSize(metricsEntity.getUploadBlobSize());
uploadMetrics.setErrorRequests(metricsEntity.getUploadErrorRequests());
uploadMetrics.setSuccessfulRequests(metricsEntity.getUploadSuccessfulRequests());
uploadMetrics.setTimeOnRequests(metricsEntity.getUploadTimeOnRequests());
uploadMetrics.add(delta.get(OperationType.UPLOAD));
OperationMetrics downloadMetrics = new OperationMetrics();
downloadMetrics.setBlobSize(metricsEntity.getDownloadBlobSize());
downloadMetrics.setErrorRequests(metricsEntity.getDownloadErrorRequests());
downloadMetrics.setSuccessfulRequests(metricsEntity.getDownloadSuccessfulRequests());
downloadMetrics.setTimeOnRequests(metricsEntity.getDownloadTimeOnRequests());
downloadMetrics.add(delta.get(OperationType.DOWNLOAD));
Map<OperationType, OperationMetrics> operationMetricsMap = new HashMap<>();
operationMetricsMap.put(OperationType.UPLOAD, uploadMetrics);
operationMetricsMap.put(OperationType.DOWNLOAD, downloadMetrics);
return Collections.unmodifiableMap(operationMetricsMap);
}
use of org.sonatype.nexus.blobstore.api.OperationMetrics in project nexus-public by sonatype.
the class BlobStoreGroup method getOperationMetricsDelta.
@Override
public Map<OperationType, OperationMetrics> getOperationMetricsDelta() {
Map<OperationType, OperationMetrics> result = new EnumMap<>(OperationType.class);
Iterable<Map<OperationType, OperationMetrics>> metrics = members.get().stream().map(BlobStore::getOperationMetricsDelta)::iterator;
for (Map<OperationType, OperationMetrics> metric : metrics) {
for (Entry<OperationType, OperationMetrics> metricsEntry : metric.entrySet()) {
OperationType type = metricsEntry.getKey();
OperationMetrics operationMetrics = metricsEntry.getValue();
OperationMetrics existingMetrics = result.get(type);
if (existingMetrics != null) {
OperationMetrics aggregatedMetrics = existingMetrics.add(operationMetrics);
result.put(type, aggregatedMetrics);
} else {
result.put(type, operationMetrics);
}
}
}
return result;
}
use of org.sonatype.nexus.blobstore.api.OperationMetrics in project nexus-public by sonatype.
the class BlobStoreAnalyticsInterceptor method invoke.
@Override
public Object invoke(final MethodInvocation invocation) throws Throwable {
String clazz = invocation.getThis().getClass().getSimpleName();
Method method = invocation.getMethod();
String methodName = method.getName();
MonitoringBlobStoreMetrics metricsAnnotation = method.getAnnotation(MonitoringBlobStoreMetrics.class);
checkState(metricsAnnotation != null);
OperationType operationType = metricsAnnotation.operationType();
BlobStore blobStore;
OperationMetrics operationMetrics;
if (invocation.getThis() instanceof BlobStore) {
blobStore = (BlobStore) invocation.getThis();
operationMetrics = blobStore.getOperationMetricsDelta().get(operationType);
} else {
log.info("Can't monitor operation metrics for class={}, methodName={}", clazz, methodName);
return invocation.proceed();
}
long start = System.currentTimeMillis();
try {
Object result = invocation.proceed();
// record metrics only in case of successful processing.
operationMetrics.addSuccessfulRequest();
operationMetrics.addTimeOnRequests(System.currentTimeMillis() - start);
if (result instanceof BlobSupport) {
long totalSize = ((BlobSupport) result).getMetrics().getContentSize();
operationMetrics.addBlobSize(totalSize);
}
return result;
} catch (Exception e) {
operationMetrics.addErrorRequest();
throw e;
}
}
Aggregations