#include "tmalloc.h"
#include "top.h"
+void
+usage() {
+ fputs(
+ "Copyright (c) 2004-2007 Teodor Sigaev <teodor@sigaev.ru>. All rights reserved.\n"
+ "rtop - read collected load of remote servers\n"
+ "./rtop [-D] -h HOST [-p PORT]\n"
+ " -D - debug mode\n"
+ " -h HOST - server\n"
+ " -p PRT - server's port\n",
+ stdout
+ );
+ exit(1);
+}
+
int
main( int argc, char *argv[] ) {
int ch;
int debug=0;
- char *host="127.0.0.1";
+ char *host=NULL;
int port=TOPD_SERVER_DEFAULT_PORT;
int i;
port=atoi(optarg);
break;
default:
+ usage();
return 1;
}
}
- if ( debug )
- opentlog( TL_OPEN_STDERR, TL_DEBUG, NULL);
- else
- opentlog( TL_OPEN_SYSLOG, TL_INFO, NULL);
+ if (!host)
+ usage();
+
+ opentlog( TL_OPEN_STDERR, (debug) ? TL_DEBUG : TL_INFO, NULL);
TC_fillConnection(&cs, host, port);
cs.buf = (char*)pmsg;
return TC_sendMsg(msg);
}
+void usage() {
+ fputs(
+ "Copyright (c) 2004-2007 Teodor Sigaev <teodor@sigaev.ru>. All rights reserved.\n"
+ "sendtop - small daemon to send load of box to server\n"
+ "Usage:\n"
+ "./sendtop [-D] -h HOST [-p PORT] [-s PERIOD]\n"
+ " -D - debug mode (do not daemonize, print to stderr instead of syslog)\n"
+ " -h HOST - server IP to send data\n"
+ " -p PORT - port number of server\n"
+ " -s PERIOD - period of of send (in seconds)\n",
+ stdout
+ );
+
+ exit(1);
+}
extern char *optarg;
int
int period=30;
msg.port = TOPD_SERVER_DEFAULT_PORT;
- msg.host = "127.0.0.1";
+ msg.host = NULL;
msg.msg = NULL;
msg.sockfd =-1;
debug=1;
break;
default:
+ usage();
return 1;
}
}
+ if (!msg.host)
+ usage();
+
signal(SIGCHLD, SIG_IGN);
if ( debug )
allocUnits(int n ) {
MassiveUnit *ptr = NULL;
- ptr = (MassiveUnit*)malloc( MUHDRSZ + n * sizeof(UnitInfo) );
- if ( !ptr )
- tlog(TL_CRIT|TL_EXIT, "allocUnits: no memoru for %d units", n);
+ ptr = (MassiveUnit*)tmalloc( MUHDRSZ + n * sizeof(UnitInfo) );
ptr->maxnumber = n;
ptr->number=0;
static void
inquireExit(int s) {
- continueWork=0;
+ continueWork=0;
}
-
+
extern char *optarg;
extern int optind;
+void
+usage() {
+ fputs(
+ "Copyright (c) 2004-2007 Teodor Sigaev <teodor@sigaev.ru>. All rights reserved.\n"
+ "topd - daemon to collect load data from clients\n"
+ "Usage:\n"
+ "./top [-D] -h IP [-p PORT] [-n NUMCLIENTS]\n"
+ " -D - debug mode (do not daemonize, print to stderr instead of syslog)\n"
+ " -h HOST - listen IP\n"
+ " -p PORT - listen port\n"
+ " -n NUMCLIENTS - max number of clients\n",
+ stdout
+ );
+ exit(1);
+}
int
main( int argc, char *argv[] ) {
int ch;
int child=0, listenport = TOPD_SERVER_DEFAULT_PORT;
- int n=1024;
- char *host="127.0.0.1";
+ int n=1024;
+ char *host=NULL;
memset( &cfg, 0, sizeof(TCServer) );
- while( (ch=getopt(argc, argv, "h:p:c:s:D"))!=-1) {
+ while( (ch=getopt(argc, argv, "h:p:c:D"))!=-1) {
switch(ch) {
- case 'D':
- cfg.debug=1;
- break;
- case 'h':
- host=strdup(optarg);
- break;
- case 'p':
- listenport=atoi(optarg);
- break;
- case 'n':
- n=atoi(optarg);
- break;
+ case 'D':
+ cfg.debug=1;
+ break;
+ case 'h':
+ host=strdup(optarg);
+ break;
+ case 'p':
+ listenport=atoi(optarg);
+ break;
+ case 'n':
+ n=atoi(optarg);
+ break;
default:
+ usage();
return 1;
}
}
+ if (!host);
+ usage();
+
signal(SIGCHLD, SIG_IGN);
- if ( cfg.debug )
- opentlog( TL_OPEN_STDERR, TL_DEBUG, NULL);
- else
- opentlog( TL_OPEN_SYSLOG, TL_INFO, NULL);
+ if ( cfg.debug )
+ opentlog( TL_OPEN_STDERR, TL_DEBUG, NULL);
+ else
+ opentlog( TL_OPEN_SYSLOG, TL_INFO, NULL);
if ( cfg.debug || (child = fork()) == 0 ) {
/* child */