contrib/php-collection: Add a PHP frontend for graph generation.
[collectd.git] / src / ascent.c
index 75d5cb6..e0b6ba2 100644 (file)
@@ -123,8 +123,8 @@ static int ascent_submit_gauge (const char *plugin_instance, /* {{{ */
   vl.values = values;
   vl.values_len = 1;
   vl.time = time (NULL);
-  strcpy (vl.host, hostname_g);
-  strcpy (vl.plugin, "ascent");
+  sstrncpy (vl.host, hostname_g, sizeof (vl.host));
+  sstrncpy (vl.plugin, "ascent", sizeof (vl.plugin));
 
   if (plugin_instance != NULL)
     sstrncpy (vl.plugin_instance, plugin_instance,
@@ -193,11 +193,12 @@ static int ascent_submit_players (player_stats_t *ps) /* {{{ */
     value = ((double) ps->level_sum) / ((double) ps->level_num);
   ascent_submit_gauge (NULL, "gauge", "avg-level", value);
 
+  /* Latency is in ms, but we store seconds. */
   if (ps->latency_num <= 0)
     value = NAN;
   else
-    value = ((double) ps->latency_sum) / ((double) ps->latency_num);
-  ascent_submit_gauge (NULL, "gauge", "avg-latency", value);
+    value = ((double) ps->latency_sum) / (1000.0 * ((double) ps->latency_num));
+  ascent_submit_gauge (NULL, "latency", "average", value);
 
   return (0);
 } /* }}} int ascent_submit_players */
@@ -270,10 +271,12 @@ static int ascent_xml_submit_gauge (xmlDoc *doc, xmlNode *node, /* {{{ */
     value = strtod (str_ptr, &end_ptr);
     if (str_ptr == end_ptr)
     {
+      xmlFree(str_ptr);
       ERROR ("ascent plugin: ascent_xml_submit_gauge: strtod failed.");
       return (-1);
     }
   }
+  xmlFree(str_ptr);
 
   return (ascent_submit_gauge (plugin_instance, type, type_instance, value));
 } /* }}} int ascent_xml_submit_gauge */
@@ -299,10 +302,12 @@ static int ascent_xml_read_int (xmlDoc *doc, xmlNode *node, /* {{{ */
     value = strtol (str_ptr, &end_ptr, 0);
     if (str_ptr == end_ptr)
     {
+      xmlFree(str_ptr);
       ERROR ("ascent plugin: ascent_xml_read_int: strtol failed.");
       return (-1);
     }
   }
+  xmlFree(str_ptr);
 
   *ret_value = value;
   return (0);