1 #if HAVE_CONFIG_H
2 #include <config.h>
3 #endif /* HAVE_CONFIG_H */
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <unistd.h>
7 #include <string.h>
8 #include <time.h>
9
10 #include "ganglia_gexec.h"
11 #include "ganglia_priv.h"
12 #include "llist.h"
13 #include <getopt.h>
14 #include "cmdline.h"
15
16 char cluster_ip[16];
17 unsigned short cluster_port;
18
19 struct gengetopt_args_info args_info;
20
21 void process_opts( int argc, char **argv );
22
23 static int debug_level;
24
main(int argc,char * argv[])25 int main(int argc, char *argv[])
26 {
27 int rval;
28 gexec_cluster_t cluster;
29 gexec_host_t *host;
30 llist_entry *li;
31
32 debug_level = 1;
33 set_debug_msg_level(debug_level);
34
35 if (cmdline_parser (argc, argv, &args_info) != 0)
36 exit(EXIT_FAILURE) ;
37
38 rval = gexec_cluster(&cluster, args_info.gmond_ip_arg, args_info.gmond_port_arg );
39 if ( rval != 0)
40 {
41 printf("Unable to get hostlist from %s %d!\n", args_info.gmond_ip_arg, args_info.gmond_port_arg);
42 //This is a non standard exit
43 exit(-1);
44 }
45
46 if( args_info.mpifile_flag )
47 {
48 if( args_info.all_flag )
49 li = cluster.hosts;
50 else
51 li = cluster.gexec_hosts;
52
53 for( ; li != NULL; li = li->next )
54 {
55 host = li->val;
56 if( host->name_resolved && ! args_info.numeric_flag )
57 {
58 if(!strcmp(host->domain, "unspecified"))
59 printf("%s:%d\n", host->name, host->cpu_num);
60 else
61 printf("%s.%s:%d\n", host->name, host->domain, host->cpu_num);
62 }
63 else
64 {
65 printf("%s:%d\n", host->ip, host->cpu_num);
66 }
67 }
68 exit(EXIT_SUCCESS);
69 }
70
71 if(! args_info.list_flag )
72 {
73 printf("CLUSTER INFORMATION\n");
74 printf(" Name: %s\n", cluster.name);
75 printf(" Hosts: %d\n", cluster.num_hosts);
76 printf("Gexec Hosts: %d\n", cluster.num_gexec_hosts);
77 printf(" Dead Hosts: %d\n", cluster.num_dead_hosts);
78 printf(" Localtime: %s\n", ctime(&(cluster.localtime)) );
79 }
80
81 if( args_info.dead_flag)
82 {
83 if(! args_info.list_flag )
84 printf("DEAD CLUSTER HOSTS\n");
85 if(cluster.num_dead_hosts)
86 {
87 if(! args_info.list_flag )
88 printf("%32.32s Last Reported\n", "Hostname");
89 for( li = cluster.dead_hosts; li != NULL; li = li->next)
90 {
91 host= li->val;
92 printf("%32.32s %s", host->name, ctime(&(host->last_reported)));
93 }
94 }
95 else
96 {
97 printf("There are no hosts down at this time\n");
98 }
99 gexec_cluster_free(&cluster);
100 exit(EXIT_SUCCESS);
101 }
102
103 if( args_info.all_flag )
104 {
105 li = cluster.hosts;
106 if(! cluster.num_hosts )
107 {
108 printf("There are no hosts up at this time\n");
109 gexec_cluster_free(&cluster);
110 exit(EXIT_SUCCESS);
111 }
112 }
113 else
114 {
115 li = cluster.gexec_hosts;
116 if(! cluster.num_gexec_hosts)
117 {
118 printf("There are no hosts running gexec at this time\n");
119 gexec_cluster_free(&cluster);
120 exit(EXIT_SUCCESS);
121 }
122 }
123
124 if(! args_info.list_flag )
125 {
126 printf("CLUSTER HOSTS\n");
127 printf("Hostname LOAD CPU Gexec\n");
128 printf(" CPUs (Procs/Total) [ 1, 5, 15min] [ User, Nice, System, Idle, Wio]\n\n");
129 }
130 for(; li != NULL; li = li->next)
131 {
132 host = li->val;
133 if( host->name_resolved && ! args_info.numeric_flag )
134 {
135 if(!strcmp(host->domain, "unspecified"))
136 printf("%s", host->name);
137 else
138 printf("%s.%s", host->name, host->domain);
139 }
140 else
141 {
142 printf("%s", host->ip);
143 }
144 if( args_info.single_line_flag )
145 printf(" ");
146 else
147 printf("\n");
148
149 printf(" %4d (%5d/%5d) [%6.2f,%6.2f,%6.2f] [%6.1f,%6.1f,%6.1f,%6.1f,%6.1f] ",
150 host->cpu_num, host->proc_run, host->proc_total,
151 host->load_one, host->load_five, host->load_fifteen,
152 host->cpu_user, host->cpu_nice, host->cpu_system, host->cpu_idle, host->cpu_wio);
153 if(host->gexec_on)
154 printf("%s\n", "ON");
155 else
156 printf("%s\n", "OFF");
157 }
158
159 gexec_cluster_free(&cluster);
160 return 0;
161 }
162
163