Ori.livneh has submitted this change and it was merged.

Change subject: Add get_hits_ratio calculation to memcached's gmond agent.
......................................................................


Add get_hits_ratio calculation to memcached's gmond agent.

We currently have only get_hits_rate in gmond, meanwhile it would be
great to calculate get_hits_ratio too. This is a proof of concept
about how I think it could be done easily, but it would need to be
tested.

Bug: T129963
Change-Id: I0ba7673feb09fa67748e4df37d59026ad5c52304
---
M modules/memcached/files/ganglia/gmond_memcached.py
1 file changed, 26 insertions(+), 3 deletions(-)

Approvals:
  Ori.livneh: Verified; Looks good to me, approved



diff --git a/modules/memcached/files/ganglia/gmond_memcached.py 
b/modules/memcached/files/ganglia/gmond_memcached.py
index 76480af..50d5ac1 100644
--- a/modules/memcached/files/ganglia/gmond_memcached.py
+++ b/modules/memcached/files/ganglia/gmond_memcached.py
@@ -103,15 +103,32 @@
     def metric_of(self, name):
         val = 0
         mp = name.split("_")[0]
-        if (name.rsplit("_", 1)[1] == "rate" and
-                name.rsplit("_", 1)[0] in self.metric):
+        name_tail = name.rsplit("_", 1)
+        if (name_tail[1] == "rate" and
+                name_tail[0] in self.metric):
             _Lock.acquire()
-            name = name.rsplit("_", 1)[0]
+            name = name_tail[0]
             if name in self.last_metric:
                 num = self.metric[name]-self.last_metric[name]
                 period = self.metric[mp+"_time"]-self.last_metric[mp+"_time"]
                 try:
                     val = num/period
+                except ZeroDivisionError:
+                    val = 0
+            _Lock.release()
+        elif (name_tail[1] == "ratio" and
+                "hits" in name_tail[0] and
+                name_tail[0] in self.metric and
+                name_tail[0].replace("hits","misses") in self.metric):
+            _Lock.acquire()
+            hits_name = name_tail[0]
+            misses_name = hits_name.replace("hits","misses")
+            if hits_name in self.last_metric and
+                    misses_name in self.last_metric:
+                hits = self.metric[hits_name]-self.last_metric[hits_name]
+                misses = self.metric[misses_name]-self.last_metric[misses_name]
+                try:
+                    val = hits/(hits+misses)
                 except ZeroDivisionError:
                     val = 0
             _Lock.release()
@@ -261,6 +278,12 @@
                 "slope": "both",
                 "description": "Sets per second",
                 }))
+    descriptors.append(create_desc(Desc_Skel, {
+                "name": mp+"_get_hits_ratio",
+                "units": "items",
+                "slope": "positive",
+                "description": "Get hits ratio (hits/(hits+misses)",
+                }))
 
     # Tokyo Tyrant
     if "type" in params and params["type"].lower().find("tokyo") == 0:

-- 
To view, visit https://gerrit.wikimedia.org/r/290233
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I0ba7673feb09fa67748e4df37d59026ad5c52304
Gerrit-PatchSet: 2
Gerrit-Project: operations/puppet
Gerrit-Branch: production
Gerrit-Owner: Elukey <[email protected]>
Gerrit-Reviewer: Ori.livneh <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to