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