Exemplo n.º 1
0
int main(int argc, char *argv[]) {
    // Options
    std::vector<String> opt(3);
    opt[0] = "all";
    opt[1] = "bytes";
    opt[2] = "host";

    // Error if there are not 3 things on the command line
    if (argc != 3)
        { output_usage_and_exit(argv[0], opt); }

    // Open file, quit if open fails
    std::ifstream in(argv[2]);
    if (!in)
        { std::cerr << "Couldn't open " << argv[2] << "\n"; exit(2); }

    // Process the log file
    std::vector<LogEntry> log_entries = parse(in);

    // Close the in file
    in.close();

    // Handle the specified option
   
    String option(argv[1]);
   
    if (option == opt[0]) {
       
      // Output everything
        output_all(std::cout, log_entries);
    }
    else if (option == opt[1]) {
      
      // Output total number of bytes
        std::cout << "Total number of bytes sent: " 
                  << byte_count(log_entries) << std::endl;
    }
    else if (option == opt[2]) {
       
      // Host names will be out-putted here
        by_host(std::cout, log_entries);
    }
    else    {
       
        std::cerr << "Unrecognized option: " << option << std::endl;
        std::cerr << "Recognized options: " 
             << opt[0] << " "
             << opt[1] << " "
             << opt[2] << std::endl;
    }

    return 0;
}
Exemplo n.º 2
0
int main(int argc, char *argv[])
{
	int ch = 0;
	struct timeval tv_last, tv;
	unsigned i;

	atexit(cleanup);
	setup_connections(argc, argv);
	init_ncurses(global.num_clamd, default_colors);

	memset(&tv_last, 0, sizeof(tv_last));
	do {
		if (toupper(ch) == 'H') {
			ch = show_help();
		}
		switch(ch) {
			case KEY_RESIZE:
				resize();
				endwin();
				refresh();
				init_windows(global.num_clamd);
				break;
			case 'R':
			case 'r':
				for (i=0;i<global.num_clamd;i++)
					global.all_stats[i].biggest_queue = 1;
				biggest_mem = 0;
				break;
			case KEY_UP:
				if (global.num_clamd > 1) {
					if (detail_selected == -1)
						detail_selected = global.num_clamd-1;
					else
						--detail_selected;
				}
				break;
			case KEY_DOWN:
				if (global.num_clamd > 1) {
					if (detail_selected == -1)
						detail_selected = 0;
					else {
						if((unsigned)++detail_selected >= global.num_clamd)
							detail_selected = -1;
					}
				}
				break;
		}
		gettimeofday(&tv, NULL);
		header();
		if(tv.tv_sec - tv_last.tv_sec >= MIN_INTERVAL) {
			free_global_stats();
			for(i=0;i<global.num_clamd;i++) {
				unsigned biggest_q;
				struct stats *stats = &global.all_stats[i];
				if (global.conn[i].sd != -1)
					send_string(&global.conn[i], "nSTATS\n");
				biggest_q = stats->biggest_queue;
				memset(stats, 0, sizeof(*stats));
				stats->biggest_queue = biggest_q;
				parse_stats(&global.conn[i], stats, i);
			}
			if (global.tasks)
				qsort(global.tasks, global.n, sizeof(*global.tasks), tasks_compare);
			tv_last = tv;
		}
		/* always show, so that screen resizes take effect instantly*/
		output_all();
		for(i=0;i<global.num_clamd;i++) {
			if (global.conn[i].sd == -1)
				reconnect(&global.conn[i]);
		}
	} while(toupper(ch = getch()) != 'Q');
	free_global_stats();
	normal_exit = 1;
	return 0;
}