2
Copyright (C) 2003-2004 Douglas Thain and the University of Wisconsin
3
Copyright (C) 2005- The University of Notre Dame
4
This software is distributed under the GNU General Public License.
5
See the file COPYING for details.
8
#include "catalog_query.h"
11
#include "stringtools.h"
24
static INT64_T minavail=0;
26
static struct nvpair_header headers[] = {
27
{ "type", NVPAIR_MODE_STRING, NVPAIR_ALIGN_LEFT, 8 },
28
{ "name", NVPAIR_MODE_STRING, NVPAIR_ALIGN_LEFT, 25 },
29
{ "port", NVPAIR_MODE_INTEGER, NVPAIR_ALIGN_LEFT, 5 },
30
{ "owner", NVPAIR_MODE_STRING, NVPAIR_ALIGN_LEFT, 10 },
31
{ "version", NVPAIR_MODE_STRING, NVPAIR_ALIGN_LEFT, 8 },
32
{ "total", NVPAIR_MODE_METRIC, NVPAIR_ALIGN_RIGHT, 8 },
33
{ "avail", NVPAIR_MODE_METRIC, NVPAIR_ALIGN_RIGHT, 8 },
37
static void show_version( const char *cmd )
39
printf("%s version %d.%d.%d built by %s@%s on %s at %s\n",cmd,CCTOOLS_VERSION_MAJOR,CCTOOLS_VERSION_MINOR,CCTOOLS_VERSION_MICRO,BUILD_USER,BUILD_HOST,__DATE__,__TIME__);
42
static void show_help( const char *cmd )
44
printf("chirp_status [options] [ <name> <value> ]\n");
45
printf("where options are:\n");
46
printf(" -c <host> Query the catalog on this host.\n");
47
printf(" -d <flag> Enable debugging for this sybsystem\n");
48
printf(" -o <file> Send debugging output to this file.\n");
49
printf(" -O <bytes> Rotate file once it reaches this size.\n");
50
printf(" -A <size> Only show servers with this space available. (example: -A 100MB)\n");
51
printf(" -t <time> Timeout.\n");
52
printf(" -s Short output.\n");
53
printf(" -l Long output.\n");
54
printf(" -T Totals output.\n");
55
printf(" -h This message.\n");
56
printf(" -v Show version info.\n");
59
int compare_entries( struct nvpair **a, struct nvpair **b )
64
x = nvpair_lookup_string(*a,"type");
67
y = nvpair_lookup_string(*b,"type");
70
result = strcasecmp(x,y);
71
if(result!=0) return result;
73
x = nvpair_lookup_string(*a,"name");
76
y = nvpair_lookup_string(*b,"name");
79
return strcasecmp(x,y);
82
static struct nvpair *table[10000];
84
int main( int argc, char *argv[] )
86
struct catalog_query *q;
88
time_t timeout=60, stoptime;
89
const char * catalog_host = 0;
93
int mode = MODE_TABLE;
94
INT64_T total=0, avail=0;
95
const char *filter_name = 0;
96
const char *filter_value = 0;
98
debug_config(argv[0]);
100
while((c=getopt(argc,argv,"A:c:d:t:o:O:sTlvh"))!=(char)-1) {
103
catalog_host = optarg;
106
debug_flags_set(optarg);
109
timeout = string_time_parse(optarg);
112
minavail = string_metric_parse(optarg);
115
debug_config_file(optarg);
118
debug_config_file_size(string_metric_parse(optarg));
121
show_version(argv[0]);
141
} else if((argc-optind)==1) {
142
filter_name = "name";
143
filter_value = argv[optind];
144
} else if((argc-optind)==2) {
145
filter_name = argv[optind];
146
filter_value = argv[optind+1];
152
stoptime = time(0)+timeout;
154
q = catalog_query_create(catalog_host,0,stoptime);
156
fprintf(stderr,"couldn't query catalog: %s\n",strerror(errno));
160
if(mode==MODE_TABLE) {
161
nvpair_print_table_header(stdout,headers);
164
while((n = catalog_query_read(q,stoptime))) {
168
qsort(table,count,sizeof(*table),(void*)compare_entries);
170
for(i=0;i<count;i++) {
172
if(minavail>nvpair_lookup_integer(table[i],"avail")) {
178
const char *v = nvpair_lookup_string(table[i],filter_name);
179
if(!v || strcmp(filter_value,v)) continue;
182
if(mode==MODE_SHORT) {
183
const char *t = nvpair_lookup_string(table[i],"type");
184
if(t && !strcmp(t,"chirp")) {
185
printf("%s:%d\n",nvpair_lookup_string(table[i],"name"),(int)nvpair_lookup_integer(table[i],"port"));
187
} else if(mode==MODE_LONG) {
188
nvpair_print_text(table[i],stdout);
189
} else if(mode==MODE_TABLE) {
190
nvpair_print_table(table[i],stdout,headers);
191
} else if(mode==MODE_TOTAL) {
192
avail += nvpair_lookup_integer(table[i],"avail");
193
total += nvpair_lookup_integer(table[i],"total");
197
if(mode==MODE_TOTAL) {
198
printf("NODES: %4d\n",count);
199
printf("TOTAL: %6sB\n",string_metric(total,-1,0));
200
printf("AVAIL: %6sB\n",string_metric(avail,-1,0));
201
printf("INUSE: %6sB\n",string_metric(total-avail,-1,0));
204
if(mode==MODE_TABLE) {
205
nvpair_print_table_footer(stdout,headers);