Search in sources :

Example 1 with OperationMetrics

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);
    }
}
Also used : OperationMetrics(org.sonatype.nexus.blobstore.api.OperationMetrics) GoogleCloudProjectException(org.sonatype.nexus.blobstore.gcloud.GoogleCloudProjectException) OperationType(org.sonatype.nexus.blobstore.api.OperationType) DatastoreException(com.google.cloud.datastore.DatastoreException)

Example 2 with OperationMetrics

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()));
    }
}
Also used : OperationMetrics(org.sonatype.nexus.blobstore.api.OperationMetrics) OperationType(org.sonatype.nexus.blobstore.api.OperationType)

Example 3 with OperationMetrics

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);
}
Also used : HashMap(java.util.HashMap) OperationMetrics(org.sonatype.nexus.blobstore.api.OperationMetrics) BlobStoreMetricsEntity(org.sonatype.nexus.blobstore.api.metrics.BlobStoreMetricsEntity) OperationType(org.sonatype.nexus.blobstore.api.OperationType)

Example 4 with OperationMetrics

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;
}
Also used : OperationMetrics(org.sonatype.nexus.blobstore.api.OperationMetrics) OperationType(org.sonatype.nexus.blobstore.api.OperationType) EnumMap(java.util.EnumMap) Map(java.util.Map) EnumMap(java.util.EnumMap)

Example 5 with OperationMetrics

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;
    }
}
Also used : OperationMetrics(org.sonatype.nexus.blobstore.api.OperationMetrics) Method(java.lang.reflect.Method) OperationType(org.sonatype.nexus.blobstore.api.OperationType) BlobStore(org.sonatype.nexus.blobstore.api.BlobStore) BlobSupport(org.sonatype.nexus.blobstore.BlobSupport)

Aggregations

OperationMetrics (org.sonatype.nexus.blobstore.api.OperationMetrics)9 OperationType (org.sonatype.nexus.blobstore.api.OperationType)8 EnumMap (java.util.EnumMap)2 Map (java.util.Map)2 BlobStoreMetricsEntity (org.sonatype.nexus.blobstore.api.metrics.BlobStoreMetricsEntity)2 DatastoreException (com.google.cloud.datastore.DatastoreException)1 IOException (java.io.IOException)1 Method (java.lang.reflect.Method)1 HashMap (java.util.HashMap)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 BlobSupport (org.sonatype.nexus.blobstore.BlobSupport)1 BlobStore (org.sonatype.nexus.blobstore.api.BlobStore)1 GoogleCloudProjectException (org.sonatype.nexus.blobstore.gcloud.GoogleCloudProjectException)1