ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/idar/idar.c
Revision: 1.21
Committed: Fri Sep 26 21:22:43 2003 UTC (21 years, 2 months ago) by tdb
Content type: text/plain
Branch: MAIN
CVS Tags: IDAR_1_2
Changes since 1.20: +1 -1 lines
Log Message:
Update some old URL's etc.

File Contents

# User Rev Content
1 tdb 1.3 /*
2     * i-scream central monitoring system
3 tdb 1.21 * http://www.i-scream.org
4 tdb 1.3 * Copyright (C) 2000-2002 i-scream
5     *
6     * This program is free software; you can redistribute it and/or
7     * modify it under the terms of the GNU General Public License
8     * as published by the Free Software Foundation; either version 2
9     * of the License, or (at your option) any later version.
10     *
11     * This program is distributed in the hope that it will be useful,
12     * but WITHOUT ANY WARRANTY; without even the implied warranty of
13     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14     * GNU General Public License for more details.
15     *
16     * You should have received a copy of the GNU General Public License
17     * along with this program; if not, write to the Free Software
18     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19     */
20    
21     #ifdef HAVE_CONFIG_H
22     #include "config.h"
23     #endif
24    
25 pajs 1.1 #include <stdio.h>
26     #include <string.h>
27     #include <sys/types.h>
28     #include <sys/socket.h>
29 tdb 1.20 #include <sys/ioctl.h>
30 pajs 1.1 #include <unistd.h>
31     #include <stdlib.h>
32     #include <ukcprog.h>
33 pajs 1.11 #include <netinet/in.h>
34 pajs 1.10 #include <netdb.h>
35 pajs 1.13 #include <sys/termios.h>
36 pajs 1.15 #include <signal.h>
37     #include <errno.h>
38 pajs 1.1
39     #include <libxml/xmlmemory.h>
40     #include <libxml/parser.h>
41     #include "genmergesort.h"
42 tdb 1.6
43     #ifdef HAVE_NCURSES_H
44     #include <ncurses.h>
45     #else
46 pajs 1.4 #include <curses.h>
47 tdb 1.6 #endif
48 pajs 1.1
49     struct host_line_t{
50     char *hostname;
51     int line;
52    
53     struct host_line_t *next;
54     };
55     typedef struct host_line_t host_line_list_t;
56    
57     struct diskio_data_t{
58     char *name;
59    
60     long long read;
61     long long write;
62    
63     struct diskio_data_t *next;
64     };
65     typedef struct diskio_data_t diskio_data_list_t;
66    
67     struct network_data_t{
68     char *name;
69    
70     long long rx;
71     long long tx;
72    
73     struct network_data_t *next;
74     };
75     typedef struct network_data_t network_data_list_t;
76    
77     /*
78     struct disk_data_t{
79     char *name;
80     char *mount_pnt;
81    
82     long long total_space;
83     long long total_used;
84     long long total_avail;
85     // Other data we are less intrested in are not stored
86    
87     struct disk_data_t *next;
88     };
89     typedef struct disk_data_t disk_data_list_t;
90     */
91     #define MAXHOSTNAMESIZE 10
92     struct machine_data_t{
93    
94     char *name;
95    
96     char sysname[MAXHOSTNAMESIZE+1];
97    
98     double cpu_user;
99     double cpu_idle;
100     double cpu_iowait;
101     double cpu_kernel;
102     double cpu_swap;
103     double cpu_used; /* 100 - idle */
104    
105     long long memory_total;
106     long long memory_free;
107     long long memory_used;
108     double memory_used_pecent;
109    
110     long long swap_total;
111     long long swap_free;
112     long long swap_used;
113     double swap_used_pecent;
114    
115     int pages_in;
116     int pages_out;
117    
118     double load_1;
119     double load_5;
120     double load_15;
121    
122     int processes_total;
123     int processes_sleeping;
124     int processes_cpu;
125     int processes_zombie;
126     int processes_stopped;
127    
128     network_data_list_t *network_data_list;
129     long long network_io_total_tx;
130     long long network_io_total_rx;
131 pajs 1.7 long long network_io_total;
132 pajs 1.1
133     diskio_data_list_t *diskio_data_list;
134     long long disk_io_total_write;
135     long long disk_io_total_read;
136 pajs 1.7 long long disk_io_total;
137 pajs 1.1
138     /* Maybe in the future */
139     /*
140     disk_data_list_t disk_data_list;
141     double disk_total_used;
142     */
143    
144     struct machine_data_t *next;
145     };
146    
147     typedef struct machine_data_t machine_data_list_t;
148    
149 pajs 1.7 #define SORTBYMAXNAME 128
150 pajs 1.1 typedef struct{
151 pajs 1.14 int maxx;
152     int maxy;
153    
154     char units;
155    
156 pajs 1.1 int cpu_user;
157     int cpu_idle;
158     int cpu_iowait;
159     int cpu_kernel;
160     int cpu_swap;
161     int cpu_used;
162    
163     int memory_total;
164     int memory_free;
165     int memory_used;
166     int memory_used_pecent;
167    
168     int swap_total;
169     int swap_free;
170     int swap_used;
171     int swap_used_pecent;
172    
173     int load_1;
174     int load_5;
175     int load_15;
176    
177     int pages_in;
178     int pages_out;
179    
180 pajs 1.15 int processes;
181 pajs 1.1
182     int network_io_total_tx;
183     int network_io_total_rx;
184     int network_all_stats;
185    
186     int disk_io_total_write;
187     int disk_io_total_read;
188     int disk_io_all_stats;
189    
190     int disk_total_used;
191     int disk_all_stats;
192 pajs 1.7
193     char sortby[SORTBYMAXNAME];
194 pajs 1.1 }display_config_t;
195    
196     GENERIC_MERGE_SORT(static, sort_machine_stats, machine_data_list_t, next)
197    
198 pajs 1.2 #define MKCMP(x) int cmp_##x(machine_data_list_t *a, machine_data_list_t *b){return ((a->x) == (b->x)? 0 : (((a->x) > (b->x))? -1 : 1));}
199    
200    
201     int (*sortby_ptr)(machine_data_list_t *a, machine_data_list_t *b);
202    
203     MKCMP(cpu_used)
204     MKCMP(load_1)
205 pajs 1.7 MKCMP(network_io_total)
206 pajs 1.2 MKCMP(network_io_total_tx)
207     MKCMP(network_io_total_rx)
208 pajs 1.7 MKCMP(disk_io_total)
209 pajs 1.2 MKCMP(disk_io_total_write)
210     MKCMP(disk_io_total_read)
211     MKCMP(memory_used_pecent)
212     MKCMP(swap_used_pecent)
213    
214 pajs 1.7 #define CPU_USED "CPU used"
215     #define LOAD "Load (1)"
216     #define NETIORX "total Network RX for all interfaces"
217     #define NETIOTX "total Network TX for all interfaces"
218     #define NETIO "total Network IO for all interfaces (rx+tx)"
219     #define MEM "Memory usage"
220     #define SWAP "Swap usage"
221     #define DISKIOR "DiskIO reads"
222     #define DISKIOW "DiskIO writes"
223     #define DISKIO "Total DiskIO (reads+writes)"
224    
225 pajs 1.15 int sig_winch=0;
226 pajs 1.9
227     #ifndef HAVE_ATOLL
228     long long int atoll (const char *nptr){
229     return strtoll (nptr, (char **) NULL, 10);
230     }
231     #endif
232    
233     #ifndef HAVE_STRLCPY
234     /*
235     * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
236     * All rights reserved.
237     *
238     * Redistribution and use in source and binary forms, with or without
239     * modification, are permitted provided that the following conditions
240     * are met:
241     * 1. Redistributions of source code must retain the above copyright
242     * notice, this list of conditions and the following disclaimer.
243     * 2. Redistributions in binary form must reproduce the above copyright
244     * notice, this list of conditions and the following disclaimer in the
245     * documentation and/or other materials provided with the distribution.
246     * 3. The name of the author may not be used to endorse or promote products
247     * derived from this software without specific prior written permission.
248     *
249     * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
250     * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
251     * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
252     * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
253     * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
254     * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
255     * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
256     * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
257     * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
258     * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
259     */
260    
261     /*
262     * Copy src to string dst of size siz. At most siz-1 characters
263     * will be copied. Always NUL terminates (unless siz == 0).
264     * Returns strlen(src); if retval >= siz, truncation occurred.
265     */
266     size_t
267     strlcpy(dst, src, siz)
268     char *dst;
269     const char *src;
270     size_t siz;
271     {
272     register char *d = dst;
273     register const char *s = src;
274     register size_t n = siz;
275    
276     /* Copy as many bytes as will fit */
277     if (n != 0 && --n != 0) {
278     do {
279     if ((*d++ = *s++) == 0)
280     break;
281     } while (--n != 0);
282     }
283    
284     /* Not enough room in dst, add NUL and traverse rest of src */
285     if (n == 0) {
286     if (siz != 0)
287     *d = '\0'; /* NUL-terminate dst */
288     while (*s++)
289     ;
290     }
291    
292     return(s - src - 1); /* count does not include NUL */
293     }
294    
295     #endif
296    
297 pajs 1.1
298     FILE *create_tcp_connection(char *hostname, int port){
299     int sock;
300     struct sockaddr_in addr;
301     struct in_addr haddr;
302     FILE *f;
303    
304     if((sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP))<0){
305     return NULL;
306     }
307    
308     if((get_host_addr(hostname, &haddr))!=0){
309     close(sock);
310     return NULL;
311     }
312    
313     memset(&addr, 0, sizeof(addr));
314     addr.sin_family = AF_INET;
315     memcpy(&addr.sin_addr, &haddr, sizeof(haddr));
316     addr.sin_port = htons(port);
317    
318     if(connect(sock, (struct sockaddr *)&addr, sizeof(addr)) !=0){
319     close(sock);
320     return NULL;
321     }
322    
323     if((f=fdopen(sock, "r+"))==NULL){
324     close(sock);
325     return NULL;
326     }
327    
328     return f;
329     }
330    
331     int tcp_comm(FILE *f, char *send, char **response, char *expected){
332    
333     if(send!=NULL){
334     fprintf(f, "%s\n", send);
335     }
336     fflush(f);
337     *response=fpgetline(f);
338     fseek(f, 0, SEEK_CUR);
339    
340     if( (*response==NULL) || (strcmp(*response, "ERROR")==0) ) return -1;
341    
342     if(expected==NULL) return 0;
343    
344     if((strcmp(expected, *response))==0) return 0;
345    
346     return -1;
347     }
348    
349     /* Takes a xml char * and a machine_data_list_t. This will parse
350     * the xml and put it into the correct entry of the machine_data
351     * linked list. This will return the number of entries in the linked
352     * list, or -1 on a error.
353     */
354     int parse_xml(char *xml, machine_data_list_t **md){
355     xmlDocPtr doc;
356     xmlNodePtr cur;
357     xmlNodePtr ele;
358     xmlAttr *list;
359    
360     static int num_hosts=0;
361    
362     machine_data_list_t *machine_data_list=*md;
363    
364     int found_host=0;
365    
366     char *hostname=NULL;
367     network_data_list_t *network_data_list=NULL;
368     network_data_list_t *ndl_ptr=NULL;
369     diskio_data_list_t *diskio_data_list=NULL;
370     diskio_data_list_t *didl_ptr=NULL;
371     char *tmp;
372    
373     doc=xmlParseDoc(xml);
374     if(doc==NULL) return -1;
375    
376     cur = xmlDocGetRootElement(doc);
377     if(cur==NULL){
378     xmlFreeDoc(doc);
379     return -1;
380     }
381    
382    
383     /* Get the hostname */
384     list=cur->properties;
385     while(list!=NULL){
386     if((xmlStrcmp(list->name, (const xmlChar *) "machine_name"))==0){
387     hostname = xmlNodeGetContent(list->children);
388     if(hostname==NULL){
389     return -1;
390     }
391     }
392     list=list->next;
393     }
394     if(hostname==NULL){
395     return -1;
396     }
397    
398     /* Get machine_data for host.. Or create if it doesn't have one */
399     while(machine_data_list!=NULL){
400     if((strncmp(machine_data_list->name, hostname, strlen(hostname)))==0){
401     found_host=1;
402     break;
403     }
404     machine_data_list=machine_data_list->next;
405     }
406    
407     if(!found_host){
408     /* We didn't find this host, but we should be at the end of the list */
409     machine_data_list=malloc(sizeof(machine_data_list_t));
410     if(machine_data_list==NULL) return -1;
411     machine_data_list->next=(*md);
412     machine_data_list->name=hostname;
413     machine_data_list->network_data_list=NULL;
414     machine_data_list->diskio_data_list=NULL;
415     *md=machine_data_list;
416     num_hosts++;
417     }
418    
419     /* Now we want to pull out the data */
420    
421     cur = cur->xmlChildrenNode;
422     while(cur != NULL) {
423     ele=cur->xmlChildrenNode;
424     while(ele != NULL){
425    
426     /* CPU Stats */
427     if(!xmlStrcmp(cur->name, (const xmlChar *) "cpu")){
428     tmp=xmlNodeGetContent(ele);
429     if(!xmlStrcmp(ele->name, (const xmlChar *) "user")){
430     machine_data_list->cpu_user=atof(tmp);
431     }
432     if(!xmlStrcmp(ele->name, (const xmlChar *) "kernel")){
433     machine_data_list->cpu_kernel=atof(tmp);
434     }
435     if(!xmlStrcmp(ele->name, (const xmlChar *) "idle")){
436     machine_data_list->cpu_idle=atof(tmp);
437     }
438     if(!xmlStrcmp(ele->name, (const xmlChar *) "iowait")){
439     machine_data_list->cpu_iowait=atof(tmp);
440     }
441     if(!xmlStrcmp(ele->name, (const xmlChar *) "swap")){
442     machine_data_list->cpu_iowait=atof(tmp);
443     }
444    
445     if(tmp!=NULL) xmlFree(tmp);
446     }
447    
448     /* Memory Stats */
449     if(!xmlStrcmp(cur->name, (const xmlChar *) "memory")){
450     tmp=xmlNodeGetContent(ele);
451     if(!xmlStrcmp(ele->name, (const xmlChar *) "total")){
452     machine_data_list->memory_total=atoll(tmp);
453     }
454     if(!xmlStrcmp(ele->name, (const xmlChar *) "free")){
455     machine_data_list->memory_free=atoll(tmp);
456     }
457     if(!xmlStrcmp(ele->name, (const xmlChar *) "used")){
458     machine_data_list->memory_used=atoll(tmp);
459     }
460    
461     if(tmp!=NULL) xmlFree(tmp);
462     }
463    
464     /* Load Stats */
465     if(!xmlStrcmp(cur->name, (const xmlChar *) "load")){
466     tmp=xmlNodeGetContent(ele);
467     if(!xmlStrcmp(ele->name, (const xmlChar *) "load1")){
468     machine_data_list->load_1=atof(tmp);
469     }
470     if(!xmlStrcmp(ele->name, (const xmlChar *) "load5")){
471     machine_data_list->load_5=atof(tmp);
472     }
473     if(!xmlStrcmp(ele->name, (const xmlChar *) "load15")){
474     machine_data_list->load_15=atof(tmp);
475     }
476    
477     if(tmp!=NULL) xmlFree(tmp);
478     }
479    
480     /* swap stats */
481     if(!xmlStrcmp(cur->name, (const xmlChar *) "swap")){
482     tmp=xmlNodeGetContent(ele);
483     if(!xmlStrcmp(ele->name, (const xmlChar *) "total")){
484     machine_data_list->swap_total=atoll(tmp);
485     }
486     if(!xmlStrcmp(ele->name, (const xmlChar *) "free")){
487     machine_data_list->swap_free=atoll(tmp);
488     }
489     if(!xmlStrcmp(ele->name, (const xmlChar *) "used")){
490     machine_data_list->swap_used=atoll(tmp);
491     }
492    
493     if(tmp!=NULL) xmlFree(tmp);
494     }
495    
496     /* Process stat */
497     if(!xmlStrcmp(cur->name, (const xmlChar *) "processes")){
498     tmp=xmlNodeGetContent(ele);
499     if(!xmlStrcmp(ele->name, (const xmlChar *) "sleeping")){
500     machine_data_list->processes_sleeping=atoi(tmp);
501     }
502     if(!xmlStrcmp(ele->name, (const xmlChar *) "cpu")){
503     machine_data_list->processes_cpu=atoi(tmp);
504     }
505     if(!xmlStrcmp(ele->name, (const xmlChar *) "zombie")){
506     machine_data_list->processes_zombie=atoi(tmp);
507     }
508     if(!xmlStrcmp(ele->name, (const xmlChar *) "total")){
509     machine_data_list->processes_total=atoi(tmp);
510     }
511    
512     if(tmp!=NULL) xmlFree(tmp);
513     }
514    
515     /* paging stats */
516     if(!xmlStrcmp(cur->name, (const xmlChar *) "pages")){
517     tmp=xmlNodeGetContent(ele);
518     if(!xmlStrcmp(ele->name, (const xmlChar *) "pageins")){
519     machine_data_list->pages_in=atoi(tmp);
520     }
521     if(!xmlStrcmp(ele->name, (const xmlChar *) "pageouts")){
522     machine_data_list->pages_out=atoi(tmp);
523     }
524    
525     if(tmp!=NULL) xmlFree(tmp);
526     }
527    
528     /* OS stats */
529     if(!xmlStrcmp(cur->name, (const xmlChar *) "os")){
530     tmp=xmlNodeGetContent(ele);
531     if(!xmlStrcmp(ele->name, (const xmlChar *) "sysname")){
532     strlcpy(machine_data_list->sysname, tmp, MAXHOSTNAMESIZE+1);
533     }
534     if(tmp!=NULL) xmlFree(tmp);
535     }
536    
537     /* Network stats */
538     /* Needs to connect current stat to a previous one. Or create it if new */
539     /* Get name.. Walk list. If match, copy rx/tx values. Else malloc, add to list */
540     if(!xmlStrcmp(cur->name, (const xmlChar *) "net")){
541    
542     list=ele->properties;
543     if(list==NULL) continue;
544     network_data_list=malloc(sizeof(network_data_list_t));
545     if(network_data_list==NULL) return -1;
546     while(list!=NULL){
547     tmp=xmlNodeGetContent(list->children);
548     if(!xmlStrcmp(list->name, (const xmlChar *) "name")){
549     network_data_list->name=strdup(tmp);
550     }
551     if(!xmlStrcmp(list->name, (const xmlChar *) "rx")){
552     network_data_list->rx=atoll(tmp);
553     }
554     if(!xmlStrcmp(list->name, (const xmlChar *) "tx")){
555     network_data_list->tx=atoll(tmp);
556     }
557    
558     xmlFree(tmp);
559     list=list->next;
560     }
561     if(network_data_list->name==NULL) continue;
562     found_host=0;
563     ndl_ptr=machine_data_list->network_data_list;
564     while(ndl_ptr!=NULL){
565     if(!strcmp(ndl_ptr->name, network_data_list->name)){
566     found_host=1;
567     break;
568     }
569     ndl_ptr=ndl_ptr->next;
570     }
571     if(found_host){
572     ndl_ptr->rx=network_data_list->rx;
573     ndl_ptr->tx=network_data_list->tx;
574     free(network_data_list->name);
575     free(network_data_list);
576     }else{
577     network_data_list->next=machine_data_list->network_data_list;
578     machine_data_list->network_data_list=network_data_list;
579     }
580     }
581    
582     /* Disk IO stats */
583     if(!xmlStrcmp(cur->name, (const xmlChar *) "diskio")){
584    
585     list=ele->properties;
586     if(list==NULL) continue;
587     diskio_data_list=malloc(sizeof(diskio_data_list_t));
588     if(diskio_data_list==NULL) return -1;
589     while(list!=NULL){
590     tmp=xmlNodeGetContent(list->children);
591     if(!xmlStrcmp(list->name, (const xmlChar *) "name")){
592     diskio_data_list->name=strdup(tmp);
593     }
594     if(!xmlStrcmp(list->name, (const xmlChar *) "rbytes")){
595     diskio_data_list->read=atoll(tmp);
596     }
597     if(!xmlStrcmp(list->name, (const xmlChar *) "wbytes")){
598     diskio_data_list->write=atoll(tmp);
599     }
600    
601     xmlFree(tmp);
602     list=list->next;
603     }
604     if(diskio_data_list->name==NULL) continue;
605     found_host=0;
606     didl_ptr=machine_data_list->diskio_data_list;
607     while(didl_ptr!=NULL){
608     if(!strcmp(didl_ptr->name, diskio_data_list->name)){
609     found_host=1;
610     break;
611     }
612     didl_ptr=didl_ptr->next;
613     }
614     if(found_host){
615     didl_ptr->read=diskio_data_list->read;
616     didl_ptr->write=diskio_data_list->write;
617     free(diskio_data_list->name);
618     free(diskio_data_list);
619     }else{
620     diskio_data_list->next=machine_data_list->diskio_data_list;
621     machine_data_list->diskio_data_list=diskio_data_list;
622     }
623     }
624    
625    
626    
627     ele=ele->next;
628     }
629     cur=cur->next;
630     }
631    
632     /* Append data we want thats not stored in the server */
633     machine_data_list->cpu_used=100.00-machine_data_list->cpu_idle;
634     machine_data_list->memory_used_pecent=((double)machine_data_list->memory_used / (double)machine_data_list->memory_total) * 100.00;
635     machine_data_list->swap_used_pecent=((double)machine_data_list->swap_used / (double)machine_data_list->swap_total) * 100.00;
636    
637     ndl_ptr=machine_data_list->network_data_list;
638     machine_data_list->network_io_total_tx=0;
639     machine_data_list->network_io_total_rx=0;
640     while(ndl_ptr!=NULL){
641     machine_data_list->network_io_total_tx+=ndl_ptr->tx;
642     machine_data_list->network_io_total_rx+=ndl_ptr->rx;
643     ndl_ptr=ndl_ptr->next;
644     }
645 pajs 1.7 machine_data_list->network_io_total=machine_data_list->network_io_total_rx+machine_data_list->network_io_total_tx;
646 pajs 1.1
647     didl_ptr=machine_data_list->diskio_data_list;
648     machine_data_list->disk_io_total_read=0;
649     machine_data_list->disk_io_total_write=0;
650     while(didl_ptr!=NULL){
651     machine_data_list->disk_io_total_read+=didl_ptr->read;
652     machine_data_list->disk_io_total_write+=didl_ptr->write;
653     didl_ptr=didl_ptr->next;
654     }
655 pajs 1.7 machine_data_list->disk_io_total=machine_data_list->disk_io_total_read+machine_data_list->disk_io_total_write;
656 pajs 1.1
657     xmlFreeDoc(doc);
658    
659     return num_hosts;
660    
661    
662     }
663    
664 pajs 1.14 void display(machine_data_list_t *machine_data_list, display_config_t *display_config, int *title){
665 pajs 1.1 int line_num=4;
666 pajs 1.7 int counter;
667 pajs 1.2 int x=1;
668    
669     if(*title){
670 pajs 1.8 clear();
671 pajs 1.14 move (display_config->maxy-3, 1);
672 pajs 1.7 printw("Sorting by %-64s", display_config->sortby);
673 pajs 1.14 move (display_config->maxy-2, 1);
674     if(display_config->units == 'b'){
675     printw("Units are measured in bytes/sec");
676     }
677     if(display_config->units == 'k'){
678     printw("Units are measured in kilobytes/sec");
679     }
680     if(display_config->units == 'm'){
681     printw("Units are measured in megabytes/sec");
682     }
683 pajs 1.7
684 pajs 1.4 move(1,1);
685     printw("%-11s", "Hostname");
686 pajs 1.2 x=x+11+1;
687 pajs 1.14 if(display_config->cpu_used && (display_config->maxx > x+6)){
688 pajs 1.4 move(1,x);
689     printw("%5s", "CPU");
690     move(2,x);
691     printw("%5s", "used%");
692 pajs 1.2 x+=6;
693     }
694 pajs 1.14 if(display_config->load_1 && (display_config->maxx > x+6)){
695 pajs 1.4 move(1,x);
696     printw("%5s", "Load");
697     move(2,x);
698     printw("%5s", "(1m)");
699 pajs 1.2 x+=6;
700     }
701 pajs 1.15
702 pajs 1.14 if(display_config->pages_in && (display_config->maxx > x+6)){
703 pajs 1.4 move(1,x);
704     printw("%5s", "Page");
705     move(2,x);
706     printw("%5s", "ins");
707 pajs 1.2 x+=6;
708     }
709 pajs 1.15
710 pajs 1.14 if(display_config->pages_out && (display_config->maxx > x+6)){
711 pajs 1.4 move(1,x);
712     printw("%5s", "Page");
713     move(2,x);
714     printw("%5s", "outs");
715 pajs 1.2 x+=6;
716     }
717 pajs 1.15
718 pajs 1.14 if(display_config->memory_used_pecent && (display_config->maxx > x+6)){
719 pajs 1.4 move(1,x);
720     printw("%5s", "Mem");
721     move(2,x);
722     printw("%5s", "used");
723 pajs 1.2 x+=6;
724     }
725 pajs 1.15
726 pajs 1.14 if(display_config->swap_used_pecent && (display_config->maxx > x+6)){
727 pajs 1.4 move(1,x);
728     printw("%5s", "Swap");
729     move(2,x);
730     printw("%5s", "used");
731 pajs 1.2 x+=6;
732     }
733 pajs 1.15
734 pajs 1.14 if(display_config->network_io_total_rx){
735     if(display_config->units=='b' && (display_config->maxx > x+9)){
736     move(1,x);
737     printw("%8s", "Net");
738     move(2,x);
739     printw("%8s", "rx");
740     x+=9;
741     }
742 pajs 1.15
743 pajs 1.14 if(display_config->units=='k' && (display_config->maxx > x+6)){
744     move(1,x);
745     printw("%5s", "Net");
746     move(2,x);
747     printw("%5s", "rx");
748     x+=6;
749     }
750 pajs 1.15
751     if(display_config->units=='m' && (display_config->maxx > x+6)){
752 pajs 1.14 move(1,x);
753 pajs 1.15 printw("%5s", "Net");
754 pajs 1.14 move(2,x);
755 pajs 1.15 printw("%5s", "rx");
756     x+=6;
757 pajs 1.14 }
758 pajs 1.15
759 pajs 1.2 }
760 pajs 1.15
761 pajs 1.2 if(display_config->network_io_total_tx){
762 pajs 1.14 if(display_config->units=='b' && (display_config->maxx > x+9)){
763     move(1,x);
764     printw("%8s", "Net");
765     move(2,x);
766     printw("%8s", "tx");
767     x+=9;
768     }
769 pajs 1.15
770 pajs 1.14 if(display_config->units=='k' && (display_config->maxx > x+6)){
771     move(1,x);
772     printw("%5s", "Net");
773     move(2,x);
774     printw("%5s", "tx");
775     x+=6;
776     }
777 pajs 1.15
778     if(display_config->units=='m' && (display_config->maxx > x+6)){
779 pajs 1.14 move(1,x);
780 pajs 1.15 printw("%5s", "Net");
781 pajs 1.14 move(2,x);
782 pajs 1.15 printw("%5s", "tx");
783     x+=6;
784 pajs 1.14 }
785 pajs 1.15
786 pajs 1.2 }
787 pajs 1.14
788 pajs 1.2 if(display_config->disk_io_total_read){
789 pajs 1.14 if(display_config->units=='b' && (display_config->maxx > x+10)){
790     move(1,x);
791     printw("%9s", "Disk");
792     move(2,x);
793     printw("%9s", "read");
794     x+=10;
795     }
796 pajs 1.15
797 pajs 1.14 if(display_config->units=='k' && (display_config->maxx > x+7)){
798     move(1,x);
799     printw("%6s", "Disk");
800     move(2,x);
801     printw("%6s", "read");
802     x+=7;
803     }
804 pajs 1.15
805     if(display_config->units=='m' && (display_config->maxx > x+7)){
806 pajs 1.14 move(1,x);
807 pajs 1.15 printw("%6s", "Disk");
808 pajs 1.14 move(2,x);
809 pajs 1.15 printw("%6s", "read");
810     x+=7;
811 pajs 1.14 }
812 pajs 1.15
813 pajs 1.2 }
814 pajs 1.14
815 pajs 1.2 if(display_config->disk_io_total_read){
816 pajs 1.14 if(display_config->units=='b' && (display_config->maxx > x+10)){
817     move(1,x);
818     printw("%9s", "Disk");
819     move(2,x);
820     printw("%9s", "write");
821     x+=10;
822     }
823 pajs 1.15
824 pajs 1.14 if(display_config->units=='k' && (display_config->maxx > x+7)){
825     move(1,x);
826     printw("%6s", "Disk");
827     move(2,x);
828     printw("%6s", "write");
829     x+=7;
830     }
831 pajs 1.15
832     if(display_config->units=='m' && (display_config->maxx > x+7)){
833 pajs 1.14 move(1,x);
834 pajs 1.15 printw("%6s", "Disk");
835 pajs 1.14 move(2,x);
836 pajs 1.15 printw("%6s", "write");
837     x+=7;
838 pajs 1.14 }
839 pajs 1.15
840 pajs 1.2 }
841 pajs 1.15
842     if(display_config->processes && (display_config->maxx > x+25)){
843     move(1,x);
844     printw("%-24s", " Number of Process");
845     move(2,x);
846     printw("%-24s", " Run Slep Zomb Stop Tot");
847     x+=25;
848     }
849    
850 pajs 1.2 *title=0;
851     }
852 pajs 1.1
853 pajs 1.7 /* Counter starts at 8, for padding (eg, headers, borders etc) */
854 pajs 1.14 for(counter=8;counter<display_config->maxy;counter++){
855 pajs 1.1 if(machine_data_list==NULL) break;
856 pajs 1.4 move(line_num++, 1);
857     printw("%-11s", machine_data_list->sysname);
858 pajs 1.14 x=13;
859 pajs 1.2
860 pajs 1.14 if(display_config->cpu_used && (display_config->maxx > x+6)){
861     printw(" %5.1f", machine_data_list->cpu_used);
862     x+=6;
863     }
864     if(display_config->load_1 && (display_config->maxx > x+6)){
865     printw(" %5.1f", machine_data_list->load_1);
866     x+=6;
867     }
868     if(display_config->pages_in && (display_config->maxx > x+6)){
869     printw(" %5d", machine_data_list->pages_in);
870     x+=6;
871     }
872     if(display_config->pages_out && (display_config->maxx > x+6)){
873     printw(" %5d", machine_data_list->pages_out);
874     x+=6;
875     }
876     if(display_config->memory_used_pecent && (display_config->maxx > x+6)){
877     printw(" %5.1f", machine_data_list->memory_used_pecent);
878     x+=6;
879     }
880     if(display_config->swap_used_pecent && (display_config->maxx > x+6)){
881     printw(" %5.1f", machine_data_list->swap_used_pecent);
882     x+=6;
883     }
884    
885     if(display_config->network_io_total_rx){
886     if(display_config->units=='b' && (display_config->maxx > x+9)){
887     printw(" %8lld", machine_data_list->network_io_total_rx);
888     x+=9;
889     }
890     if(display_config->units=='k' && (display_config->maxx > x+6)){
891     printw(" %5lld", machine_data_list->network_io_total_rx/1024);
892     x+=6;
893     }
894 pajs 1.15 if(display_config->units=='m' && (display_config->maxx > x+6)){
895     printw(" %5.2f", (double)(machine_data_list->network_io_total_rx/(1024.00*1024.00)));
896     x+=6;
897 pajs 1.14 }
898     }
899    
900     if(display_config->network_io_total_tx){
901     if(display_config->units=='b' && (display_config->maxx > x+9)){
902     printw(" %8lld", machine_data_list->network_io_total_tx);
903     x+=9;
904     }
905     if(display_config->units=='k' && (display_config->maxx > x+6)){
906     printw(" %5lld", machine_data_list->network_io_total_tx/1024);
907     x+=6;
908     }
909 pajs 1.15 if(display_config->units=='m' && (display_config->maxx > x+6)){
910     printw(" %5.2f", (double)(machine_data_list->network_io_total_tx/(1024.00*1024.00)));
911     x+=6;
912 pajs 1.14 }
913     }
914    
915     if(display_config->disk_io_total_read){
916     if(display_config->units=='b' && (display_config->maxx > x+10)){
917     printw(" %9lld", machine_data_list->disk_io_total_read);
918     x+=10;
919     }
920     if(display_config->units=='k' && (display_config->maxx > x+7)){
921     printw(" %6lld", machine_data_list->disk_io_total_read/1024);
922     x+=7;
923     }
924 pajs 1.15 if(display_config->units=='m' && (display_config->maxx > x+7)){
925     printw(" %6.2f", (double)(machine_data_list->disk_io_total_read/(1024.00*1024.00)));
926     x+=7;
927 pajs 1.14 }
928     }
929    
930     if(display_config->disk_io_total_write){
931     if(display_config->units=='b' && (display_config->maxx > x+10)){
932     printw(" %9lld", machine_data_list->disk_io_total_write);
933     x+=10;
934     }
935     if(display_config->units=='k' && (display_config->maxx > x+7)){
936     printw(" %6lld", machine_data_list->disk_io_total_write/1024);
937     x+=7;
938     }
939 pajs 1.15 if(display_config->units=='m' && (display_config->maxx > x+7)){
940     printw(" %6.2f", (double)(machine_data_list->disk_io_total_write/(1024.00*1024.00)));
941     x+=7;
942 pajs 1.14 }
943     }
944 pajs 1.15 if(display_config->processes && display_config->maxx > x+25){
945     printw(" %4d %4d %4d %4d %4d", machine_data_list->processes_cpu, \
946     machine_data_list->processes_sleeping, \
947     machine_data_list->processes_zombie, \
948     machine_data_list->processes_stopped, \
949     machine_data_list->processes_total);
950     x+=25;
951     }
952 pajs 1.2
953 pajs 1.1 machine_data_list=machine_data_list->next;
954     }
955    
956 pajs 1.2
957 pajs 1.4 refresh();
958 pajs 1.1
959     }
960    
961 pajs 1.15 void sig_winch_handler(int sig){
962    
963     sig_winch=1;
964     signal(SIGWINCH, sig_winch_handler);
965     }
966    
967 tdb 1.17 void usage() {
968     printf("Usage: idar [-o order] [-s server] [-p port] [-l list] [-h]\n\n");
969     printf(" -o Sets the initial sort order. Accepted arguments are one of:\n");
970     printf(" cpu load mem swap net disk\n");
971     printf(" -s Specifies the i-scream server to connect to.\n");
972     printf(" default: %s\n", DEF_SERVER_NAME);
973     printf(" -p Specifies the i-scream server port.\n");
974     printf(" default: %d\n", DEF_SERVER_PORT);
975 tdb 1.18 printf(" -l Sets the list of hosts to monitor in a semi-colon separated list.\n");
976 tdb 1.17 printf(" -h Displays this help information.\n");
977     printf("\nReport bugs to <%s>.\n", PACKAGE_BUGREPORT);
978     exit(1);
979     }
980    
981 pajs 1.1 int main(int argc, char **argv){
982 pajs 1.4 WINDOW *window;
983 pajs 1.5 fd_set infds;
984 pajs 1.13 struct winsize size;
985 pajs 1.4
986 pajs 1.1 FILE *control;
987     FILE *data;
988    
989     char *machine_list=NULL;
990     char *response=NULL;
991    
992 tdb 1.17 char *server_name;
993 pajs 1.1 int server_control_port;
994     int server_data_port;
995    
996     machine_data_list_t *machine_data_list=NULL;
997    
998     int num_hosts;
999 pajs 1.7 int title=1;
1000 pajs 1.1
1001     int cmdopt;
1002     extern int optind;
1003     extern char *optarg;
1004 pajs 1.15
1005     extern int errno;
1006 pajs 1.1
1007     display_config_t display_config;
1008 pajs 1.4 char ch;
1009    
1010 pajs 1.5 int data_fileno, stdin_fileno, biggest_fileno;
1011    
1012 pajs 1.4 sortby_ptr=NULL;
1013 pajs 1.1
1014     /* What to display defaults */
1015 pajs 1.14 display_config.units='b';
1016    
1017 pajs 1.1 display_config.cpu_user=0;
1018     display_config.cpu_idle=0;
1019     display_config.cpu_iowait=0;
1020     display_config.cpu_kernel=0;
1021     display_config.cpu_swap=0;
1022     display_config.cpu_used=1;
1023    
1024     display_config.memory_total=0;
1025     display_config.memory_free=0;
1026     display_config.memory_used=0;
1027     display_config.memory_used_pecent=1;
1028    
1029     display_config.swap_total=0;
1030     display_config.swap_free=0;
1031     display_config.swap_used=0;
1032     display_config.swap_used_pecent=1;
1033    
1034     display_config.load_1=1;
1035     display_config.load_5=0;
1036     display_config.load_15=0;
1037    
1038     display_config.pages_in=1;
1039     display_config.pages_out=1;
1040    
1041 pajs 1.15 display_config.processes=1;
1042 pajs 1.1
1043 pajs 1.2 display_config.network_io_total_tx=1;
1044     display_config.network_io_total_rx=1;
1045 pajs 1.8 display_config.network_all_stats=0;
1046 pajs 1.1
1047 pajs 1.8 display_config.disk_io_total_write=1;
1048     display_config.disk_io_total_read=1;
1049 pajs 1.2 display_config.disk_io_all_stats=0;
1050 pajs 1.1
1051     display_config.disk_total_used=0;
1052 pajs 1.15 display_config.disk_all_stats=0;
1053    
1054     signal(SIGWINCH, sig_winch_handler);
1055 pajs 1.1
1056 tdb 1.17 server_name=DEF_SERVER_NAME;
1057     server_control_port=DEF_SERVER_PORT;
1058    
1059     while((cmdopt=getopt(argc, argv, "o:s:p:l:h")) != -1){
1060 pajs 1.1 switch(cmdopt){
1061 tdb 1.17 case 'o':
1062 pajs 1.2 if(!strcmp(optarg, "cpu")){
1063     sortby_ptr=cmp_cpu_used;
1064 pajs 1.7 strlcpy(display_config.sortby, CPU_USED, SORTBYMAXNAME);
1065 pajs 1.2 }
1066     if(!strcmp(optarg, "load")){
1067     sortby_ptr=cmp_load_1;
1068 pajs 1.7 strlcpy(display_config.sortby, LOAD, SORTBYMAXNAME);
1069 pajs 1.2 }
1070     if(!strcmp(optarg, "mem")){
1071     sortby_ptr=cmp_memory_used_pecent;
1072 pajs 1.7 strlcpy(display_config.sortby, MEM, SORTBYMAXNAME);
1073 pajs 1.2 }
1074 pajs 1.7 if(!strcmp(optarg, "swap")){
1075 tdb 1.17 sortby_ptr=cmp_swap_used_pecent;
1076     strlcpy(display_config.sortby, SWAP, SORTBYMAXNAME);
1077     }
1078     if(!strcmp(optarg, "net")){
1079     sortby_ptr=cmp_network_io_total;
1080     strlcpy(display_config.sortby, NETIO, SORTBYMAXNAME);
1081     }
1082     if(!strcmp(optarg, "disk")){
1083     sortby_ptr=cmp_disk_io_total;
1084     strlcpy(display_config.sortby, DISKIO, SORTBYMAXNAME);
1085     }
1086 pajs 1.2 if(sortby_ptr==NULL){
1087 tdb 1.17 errf("Invalid order given.");
1088     usage();
1089 pajs 1.2 }
1090 tdb 1.17 break;
1091     case 's':
1092     server_name=optarg;
1093     break;
1094     case 'p':
1095     server_control_port=atoi(optarg);
1096     break;
1097     case 'l':
1098     /* We've been passed a machine list */
1099     /* list currently needs to be ; seperated */
1100     machine_list=strdup(optarg);
1101     break;
1102     case 'h':
1103 tdb 1.19 default:
1104 tdb 1.17 usage();
1105     break;
1106 pajs 1.1 }
1107     }
1108    
1109 tdb 1.17 /* Don't take any other arguments */
1110     if(argc>optind){
1111     usage();
1112     }
1113    
1114 pajs 1.7 if(sortby_ptr==NULL){
1115     sortby_ptr=cmp_cpu_used;
1116     strlcpy(display_config.sortby, "CPU Used", SORTBYMAXNAME);
1117     }
1118 pajs 1.1
1119 tdb 1.17 control=create_tcp_connection(server_name, server_control_port);
1120 pajs 1.1 if(control==NULL){
1121     errf("Failed to connect (%m)");
1122 pajs 1.12 exit(1);
1123 pajs 1.1 }
1124    
1125     if((tcp_comm(control, NULL, &response, "PROTOCOL 1.1"))!=0){
1126     errf("Incorrect version number (%s)", response);
1127     exit(1);
1128     }
1129    
1130     if((tcp_comm(control, "stattop", &response, "OK"))!=0){
1131     errf("Unexpected response %s", response);
1132     exit(1);
1133     }
1134    
1135     if(machine_list!=NULL){
1136     if((tcp_comm(control, "SETHOSTLIST", &response, "OK"))!=0){
1137     errf("Unexpected response %s", response);
1138     exit(1);
1139     }
1140     if((tcp_comm(control, machine_list, &response, "OK"))!=0){
1141     errf("Unexpected response %s", response);
1142     exit(1);
1143     }
1144     }
1145    
1146     if((tcp_comm(control, "STARTDATA", &response, NULL))!=0){
1147     errf("Unexpected response %s", response);
1148     exit(1);
1149     }
1150    
1151     server_data_port=atoi(response);
1152     if(server_data_port==0){
1153     errf("Unexpected response %s", response);
1154     exit(1);
1155     }
1156    
1157 tdb 1.17 data=create_tcp_connection(server_name, server_data_port);
1158 pajs 1.1 if(data==NULL){
1159 tdb 1.17 errf("Failed to connect to host %s on port %d (%m)",server_name, server_data_port);
1160 pajs 1.13 exit(1);
1161 pajs 1.1 }
1162    
1163 pajs 1.4 initscr();
1164     nonl();
1165     cbreak();
1166 pajs 1.15 noecho();
1167 pajs 1.4 window=newwin(0, 0, 0, 0);
1168 pajs 1.14 getmaxyx(window, display_config.maxy, display_config.maxx);
1169 pajs 1.4
1170 pajs 1.5 stdin_fileno=fileno(stdin);
1171     data_fileno=fileno(data);
1172     biggest_fileno=(data_fileno>stdin_fileno) ? (data_fileno+1) : (stdin_fileno+1);
1173 pajs 1.7
1174 pajs 1.1 for(;;){
1175 pajs 1.5 FD_ZERO(&infds);
1176     FD_SET(stdin_fileno, &infds);
1177     FD_SET(data_fileno, &infds);
1178 pajs 1.13 if((select(biggest_fileno, &infds, NULL, NULL, NULL))==-1){
1179 pajs 1.15 if(errno!=EINTR){
1180     errf("select failed with (%m)");
1181     exit(1);
1182     }
1183     }
1184    
1185     if(sig_winch){
1186 pajs 1.13 if (ioctl(fileno(stdout), TIOCGWINSZ, &size) == 0) {
1187     resizeterm(size.ws_row, size.ws_col);
1188     wrefresh(curscr);
1189     }
1190 pajs 1.14 getmaxyx(window, display_config.maxy, display_config.maxx);
1191 pajs 1.13 title=1;
1192 pajs 1.14 display(machine_data_list, &display_config, &title);
1193 pajs 1.13 refresh();
1194 pajs 1.15 sig_winch=0;
1195 pajs 1.13 continue;
1196     }
1197 pajs 1.5
1198     if(FD_ISSET(stdin_fileno, &infds)){
1199    
1200 pajs 1.15 ch=getch();
1201 pajs 1.7 switch(ch){
1202 pajs 1.15 case KEY_RESIZE:
1203     sig_winch=1;
1204     break;
1205 pajs 1.8
1206     /* Quit */
1207 pajs 1.7 case 'Q':
1208     case 'q':
1209     endwin();
1210     exit(0);
1211     break;
1212 pajs 1.14 /* Units */
1213     case 'U':
1214     case 'u':
1215     if(display_config.units == 'b'){
1216     display_config.units = 'k';
1217     }else if(display_config.units == 'k'){
1218     display_config.units = 'm';
1219     }else{
1220     display_config.units = 'b';
1221     }
1222     break;
1223 pajs 1.7
1224 pajs 1.8 /* Sort by */
1225 pajs 1.7 case 'C':
1226     sortby_ptr=cmp_cpu_used;
1227     strlcpy(display_config.sortby, CPU_USED, SORTBYMAXNAME);
1228     break;
1229    
1230     case 'M':
1231     sortby_ptr=cmp_memory_used_pecent;
1232     strlcpy(display_config.sortby, MEM, SORTBYMAXNAME);
1233     break;
1234    
1235     case 'L':
1236     sortby_ptr=cmp_load_1;
1237     strlcpy(display_config.sortby, LOAD, SORTBYMAXNAME);
1238     break;
1239    
1240     case 'S':
1241     sortby_ptr=cmp_swap_used_pecent;
1242     strlcpy(display_config.sortby, SWAP, SORTBYMAXNAME);
1243     break;
1244    
1245     case 'N':
1246     if(sortby_ptr==cmp_network_io_total){
1247     strlcpy(display_config.sortby, NETIORX, SORTBYMAXNAME);
1248     sortby_ptr=cmp_network_io_total_rx;
1249     }else if(sortby_ptr==cmp_network_io_total_rx){
1250     strlcpy(display_config.sortby, NETIOTX, SORTBYMAXNAME);
1251     sortby_ptr=cmp_network_io_total_tx;
1252     }else{
1253     strlcpy(display_config.sortby, NETIO, SORTBYMAXNAME);
1254     sortby_ptr=cmp_network_io_total;
1255     }
1256     break;
1257 pajs 1.8 case 'D':
1258     if(sortby_ptr==cmp_disk_io_total){
1259     strlcpy(display_config.sortby, DISKIOR, SORTBYMAXNAME);
1260     sortby_ptr=cmp_disk_io_total_read;
1261     }else if(sortby_ptr==cmp_disk_io_total_read){
1262     strlcpy(display_config.sortby, DISKIOW, SORTBYMAXNAME);
1263     sortby_ptr=cmp_disk_io_total_write;
1264     }else{
1265     strlcpy(display_config.sortby, DISKIO, SORTBYMAXNAME);
1266     sortby_ptr=cmp_disk_io_total;
1267     }
1268     break;
1269    
1270     /* Display */
1271    
1272     case 'd':
1273     if(display_config.disk_io_total_read){
1274     display_config.disk_io_total_read=0;
1275     display_config.disk_io_total_write=0;
1276     }else{
1277     display_config.disk_io_total_read=1;
1278     display_config.disk_io_total_write=1;
1279     }
1280     break;
1281     case 'n':
1282     if(display_config.network_io_total_rx){
1283     display_config.network_io_total_rx=0;
1284     display_config.network_io_total_tx=0;
1285     }else{
1286     display_config.network_io_total_rx=1;
1287     display_config.network_io_total_tx=1;
1288     }
1289     break;
1290     case 'm':
1291     if(display_config.memory_used_pecent){
1292     display_config.memory_used_pecent=0;
1293     }else{
1294     display_config.memory_used_pecent=1;
1295     }
1296     break;
1297    
1298     case 's':
1299     if(display_config.swap_used_pecent){
1300     display_config.swap_used_pecent=0;
1301     }else{
1302     display_config.swap_used_pecent=1;
1303     }
1304     break;
1305     case 'l':
1306     if(display_config.load_1){
1307     display_config.load_1=0;
1308     }else{
1309     display_config.load_1=1;
1310     }
1311     break;
1312     case 'p':
1313     if(display_config.pages_in){
1314     display_config.pages_in=0;
1315     display_config.pages_out=0;
1316     }else{
1317     display_config.pages_in=1;
1318     display_config.pages_out=1;
1319     }
1320     break;
1321     case 'c':
1322     if(display_config.cpu_used){
1323     display_config.cpu_used=0;
1324     }else{
1325     display_config.cpu_used=1;
1326     }
1327     break;
1328 pajs 1.15 case 'r':
1329     if(display_config.processes){
1330     display_config.processes=0;
1331     }else{
1332     display_config.processes=1;
1333     }
1334     break;
1335 pajs 1.5
1336 pajs 1.8 default:
1337 pajs 1.15 continue;
1338 pajs 1.5 }
1339 pajs 1.8
1340     /* Increment title so it becomes true (and making the screen update */
1341     title++;
1342 pajs 1.7
1343 pajs 1.5 }
1344     if(FD_ISSET(data_fileno, &infds)){
1345     response=fpgetline(data);
1346     if (response==NULL){
1347     errf("Failed to read data (%m)");
1348     exit(1);
1349     }
1350 pajs 1.1 }
1351    
1352 pajs 1.4
1353 pajs 1.1 num_hosts=parse_xml(response, &machine_data_list);
1354     if(num_hosts==-1) continue;
1355 pajs 1.2 machine_data_list=sort_machine_stats(machine_data_list, num_hosts, sortby_ptr);
1356 pajs 1.14 display(machine_data_list, &display_config, &title);
1357 pajs 1.1
1358     }
1359     exit(0);
1360     }