Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

*** empty log message ***

  • Loading branch information...
commit 172b923e095a931955d3072eef77943131961f98 1 parent 73a2264
massie authored
View
2  NEWS
@@ -1,2 +1,2 @@
===== Ganglia Monitoring Core =====
-Visit http://ganglia.sourceforge.net/ for the latest news
+Visit http://ganglia.info/ for the latest news
View
4 configure.in
@@ -132,6 +132,10 @@ echo $ac_n "${nl}Configuring apr ...${nl}"
cd srclib/apr && ./configure --cache-file=$ganglia_popdir/config.cache
cd $ganglia_popdir
+echo $ac_n "${nl}Configuring libconfuse ...${nl}"
+cd srclib/confuse && ./configure --cache-file=$ganglia_popdir/config.cache
+cd $ganglia_popdir
+
dnl ##################################################################
dnl Checks for programs.
View
14 gmond/Makefile.am
@@ -2,11 +2,17 @@ SUBDIRS = gstat
EXTRA_DIST = gmond.init gmond.conf
-AM_CFLAGS = -I$(top_builddir)/lib -I$(top_builddir)/srclib/libmetrics/ -I$(top_builddir)/srclib/expat/lib/
+AM_CFLAGS = -I$(top_builddir)/lib -I$(top_builddir)/srclib/libmetrics/ -I$(top_builddir)/srclib/expat/lib/ -I$(top_builddir)/srclib/apr/include/ -I$(top_builddir)/srclib/confuse/src/
sbin_PROGRAMS = gmond
-gmond_SOURCES = gmond.c monitor.c server.c listen.c cleanup.c \
- metric.h cmdline.c cmdline.h dtd.h conf.c conf.h
+gmond_SOURCES = gmond.c cmdline.c cmdline.h conf.h
+
+#monitor.c server.c listen.c cleanup.c \
+#metric.h cmdline.c cmdline.h dtd.h conf.c conf.h
+# Add -lintl??? for libconfuse?
gmond_LDADD = $(top_builddir)/lib/libganglia.la \
- $(top_builddir)/lib/libgetopthelper.a $(top_builddir)/srclib/libmetrics/libmetrics.la
+ $(top_builddir)/lib/libgetopthelper.a \
+ $(top_builddir)/srclib/libmetrics/libmetrics.la \
+ $(top_builddir)/srclib/apr/libapr-0.la \
+ $(top_builddir)/srclib/confuse/src/libconfuse.la
gmond_LDFLAGS = -static
View
17 gmond/cmdline.c
@@ -46,6 +46,7 @@ cmdline_parser_print_help (void)
printf(" -l, --location=STRING Location of this host in the cluster \n 'rack,rank,plane'. (default=`0,0,0')\n");
printf(" -d, --debug=INT Debug level. If greater than zero, daemon will stay \n in foreground. (default=`0')\n");
printf(" -f, --foreground Run in foreground (don't daemonize) (default=off)\n");
+ printf(" -t, --default_config Print the default configuration and exit (default=\n off)\n");
}
@@ -75,11 +76,13 @@ cmdline_parser (int argc, char * const *argv, struct gengetopt_args_info *args_i
args_info->location_given = 0 ;
args_info->debug_given = 0 ;
args_info->foreground_given = 0 ;
+ args_info->default_config_given = 0 ;
#define clear_args() { \
args_info->conf_arg = gengetopt_strdup("/etc/gmond.conf") ;\
args_info->location_arg = gengetopt_strdup("0,0,0") ;\
args_info->debug_arg = 0 ;\
args_info->foreground_flag = 0;\
+ args_info->default_config_flag = 0;\
}
clear_args();
@@ -101,11 +104,12 @@ cmdline_parser (int argc, char * const *argv, struct gengetopt_args_info *args_i
{ "location", 1, NULL, 'l' },
{ "debug", 1, NULL, 'd' },
{ "foreground", 0, NULL, 'f' },
+ { "default_config", 0, NULL, 't' },
{ NULL, 0, NULL, 0 }
};
stop_char = 0;
- c = getopt_long (argc, argv, "hVc:l:d:f", long_options, &option_index);
+ c = getopt_long (argc, argv, "hVc:l:d:ft", long_options, &option_index);
if (c == -1) break; /* Exit from `while (1)' loop. */
@@ -169,6 +173,17 @@ cmdline_parser (int argc, char * const *argv, struct gengetopt_args_info *args_i
args_info->foreground_flag = !(args_info->foreground_flag);
break;
+ case 't': /* Print the default configuration and exit. */
+ if (args_info->default_config_given)
+ {
+ fprintf (stderr, "%s: `--default_config' (`-t') option given more than once\n", CMDLINE_PARSER_PACKAGE);
+ clear_args ();
+ exit (EXIT_FAILURE);
+ }
+ args_info->default_config_given = 1;
+ args_info->default_config_flag = !(args_info->default_config_flag);
+ break;
+
case 0: /* Long option with no short option */
View
2  gmond/cmdline.h
@@ -28,6 +28,7 @@ struct gengetopt_args_info
char * location_arg; /* Location of this host in the cluster 'rack,rank,plane'. (default='0,0,0'). */
int debug_arg; /* Debug level. If greater than zero, daemon will stay in foreground. (default='0'). */
int foreground_flag; /* Run in foreground (don't daemonize) (default=off). */
+ int default_config_flag; /* Print the default configuration and exit (default=off). */
int help_given ; /* Whether help was given. */
int version_given ; /* Whether version was given. */
@@ -35,6 +36,7 @@ struct gengetopt_args_info
int location_given ; /* Whether location was given. */
int debug_given ; /* Whether debug was given. */
int foreground_given ; /* Whether foreground was given. */
+ int default_config_given ; /* Whether default_config was given. */
} ;
View
1  gmond/cmdline.sh
@@ -10,6 +10,7 @@ option "conf" c "Location of gmond configuration file" string default="/etc/gmon
option "location" l "Location of this host in the cluster 'rack,rank,plane'." string default="0,0,0" no
option "debug" d "Debug level. If greater than zero, daemon will stay in foreground." int default="0" no
option "foreground" f "Run in foreground (don't daemonize)" flag off
+option "default_config" t "Print the default configuration and exit" flag off
#Usage (a little tutorial)
#
View
375 gmond/conf.c
@@ -1,375 +0,0 @@
-/* $Id$ */
-#include <stdio.h>
-#include <dotconf.h>
-#include "conf.h"
-#include "net.h"
-#include "error.h"
-#include "hash.h"
-#include "llist.h"
-#include "net.h"
-#include "expat.h"
-#include "ganglia.h"
-
-gmond_config_t gmond_config;
-const char * my_inet_ntop( int af, void *src, char *dst, size_t cnt );
-
-static char *
-conf_strdup (const char *s)
-{
- char *result = (char*)malloc(strlen(s) + 1);
- if (result == (char*)0)
- return (char*)0;
- strcpy(result, s);
- return result;
-}
-
-static FUNC_ERRORHANDLER(errorhandler)
-{
- printf("gmond config file error: %s\n", msg);
- exit(1);
-}
-
-static DOTCONF_CB(cb_name)
-{
- gmond_config_t *c = (gmond_config_t *)cmd->option->info;
- free(c->name);
- c->name = conf_strdup(cmd->data.str);
- return NULL;
-}
-
-static DOTCONF_CB(cb_owner)
-{
- gmond_config_t *c = (gmond_config_t *)cmd->option->info;
- free(c->owner);
- c->owner = conf_strdup(cmd->data.str);
- return NULL;
-}
-
-static DOTCONF_CB(cb_latlong)
-{
- gmond_config_t *c = (gmond_config_t *)cmd->option->info;
- free(c->latlong);
- c->latlong = conf_strdup(cmd->data.str);
- return NULL;
-}
-
-static DOTCONF_CB(cb_location)
-{
- gmond_config_t *c = (gmond_config_t *)cmd->option->info;
- free(c->location);
- c->location = conf_strdup(cmd->data.str);
- return NULL;
-}
-
-static DOTCONF_CB(cb_url)
-{
- gmond_config_t *c = (gmond_config_t *)cmd->option->info;
- free(c->url);
- c->url = conf_strdup(cmd->data.str);
- return NULL;
-}
-
-static DOTCONF_CB(cb_send_bind)
-{
- gmond_config_t *c = (gmond_config_t *)cmd->option->info;
- free(c->send_bind);
- c->send_bind_given = 1;
- c->send_bind = conf_strdup(cmd->data.str);
- return NULL;
-}
-
-static DOTCONF_CB(cb_mcast_channel)
-{
- gmond_config_t *c = (gmond_config_t *)cmd->option->info;
- free(c->mcast_channel);
- c->mcast_channel = conf_strdup(cmd->data.str);
- return NULL;
-}
-
-static DOTCONF_CB(cb_mcast_port)
-{
- gmond_config_t *c = (gmond_config_t *)cmd->option->info;
- c->mcast_port = cmd->data.value;
- return NULL;
-}
-
-static DOTCONF_CB(cb_mcast_if)
-{
- gmond_config_t *c = (gmond_config_t *)cmd->option->info;
- /* no free.. set to NULL by default */
- c->mcast_if_given = 1;
- c->mcast_if = conf_strdup(cmd->data.str);
- return NULL;
-}
-
-static DOTCONF_CB(cb_mcast_ttl)
-{
- gmond_config_t *c = (gmond_config_t *)cmd->option->info;
- c->mcast_ttl = cmd->data.value;
- return NULL;
-}
-
-static DOTCONF_CB(cb_mcast_threads)
-{
- gmond_config_t *c = (gmond_config_t *)cmd->option->info;
- c->mcast_threads = cmd->data.value;
- return NULL;
-}
-
-static DOTCONF_CB(cb_xml_port)
-{
- gmond_config_t *c = (gmond_config_t *)cmd->option->info;
- c->xml_port = cmd->data.value;
- return NULL;
-}
-
-static DOTCONF_CB(cb_xml_threads)
-{
- gmond_config_t *c = (gmond_config_t *)cmd->option->info;
- c->xml_threads = cmd->data.value;
- return NULL;
-}
-
-static DOTCONF_CB(cb_trusted_hosts)
-{
- int i, rv;
- llist_entry *le;
- gmond_config_t *c = (gmond_config_t *)cmd->option->info;
- struct sockaddr_in sa;
-
- for (i = 0; i < cmd->arg_count; i++)
- {
- le = (llist_entry *)malloc(sizeof(llist_entry));
- rv = g_gethostbyname( cmd->data.list[i], &sa, NULL);
- if (!rv) {
- err_msg("Warning: we failed to resolve trusted host name %s", cmd->data.list[i]);
- continue;
- }
- le->val = (char*) malloc(MAXHOSTNAMELEN);
- my_inet_ntop(AF_INET, &sa.sin_addr, le->val, MAXHOSTNAMELEN);
- /* printf("Adding trusted host %s (IP %s)\n", cmd->data.list[i], le->val); */
- llist_add(&(c->trusted_hosts), le);
- }
- return NULL;
-}
-
-static DOTCONF_CB(cb_num_nodes)
-{
- gmond_config_t *c = (gmond_config_t *)cmd->option->info;
- c->num_nodes = cmd->data.value;
- return NULL;
-}
-
-static DOTCONF_CB(cb_num_custom_metrics)
-{
- gmond_config_t *c = (gmond_config_t *)cmd->option->info;
- c->num_custom_metrics = cmd->data.value;
- return NULL;
-}
-
-static DOTCONF_CB(cb_mute)
-{
- gmond_config_t *c = (gmond_config_t *)cmd->option->info;
- c->mute = cmd->data.value;
- return NULL;
-}
-
-static DOTCONF_CB(cb_deaf)
-{
- gmond_config_t *c = (gmond_config_t *)cmd->option->info;
- c->deaf = cmd->data.value;
- return NULL;
-}
-
-static DOTCONF_CB(cb_debug_level)
-{
- gmond_config_t *c = (gmond_config_t *)cmd->option->info;
- c->debug_level = cmd->data.value;
- return NULL;
-}
-
-static DOTCONF_CB(cb_daemonize)
-{
- gmond_config_t *c = (gmond_config_t *)cmd->option->info;
- c->daemonize = cmd->data.value;
- return NULL;
-}
-
-static DOTCONF_CB(cb_no_setuid)
-{
- gmond_config_t *c = (gmond_config_t *)cmd->option->info;
- c->no_setuid = cmd->data.value;
- return NULL;
-}
-
-static DOTCONF_CB(cb_setuid)
-{
- gmond_config_t *c = (gmond_config_t *)cmd->option->info;
- c->setuid = conf_strdup( cmd->data.str );
- return NULL;
-}
-
-static DOTCONF_CB(cb_no_gexec)
-{
- gmond_config_t *c = (gmond_config_t *)cmd->option->info;
- c->no_gexec = cmd->data.value;
- return NULL;
-}
-
-static DOTCONF_CB(cb_all_trusted)
-{
- gmond_config_t *c = (gmond_config_t *)cmd->option->info;
- c->all_trusted = cmd->data.value;
- return NULL;
-}
-
-static DOTCONF_CB(cb_host_dmax)
-{
- gmond_config_t *c = (gmond_config_t *)cmd->option->info;
- c->host_dmax = cmd->data.value;
- return NULL;
-}
-
-static int
-set_defaults(gmond_config_t *config )
-{
- /* Gmond defaults */
- config->name = conf_strdup("unspecified");
- config->owner = conf_strdup("unspecified");
- config->latlong = conf_strdup("unspecified");
- config->url = conf_strdup("unspecified");
- config->location = conf_strdup("unspecified");
- config->mcast_channel = conf_strdup("239.2.11.71");
- config->send_bind = conf_strdup("unspecified");
- config->send_bind_given = 0;
- config->mcast_port = 8649;
- config->mcast_if_given = 0;
- config->mcast_ttl = 1;
- config->mcast_threads = 2;
- config->xml_port = 8649;
- config->xml_threads = 2;
- config->trusted_hosts = NULL;
- config->num_nodes = 1024;
- config->num_custom_metrics = 16;
- config->mute = 0;
- config->deaf = 0;
- config->debug_level = 0;
- config->no_setuid = 0;
- config->setuid = conf_strdup("nobody");
- config->no_gexec = 0;
- config->all_trusted = 0;
- config->host_dmax = 0;
- config->daemonize = 1; /* by default we daemonize */
- return 0;
-}
-
-static void
-print_conf( gmond_config_t *config )
-{
- printf("name is %s\n", config->name);
- printf("owner is %s\n", config->owner);
- printf("latlong is %s\n", config->latlong);
- printf("Cluster URL is %s\n", config->url);
- printf("Host location is (x,y,z): %s\n", config->location);
- printf("mcast_channel is %s\n", config->mcast_channel);
- printf("mcast_port is %d\n", config->mcast_port);
- if(config->mcast_if_given)
- printf("mcast_if is %s\n", config->mcast_if);
- else
- printf("mcast_if is chosen by the kernel\n");
- printf("mcast_ttl is %ld\n", config->mcast_ttl);
- printf("mcast_threads is %ld\n", config->mcast_threads);
- printf("xml_port is %d\n", config->xml_port);
- printf("xml_threads is %ld\n", config->xml_threads);
- printf("trusted hosts are: ");
- llist_print(&(config->trusted_hosts));
- printf("\n");
- printf("num_nodes is %ld\n", config->num_nodes);
- printf("num_custom_metrics is %ld\n", config->num_custom_metrics);
- printf("mute is %ld\n", config->mute);
- printf("deaf is %ld\n", config->deaf);
- printf("debug_level is %ld\n", config->debug_level);
- printf("no_setuid is %ld\n", config->no_setuid);
- printf("setuid is %s\n", config->setuid);
- printf("no_gexec is %ld\n", config->no_gexec);
- printf("all_trusted is %ld\n", config->all_trusted);
- printf("host_dmax is %ld\n", config->host_dmax);
-}
-
-int
-get_gmond_config( char *conffile )
-{
- int rval;
- configfile_t *configfile;
- char default_conffile[]=DEFAULT_GMOND_CONFIG_FILE;
- FILE *fp;
- static configoption_t gmond_options[] =
- {
- {"name", ARG_STR, cb_name, &gmond_config, 0},
- {"owner", ARG_STR, cb_owner, &gmond_config, 0},
- {"latlong", ARG_STR, cb_latlong, &gmond_config, 0},
- {"url", ARG_STR, cb_url, &gmond_config, 0},
- {"location", ARG_STR, cb_location, &gmond_config, 0},
- {"send_channel", ARG_STR, cb_mcast_channel, &gmond_config, 0},
- {"mcast_channel", ARG_STR, cb_mcast_channel, &gmond_config, 0},
- {"send_port", ARG_INT, cb_mcast_port, &gmond_config, 0},
- {"mcast_port", ARG_INT, cb_mcast_port, &gmond_config, 0},
- {"send_bind", ARG_STR, cb_send_bind, &gmond_config, 0},
- {"mcast_if", ARG_STR, cb_mcast_if, &gmond_config, 0},
- {"mcast_ttl", ARG_INT, cb_mcast_ttl, &gmond_config, 0},
- {"mcast_threads", ARG_INT, cb_mcast_threads, &gmond_config, 0},
- {"xml_port", ARG_INT, cb_xml_port, &gmond_config, 0},
- {"xml_threads", ARG_INT, cb_xml_threads, &gmond_config, 0},
- {"trusted_hosts", ARG_LIST, cb_trusted_hosts, &gmond_config, 0},
- {"num_nodes", ARG_INT, cb_num_nodes, &gmond_config, 0},
- {"num_custom_metrics", ARG_INT, cb_num_custom_metrics, &gmond_config, 0},
- {"mute", ARG_TOGGLE, cb_mute, &gmond_config, 0},
- {"deaf", ARG_TOGGLE, cb_deaf, &gmond_config, 0},
- {"debug_level", ARG_INT, cb_debug_level, &gmond_config, 0},
- {"no_setuid", ARG_TOGGLE, cb_no_setuid, &gmond_config, 0},
- {"setuid", ARG_STR, cb_setuid, &gmond_config, 0},
- {"no_gexec", ARG_TOGGLE, cb_no_gexec, &gmond_config, 0},
- {"all_trusted", ARG_TOGGLE, cb_all_trusted, &gmond_config, 0},
- {"daemonize", ARG_TOGGLE, cb_daemonize, &gmond_config, 0},
- {"host_dmax", ARG_INT, cb_host_dmax, &gmond_config, 0},
- LAST_OPTION
- };
-
- rval = set_defaults(&gmond_config );
- if( rval<0)
- return -1;
-
- /* Check if the conffile exists, it's not an error if it doesn't */
- if(conffile)
- fp = fopen( conffile, "r");
- else
- fp = fopen( default_conffile, "r");
-
- if(!fp)
- return 0;
-
- if(conffile)
- configfile = dotconf_create(conffile, gmond_options, 0, CASE_INSENSITIVE);
- else
- configfile = dotconf_create(default_conffile, gmond_options, 0, CASE_INSENSITIVE);
-
- if (!configfile)
- return -1;
-
- configfile->errorhandler = (dotconf_errorhandler_t) errorhandler;
-
- if (dotconf_command_loop(configfile) == 0)
- {
- dotconf_cleanup(configfile);
- return -1;
- }
-
- if(gmond_config.debug_level)
- {
- fprintf(stderr,"%s configuration\n", conffile);
- print_conf( &gmond_config );
- }
-
- dotconf_cleanup(configfile);
- return 1;
-}
View
127 gmond/conf.h
@@ -1,43 +1,84 @@
-#ifndef GMOND_CONFIG_H
-#define GMOND_CONFIG_H 1
-#include <stdlib.h>
-#include <string.h>
-#include "llist.h"
-
-/* autoconf me later */
-#define DEFAULT_GMOND_CONFIG_FILE "/etc/gmond.conf"
-
-typedef struct
- {
- char *name;
- char *owner;
- char *latlong;
- char *url;
- char *location;
- char *mcast_channel;
- char *send_bind;
- int send_bind_given;
- unsigned short mcast_port;
- long int mcast_if_given;
- char *mcast_if;
- long int mcast_ttl;
- long int mcast_threads;
- unsigned short xml_port;
- long int xml_threads;
- llist_entry *trusted_hosts;
- long int num_nodes;
- long int num_custom_metrics;
- long int mute;
- long int deaf;
- long int debug_level;
- long int no_setuid;
- char *setuid;
- long int no_gexec;
- long int all_trusted;
- long int host_dmax;
- long int daemonize;
-} gmond_config_t;
-
-int get_gmond_config( char *conffile);
-
-#endif
+#ifndef CONF_H
+#define CONF_H 1
+
+#include "confuse.h"
+
+#define DEFAULT_CONFIGURATION "\
+behavior { \n\
+ setuid = no \n\
+ user = nobody \n\
+} \n\
+udp_send_channel { \n\
+ ip = 127.0.0.1 \n\
+ port = 8649 \n\
+} \n\
+udp_recv_channel { \n\
+ port = 8649 \n\
+} \n\
+"
+
+static cfg_opt_t location_opts[] = {
+ CFG_INT("rack", -1, CFGF_NONE ),
+ CFG_INT("rank", -1, CFGF_NONE ),
+ CFG_INT("plane", -1, CFGF_NONE ),
+ CFG_END()
+};
+
+static cfg_opt_t id_opts[] = {
+ CFG_STR("cluster", NULL, CFGF_NONE ),
+ CFG_STR("owner", NULL, CFGF_NONE ),
+ CFG_STR("latitude", NULL, CFGF_NONE ),
+ CFG_STR("longitude", NULL, CFGF_NONE ),
+ CFG_STR("url", NULL, CFGF_NONE ),
+ CFG_END()
+};
+
+static cfg_opt_t behavior_opts[] = {
+ CFG_BOOL("daemonize", 1, CFGF_NONE),
+ CFG_BOOL("setuid", 1, CFGF_NONE),
+ CFG_STR("user", "nobody", CFGF_NONE),
+ /* later i guess we should add "group" as well */
+ CFG_INT("debug_level", 0, CFGF_NONE),
+ CFG_BOOL("mute", 0, CFGF_NONE),
+ CFG_BOOL("deaf", 0, CFGF_NONE),
+ CFG_INT("host_dmax", 0, CFGF_NONE),
+ CFG_END()
+};
+
+static cfg_opt_t udp_send_channel_opts[] = {
+ CFG_STR("mcast_ip", NULL, CFGF_NONE),
+ CFG_STR("mcast_if", NULL, CFGF_NONE),
+ CFG_STR("ip", NULL, CFGF_NONE ),
+ CFG_INT("port", -1, CFGF_NONE ),
+ CFG_STR("protocol", "xdr", CFGF_NONE),
+ CFG_END()
+};
+
+static cfg_opt_t udp_recv_channel_opts[] = {
+ CFG_STR("mcast_ip", NULL, CFGF_NONE ),
+ CFG_STR("bind", NULL, CFGF_NONE ),
+ CFG_INT("port", -1, CFGF_NONE ),
+ CFG_STR("mcast_if", NULL, CFGF_NONE),
+ CFG_STR("protocol", "xdr", CFGF_NONE),
+ CFG_END()
+};
+
+static cfg_opt_t xml_out_channel_opts[] = {
+ CFG_STR("bind", NULL, CFGF_NONE ),
+ CFG_INT("port", -1, CFGF_NONE ),
+ CFG_STR("interface", NULL, CFGF_NONE),
+ CFG_END()
+};
+
+
+static cfg_opt_t gmond_opts[] = {
+ CFG_SEC("location", location_opts, CFGF_NONE),
+ CFG_SEC("identification", id_opts, CFGF_NONE),
+ CFG_SEC("behavior", behavior_opts, CFGF_NONE),
+ CFG_SEC("udp_send_channel", udp_send_channel_opts, CFGF_MULTI),
+ CFG_SEC("udp_recv_channel", udp_recv_channel_opts, CFGF_MULTI),
+ CFG_SEC("xml_out_channel", xml_out_channel_opts, CFGF_MULTI),
+ CFG_END()
+};
+
+#endif /* CONF_H */
View
814 gmond/gmond.c
@@ -1,429 +1,439 @@
-/* $Id$ */
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include <sys/time.h>
-#include <sys/socket.h>
-#include <sys/types.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <pwd.h>
-#include <signal.h>
-
-#include "conf.h"
-
-#include "metric.h"
-#include "key_ugly.h"
-
-#include "interface.h"
-#include "dotconf.h"
-
-#include "lib/daemon_init.h"
-#include "lib/debug_msg.h"
-#include "lib/error.h"
-#include "lib/hash.h"
-#include "lib/llist.h"
-#include "lib/net.h"
-#include "expat.h"
-#include "lib/hash.h"
-#include "lib/barrier.h"
-#include "lib/become_a_nobody.h"
-#include "lib/net.h"
-#include "cmdline.h"
-
-/* The entire cluster this gmond knows about */
-hash_t *cluster;
-
-g_mcast_socket * mcast_socket;
-pthread_mutex_t mcast_socket_mutex = PTHREAD_MUTEX_INITIALIZER;
-
-g_mcast_socket * mcast_join_socket;
-pthread_mutex_t mcast_join_socket_mutex = PTHREAD_MUTEX_INITIALIZER;
-
-g_tcp_socket * server_socket;
-pthread_mutex_t server_socket_mutex = PTHREAD_MUTEX_INITIALIZER;
-
-/* In dmonitor.c */
-extern void *monitor_thread(void *arg);
-extern int mcast_value ( uint32_t key );
-
-/* In dlisten.c */
-extern void *mcast_listen_thread(void *arg);
-
-/* In dserver.c */
-extern void *server_thread(void *arg);
-
-/* In cleanup.c */
-extern void *cleanup_thread(void *arg);
-
-/* In debug_msg.c */
-extern int debug_level;
-
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include <apr.h>
+#include <apr_time.h>
+#include <apr_pools.h>
+#include <apr_poll.h>
+#include <apr_network_io.h>
+#include <apr_signal.h>
+#include <apr_thread_proc.h> /* for apr_proc_detach(). no threads. */
+#include <apr_tables.h>
+
+#include "cmdline.h" /* generated by cmdline.sh which runs gengetopt */
+#include "confuse.h" /* header for libconfuse in ./srclib/confuse */
+#include "conf.h" /* configuration file definition in libconfuse format */
+#include "become_a_nobody.h"
+#include "libmetrics.h"/* libmetrics header in ./srclib/libmetrics */
+#include "apr_net.h" /* our private network functions based on apr */
+#include "debug_msg.h"
+#include "protocol.h"
+
+/* When this gmond was started */
+apr_time_t started;
+/* My name */
+char myname[APRMAXHOSTLEN+1];
+/* The commandline options */
struct gengetopt_args_info args_info;
-
-extern gmond_config_t gmond_config;
-
-uint32_t start_time;
-
-void
-send_all_metric_data( void )
+/* The configuration file */
+cfg_t *config_file;
+/* The debug level (in debug_msg.c) */
+extern int debug_level;
+/* The global context */
+apr_pool_t *global_context = NULL;
+/* Deaf mode boolean */
+int deaf;
+/* Mute mode boolean */
+int mute;
+/* Maximum UDP message size.. TODO: allow tweakability */
+int max_udp_message_len = 1500;
+/* The pollset for incoming UDP messages */
+apr_pollset_t *udp_recv_pollset = NULL;
+/* The array for outgoing UDP message */
+apr_array_header_t *udp_send_array = NULL;
+
+static void
+process_configuration_file(void)
{
- uint32_t i;
- struct timeval now;
- int waiting_period = 600; /* secs .. 10 mins */
-
- gettimeofday(&now, NULL);
-
- /* Did this gmond just restart in the last "waiting_period" secs? */
- if( (now.tv_sec - start_time) < waiting_period )
- {
- for (i=1; i< num_key_metrics; i++)
- {
- /* Will the next multicast be forced beyond the waiting period? */
- if( metric[i].mcast_threshold > (now.tv_sec + waiting_period) )
- {
-
- /* Make sure it multicasts in the 2 mins following the
- waiting period */
- metric[i].mcast_threshold = now.tv_sec + waiting_period +
- 1+ (int)(120.0*rand()/(RAND_MAX+1.0));
- }
- }
- }
- else /* Gmond has been running at least "waiting_period" secs. */
- {
- for (i=1; i< num_key_metrics; i++)
- {
- metric[i].mcast_threshold = 0;
- }
- }
+ config_file = cfg_init( gmond_opts, CFGF_NOCASE );
+ switch( cfg_parse( config_file, args_info.conf_arg ) )
+ {
+ case CFG_FILE_ERROR:
+ /* Unable to open file so we'll go with the configuration defaults */
+ fprintf(stderr,"Configuration file '%s' not found.\n", args_info.conf_arg);
+ if(args_info.conf_given)
+ {
+ /* If they explicitly stated a configuration file exit with error... */
+ exit(1);
+ }
+ /* .. otherwise use our default configuration */
+ fprintf(stderr,"Using defaults.\n");
+ cfg_parse_buf(config_file, DEFAULT_CONFIGURATION);
+ break;
+ case CFG_PARSE_ERROR:
+ fprintf(stderr,"Parse error for '%s'\n", args_info.conf_arg);
+ exit(1);
+ case CFG_SUCCESS:
+ break;
+ default:
+ /* I have no cluse whats goin' on here... */
+ exit(1);
+ }
}
-/* Added temporarily to make gexec work until I build the service model */
-g_val_t
-gexec_func ( void )
+static void
+initialize_apr_library( void )
{
- g_val_t val;
+ apr_status_t status;
+
+ /* Initialize apr */
+ status = apr_initialize();
+ if(status != APR_SUCCESS)
+ {
+ fprintf(stderr,"Unable to initialize APR library. Exiting.\n");
+ exit(1);
+ }
+
+ /* Create the global context */
+ status = apr_pool_create( &global_context, NULL );
+ if(status != APR_SUCCESS)
+ {
+ fprintf(stderr,"Unable to create global context. Exiting.\n");
+ exit(1);
+ }
+
+ /* Setup atexit() calls to cleanup? */
+}
- if( gmond_config.no_gexec || ( SUPPORT_GEXEC == 0 ) )
- snprintf(val.str, MAX_G_STRING_SIZE, "%s", "OFF");
- else
- snprintf(val.str, MAX_G_STRING_SIZE, "%s", "ON");
+static void
+daemonize_if_necessary( char *argv[] )
+{
+ int should_daemonize;
+ cfg_t *tmp;
+ tmp = cfg_getsec( config_file, "behavior");
+ should_daemonize = cfg_getbool( tmp, "daemonize");
+
+ /* Commandline for debug_level trumps configuration file behaviour ... */
+ if (args_info.debug_given)
+ {
+ debug_level = args_info.debug_arg;
+ }
+ else
+ {
+ debug_level = cfg_getint ( tmp, "debug_level");
+ }
+
+ /* Daemonize if needed */
+ if(!args_info.foreground_flag && should_daemonize && !debug_level)
+ {
+ apr_proc_detach(1);
+ }
+}
- return val;
+static void
+setuid_if_necessary( void )
+{
+ cfg_t *tmp;
+ int setuid;
+ char *user;
+
+ tmp = cfg_getsec( config_file, "behavior");
+ setuid = cfg_getbool( tmp, "setuid" );
+ if(setuid)
+ {
+ user = cfg_getstr(tmp, "user" );
+ become_a_nobody(user);
+ }
}
-g_val_t
-heartbeat_func( void )
+static void
+process_deaf_mute_mode( void )
{
- g_val_t val;
+ cfg_t *tmp = cfg_getsec( config_file, "behavior");
+ deaf = cfg_getbool( tmp, "deaf");
+ mute = cfg_getbool( tmp, "mute");
+ if(deaf && mute)
+ {
+ fprintf(stderr,"Configured to run both deaf and mute. Nothing to do. Exiting.\n");
+ exit(1);
+ }
+}
- val.uint32 = start_time;
- debug_msg("my start_time is %d\n", val.uint32);
- return val;
+static void
+setup_udp_recv_pollset( void )
+{
+ apr_status_t status;
+ /* We will open sockets to listen for messages */
+ int i, num_udp_recv_channels = cfg_size( config_file, "udp_recv_channel");
+
+ /* Create my UDP recv pollset */
+ apr_pollset_create(&udp_recv_pollset, num_udp_recv_channels, global_context, 0);
+
+ for(i = 0; i< num_udp_recv_channels; i++)
+ {
+ cfg_t *udp_recv_channel;
+ char *mcast_ip, *mcast_if, *bindaddr, *protocol;
+ int port;
+ apr_socket_t *socket = NULL;
+ apr_pollfd_t socket_pollfd;
+
+ udp_recv_channel = cfg_getnsec( config_file, "udp_recv_channel", i);
+ mcast_ip = cfg_getstr( udp_recv_channel, "mcast_ip" );
+ mcast_if = cfg_getstr( udp_recv_channel, "mcast_if" );
+ port = cfg_getint( udp_recv_channel, "port");
+ bindaddr = cfg_getstr( udp_recv_channel, "bind");
+ protocol = cfg_getstr( udp_recv_channel, "protocol");
+
+ debug_msg("udp_recv_channel mcast_ip=%s mcast_if=%s port=%d bind=%s protocol=%s\n",
+ mcast_ip? mcast_ip:"NULL",
+ mcast_if? mcast_if:"NULL",
+ port,
+ bindaddr? bindaddr: "NULL",
+ protocol? protocol:"NULL");
+
+ /* Create the socket */
+ if( mcast_ip )
+ {
+ /* We'll be listening on a multicast channel */
+ socket = NULL;
+ /*create_mcast_server( global_context, mcast_ip, port, mcast_if );*/
+ if(!socket)
+ {
+ fprintf(stderr,"Error creating multicast server mcast_ip=%s port=%d mcast_if=%s. Exiting.\n",
+ mcast_ip? mcast_ip: "NULL", port, mcast_if? mcast_if:"NULL");
+ exit(1);
+ }
+
+ }
+ else
+ {
+ /* We'll be listening on a standard UDP channel */
+ socket = create_udp_server( global_context, port, bindaddr );
+ if(!socket)
+ {
+ fprintf(stderr,"Error creating UDP server on port %d bind=%s. Exiting.\n",
+ port, bindaddr? bindaddr: "unspecified");
+ exit(1);
+ }
+ }
+
+ /* Build the socket poll file descriptor structure */
+ socket_pollfd.desc_type = APR_POLL_SOCKET;
+ socket_pollfd.reqevents = APR_POLLIN;
+ socket_pollfd.desc.s = socket;
+ socket_pollfd.client_data = protocol;
+
+ /* Add the socket to the pollset */
+ status = apr_pollset_add(udp_recv_pollset, &socket_pollfd);
+ if(status != APR_SUCCESS)
+ {
+ fprintf(stderr,"Failed to add socket to pollset. Exiting.\n");
+ exit(1);
+ }
+ }
}
-g_val_t
-location_func(void)
+static void
+poll_udp_recv_channels(apr_interval_time_t timeout)
{
- g_val_t val;
+ apr_status_t status;
+ const apr_pollfd_t *descs = NULL;
+ apr_int32_t i, num;
+ apr_socket_t *socket = NULL;
+
+ /* Poll for data with given timeout */
+ apr_pollset_poll(udp_recv_pollset, timeout, &num, &descs);
+ if(num>0)
+ {
+ /* We have data to read */
+ for(i=0; i< num; i++)
+ {
+ char buf[max_udp_message_len];
+ apr_sockaddr_t from;
+ apr_size_t len = 1500;
+ char *protocol;
+
+ socket = descs[i].desc.s;
+ protocol = descs[i].client_data;
+
+ status = apr_socket_recvfrom(&from, socket, 0, buf, &len);
+ if(status != APR_SUCCESS)
+ {
+ continue;
+ }
+
+ /* TODO: Check the "from" apr_sockaddr_t to see if we trust 'em */
+
+ if(!strcasecmp(protocol, "xdr"))
+ {
+ XDR x;
+ gangliaMessage message;
+
+ /* Create the XDR receive stream */
+ xdrmem_create(&x, buf, max_udp_message_len, XDR_DECODE);
+
+ /* Flush the data in the (last) received gangliaMessage
+ * TODO: Free memory from xdr_string calls */
+ memset( &message, 0, sizeof(gangliaMessage));
+
+ /* Read the gangliaMessage from the stream */
+ if(!xdr_gangliaMessage(&x, &message))
+ {
+ continue;
+ }
+
+ /* If I want to find out how much data I decoded
+ decoded = xdr_getpos(&x); */
+ fprintf(stderr,"Got a complete ganglia message (format=%d) (len=%d)\n", message.format,len);
+ }
+ }
+ }
+}
- strncpy(val.str, gmond_config.location, MAX_G_STRING_SIZE);
- debug_msg("my location is %s", val.str);
- return val;
+static void
+setup_udp_send_array( void )
+{
+ int i, num_udp_send_channels = cfg_size( config_file, "udp_send_channel");
+
+ if(num_udp_send_channels <= 0)
+ return;
+
+ /* Create my UDP send array */
+ udp_send_array = apr_array_make( global_context, num_udp_send_channels,
+ sizeof(apr_socket_t *));
+
+ for(i = 0; i< num_udp_send_channels; i++)
+ {
+ cfg_t *udp_send_channel;
+ char *mcast_ip, *mcast_if, *protocol, *ip;
+ int port;
+ apr_socket_t *socket = NULL;
+
+ udp_send_channel = cfg_getnsec( config_file, "udp_send_channel", i);
+ ip = cfg_getstr( udp_send_channel, "ip" );
+ mcast_ip = cfg_getstr( udp_send_channel, "mcast_ip" );
+ mcast_if = cfg_getstr( udp_send_channel, "mcast_if" );
+ port = cfg_getint( udp_send_channel, "port");
+ protocol = cfg_getstr( udp_send_channel, "protocol");
+
+ debug_msg("udp_send_channel mcast_ip=%s mcast_if=%s ip=%s port=%d protocol=%s\n",
+ mcast_ip? mcast_ip:"NULL",
+ mcast_if? mcast_if:"NULL",
+ ip,
+ port,
+ protocol? protocol:"NULL");
+
+ /* Create the socket */
+ if( mcast_ip )
+ {
+ /* We'll be listening on a multicast channel */
+ socket = NULL;
+ if(!socket)
+ {
+ fprintf(stderr,"Unable to multicast client for %s:%d. Exiting\n",
+ mcast_ip, port);
+ exit(1);
+ }
+ }
+ else
+ {
+ /* We'll be listening on a standard UDP channel */
+ socket = create_udp_client( global_context, ip, port );
+ if(!socket)
+ {
+ fprintf(stderr,"Unable to create UDP client for %s:%d. Exiting.\n",
+ ip? ip: "NULL", port);
+ exit(1);
+ }
+ }
+
+ /* Add the socket to the array */
+ *(apr_socket_t **)apr_array_push(udp_send_array) = socket;
+ }
}
-/* This only works on IPv4 for right now */
+/* This function will send a datagram to every udp_send_channel specified */
static int
-is_multicast (const char *ip)
+udp_send_message( char *buf, int len )
{
- struct in_addr haddr;
- unsigned int addr;
-
- if(!ip)
- return -1;
+ apr_status_t status;
+ int i;
+ int num_errors = 0;
+ apr_size_t size;
- if(!inet_aton(ip, &haddr))
- return -1; /* not a valid address */
-
- addr = htonl( haddr.s_addr );
-
- if ((addr & 0xF0000000) == 0xE0000000)
+ if(!buf)
return 1;
- return 0;
+ for(i=0; i< udp_send_array->nelts; i++)
+ {
+ apr_socket_t *socket = ((apr_socket_t **)(udp_send_array->elts))[i];
+ size = len;
+ status = apr_socket_send( socket, buf, &size );
+ if(status != APR_SUCCESS)
+ {
+ num_errors++;
+ }
+ }
+ return num_errors;
}
-int
+int
main ( int argc, char *argv[] )
{
- int rval, i=0;
- g_val_t initval;
- pthread_t tid;
- pthread_attr_t attr;
- barrier *mcast_listen_barrier, *server_barrier;
- struct timeval tv;
- struct ifi_info *entry = NULL;
-
- gettimeofday(&tv, NULL);
- start_time = (uint32_t) tv.tv_sec;
-
- if (cmdline_parser (argc, argv, &args_info) != 0)
- exit(1) ;
-
- rval = get_gmond_config(args_info.conf_arg);
- if ( rval == 0 )
- {
- debug_msg("no config file found.. going with defaults");
- }
- else if( rval == 1)
- {
- debug_msg("config file %s processed with no errors", args_info.conf_arg);
- }
- else
- {
- err_quit("failed to process %s. Exiting.", args_info.conf_arg);
- }
-
- /* If given, use command line directives over config file ones. */
- if (args_info.debug_given) {
- gmond_config.debug_level = args_info.debug_arg;
- }
- if (args_info.location_given) {
- debug_msg("Cmd line: Setting location to %s\n", args_info.location_arg);
- free(gmond_config.location);
- gmond_config.location = strdup(args_info.location_arg);
- }
-
- debug_level = gmond_config.debug_level;
- if(!args_info.foreground_flag && gmond_config.daemonize && !debug_level)
- {
- daemon_init ( argv[0], 0);
- }
-
- initval = metric_init();
- if ( initval.int32 <0)
- {
- err_quit("metric_init() returned an error");
- }
-
- if(!gmond_config.no_setuid)
- become_a_nobody(gmond_config.setuid);
-
- debug_msg("pthread_attr_init");
- pthread_attr_init( &attr );
- pthread_attr_setdetachstate( &attr, PTHREAD_CREATE_DETACHED );
-
- debug_msg("creating cluster hash for %d nodes", gmond_config.num_nodes);
- cluster = hash_create(gmond_config.num_nodes);
- debug_msg("gmond initialized cluster hash");
-
- srand(1);
-
- /* Ignore any SIGPIPE signals */
- signal( SIGPIPE, SIG_IGN );
-
- if(! gmond_config.mcast_if_given )
- {
- entry = get_first_multicast_interface();
- if(!entry) {
- err_msg("Warning: Could not find a multicast-enabled interface, using anything we can find.\n");
- entry = get_first_interface();
- if (!entry)
- err_quit("We don't have any interfaces besides loopback, exiting.\n");
- }
- debug_msg("Using interface %s", entry->ifi_name);
- }
- else
- {
- if( is_multicast( gmond_config.mcast_channel ))
- {
- entry = get_interface ( gmond_config.mcast_if );
- if(!entry)
- err_quit("%s is not a valid multicast-enabled interface", gmond_config.mcast_if);
- debug_msg("Using multicast-enabled interface %s", gmond_config.mcast_if);
- }
- }
-
- /* fd for incoming multicast messages */
- if(! gmond_config.deaf )
- {
- struct in_addr *addr = &(((struct sockaddr_in *)(entry->ifi_addr))->sin_addr);
- if( is_multicast( gmond_config.mcast_channel ))
- {
- mcast_join_socket = g_mcast_in ( gmond_config.mcast_channel, gmond_config.mcast_port,
- addr);
- }
- else
- {
- const int on = 1;
- struct sockaddr_in localaddr;
-
- mcast_join_socket = malloc(sizeof(g_mcast_socket));
- if(!mcast_join_socket)
- {
- perror("unable to malloc data for UDP server socket\n");
- return -1;
- }
- (mcast_join_socket->ref_count)++;
- mcast_join_socket->sockfd = socket( AF_INET, SOCK_DGRAM, 0);
- if(mcast_join_socket->sockfd < 0)
- {
- perror("unable to create UDP server socket\n");
- return -1;
- }
- if(setsockopt(mcast_join_socket->sockfd, SOL_SOCKET, SO_REUSEADDR, (void*) &on, sizeof(on)) != 0)
- {
- perror("gmond could not setsockopt on UDP server socket");
- return -1;
- }
- localaddr.sin_family = AF_INET;
- localaddr.sin_port = htons(gmond_config.mcast_port);
- if( gmond_config.send_bind_given )
- {
- /* bind to a specific local address */
- struct in_addr inaddr;
- /* Try to read the name as if were dotted decimal */
- if (inet_aton(gmond_config.send_bind, &inaddr) == 0)
- {
- fprintf(stderr,"send_bind address is not dotted decimal notation\n");
- return -1;
- }
- memcpy(&localaddr.sin_addr, (char*) &inaddr, sizeof(struct in_addr));
- }
- else
- {
- /* let the kernel decide which local address to bind to */
- localaddr.sin_addr.s_addr = htonl(INADDR_ANY);
- }
-
- /* bind to the local address */
- if (bind(mcast_join_socket->sockfd, (struct sockaddr *)&localaddr, sizeof(localaddr)) <0)
- {
- perror("unable to bind to local UDP server address\n");
- return -1;
- }
- }
-
- if (! mcast_join_socket )
- {
- perror("g_mcast_in() failed");
- return -1;
- }
-
- debug_msg("mcast listening on %s %hu", gmond_config.mcast_channel, gmond_config.mcast_port);
-
- server_socket = g_tcp_socket_server_new( gmond_config.xml_port );
- if (! server_socket )
- {
- perror("tcp_listen() on xml_port failed");
- return -1;
- }
- debug_msg("XML listening on port %d", gmond_config.xml_port);
-
- /* thread(s) to listen to the multicast traffic */
- if(barrier_init(&mcast_listen_barrier, gmond_config.mcast_threads))
- {
- perror("barrier_init() error");
- return -1;
- }
-
- for ( i = 0 ; i < gmond_config.mcast_threads; i++ )
- {
- pthread_create(&tid, &attr, mcast_listen_thread, (void *)mcast_listen_barrier);
- }
- debug_msg("listening thread(s) have been started");
-
- /* threads to answer requests for XML */
- if(barrier_init(&server_barrier, (gmond_config.xml_threads)))
- {
- perror("barrier_init() error");
- return -1;
- }
- for ( i=0 ; i < gmond_config.xml_threads; i++ )
- {
- pthread_create(&tid, &attr, server_thread, (void *)server_barrier);
- }
- debug_msg("listening thread(s) have been started");
-
- /* A thread to cleanup old metrics and hosts */
- pthread_create(&tid, &attr, cleanup_thread, (void *) NULL);
- debug_msg("cleanup thread has been started");
- }
-
- /* fd for outgoing multicast messages */
- if(! gmond_config.mute )
- {
- if( is_multicast( gmond_config.mcast_channel ))
- {
- struct in_addr *addr = &( ((struct sockaddr_in *)(entry->ifi_addr)) ->sin_addr);
- mcast_socket = g_mcast_out ( gmond_config.mcast_channel, gmond_config.mcast_port,
- addr, gmond_config.mcast_ttl);
- }
- else
- {
- struct sockaddr_in remoteaddr;
- struct in_addr inaddr;
- const int on = 1;
-
- mcast_socket = malloc(sizeof(g_mcast_socket));
- if(!mcast_socket)
- {
- perror("gmond unable to malloc memory for UDP channel\n");
- return -1;
- }
- memset( mcast_socket, 0, sizeof(g_mcast_socket));
- (mcast_socket->ref_count)++;
-
- mcast_socket->sockfd = socket( AF_INET, SOCK_DGRAM, 0);
- if(mcast_socket->sockfd < 0)
- {
- perror("gmond could not create UDP socket");
- return -1;
- }
-
- if(setsockopt(mcast_socket->sockfd, SOL_SOCKET, SO_REUSEADDR, (void*) &on, sizeof(on)) != 0)
- {
- perror("gmond could not setsockopt on UDP socket");
- return -1;
- }
-
- /* create the sockaddr_in structure */
- if (inet_aton(gmond_config.mcast_channel, &inaddr) == 0)
- {
- fprintf(stderr,"mcast_channel/send_channel is not in dotted decimal notation\n");
- return -1;
- }
- remoteaddr.sin_family = AF_INET;
- remoteaddr.sin_port = htons(gmond_config.mcast_port);
- memcpy(&remoteaddr.sin_addr, (char*) &inaddr, sizeof(struct in_addr));
-
- /* connect the socket to the UDP address */
- if(connect(mcast_socket->sockfd, (struct sockaddr *)&remoteaddr, sizeof(remoteaddr)) < 0)
- {
- fprintf(stderr,"unable to connect to UDP channel '%s:%d\n", gmond_config.mcast_channel,
- gmond_config.mcast_port);
- return -1;
- }
- }
-
- if ( !mcast_socket )
- {
- perror("gmond could not connect to multicast channel");
- return -1;
- }
- debug_msg("multicasting on channel %s %d",
- gmond_config.mcast_channel, gmond_config.mcast_port);
-
- pthread_create(&tid, &attr, monitor_thread, NULL);
- debug_msg("created monitor thread");
- }
-
-
- for(;;)
- {
- pause();
- }
- return 0;
+ apr_interval_time_t start, end;
+ apr_interval_time_t timeout = 0;
+
+ /* Mark the time this gmond started */
+ started = apr_time_now();
+
+ if (cmdline_parser (argc, argv, &args_info) != 0)
+ exit(1) ;
+
+ if(args_info.default_config_flag)
+ {
+ fprintf(stderr, DEFAULT_CONFIGURATION);
+ exit(0);
+ }
+
+ process_configuration_file();
+
+ daemonize_if_necessary( argv );
+
+ /* Initializes the apr library in ./srclib/apr */
+ initialize_apr_library();
+
+ /* Collect my hostname */
+ apr_gethostname( myname, APRMAXHOSTLEN+1, global_context);
+
+ /* Initialize the libmetrics library in ./srclib/libmetrics */
+ libmetrics_init();
+
+ /* Ignore any SIGPIPE signals */
+ apr_signal( SIGPIPE, SIG_IGN );
+
+ setuid_if_necessary();
+
+ process_deaf_mute_mode();
+
+ if(!deaf)
+ {
+ setup_udp_recv_pollset();
+ }
+
+ if(!mute)
+ {
+ setup_udp_send_array();
+ }
+
+ for(;;)
+ {
+ start = apr_time_now();
+ if(!deaf)
+ {
+ poll_udp_recv_channels(timeout);
+ }
+
+ if(!mute)
+ {
+ udp_send_message( "This is a test", 15);
+ }
+ timeout = 999999999;
+ /*
+ timeout = check_local_metrics();
+ */
+ end = apr_time_now();
+ }
+
+ return 0;
}
View
127 gmond/gmond.conf
@@ -1,119 +1,8 @@
-# $Id$
-# This is the configuration file for the Ganglia Monitor Daemon (gmond)
-# Documentation can be found at http://ganglia.sourceforge.net/docs/
-#
-# To change a value from it's default simply uncomment the line
-# and alter the value
-#####################
-#
-# The name of the cluster this node is a part of
-# default: "unspecified"
-# name "My Cluster"
-#
-# The owner of this cluster. Represents an administrative
-# domain. The pair name/owner should be unique for all clusters
-# in the world.
-# default: "unspecified"
-# owner "My Organization"
-#
-# The latitude and longitude GPS coordinates of this cluster on earth.
-# Specified to 1 mile accuracy with two decimal places per axis in Decimal
-# DMS format: "N61.18 W130.50".
-# default: "unspecified"
-# latlong "N32.87 W117.22"
-#
-# The URL for more information on the Cluster. Intended to give purpose,
-# owner, administration, and account details for this cluster.
-# default: "unspecified"
-# url "http://www.mycluster.edu/"
-#
-# The location of this host in the cluster. Given as a 3D coordinate:
-# "Rack,Rank,Plane" that corresponds to a Euclidean coordinate "x,y,z".
-# default: "unspecified"
-# location "0,0,0"
-#
-# The multicast channel for gmond to send/receive data on
-# default: 239.2.11.71
-# mcast_channel 239.2.11.71
-#
-# The multicast port for gmond to send/receive data on
-# default: 8649
-# mcast_port 8649
-#
-# The multicast interface for gmond to send/receive data on
-# default: the kernel decides based on routing configuration
-# mcast_if eth1
-#
-# The multicast Time-To-Live (TTL) for outgoing messages
-# default: 1
-# mcast_ttl 1
-#
-# The number of threads listening to multicast traffic
-# default: 2
-# mcast_threads 2
-#
-# Which port should gmond listen for XML requests on
-# default: 8649
-# xml_port 8649
-#
-# The number of threads answering XML requests
-# default: 2
-# xml_threads 2
-#
-# Hosts ASIDE from "127.0.0.1"/localhost and those multicasting
-# on the same multicast channel which you will share your XML
-# data with. Multiple hosts are allowed on multiple lines.
-# Can be specified with either hostnames or IP addresses.
-# default: none
-# trusted_hosts 1.1.1.1 1.1.1.2 1.1.1.3 \
-# 2.3.2.3 3.4.3.4 5.6.5.6
-#
-# The number of nodes in your cluster. This value is used in the
-# creation of the cluster hash.
-# default: 1024
-# num_nodes 1024
-#
-# The number of custom metrics this gmond will be storing. This
-# value is used in the creation of the host custom_metrics hash.
-# default: 16
-# num_custom_metrics 16
-#
-# Run gmond in "mute" mode. Gmond will only listen to the multicast
-# channel but will not send any data on the channel.
-# default: off
-# mute on
-#
-# Run gmond in "deaf" mode. Gmond will only send data on the multicast
-# channel but will not listen/store any data from the channel.
-# default: off
-# deaf on
-#
-# Run gmond in "debug" mode. Gmond will not background. Debug messages
-# are sent to stdout. Value from 0-100. The higher the number the more
-# detailed debugging information will be sent.
-# default: 0
-# debug_level 10
-#
-# If you don't want gmond to setuid, set this to "on"
-# default: off
-# no_setuid on
-#
-# Which user should gmond run as?
-# default: nobody
-# setuid nobody
-#
-# If you do not want this host to appear in the gexec host list, set
-# this value to "on"
-# default: off
-# no_gexec on
-#
-# If you want any host which connects to the gmond XML to receive
-# data, then set this value to "on"
-# default: off
-# all_trusted on
-#
-# If you want dead nodes to "time out", enter a nonzero value here. If specified,
-# a host will be removed from our state if we have not heard from it in this
-# number of seconds.
-# default: 0 (immortal)
-# host_dmax 108000
+behavior {
+ setuid = no
+ user = "nobody"
+}
+
+udp_recv_channel {
+ port = "8649"
+}
View
6 lib/Makefile.am
@@ -11,11 +11,11 @@ protocol_xdr.c: protocol.x
lib_LTLIBRARIES = libganglia.la
libganglia_la_SOURCES = barrier.c barrier.h become_a_nobody.c become_a_nobody.h \
-daemon_inetd.c daemon_init.c daemon_init.h debug_msg.c debug_msg.h \
-dotconf.c dotconf.h error.c error.h file.c file.h ganglia_priv.h \
+debug_msg.c debug_msg.h daemon_init.c daemon_init.h file.c file.h \
+dotconf.c dotconf.h error.c error.h ganglia_priv.h \
ganglia.c hash.c hash.h inetaddr.c llist.c llist.h \
mcast.c my_inet_ntop.c my_inet_ntop.h net.h rdwr.c rdwr.h readdir.c readdir.h tcp.c \
-protocol_xdr.c protocol.h apr_net.c
+protocol_xdr.c protocol.h apr_net.c apr_net.h
libganglia_la_LDFLAGS = \
-version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE) \
-release $(LT_RELEASE) \
View
78 lib/apr_net.c
@@ -10,57 +10,95 @@
#include <sys/sockio.h> /* for SIOCGIFADDR */
#endif
+apr_socket_t *
+create_udp_client(apr_pool_t *context, char *ipaddr, apr_port_t port)
+{
+ apr_sockaddr_t *remotesa = NULL;
+ apr_socket_t *sock = NULL;
+ apr_status_t status;
+ int family = APR_UNSPEC;
+
+ status = apr_sockaddr_info_get(&remotesa, ipaddr, APR_UNSPEC, port, 0, context);
+ if(status!= APR_SUCCESS)
+ {
+ return NULL;
+ }
+ family = remotesa->sa.sin.sin_family;
+
+ /* Created the socket */
+ status = apr_socket_create(&sock, family, SOCK_DGRAM, context);
+ if(status != APR_SUCCESS)
+ {
+ return NULL;
+ }
+
+ /* Connect the socket to the address */
+ status = apr_connect(sock, remotesa);
+ if(status != APR_SUCCESS)
+ {
+ apr_socket_close(sock);
+ return NULL;
+ }
+
+ return sock;
+}
apr_socket_t *
-create_udp_server(apr_pool_t *context, char *ipaddr, apr_port_t port, apr_sockaddr_t **sa )
+create_udp_server(apr_pool_t *context, apr_port_t port, char *bind)
{
+ apr_sockaddr_t *localsa = NULL;
apr_socket_t *sock = NULL;
apr_status_t stat;
- char buf[128];
+ int family = APR_UNSPEC;
- stat = apr_sockaddr_info_get(sa, ipaddr, APR_UNSPEC, port, 0, context);
- if (stat != APR_SUCCESS)
+ if(bind)
{
- fprintf(stderr, "Couldn't build the socket address correctly: %s\n",
- apr_strerror(stat, buf, sizeof buf));
- exit(-1);
+ stat = apr_sockaddr_info_get(&localsa, bind, APR_UNSPEC, port, 0, context);
+ if (stat != APR_SUCCESS)
+ return NULL;
+
+ family = localsa->sa.sin.sin_family;
}
- stat = apr_socket_create(&sock,(*sa)->sa.sin.sin_family, SOCK_DGRAM, context);
+ stat = apr_socket_create(&sock, family, SOCK_DGRAM, context);
if( stat != APR_SUCCESS )
- {
- fprintf(stderr, "Couldn't create socket\n");
- exit(-1);
- }
+ return NULL;
/* Setup to be non-blocking */
stat = apr_setsocketopt(sock, APR_SO_NONBLOCK, 1);
if (stat != APR_SUCCESS)
{
apr_socket_close(sock);
- fprintf(stderr, "Couldn't set socket option non-blocking\n");
- exit(-1);
+ return NULL;
}
stat = apr_setsocketopt(sock, APR_SO_REUSEADDR, 1);
if (stat != APR_SUCCESS)
{
apr_socket_close(sock);
- fprintf(stderr, "Couldn't set socket option reuseaddr\n");
- exit(-1);
+ return NULL;
}
- stat = apr_bind(sock, *sa);
+ if(!localsa)
+ {
+ apr_socket_addr_get(&localsa, APR_LOCAL, sock);
+ apr_sockaddr_port_set(localsa, port);
+ }
+
+ stat = apr_bind(sock, localsa);
if( stat != APR_SUCCESS)
{
apr_socket_close(sock);
+ /*
fprintf(stderr, "Could not bind: %s\n", apr_strerror(stat, buf, sizeof buf));
- exit(-1);
+ */
+ return NULL;
}
return sock;
}
+#if 0
apr_socket_t *
create_mcast_server_socket( apr_pool_t *context, char *mcastaddr, apr_port_t port, char *interface_name, apr_sockaddr_t **sa)
{
@@ -68,6 +106,7 @@ create_mcast_server_socket( apr_pool_t *context, char *mcastaddr, apr_port_t por
apr_multicast_join( sock, sa, interface_name );
return sock;
}
+#endif
apr_socket_t *
create_tcp_server_socket(apr_pool_t *context, char *ipaddr, apr_port_t port, apr_sockaddr_t **sa )
@@ -281,8 +320,5 @@ apr_multicast_join( apr_socket_t *sock, apr_sockaddr_t **sa, char *ifname )
apr_status_t
apr_multicast_leave( apr_socket_t *sock, apr_sockaddr_t **sa )
{
- apr_status_t status;
-
-
return APR_SUCCESS;
}
View
11 lib/apr_net.h
@@ -0,0 +1,11 @@
+#ifndef APR_NET_H
+#define APR_NET_H 1
+
+apr_socket_t *
+create_udp_client(apr_pool_t *context, char *ipaddr, apr_port_t port);
+
+apr_socket_t *
+create_udp_server(apr_pool_t *context, apr_port_t port, char *bind);
+
+
+#endif
View
8 lib/protocol.x
@@ -64,10 +64,10 @@ enum gangliaFormats {
metric_mem_rm,
metric_mem_avm,
metric_mem_vm,
-
- /* New message formats versions are to be added here...
- */
- GANGLIA_METRIC_GROUP = 1024
+ GANGLIA_METRIC_GROUP,
+/* Insert new message formats here */
+
+ MAX_NUM_GANGLIA_FORMATS /* Make sure this is always the last in the enum */
};
struct gmetricMessage {
View
2  srclib/Makefile.am
@@ -1,4 +1,4 @@
-SUBDIRS = libmetrics expat apr
+SUBDIRS = libmetrics expat apr confuse
test:
echo
Please sign in to comment.
Something went wrong with that request. Please try again.