| 1 |
|
/* |
| 2 |
|
* i-scream central monitoring system |
| 3 |
< |
* http://www.i-scream.org.uk |
| 4 |
< |
* Copyright (C) 2000-2002 i-scream |
| 3 |
> |
* http://www.i-scream.org |
| 4 |
> |
* Copyright (C) 2000-2003 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 |
| 23 |
|
* a total |
| 24 |
|
* Takes several arguments : |
| 25 |
|
* -d <number> Takes the number of seconds to wait to get traffic sent since last call |
| 26 |
< |
* Note, this is not network traffic per second. Its the traffic since last |
| 27 |
< |
* call. If you want it traffic per second averaged over time since last call |
| 26 |
> |
* Note, this is not network traffic per second. Its the traffic since last |
| 27 |
> |
* call. If you want it traffic per second averaged over time since last call |
| 28 |
|
* You need to divide against the time since last time this was called. The time |
| 29 |
|
* between 2 calls is stored in systime in the network_stat_t structure. |
| 30 |
|
* -b Display in bytes |
| 31 |
|
* -k Display in kilobytes |
| 32 |
< |
* -m Display in megabytes |
| 32 |
> |
* -m Display in megabytes |
| 33 |
|
*/ |
| 34 |
|
|
| 35 |
|
#include <stdio.h> |
| 51 |
|
int num_network_stats; |
| 52 |
|
|
| 53 |
|
/* Parse command line options */ |
| 54 |
< |
while ((c = getopt(argc, argv, "d:bkm")) != EOF){ |
| 54 |
> |
while ((c = getopt(argc, argv, "d:bkm")) != -1){ |
| 55 |
|
switch (c){ |
| 56 |
|
case 'd': |
| 57 |
|
delay = atoi(optarg); |
| 68 |
|
} |
| 69 |
|
} |
| 70 |
|
|
| 71 |
< |
/* We are not intrested in the amount of traffic ever transmitted, just differences. |
| 71 |
> |
/* Initialise statgrab */ |
| 72 |
> |
statgrab_init(); |
| 73 |
> |
|
| 74 |
> |
/* We are not interested in the amount of traffic ever transmitted, just differences. |
| 75 |
|
* Because of this, we do nothing for the very first call. |
| 76 |
|
*/ |
| 77 |
< |
|
| 77 |
> |
|
| 78 |
|
network_stats = get_network_stats_diff(&num_network_stats); |
| 79 |
|
if (network_stats == NULL){ |
| 80 |
|
perror("Error. Failed to get network stats"); |
| 83 |
|
|
| 84 |
|
/* Clear the screen ready for display the network stats */ |
| 85 |
|
printf("\033[2J"); |
| 86 |
< |
|
| 86 |
> |
|
| 87 |
|
/* Keep getting the network stats */ |
| 88 |
|
while ( (network_stats = get_network_stats_diff(&num_network_stats)) != NULL){ |
| 89 |
|
int x; |
| 103 |
|
break; |
| 104 |
|
case 'k': |
| 105 |
|
printf("\033[%d;2H%-25s : %5lld k", line_number++, "Network Interface Rx", (network_stats->rx / 1024)); |
| 106 |
< |
printf("\033[%d;2H%-25s : %5lld", line_number++, "Network Interface Tx", (network_stats->tx / 1024)); |
| 107 |
< |
break; |
| 106 |
> |
printf("\033[%d;2H%-25s : %5lld", line_number++, "Network Interface Tx", (network_stats->tx / 1024)); |
| 107 |
> |
break; |
| 108 |
|
case 'm': |
| 109 |
|
printf("\033[%d;2H%-25s : %5.2f m", line_number++, "Network Interface Rx", network_stats->rx / (1024.00*1024.00)); |
| 110 |
|
printf("\033[%d;2H%-25s : %5.2f m", line_number++, "Network Interface Tx", network_stats->tx / (1024.00*1024.00)); |
| 111 |
|
} |
| 112 |
|
printf("\033[%d;2H%-25s : %ld ", line_number++, "Network Interface systime", (long) network_stats->systime); |
| 113 |
< |
|
| 113 |
> |
|
| 114 |
|
/* Add a blank line between interfaces */ |
| 115 |
|
line_number++; |
| 116 |
|
|
| 122 |
|
* to keep track of the orginal pointer to free later */ |
| 123 |
|
network_stats++; |
| 124 |
|
} |
| 125 |
< |
|
| 125 |
> |
|
| 126 |
|
printf("\033[%d;2H%-25s : %-10s", line_number++, "Network Interface Name", "Total Network IO"); |
| 127 |
|
switch(units){ |
| 128 |
|
case 'b': |
| 138 |
|
printf("\033[%d;2H%-25s : %5.2f m", line_number++, "Network Total Tx", (total_tx / (1024.00*1024.00))); |
| 139 |
|
break; |
| 140 |
|
} |
| 141 |
< |
|
| 141 |
> |
|
| 142 |
|
fflush(stdout); |
| 143 |
|
|
| 144 |
|
sleep(delay); |