summaryrefslogtreecommitdiffstats
path: root/vespaclient-container-plugin/src/main/java/com/yahoo/documentapi/metrics/DocumentApiMetricsHelper.java
diff options
context:
space:
mode:
authorvalerijf <valerijf@yahoo-inc.com>2017-05-11 12:54:47 +0200
committervalerijf <valerijf@yahoo-inc.com>2017-05-11 12:54:47 +0200
commit605ae73f3699b35a9071b0736235b5c5cfbc5ad4 (patch)
tree64e10d1129e591575ccc5ed7e99d39e679d62202 /vespaclient-container-plugin/src/main/java/com/yahoo/documentapi/metrics/DocumentApiMetricsHelper.java
parent2ffb9f91d8cefb9a83e3018c599445ce1990d251 (diff)
Created helper classes to collect feed metrics
Diffstat (limited to 'vespaclient-container-plugin/src/main/java/com/yahoo/documentapi/metrics/DocumentApiMetricsHelper.java')
-rw-r--r--vespaclient-container-plugin/src/main/java/com/yahoo/documentapi/metrics/DocumentApiMetricsHelper.java53
1 files changed, 53 insertions, 0 deletions
diff --git a/vespaclient-container-plugin/src/main/java/com/yahoo/documentapi/metrics/DocumentApiMetricsHelper.java b/vespaclient-container-plugin/src/main/java/com/yahoo/documentapi/metrics/DocumentApiMetricsHelper.java
new file mode 100644
index 00000000000..a082f7dba8a
--- /dev/null
+++ b/vespaclient-container-plugin/src/main/java/com/yahoo/documentapi/metrics/DocumentApiMetricsHelper.java
@@ -0,0 +1,53 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.documentapi.metrics;
+
+import com.yahoo.metrics.simple.Counter;
+import com.yahoo.metrics.simple.Gauge;
+import com.yahoo.metrics.simple.MetricReceiver;
+import com.yahoo.metrics.simple.Point;
+
+import java.util.HashMap;
+import java.util.Map;
+
+
+/**
+ * @author freva
+ */
+public class DocumentApiMetricsHelper {
+ private final Counter feeds;
+ private final Gauge feedLatency;
+ private final Map<DocumentOperationStatus, Map<DocumentOperationType, Point>> points = new HashMap<>();
+
+ public DocumentApiMetricsHelper(MetricReceiver metricReceiver, String apiName) {
+ Map<String, String> dimensions = new HashMap<>();
+ dimensions.put("api", apiName);
+ for (DocumentOperationStatus status : DocumentOperationStatus.values()) {
+ points.put(status, new HashMap<>());
+ dimensions.put("status", status.name());
+ for (DocumentOperationType operation : DocumentOperationType.values()) {
+ dimensions.put("operation", operation.name());
+ points.get(status).put(operation, new Point(dimensions));
+ }
+ }
+
+ feeds = metricReceiver.declareCounter("feed_operations");
+ feedLatency = metricReceiver.declareGauge("feed_latency");
+ }
+
+ public void reportSuccessful(DocumentOperationType documentOperationType, double latency) {
+ Point point = points.get(DocumentOperationStatus.OK).get(documentOperationType);
+
+ feedLatency.sample(latency, point);
+ feeds.add(point);
+ }
+
+ public void reportSuccessful(DocumentOperationType documentOperationType, long startTime) {
+ final double latency = (System.currentTimeMillis() - startTime) / 1000.0d;
+ reportSuccessful(documentOperationType, latency);
+ }
+
+ public void reportFailure(DocumentOperationType documentOperationType, DocumentOperationStatus documentOperationStatus) {
+ Point point = points.get(documentOperationStatus).get(documentOperationType);
+ feeds.add(point);
+ }
+}