Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.fasterxml.clustermate.service.metrics;
  
  
Helper class for aggregating sets of internal CRUD endpoint metrics.
 
 public class OperationMetrics
 {
     protected final ServiceConfig _serviceConfig;
 
     /*
     /**********************************************************************
     /* Actual metric aggregators
     /**********************************************************************
      */
 
     protected final Counter _metricInFlight;
 
     protected final Timer _metricTimes;
 
     // // Size metrics (optional)
 
     protected final Histogram _metricSizes;
 
     protected final Histogram _metricEntryCounts;
 
     /*
     /**********************************************************************
     /* Public API for JSON serialization
     /**********************************************************************
      */
 
     public Counter getInFlight() {
         return ;
     }
 
     public Timer getTimes() {
         return ;
     }
 
     public Histogram getSizes() {
         return ;
     }
 
     public Histogram getEntryCounts() {
         return ;
     }
     
     /*
     /**********************************************************************
     /* Life-cycle
     /**********************************************************************
      */
 
     private OperationMetrics(ServiceConfig serviceConfigString operationName,
             boolean includeSizesboolean includeEntryCounts)
     {
          = serviceConfig;
         String metricGroup = serviceConfig.metricsJmxRoot;
         if (!metricGroup.endsWith(".")) {
             metricGroup += ".";
         }
         
         // and then create metrics
         
         // first: in-flight counter, "active" requests
          = Metrics.newCounter(metricGroup + operationName + ".active");
          = Metrics.newTimer(metricGroup + operationName + ".times");
 
          = includeSizes ?
                 Metrics.newHistogram(metricGroup + operationName + ".sizes") : null;
          = includeEntryCounts ?
                 Metrics.newHistogram(metricGroup + operationName + ".counts") : null;
     }
 
     public static OperationMetrics forEntityOperation(ServiceConfig serviceConfigString operationName)
     {
         return new OperationMetrics(serviceConfigoperationNametruefalse);
     }
 
     public static OperationMetrics forListingOperation(ServiceConfig serviceConfigString operationName)
     {
         return new OperationMetrics(serviceConfigoperationNamefalsetrue);
     }
 
     public static OperationMetrics forNonPayloadOperation(ServiceConfig serviceConfigString operationName)
     {
         return new OperationMetrics(serviceConfigoperationNamefalsefalse);
     }
     
     public Context start()
     {
        if (!.) {
            return null;
        }
        .inc();
        return .time();
    }
    public void finish(Context timerOperationDiagnostics opStats)
    {
        .dec();
        if (timer != null) {
            timer.stop();
        }
        if (opStats != null) {
            if ( != null) {
                Storable entity = opStats.getEntry();
                if (entity != null) {
                    .update(entity.getActualUncompressedLength());
                }
            }
            if ( != null) {
                .update(opStats.getItemCount());
            }
        }
    }
New to GrepCode? Check out our FAQ X