pinba plugin: service_statnode_collect: Coding style changes.
[collectd.git] / src / pinba.c
index 40cc55e..c3cc682 100644 (file)
@@ -1,5 +1,6 @@
 /**
- * collectd - src/pinba.c
+ * collectd - src/pinba.c (based on code from pinba_engine 0.0.5)
+ * Copyright (c) 2007-2009  Antony Dovgal
  * Copyright (C) 2010       Phoenix Kayo
  *
  * This program is free software; you can redistribute it and/or modify it
@@ -16,6 +17,7 @@
  * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
  *
  * Authors:
+ *   Antony Dovgal <tony at daylessday.org>
  *   Phoenix Kayo <kayo.k11.4 at gmail.com>
  **/
 
@@ -44,6 +46,17 @@ typedef uint8_t u_char;
 # define PINBA_UDP_BUFFER_SIZE 65536
 #endif
 
+#ifndef PINBA_DEFAULT_ADDRESS
+# define PINBA_DEFAULT_ADDRESS "127.0.0.1" /* FIXME */
+#endif
+
+#ifndef PINBA_DEFAULT_PORT
+# define PINBA_DEFAULT_PORT 12345 /* FIXME */
+#endif
+
+/*
+ * Private data structures
+ */
 typedef struct _pinba_statres_ pinba_statres;
 struct _pinba_statres_ {
   const char *name;
@@ -211,46 +224,45 @@ static void service_statnode_end (void)
   pthread_rwlock_unlock(&temp_lock);
 }
 
-static unsigned int service_statnode_collect (pinba_statres *res,
-    unsigned int i)
+static unsigned int service_statnode_collect (pinba_statres *res, /* {{{ */
+    unsigned int index)
 {
   pinba_statnode* node;
+  pinba_time delta;
   
-  if(stat_nodes_count==0) return 0;
+  if (stat_nodes_count == 0)
+    return 0;
   
   /* begin collecting */
-  if(i==0){
-    pthread_rwlock_wrlock(&temp_lock);
-  }
-  
-  /* find non-empty node */
-  //for(node=stat_nodes+i; node->req_count==0 && ++i<stat_nodes_count; node=stat_nodes+i);
+  if (index == 0)
+    pthread_rwlock_wrlock (&temp_lock);
   
   /* end collecting */
-  if(i>=stat_nodes_count){
-    pthread_rwlock_unlock(&temp_lock);
+  if (index >= stat_nodes_count)
+  {
+    pthread_rwlock_unlock (&temp_lock);
     return 0;
   }
   
-  node=stat_nodes+i;
-  
-  pinba_time delta=now()-node->last_coll;
+  node = stat_nodes + index;
+  delta = now() - node->last_coll;
   
-  res->name=node->name;
+  res->name = node->name;
+  res->req_per_sec = node->req_count / delta;
   
-  res->req_per_sec=node->req_count/delta;
-  
-  if(node->req_count==0)node->req_count=1;
-  res->req_time=node->req_time/node->req_count;
-  res->ru_utime=node->ru_utime/node->req_count;
-  res->ru_stime=node->ru_stime/node->req_count;
-  res->ru_stime=node->ru_stime/node->req_count;
-  res->doc_size=node->doc_size/node->req_count;
-  res->mem_peak=node->mem_peak/node->req_count;
+  if (node->req_count == 0)
+    node->req_count = 1;
+
+  res->req_time = node->req_time / node->req_count;
+  res->ru_utime = node->ru_utime / node->req_count;
+  res->ru_stime = node->ru_stime / node->req_count;
+  res->ru_stime = node->ru_stime / node->req_count;
+  res->doc_size = node->doc_size / node->req_count;
+  res->mem_peak = node->mem_peak / node->req_count;
   
-  service_statnode_reset(node);
-  return ++i;
-}
+  service_statnode_reset (node);
+  return (index + 1);
+} /* }}} unsigned int service_statnode_collect */
 
 static void service_statnode_process (pinba_statnode *node,
     Pinba__Request* request)
@@ -420,7 +432,7 @@ static pinba_socket *pinba_socket_open (const char *ip, /* {{{ */
   event_add(s->accept_event, NULL);
   
   return s;
-} /* }}} */
+} /* }}} pinba_socket_open */
 
 static int service_cleanup (void)
 {
@@ -602,8 +614,7 @@ static int plugin_shutdown (void)
   return 0;
 }
 
-static int
-plugin_submit (const char *plugin_instance,
+static int plugin_submit (const char *plugin_instance,
               const char *type,
               const pinba_statres *res) {
   value_t values[6];
@@ -650,4 +661,4 @@ void module_register (void)
   plugin_register_shutdown ("pinba", plugin_shutdown);
 } /* void module_register */
 
-/* vim: set sw=2 sts=2 et : */
+/* vim: set sw=2 sts=2 et fdm=marker : */