newClientMetrics creates a new bundle of metrics about an instance of a cache client. Note that there may be multiple cache clients at any given time so the prometheus.Registerer passed to this method should include labels unique to this particular client (e.g. a name for each different cache being
(reg prometheus.Registerer)
| 55 | // to this method should include labels unique to this particular client (e.g. a name for each |
| 56 | // different cache being used). |
| 57 | func newClientMetrics(reg prometheus.Registerer) *clientMetrics { |
| 58 | cm := &clientMetrics{} |
| 59 | |
| 60 | cm.requests = promauto.With(reg).NewCounter(prometheus.CounterOpts{ |
| 61 | Name: "requests_total", |
| 62 | Help: "Total number of items requests to cache.", |
| 63 | }) |
| 64 | cm.hits = promauto.With(reg).NewCounter(prometheus.CounterOpts{ |
| 65 | Name: "hits_total", |
| 66 | Help: "Total number of items requests to the cache that were a hit.", |
| 67 | }) |
| 68 | cm.operations = promauto.With(reg).NewCounterVec(prometheus.CounterOpts{ |
| 69 | Name: "operations_total", |
| 70 | Help: "Total number of operations against cache.", |
| 71 | }, []string{"operation"}) |
| 72 | cm.operations.WithLabelValues(opGetMulti) |
| 73 | cm.operations.WithLabelValues(opAdd) |
| 74 | cm.operations.WithLabelValues(opSet) |
| 75 | cm.operations.WithLabelValues(opDelete) |
| 76 | cm.operations.WithLabelValues(opIncrement) |
| 77 | cm.operations.WithLabelValues(opDecrement) |
| 78 | cm.operations.WithLabelValues(opTouch) |
| 79 | cm.operations.WithLabelValues(opCompareAndSwap) |
| 80 | cm.operations.WithLabelValues(opFlush) |
| 81 | |
| 82 | cm.failures = promauto.With(reg).NewCounterVec(prometheus.CounterOpts{ |
| 83 | Name: "operation_failures_total", |
| 84 | Help: "Total number of operations against cache that failed.", |
| 85 | }, []string{"operation", "reason"}) |
| 86 | for _, op := range []string{opGetMulti, opAdd, opSet, opDelete, opIncrement, opDecrement, opFlush, opTouch, opCompareAndSwap} { |
| 87 | cm.failures.WithLabelValues(op, reasonConnectTimeout) |
| 88 | cm.failures.WithLabelValues(op, reasonTimeout) |
| 89 | cm.failures.WithLabelValues(op, reasonMalformedKey) |
| 90 | cm.failures.WithLabelValues(op, reasonInvalidTTL) |
| 91 | cm.failures.WithLabelValues(op, reasonNotStored) |
| 92 | cm.failures.WithLabelValues(op, reasonServerError) |
| 93 | cm.failures.WithLabelValues(op, reasonNetworkError) |
| 94 | cm.failures.WithLabelValues(op, reasonCanceled) |
| 95 | cm.failures.WithLabelValues(op, reasonOther) |
| 96 | } |
| 97 | |
| 98 | cm.skipped = promauto.With(reg).NewCounterVec(prometheus.CounterOpts{ |
| 99 | Name: "operation_skipped_total", |
| 100 | Help: "Total number of operations against cache that have been skipped.", |
| 101 | }, []string{"operation", "reason"}) |
| 102 | cm.skipped.WithLabelValues(opGetMulti, reasonMaxItemSize) |
| 103 | cm.skipped.WithLabelValues(opAdd, reasonMaxItemSize) |
| 104 | cm.skipped.WithLabelValues(opSet, reasonMaxItemSize) |
| 105 | cm.skipped.WithLabelValues(opSet, reasonAsyncBufferFull) |
| 106 | |
| 107 | cm.duration = promauto.With(reg).NewHistogramVec(prometheus.HistogramOpts{ |
| 108 | Name: "operation_duration_seconds", |
| 109 | Help: "Duration of operations against cache.", |
| 110 | Buckets: []float64{0.001, 0.005, 0.01, 0.025, 0.05, 0.1, 0.2, 0.5, 1, 3, 6, 10}, |
| 111 | // Use defaults recommended by Prometheus for native histograms. |
| 112 | NativeHistogramBucketFactor: 1.1, |
| 113 | NativeHistogramMaxBucketNumber: 100, |
| 114 | NativeHistogramMinResetDuration: time.Hour, |
no test coverage detected