173a380270
TTG is a small command-line utility to display the throughput (bandwidth usage) on an interface of a remote device such as a router, switch, etc., over SNMP. Unlike tools like MRTG which sample bandwidth over a relatively long interval (often 5 minutes), TTG is normally used to display throughput over as little as one second.
131 lines
4.6 KiB
Plaintext
131 lines
4.6 KiB
Plaintext
$OpenBSD: patch-ttg_c,v 1.1.1.1 2012/07/16 15:22:05 sthen Exp $
|
|
|
|
- the net-snmp package does not use PACKAGE_VERSION
|
|
|
|
- lookup interface id as specified before handling Cisco-style
|
|
abbreviations (vl5 -> Vlan5, etc)
|
|
|
|
--- ttg.c.orig Mon May 28 21:24:46 2012
|
|
+++ ttg.c Wed Jul 4 12:42:15 2012
|
|
@@ -58,7 +58,7 @@ struct snmp_session *ses;
|
|
|
|
uint64_t getcntr(int dir, oid inst);
|
|
int ifstatus(int type, oid inst);
|
|
-int lsif(char *ifname);
|
|
+int lsif(char *ifname, int);
|
|
void thr(int ifno);
|
|
void kbprint(uint64_t var);
|
|
void finish(void);
|
|
@@ -130,6 +130,7 @@ int main(int argc, char **argv) {
|
|
if((argc-optind)!=3)
|
|
usage();
|
|
|
|
+#if 0
|
|
if(strcmp(netsnmp_get_version(), PACKAGE_VERSION)!=0) {
|
|
fprintf(stderr,
|
|
"ERROR: Net-SNMP version mismatch!\n"
|
|
@@ -138,6 +139,7 @@ int main(int argc, char **argv) {
|
|
PACKAGE_VERSION, netsnmp_get_version());
|
|
exit(1);
|
|
}
|
|
+#endif
|
|
|
|
if(UINT32_MAX == UINT64_MAX) {
|
|
fprintf(stderr, "ERROR: UINT32_MAX == UINT64_MAX\n");
|
|
@@ -166,11 +168,13 @@ int main(int argc, char **argv) {
|
|
}
|
|
|
|
if(strcasecmp(argv[optind+2], "list")==0 || strcasecmp(argv[optind+2], "ls")==0)
|
|
- lsif(NULL);
|
|
+ lsif(NULL, 1);
|
|
else if(isdigit((int)argv[optind+2][0]))
|
|
thr(atoi(argv[optind+2]));
|
|
else if(strlen(argv[optind+2])>=2) {
|
|
- if(argv[optind+2][0]=='s' && argv[optind+2][1]=='e')
|
|
+ if(lsif(argv[optind+2], 0))
|
|
+ snprintf(finame, sizeof(finame), "%s", argv[optind+2]);
|
|
+ else if(argv[optind+2][0]=='s' && argv[optind+2][1]=='e')
|
|
snprintf(finame, sizeof(finame), "Serial%s", argv[optind+2]+2);
|
|
else if(argv[optind+2][0]=='e' && argv[optind+2][1]=='t')
|
|
snprintf(finame, sizeof(finame), "Ethernet%s", argv[optind+2]+2);
|
|
@@ -193,9 +197,9 @@ int main(int argc, char **argv) {
|
|
else if(argv[optind+2][0]=='t' && argv[optind+2][1]=='u')
|
|
snprintf(finame, sizeof(finame), "Tunnel%s", argv[optind+2]+2);
|
|
else
|
|
- thr(lsif(argv[optind+2]));
|
|
+ thr(lsif(argv[optind+2], 1));
|
|
|
|
- thr(lsif(finame));
|
|
+ thr(lsif(finame, 1));
|
|
}
|
|
else
|
|
usage();
|
|
@@ -372,7 +376,7 @@ void prifalias(oid inst) {
|
|
|
|
}
|
|
|
|
-int lsif(char *ifname) {
|
|
+int lsif(char *ifname, int print) {
|
|
struct snmp_pdu *pdu, *resp;
|
|
oid tmp_oid[MAX_OID_LEN];
|
|
size_t tmp_oid_len;
|
|
@@ -395,11 +399,12 @@ int lsif(char *ifname) {
|
|
tmp[resp->variables->val_len]=0;
|
|
if(ifname) {
|
|
if(strcasecmp(ifname, tmp)==0) {
|
|
- printf("Found \"%s\" at index %lu:\n", tmp, resp->variables->name[resp->variables->name_length-1]);
|
|
+ if(print)
|
|
+ printf("Found \"%s\" at index %lu:\n", tmp, resp->variables->name[resp->variables->name_length-1]);
|
|
return resp->variables->name[resp->variables->name_length-1];
|
|
}
|
|
}
|
|
- else {
|
|
+ else if(print) {
|
|
printf("%lu : \"%s\" [%s/%s]",
|
|
resp->variables->name[resp->variables->name_length-1],
|
|
tmp,
|
|
@@ -423,7 +428,7 @@ int lsif(char *ifname) {
|
|
}
|
|
if(resp)
|
|
snmp_free_pdu(resp);
|
|
- if(ifname) {
|
|
+ if(print && ifname) {
|
|
fprintf(stderr, "Unable to find \"%s\". Use 'list' to display all interfaces.\n", ifname);
|
|
snmp_close(ses);
|
|
SOCK_CLEANUP;
|
|
@@ -439,6 +444,7 @@ void finish(void) {
|
|
kbprint(maxin/interval);
|
|
putchar(' ');
|
|
kbprint(maxout/interval);
|
|
+ if(iterations>1) {
|
|
printf( "\n"
|
|
"average throughput: ");
|
|
kbprint((uint64_t)(sumin/(iterations-1)/interval));
|
|
@@ -449,6 +455,7 @@ void finish(void) {
|
|
kbprint(minin/interval);
|
|
putchar(' ');
|
|
kbprint(minout/interval);
|
|
+ }
|
|
putchar('\n');
|
|
snmp_close(ses);
|
|
SOCK_CLEANUP;
|
|
@@ -514,7 +521,8 @@ void version(void) {
|
|
"SNMP Text Traffic Grapher\n"
|
|
"Copyright (c) 2005 - 2009 by Antoni Sawicki\n"
|
|
"Version %s [Build: %s, %s]\n"
|
|
- "NET-SNMP Libraries=%s Headers=%s\n"
|
|
+ "NET-SNMP Libraries=%s\n"
|
|
+ /* "NET-SNMP Libraries=%s Headers=%s\n" */
|
|
"GCC Version %s\n"
|
|
"Kilo=%d (default)\n"
|
|
"Max uint32=%u uint64=%llu\n"
|
|
@@ -525,7 +533,7 @@ void version(void) {
|
|
" mike@mk.tc\n"
|
|
" tommy@ntinternals.net\n"
|
|
" piston@otel.net\n",
|
|
- VERSION, __DATE__, __TIME__, netsnmp_get_version(), PACKAGE_VERSION, __VERSION__,
|
|
+ VERSION, __DATE__, __TIME__, netsnmp_get_version(), __VERSION__,
|
|
(int)S_KB, UINT32_MAX, UINT64_MAX);
|
|
exit(0);
|
|
}
|