From: "Nikolai Vladychevski" <niko@isl.net.mx>
To: lartc@vger.kernel.org
Subject: [LARTC] Re: Monitoring traffic
Date: Sat, 22 Sep 2001 14:51:46 +0000 [thread overview]
Message-ID: <marc-lartc-100117359608816@msgid-missing> (raw)
[-- Attachment #1: Type: text/plain, Size: 712 bytes --]
bert hubert writes:
>
> Target[traffic]: `/var/www/mrtg.ds9a.nl/traffic`
>
> and /var/www/mrtg.ds9a.nl/traffic:
>
> #!/bin/sh
> /sbin/iptables -L -n -v -x | grep mrtg- |grep "^ " | awk "{print \$2}"
> uptime
> uname -a
>
I made a little proggie to avoid piping awk or perl or any other reporting
languge... Right now it uses this format:
rulenum [packets:bytes]
this format is for my own application, but you can modify the printf to
report whatever you need with whatever separator you want, or even add
another param to accept the rule number and get statistics of the desired
rule. This can be adapted to mrtg so it will run faster without perl
invocation.
I attach the code.
Nikolai
[-- Attachment #2: iptables-counters.c --]
[-- Type: text/plain, Size: 1424 bytes --]
// iptables-counters.c , took from iptables sources
// 4 Aug 2001, Nikolai Vladychevski, niko@isl.net.mx
//
// Instructions:
// place this file into iptables source directory to compile
//
// add this to Makefile :
// iptables-counters: iptables-counters.c iptables.o libiptc/libiptc.a
// $(CC) $(CFLAGS) -DIPT_LIB_DIR=\"$(IPT_LIBDIR)\" -rdynamic -o $@ $^ -ldl
// do "make"
// usage: iptables-counters [table] [chain]
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include "libiptc/libiptc.h"
#include "iptables.h"
int main(int argc, char *argv[]) {
char *tablename="filter",*chainname;
const char *chain=NULL;
iptc_handle_t h;
if (argc<3) { printf("usage: %s table chain\n",argv[0]); return(1);}
tablename=argv[1];
chainname=argv[2];
if (!tablename || !chainname) { printf ("null paramms\n"); return(1);}
h=iptc_init(tablename);
if (!h) {
printf("Can't initialize:\n");
return(1);
}
for (chain = iptc_first_chain(&h); chain; chain = iptc_next_chain(&h)) {
const struct ipt_entry *e;
int rule=1;
if (strcmp(chain,chainname)) continue;
e = iptc_first_rule(chain, &h);
while(e) {
if (1) {
printf("%d [%llu:%llu]\n", rule,e->counters.pcnt, e->counters.bcnt);
rule++;
}
e = iptc_next_rule(e, &h);
}
}
return(0);
}
reply other threads:[~2001-09-22 14:51 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=marc-lartc-100117359608816@msgid-missing \
--to=niko@isl.net.mx \
--cc=lartc@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.