From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Nikolai Vladychevski" Date: Sat, 22 Sep 2001 14:51:46 +0000 Subject: [LARTC] Re: Monitoring traffic MIME-Version: 1 Content-Type: multipart/mixed; boundary="=_0_2637_1001170306" Message-Id: List-Id: To: lartc@vger.kernel.org This is a MIME-formatted message. If you see this text it means that your mail software cannot handle MIME-formatted messages. --=_0_2637_1001170306 Content-Type: text/plain; format=flowed; charset=iso-8859-1 Content-Transfer-Encoding: 7bit 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 --=_0_2637_1001170306 Content-Disposition: attachment; filename="iptables-counters.c" Content-Type: text/plain; charset="iso-8859-1"; name="iptables-counters.c" Content-Transfer-Encoding: 7bit // 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 #include #include #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); } --=_0_2637_1001170306-- _______________________________________________ LARTC mailing list / LARTC@mailman.ds9a.nl http://mailman.ds9a.nl/mailman/listinfo/lartc HOWTO: http://ds9a.nl/2.4Routing/