import { MetricsCollector } from './MetricsCollector' ; import { BucketCounter , ICounter , IHistogram , IMeter , ITimer , MetricName , Snapshot } from '../common' ; import { MetricObject } from './MetricObject' ; export class NormalMetricsCollector extends MetricsCollector { collectTimer ( name , timer , timestamp ) { let snapshot = timer . getSnapshot ( ) ; this . addMetricWithSuffix ( name , 'count' , timer . getCount ( ) , timestamp , MetricObject . MetricType . COUNTER ) . addMetricWithSuffix ( name , 'm1' , this . convertRate ( timer . getOneMinuteRate ( ) ) , timestamp ) . addMetricWithSuffix ( name , 'm5' , this . convertRate ( timer . getFiveMinuteRate ( ) ) , timestamp ) . addMetricWithSuffix ( name , 'm15' , this . convertRate ( timer . getFifteenMinuteRate ( ) ) , timestamp ) . addMetricWithSuffix ( name , 'max' , this . convertDuration ( snapshot . getMax ( ) ) , timestamp ) . addMetricWithSuffix ( name , 'min' , this . convertDuration ( snapshot . getMin ( ) ) , timestamp ) . addMetricWithSuffix ( name , 'mean' , this . convertDuration ( snapshot . getMean ( ) ) , timestamp ) . addMetricWithSuffix ( name , 'rt' , this . convertDuration ( snapshot . getMean ( ) ) , timestamp ) . addMetricWithSuffix ( name , 'stddev' , this . convertDuration ( snapshot . getStdDev ( ) ) , timestamp ) . addMetricWithSuffix ( name , 'median' , this . convertDuration ( snapshot . getMedian ( ) ) , timestamp ) . addMetricWithSuffix ( name , 'p75' , this . convertDuration ( snapshot . get75thPercentile ( ) ) , timestamp ) . addMetricWithSuffix ( name , 'p95' , this . convertDuration ( snapshot . get95thPercentile ( ) ) , timestamp ) . addMetricWithSuffix ( name , 'p99' , this . convertDuration ( snapshot . get99thPercentile ( ) ) , timestamp ) ; this . addInstantCountMetric ( timer . getInstantCount ( ) , name , timer . getInstantCountInterval ( ) , timestamp ) ; } collectHistogram ( name , histogram , timestamp ) { let snapshot = histogram . getSnapshot ( ) ; this . addMetricWithSuffix ( name , 'count' , histogram . getCount ( ) , timestamp , MetricObject . MetricType . COUNTER ) . addMetricWithSuffix ( name , 'max' , snapshot . getMax ( ) , timestamp ) . addMetricWithSuffix ( name , 'min' , snapshot . getMin ( ) , timestamp ) . addMetricWithSuffix ( name , 'mean' , snapshot . getMean ( ) , timestamp ) . addMetricWithSuffix ( name , 'stddev' , snapshot . getStdDev ( ) , timestamp ) . addMetricWithSuffix ( name , 'median' , snapshot . getMedian ( ) , timestamp ) . addMetricWithSuffix ( name , 'p75' , snapshot . get75thPercentile ( ) , timestamp ) . addMetricWithSuffix ( name , 'p95' , snapshot . get95thPercentile ( ) , timestamp ) . addMetricWithSuffix ( name , 'p99' , snapshot . get99thPercentile ( ) , timestamp ) ; } collectGauge ( name , value , timestamp ) { this . addMetric ( name , value , timestamp , MetricObject . MetricType . GAUGE , - 1 ) ; } collectCounter ( name , counter , timestamp ) { let normalizedName = name . getKey ( ) . endsWith ( 'count' ) ? name : name . resolve ( 'count' ) ; this . addMetric ( normalizedName , counter . getCount ( ) , timestamp , MetricObject . MetricType . COUNTER , - 1 ) ; if ( counter instanceof BucketCounter ) { let countInterval = ( < BucketCounter > counter ) . getBucketInterval ( ) ; this . addInstantCountMetric ( ( < BucketCounter > counter ) . getBucketCounts ( ) , name , countInterval , timestamp ) ; } } collectMeter ( name , meter , timestamp ) { this . addMetricWithSuffix ( name , 'count' , meter . getCount ( ) , timestamp , MetricObject . MetricType . COUNTER ) . addMetricWithSuffix ( name , 'm1' , this . convertRate ( meter . getOneMinuteRate ( ) ) , timestamp ) . addMetricWithSuffix ( name , 'm5' , this . convertRate ( meter . getFiveMinuteRate ( ) ) , timestamp ) . addMetricWithSuffix ( name , 'm15' , this . convertRate ( meter . getFifteenMinuteRate ( ) ) , timestamp ) ; this . addInstantCountMetric ( meter . getInstantCount ( ) , name , meter . getInstantCountInterval ( ) , timestamp ) ; } }