2 * Copyright (c) 2004 Teodor Sigaev <teodor@sigaev.ru>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the author nor the names of any co-contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY CONTRIBUTORS ``AS IS'' AND ANY EXPRESS
18 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL CONTRIBUTORS BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
23 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 #include <sys/sysctl.h>
36 #include <sys/types.h>
38 #include <sys/socket.h>
39 #include <netinet/in.h>
40 #include <arpa/inet.h>
43 #include "connection.h"
48 main( int argc, char *argv[] ) {
51 char *host="127.0.0.1";
52 int port=TOPD_SERVER_DEFAULT_PORT;
56 TCMsg *pmsg = (TCMsg*)malloc( TCMSGHDRSZ );
59 pmsg->type = TOPGETTYPE;
60 pmsg->len = TCMSGHDRSZ;
62 while( (ch=getopt(argc, argv, "Dh:p:"))!=-1) {
79 opentlog( TL_OPEN_STDERR, TL_DEBUG, NULL);
81 opentlog( TL_OPEN_SYSLOG, TL_INFO, NULL);
83 TC_fillConnection(&cs, host, port);
86 if ( TC_Talk(&cs) == CS_OK ) {
87 pmsg = (TCMsg*) cs.buf;
88 mu = (MassiveUnit*)pmsg->data;
90 printf("\tIP\tLoad\tFree\tTotal\tData\n");
91 for(i=0; i<mu->number; i++)
92 printf("%s\t%.2f\t%.1fM\t%.1fM\t%s",
93 inet_ntoa(mu->units[i].ip),
94 mu->units[i].top.load,
95 ((float) mu->units[i].top.freemem)/( 1024*1024.0 ),
96 ((float) mu->units[i].top.usermem)/( 1024*1024.0 ),
97 ctime( &(mu->units[i].stamp) )
101 TC_FreeConnection(&cs);