[collectd] apache and collectd plugin

Amit Gupta amit.gupta221 at gmail.com
Mon Apr 20 18:40:49 CEST 2009


Hi,

Do find the patch for lighttpd scoreboard attached. Let me know if
this patch looks okay.

Regards
Amit

On Thu, Apr 16, 2009 at 4:35 PM, Amit Gupta <amit.gupta221 at gmail.com> wrote:
> On Thu, Apr 16, 2009 at 4:19 PM, Florian Forster <octo at verplant.org> wrote:
>> Hi Amit,
>>
>> On Thu, Apr 16, 2009 at 03:57:51PM +0530, Amit Gupta wrote:
>>> yeah :). Do find the patch attached. I have moved apache_buffer and
>>> friends to the apache_t structure and set the plugin_instance if
>>> there. There are other changes as well like freeing up  the
>>> lci->values etc. Have a look at the patch and let me know if this
>>> looks okay to you.
>>
>> yes, looks great now, thank you very much :) I've applied the patch and
>> merged the changes into the master branch of the Git repository.
>>
>> I will change the plugin later to use that “complex read” infra-
>> structure, so that the servers are queries in parallel.
>
> Thanks for applying the patch. Which version of collectd will this
> patch be available?. Is this fix checked in to the git repository, so
> that I can checkout and start working on the lighttpd scoreboard issue
> on the top of it?
>
> Regards
> Amit
>
>>
>> Best regards,
>> -octo
>> --
>> Florian octo Forster
>> Hacker in training
>> GnuPG: 0x91523C3D
>> http://verplant.org/
>>
>> -----BEGIN PGP SIGNATURE-----
>> Version: GnuPG v1.4.6 (GNU/Linux)
>>
>> iD8DBQFJ5w1VHdggu3Q05IYRAoATAJ0Zp6DXhVIGHvPb7FTNr297WJRyYwCdHRv5
>> AKId+vAhf4Wx5er3M7pIePU=
>> =ghlT
>> -----END PGP SIGNATURE-----
>>
>>
>
-------------- next part --------------
Common subdirectories: collectd-4.6.1/bindings and collectd-4.6.1-mine/bindings
Common subdirectories: collectd-4.6.1/contrib and collectd-4.6.1-mine/contrib
Common subdirectories: collectd-4.6.1/libltdl and collectd-4.6.1-mine/libltdl
Common subdirectories: collectd-4.6.1/src and collectd-4.6.1-mine/src
Common subdirectories: collectd-4.6.1/bindings/perl and collectd-4.6.1-mine/bindings/perl
Common subdirectories: collectd-4.6.1/bindings/perl/Collectd and collectd-4.6.1-mine/bindings/perl/Collectd
Common subdirectories: collectd-4.6.1/contrib/SpamAssassin and collectd-4.6.1-mine/contrib/SpamAssassin
Common subdirectories: collectd-4.6.1/contrib/collection3 and collectd-4.6.1-mine/contrib/collection3
Common subdirectories: collectd-4.6.1/contrib/examples and collectd-4.6.1-mine/contrib/examples
Common subdirectories: collectd-4.6.1/contrib/fedora and collectd-4.6.1-mine/contrib/fedora
Common subdirectories: collectd-4.6.1/contrib/iptables and collectd-4.6.1-mine/contrib/iptables
Common subdirectories: collectd-4.6.1/contrib/oracle and collectd-4.6.1-mine/contrib/oracle
Common subdirectories: collectd-4.6.1/contrib/php-collection and collectd-4.6.1-mine/contrib/php-collection
Common subdirectories: collectd-4.6.1/contrib/redhat and collectd-4.6.1-mine/contrib/redhat
Common subdirectories: collectd-4.6.1/contrib/sles10.1 and collectd-4.6.1-mine/contrib/sles10.1
Common subdirectories: collectd-4.6.1/contrib/solaris-smf and collectd-4.6.1-mine/contrib/solaris-smf
Common subdirectories: collectd-4.6.1/contrib/collection3/bin and collectd-4.6.1-mine/contrib/collection3/bin
Common subdirectories: collectd-4.6.1/contrib/collection3/etc and collectd-4.6.1-mine/contrib/collection3/etc
Common subdirectories: collectd-4.6.1/contrib/collection3/lib and collectd-4.6.1-mine/contrib/collection3/lib
Common subdirectories: collectd-4.6.1/contrib/collection3/share and collectd-4.6.1-mine/contrib/collection3/share
Common subdirectories: collectd-4.6.1/contrib/collection3/lib/Collectd and collectd-4.6.1-mine/contrib/collection3/lib/Collectd
Common subdirectories: collectd-4.6.1/contrib/collection3/lib/Collectd/Graph and collectd-4.6.1-mine/contrib/collection3/lib/Collectd/Graph
Common subdirectories: collectd-4.6.1/contrib/collection3/lib/Collectd/Graph/Type and collectd-4.6.1-mine/contrib/collection3/lib/Collectd/Graph/Type
diff -ur collectd-4.6.1/src/apache.c collectd-4.6.1-mine/src/apache.c
--- collectd-4.6.1/src/apache.c	Mon Apr 20 20:15:56 2009
+++ collectd-4.6.1-mine/src/apache.c	Mon Apr 20 21:20:00 2009
@@ -31,6 +31,12 @@
 
 #include <curl/curl.h>
 
+enum server_type 
+{
+	APACHE = 0, 
+	LIGHTTPD
+};
+
 struct apache_s
 {
 	char *name;
@@ -434,14 +440,19 @@
 	plugin_dispatch_values (&vl);
 } /* void submit_counter */
 
-static void submit_scoreboard (char *buf, apache_t *st)
+static void submit_scoreboard (char *buf, int server, apache_t *st)
 {
 	/*
 	 * Scoreboard Key:
-	 * "_" Waiting for Connection, "S" Starting up, "R" Reading Request,
+	 * "_" Waiting for Connection, "S" Starting up, 
+	 * "R" Reading Request for apache and read-POST for lighttpd,
 	 * "W" Sending Reply, "K" Keepalive (read), "D" DNS Lookup,
 	 * "C" Closing connection, "L" Logging, "G" Gracefully finishing,
 	 * "I" Idle cleanup of worker, "." Open slot with no current process
+	 * Lighttpd specific legends -
+	 * "E" hard error, "." connect, "h" handle-request,
+	 * "q" request-start, "Q" request-end, "s" response-start
+	 * "S" response-end, "r" read
 	 */
 	long long open      = 0LL;
 	long long waiting   = 0LL;
@@ -455,6 +466,16 @@
 	long long finishing = 0LL;
 	long long idle_cleanup = 0LL;
 
+	// lighttpd specific
+	long long connect        = 0LL;
+	long long hard_error     = 0LL;
+	long long lighttpd_read  = 0LL;
+	long long handle_request = 0LL;
+	long long request_start  = 0LL;
+	long long request_end    = 0LL;
+	long long response_start = 0LL;
+	long long response_end   = 0LL;
+	
 	int i;
 
 	for (i = 0; buf[i] != '\0'; i++)
@@ -470,19 +491,44 @@
 		else if (buf[i] == 'L') logging++;
 		else if (buf[i] == 'G') finishing++;
 		else if (buf[i] == 'I') idle_cleanup++;
+		else if (buf[i] == '.') connect++;
+		else if (buf[i] == 'r') lighttpd_read++;
+		else if (buf[i] == 'h') handle_request++;
+		else if (buf[i] == 'E') hard_error++;
+		else if (buf[i] == 'q') request_start++;
+		else if (buf[i] == 'Q') request_end++;
+		else if (buf[i] == 's') response_start++;
+		else if (buf[i] == 'S') response_end++;
 	}
 
-	submit_gauge ("apache_scoreboard", "open"     , open, st);
-	submit_gauge ("apache_scoreboard", "waiting"  , waiting, st);
-	submit_gauge ("apache_scoreboard", "starting" , starting, st);
-	submit_gauge ("apache_scoreboard", "reading"  , reading, st);
-	submit_gauge ("apache_scoreboard", "sending"  , sending, st);
-	submit_gauge ("apache_scoreboard", "keepalive", keepalive, st);
-	submit_gauge ("apache_scoreboard", "dnslookup", dnslookup, st);
-	submit_gauge ("apache_scoreboard", "closing"  , closing, st);
-	submit_gauge ("apache_scoreboard", "logging"  , logging, st);
-	submit_gauge ("apache_scoreboard", "finishing", finishing, st);
-	submit_gauge ("apache_scoreboard", "idle_cleanup", idle_cleanup, st);
+	if (server == APACHE)
+	{
+		submit_gauge ("apache_scoreboard", "open"     , open, st);
+		submit_gauge ("apache_scoreboard", "waiting"  , waiting, st);
+		submit_gauge ("apache_scoreboard", "starting" , starting, st);
+		submit_gauge ("apache_scoreboard", "reading"  , reading, st);
+		submit_gauge ("apache_scoreboard", "sending"  , sending, st);
+		submit_gauge ("apache_scoreboard", "keepalive", keepalive, st);
+		submit_gauge ("apache_scoreboard", "dnslookup", dnslookup, st);
+		submit_gauge ("apache_scoreboard", "closing"  , closing, st);
+		submit_gauge ("apache_scoreboard", "logging"  , logging, st);
+		submit_gauge ("apache_scoreboard", "finishing", finishing, st);
+		submit_gauge ("apache_scoreboard", "idle_cleanup", idle_cleanup, st);
+	} else
+	{
+		submit_gauge ("apache_scoreboard", "connect"       , connect, st);
+		submit_gauge ("apache_scoreboard", "close"         , closing, st);
+		submit_gauge ("apache_scoreboard", "hard_error"    , hard_error, st);
+		submit_gauge ("apache_scoreboard", "read"          , lighttpd_read, st);
+		submit_gauge ("apache_scoreboard", "read_post"     , reading, st);
+		submit_gauge ("apache_scoreboard", "write"         , sending, st);
+		submit_gauge ("apache_scoreboard", "handle_request", handle_request, st);
+		submit_gauge ("apache_scoreboard", "request_start" , request_start, st);
+		submit_gauge ("apache_scoreboard", "request_end"   , request_end, st);
+		submit_gauge ("apache_scoreboard", "response_start", response_start, st);
+		submit_gauge ("apache_scoreboard", "response_end"  , response_end, st);
+
+	}
 }
 
 static int apache_read_host (apache_t *st)
@@ -496,6 +542,7 @@
 
 	char *fields[4];
 	int   fields_num;
+	int server = LIGHTTPD; // default is lighttpd
 
 	if (st->curl == NULL)
 		return (-1);
@@ -544,8 +591,16 @@
 		}
 		else if (fields_num == 2)
 		{
-			if (strcmp (fields[0], "Scoreboard:") == 0)
-				submit_scoreboard (fields[1], st);
+			// find out if the server is apache from the mod_status output.
+			// apache mod_status output has additional fields which lighttpd
+			// mod_status output doesn't have e.g: ReqPerSec.
+			// submit_scoreboard needs server type information and thus it is 
+			// important to pick up a field before scoreboard gets parsed 
+			// to set the server type
+			if (strcmp (fields[0], "ReqPerSec:") == 0)
+				server = APACHE;
+			else if (strcmp (fields[0], "Scoreboard:") == 0)
+				submit_scoreboard (fields[1], server, st);
 			else if (strcmp (fields[0], "BusyServers:") == 0)
 				submit_gauge ("apache_connections", NULL, atol (fields[1]), st);
 		}
Common subdirectories: collectd-4.6.1/src/libcollectdclient and collectd-4.6.1-mine/src/libcollectdclient
Common subdirectories: collectd-4.6.1/src/libiptc and collectd-4.6.1-mine/src/libiptc
Common subdirectories: collectd-4.6.1/src/liboconfig and collectd-4.6.1-mine/src/liboconfig
Common subdirectories: collectd-4.6.1/src/liboping and collectd-4.6.1-mine/src/liboping


More information about the collectd mailing list