Code

memcached plugin: Add hitratio metric.
authorDoug MacEachern <dougm@hyperic.com>
Thu, 8 Jan 2009 01:58:49 +0000 (17:58 -0800)
committerFlorian Forster <octo@huhu.verplant.org>
Tue, 20 Jan 2009 09:32:51 +0000 (10:32 +0100)
Signed-off-by: Doug MacEachern <dougm@hyperic.com>
Signed-off-by: Florian Forster <octo@huhu.verplant.org>
src/memcached.c

index 7bdad0a01a475f42d7d5c9c37b07c1abf62a0144..fb33880ff5cc68aae4764723742e4cc3e0944f99 100644 (file)
@@ -321,6 +321,8 @@ static int memcached_read (void) /* {{{ */
 
        gauge_t bytes_used = NAN;
        gauge_t bytes_total = NAN;
+       gauge_t hits = NAN;
+       gauge_t gets = NAN;
        counter_t rusage_user = 0;
        counter_t rusage_syst = 0;
        counter_t octets_rx = 0;
@@ -430,6 +432,8 @@ static int memcached_read (void) /* {{{ */
                {
                        const char *name = fields[1] + 4;
                        submit_counter ("memcached_command", name, atoll (fields[2]));
+                       if (strcmp (name, "get") == 0)
+                               gets = atof (fields[2]);
                }
 
                /*
@@ -438,6 +442,7 @@ static int memcached_read (void) /* {{{ */
                else if (FIELD_IS ("get_hits"))
                {
                        submit_counter ("memcached_ops", "hits", atoll (fields[2]));
+                       hits = atof (fields[2]);
                }
                else if (FIELD_IS ("get_misses"))
                {
@@ -470,6 +475,8 @@ static int memcached_read (void) /* {{{ */
        if ((octets_rx != 0) || (octets_tx != 0))
                submit_counter2 ("memcached_octets", NULL, octets_rx, octets_tx);
        
+       if (! isnan (gets) && !isnan (hits))
+               submit_gauge ("percent", "hitratio", (hits / gets) * 100.0);
        return 0;
 }
 /* }}} */