Permalink
Switch branches/tags
test start release_0_3_4 release_0_2_2 release_0_2_1 preGmetricMessageUpdate@611 preGmetricMessageUpdate monitor-core-3.1.7 monitor-core-3.1.6 monitor-core-3.1.5 monitor-core-3.1.4 monitor-core-3.1.3 monitor-core-3.1.2 monitor-core-3.1.1 monitor-core-3.1.0 monitor-core-3.0.7 monitor-core-3.0.6 monitor-core-3.0.5 monitor-core-3.0.4 monitor-core-3.0.3 monitor-core-3.0.2 monitor-core-3.0.1 monitor-core-3.0.0 monitor-core-3.0-beta monitor-core-2.5.7 monitor-core-2.5.6 monitor-core-2.5.4 monitor-core-2.5.3 monitor-core-2.5.2 monitor-core-2.5.1 monitor-core-2.5.0 monitor-core-2.5.0-update monitor-core-2.4.1 massie_3_0_0_fixed_darwin_gstat_bug@542 massie_3_0_0_fixed_darwin_gstat_bug massie_3_0_0_IPv6_to_IPv4_mapping_removed_for_security@537 massie_3_0_0_IPv6_to_IPv4_mapping_removed_for_security massie_2_6_0_updated_protocol_for_HPUX_solaris_now_complete@492 massie_2_6_0_updated_protocol_for_HPUX_solaris_now_complete massie_2_6_0_updated_darwin_metric_altered_default_gmond_conf@523 massie_2_6_0_updated_darwin_metric_altered_default_gmond_conf massie_2_6_0_tcp_accept_channels_functional@466 massie_2_6_0_tcp_accept_channels_functional massie_2_6_0_protocol_definition_contains_2_5_compat@461 massie_2_6_0_protocol_definition_contains_2_5_compat massie_2_6_0_near_beta@487 massie_2_6_0_near_beta massie_2_6_0_multicast_support_added@454 massie_2_6_0_multicast_support_added massie_2_6_0_gmond_tmax_values_corrected@475 massie_2_6_0_gmond_tmax_values_corrected massie_2_6_0_gmond_now_listens_saves_all_udp_data@472 massie_2_6_0_gmond_now_listens_saves_all_udp_data massie_2_6_0_gmond_nearly_complete_send_metrics@478 massie_2_6_0_gmond_nearly_complete_send_metrics massie_2_6_0_gmond_host_and_gmetric_cleanup_added_feature_complete@508 massie_2_6_0_gmond_host_and_gmetric_cleanup_added_feature_complete massie_2_6_0_gmond_gmetric_support_added@490 massie_2_6_0_gmond_gmetric_support_added massie_2_6_0_gmetric_complete_now_parses_config@503 massie_2_6_0_gmetric_complete_now_parses_config massie_2_6_0_config_convertion_code_complete@530 massie_2_6_0_config_convertion_code_complete massie_2_6_0_all_metrics_available_add_bandwidth_metric_commandline_flags@484 massie_2_6_0_all_metrics_available_add_bandwidth_metric_commandline_flags massie_2_6_0_added_xdr_protocol_file_apache_runtime@436 massie_2_6_0_added_xdr_protocol_file_apache_runtime massie_2_6_0_added_webfrontend_gmond_based_on_apr@454 massie_2_6_0_added_webfrontend_gmond_based_on_apr massie_2_6_0_added_code_to_convert_25_config_files@525 massie_2_6_0_added_code_to_convert_25_config_files massie_2_6_0_access_control_lists_added@518 massie_2_6_0_access_control_lists_added massie_2_5_8_tested_on_solaris_freebsd_linux@399 massie_2_5_8_tested_on_solaris_freebsd_linux massie_2_5_8_new_gmond_conf_daemonize_flag_foreground@416 massie_2_5_8_new_gmond_conf_daemonize_flag_foreground massie_2_5_8_major_code_cleanup@396 massie_2_5_8_major_code_cleanup massie_2_5_8_libmetrics_cygwin_windows_native_api@416 massie_2_5_8_libmetrics_cygwin_windows_native_api massie_2_5_8_fixed_rpmspec_libtool_for_libganglia@407 massie_2_5_8_fixed_rpmspec_libtool_for_libganglia massie_2_5_8_cygwin_support@411 massie_2_5_8_cygwin_support massie_2_5_8_cleaned_up_libganglia@405 massie_2_5_8_cleaned_up_libganglia gweb-2.0.0 gexec-0.3.9@1383 gexec-0.3.9 gexec-0.3.4 gexec-0.2.2 gexec-0.2.1 Release_06192002_2_4_1 Release_30_01_2003_Version_2-5-2@172 Release_30_01_2003_Version_2-5-2 Release_12_10_2004_Version-2-5-7@242 Release_12_10_2004_Version-2-5-7 Release_09-20-2002_Version_2-5-0@142 Release_09-20-2002_Version_2-5-0
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
142 lines (123 sloc) 4.53 KB
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <confuse.h> /* header for libconfuse */
#include <apr.h>
#include <apr_strings.h>
#include <apr_pools.h>
#include "ganglia.h"
#include "cmdline.h"
Ganglia_pool global_context;
Ganglia_metric gmetric;
Ganglia_gmond_config gmond_config;
Ganglia_udp_send_channels send_channels;
/* The commandline options */
struct gengetopt_args_info args_info;
int
main( int argc, char *argv[] )
{
int rval;
/* process the commandline options */
if (cmdline_parser (argc, argv, &args_info) != 0)
exit(EXIT_FAILURE);
/* create the global context */
global_context = Ganglia_pool_create(NULL);
if(!global_context)
{
fprintf(stderr,"Unable to create global context. Exiting.\n");
exit(EXIT_FAILURE);
}
/* parse the configuration file */
gmond_config = Ganglia_gmond_config_create( args_info.conf_arg, !args_info.conf_given);
/* deal with spoof overrides */
cfg_t *globals = (cfg_t*) cfg_getsec( (cfg_t *)gmond_config, "globals" );
char *override_hostname = cfg_getstr( globals, "override_hostname" );
char *override_ip = cfg_getstr( globals, "override_ip" );
/* build the udp send channels */
send_channels = Ganglia_udp_send_channels_create(global_context, gmond_config);
if(!send_channels)
{
fprintf(stderr,"Unable to create ganglia send channels. Exiting.\n");
exit(EXIT_FAILURE);
}
/* create the message */
gmetric = Ganglia_metric_create(global_context);
if(!gmetric)
{
fprintf(stderr,"Unable to allocate gmetric structure. Exiting.\n");
exit(EXIT_FAILURE);
}
apr_pool_t *gm_pool = (apr_pool_t*)gmetric->pool;
if(args_info.spoof_given && args_info.heartbeat_given){
rval = Ganglia_metric_set(gmetric, "heartbeat", "0", "uint32", "", 0, 0, 0);
}else{
if( ! (args_info.name_given && args_info.value_given && args_info.type_given))
{
fprintf(stderr,"Incorrect options supplied, exiting.\n");
exit(EXIT_FAILURE);
}
rval = Ganglia_metric_set( gmetric, args_info.name_arg, args_info.value_arg,
args_info.type_arg, args_info.units_arg, cstr_to_slope(args_info.slope_arg),
args_info.tmax_arg, args_info.dmax_arg);
}
/* TODO: make this less ugly later */
switch(rval)
{
case 1:
fprintf(stderr,"gmetric parameters invalid. exiting.\n");
exit(EXIT_FAILURE);
case 2:
fprintf(stderr,"one of your parameters has an invalid character '\"'. exiting.\n");
exit(EXIT_FAILURE);
case 3:
fprintf(stderr,"the type parameter \"%s\" is not a valid type. exiting.\n", args_info.type_arg);
exit(EXIT_FAILURE);
case 4:
fprintf(stderr,"the value parameter \"%s\" does not represent a number. exiting.\n", args_info.value_arg);
exit(EXIT_FAILURE);
}
/* TODO: Try to validate the spoof arg format. A better validation could
* be done here. This is just checking for a colon. */
if(args_info.spoof_given && !strchr(args_info.spoof_arg,':'))
{
fprintf(stderr,"Incorrect format for spoof argument. exiting.\n");
exit(EXIT_FAILURE);
}
if(args_info.spoof_given)
Ganglia_metadata_add(gmetric, SPOOF_HOST, args_info.spoof_arg);
if(!args_info.spoof_given && override_hostname != NULL)
{
char *spoof_string = apr_pstrcat(gm_pool, override_ip != NULL ? override_ip : override_hostname, ":", override_hostname, NULL);
Ganglia_metadata_add(gmetric, SPOOF_HOST, spoof_string);
}
if(args_info.heartbeat_given)
Ganglia_metadata_add(gmetric, SPOOF_HEARTBEAT, "yes");
if(args_info.cluster_given)
Ganglia_metadata_add(gmetric, "CLUSTER", args_info.cluster_arg);
if(args_info.group_given)
{
char *last;
char *group;
for (group = apr_strtok(args_info.group_arg, ", ", &last); group != NULL; group = apr_strtok(NULL, ", ", &last)) {
Ganglia_metadata_add(gmetric, "GROUP", group);
}
}
if(args_info.desc_given)
Ganglia_metadata_add(gmetric, "DESC", args_info.desc_arg);
if(args_info.title_given)
Ganglia_metadata_add(gmetric, "TITLE", args_info.title_arg);
/* send the message */
rval = Ganglia_metric_send(gmetric, send_channels);
if(rval)
{
fprintf(stderr,"There was an error sending to %d of the send channels.\n", rval);
Ganglia_metric_destroy(gmetric);
Ganglia_pool_destroy(global_context);
exit(EXIT_FAILURE);
}
/* cleanup */
Ganglia_metric_destroy(gmetric); /* not really necessary but for symmetry */
Ganglia_pool_destroy(global_context);
return 0;
}