/* * Copyright (c) 2004 Teodor Sigaev * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the author nor the names of any co-contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY CONTRIBUTORS ``AS IS'' AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL CONTRIBUTORS BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #include #include #include #include #include #include #include #include #include #include #include "tlog.h" #include "connection.h" #include "tmalloc.h" #include "top.h" int main( int argc, char *argv[] ) { int ch; int debug=0; char *host="127.0.0.1"; int port=TOPD_SERVER_DEFAULT_PORT; int i; MassiveUnit *mu; TCMsg *pmsg = (TCMsg*)malloc( TCMSGHDRSZ ); TC_Connection cs; pmsg->type = TOPGETTYPE; pmsg->len = TCMSGHDRSZ; while( (ch=getopt(argc, argv, "Dh:p:"))!=-1) { switch(ch) { case 'D': debug=1; break; case 'h': host=strdup(optarg); break; case 'p': port=atoi(optarg); break; default: return 1; } } if ( debug ) opentlog( TL_OPEN_STDERR, TL_DEBUG, NULL); else opentlog( TL_OPEN_SYSLOG, TL_INFO, NULL); TC_fillConnection(&cs, host, port); cs.buf = (char*)pmsg; cs.len = pmsg->len; if ( TC_Talk(&cs) == CS_OK ) { pmsg = (TCMsg*) cs.buf; mu = (MassiveUnit*)pmsg->data; printf("\tIP\tLoad\tFree\tTotal\tData\n"); for(i=0; inumber; i++) printf("%s\t%.2f\t%.1fM\t%.1fM\t%s", inet_ntoa(mu->units[i].ip), mu->units[i].top.load, ((float) mu->units[i].top.freemem)/( 1024*1024.0 ), ((float) mu->units[i].top.usermem)/( 1024*1024.0 ), ctime( &(mu->units[i].stamp) ) ); } TC_FreeConnection(&cs); return 0; }