While waiting for a never ending compile to end I decided to hack Ganglia
myself :-) to do what I proposed. I changed the process_tcp_accept_channel
to listen for "commands" in the format of
HOSTNAME METRIC
As a result you get something like this
$ echo "localhost.localdomain cpu_nice" | nc localhost 8700
<HOST NAME="localhost.localdomain">
<METRIC NAME="cpu_nice" VAL="0.0" TYPE="float" UNITS="%" TN="0" TMAX="90"
DMAX="0" SLOPE="both">
<EXTRA_DATA>
<EXTRA_ELEMENT NAME="GROUP" VAL="cpu"/>
<EXTRA_ELEMENT NAME="DESC" VAL="Percentage of CPU utilization that
occurred while executing at the user level with nice priority"/>
<EXTRA_ELEMENT NAME="TITLE" VAL="cpu_nice"/>
</EXTRA_DATA>
</METRIC>
</HOST>
$
Code is not particularly beautiful and likely needs security checks etc.
but does the job. Obviously this breaks tcp_accept_channel behaviour.
Possibly it should be run on a separate port or if you don't care about
breaking legacy behavior it could be run on the same port ie. by having
gmetad send SEND_ALL command.
Patch is attached.
Vladimir
On Wed, 16 Sep 2009, Bernard Li wrote:
+1 on the general idea, not sure about the implementation though.
Let's get Spike into this discussion -- yes Spike, I'm calling you out! ;-)
Cheers,
Bernard
On Wed, Sep 16, 2009 at 11:49 AM, Vladimir Vuksan <[email protected]> wrote:
There have been some tweets that someone was working on a REST interface
for Ganglia. At first I thought it wasn't such a big deal but I think that
adding a simplistic interface to Ganglia would be a nice addition ie.
something like
telnet ganglia 8653
METRIC web1 load_one
Which would echo out the current value for load_one. That way you can
avoid parsing out the XML to get those values. I think for large sites it
makes a lot of sense. Granted there are "workarounds" that could be
implemented and people have.
I believe all that needs to be done is add a function similar to
process_tcp_accept_channel
which doesn't dump out the whole XML but selective value. I would put it
on a separate port call it tcp_get_metric. If you were so inclined you
could even make it a HTTP interface.
Thoughts ?
Vladimir
------------------------------------------------------------------------------
Come build with us! The BlackBerry® Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9-12, 2009. Register now!
http://p.sf.net/sfu/devconf
_______________________________________________
Ganglia-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ganglia-general
--- gmond.c.orig 2009-09-21 15:36:04.473355906 -0400
+++ gmond.c 2009-09-21 15:55:00.461391181 -0400
@@ -1513,4 +1513,7 @@
Ganglia_channel *channel;
+ apr_interval_time_t timeout = apr_time_from_sec(10);
+
+
server = desc->desc.s;
/* We could also use the apr_socket_data_get/set() functions
@@ -1529,5 +1532,23 @@
/* Set the timeout for writing to the client */
- apr_socket_timeout_set( client, channel->timeout);
+ apr_socket_timeout_set( client, timeout);
+
+ // Define for input
+ char input_str[256];
+ char mystr[1024];
+ apr_size_t len;
+ apr_status_t stat;
+ char *host_str;
+ char *metric_str;
+
+ // Read the command
+ if ((stat = apr_socket_recv(client, input_str, &len)) != APR_SUCCESS) {
+ apr_socket_close(client);
+ fprintf(stdout, "Failed!\n");
+ exit(-1);
+ }
+
+ host_str = strtok ( input_str, " " );
+ metric_str = strtok ( NULL, " " );
apr_socket_addr_get(&remotesa, APR_REMOTE, client);
@@ -1541,9 +1562,4 @@
goto close_accept_socket;
- /* Print the DTD, GANGLIA_XML and CLUSTER tags */
- status = print_xml_header(client);
- if(status != APR_SUCCESS)
- goto close_accept_socket;
-
/* Walk the host hash */
for(hi = apr_hash_first(client_context, hosts);
@@ -1552,36 +1568,53 @@
{
apr_hash_this(hi, NULL, NULL, &val);
- status = print_host_start(client, (Ganglia_host *)val);
- if(status != APR_SUCCESS)
- {
- goto close_accept_socket;
- }
- /* Send the metric info for this particular host */
- for(metric_hi = apr_hash_first(client_context, ((Ganglia_host
*)val)->metrics);
- metric_hi; metric_hi = apr_hash_next(metric_hi))
- {
- void *metric, *mval;
- apr_hash_this(metric_hi, NULL, NULL, &metric);
+ // Only print out if strings are equal
+ if ( strncmp ( host_str, ((Ganglia_host *)val)->hostname,
strlen(((Ganglia_host *)val)->hostname) ) == 0 ) {
- mval = apr_hash_get(((Ganglia_host *)val)->gmetrics,
((Ganglia_metadata*)metric)->name, APR_HASH_KEY_STRING);
+ len = apr_snprintf(mystr, 1024, "<HOST NAME=\"%s\">\n",
((Ganglia_host *)val)->hostname);
+
+ apr_socket_send(client, mystr, &len);
+
+ if(status != APR_SUCCESS)
+ {
+ goto close_accept_socket;
+ }
+
+ /* Send the metric info for this particular host */
+ for(metric_hi = apr_hash_first(client_context, ((Ganglia_host
*)val)->metrics);
+ metric_hi; metric_hi = apr_hash_next(metric_hi))
+ {
+ void *metric, *mval;
+ apr_hash_this(metric_hi, NULL, NULL, &metric);
+
+ mval = apr_hash_get(((Ganglia_host *)val)->gmetrics,
((Ganglia_metadata*)metric)->name, APR_HASH_KEY_STRING);
+
+ // Search for the supplied metric
+ if ( strncmp ( metric_str, ((Ganglia_metadata*)metric)->name,
strlen(((Ganglia_metadata*)metric)->name) ) == 0 ) {
+ /* Print each of the metrics for a host ... */
+ if(print_host_metric(client, metric, mval, now) != APR_SUCCESS)
+ {
+ goto close_accept_socket;
+ }
+
+ break;
+ }
+
+ }
+
+ /* Close the host tag */
+ status = print_host_end(client);
+
+ if(status != APR_SUCCESS)
+ {
+ goto close_accept_socket;
+ }
+
+ break;
- /* Print each of the metrics for a host ... */
- if(print_host_metric(client, metric, mval, now) != APR_SUCCESS)
- {
- goto close_accept_socket;
- }
- }
- /* Close the host tag */
- status = print_host_end(client);
- if(status != APR_SUCCESS)
- {
- goto close_accept_socket;
- }
- }
+ }
- /* Close the CLUSTER and GANGLIA_XML tags */
- print_xml_footer(client);
+ }
/* Close down the accepted socket */
------------------------------------------------------------------------------
Come build with us! The BlackBerry® Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9-12, 2009. Register now!
http://p.sf.net/sfu/devconf
_______________________________________________
Ganglia-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ganglia-general