From bf59a20b46290db34e1761926a39ee68164d636b Mon Sep 17 00:00:00 2001 From: xchaos Date: Tue, 31 Mar 2015 20:10:12 +0000 Subject: [PATCH] more work on aggregation git-svn-id: https://dev.arachne.cz/repos/prometheus/trunk@250 251d49ef-1d17-4917-a970-b30cf55b089b --- htmlandlogs.c | 18 +++++++++++++----- ipstruct.h | 3 +++ parsehosts.c | 45 ++++++++++++++++++++++++--------------------- parseiptables.c | 2 ++ prometheus.c | 15 +++++++++------ 5 files changed, 51 insertions(+), 32 deletions(-) diff --git a/htmlandlogs.c b/htmlandlogs.c index 2cb7898..7037784 100644 --- a/htmlandlogs.c +++ b/htmlandlogs.c @@ -130,7 +130,7 @@ void write_htmlandlogs(char *html, char *d, int total, int just_preview) int active_classes = 0; // int colspan = 14; struct Sum {unsigned long long l; int i; list(Sum);} *sum,*sums = NULL; - int limit_count = 0, prio_count = 0; + int agreg_count = 0, limit_count = 0, prio_count = 0; int popup_button = 0; /* IPv6 vs. IPv4 stats */ unsigned long long pkts4 =0, pkts6 = 0, bytes4 = 0, bytes6 = 0; @@ -197,7 +197,13 @@ $(\'#pktsup_\'+n).show();\ char *f1="", *f2=""; i++; - if(ip->max < ip->desired) + if(ip->aggregated > 1) + { + f1 = ""; + f2 = ""; + agreg_count++; + } + else if(ip->max < ip->desired) { f1 = ""; f2 = ""; @@ -419,9 +425,11 @@ style=\"cursor: pointer;\">+%d]", */ fprintf(f, "%Lu%d", total_direct, total_pktdown/i); - fprintf(f, "LIMIT %dx \ -LOW-PRIO %dx\n\n", - limit_count, prio_count); + fprintf(f, "\ +AGR %dx \ +FUP %dx \ +PRIO %dx\n\n", + agreg_count, limit_count, prio_count); if(ip6prefix) { diff --git a/ipstruct.h b/ipstruct.h index d4383b3..542cb0a 100644 --- a/ipstruct.h +++ b/ipstruct.h @@ -10,12 +10,15 @@ struct IP int max; int mark; int prio; + int aggregated; int fixedprio; int group; int lmsid; int pps_limit; unsigned long long direct; unsigned long long proxy; + unsigned long long traffic_down; + unsigned long long traffic_up; unsigned long long upload; unsigned long long traffic; unsigned long long credit; diff --git a/parsehosts.c b/parsehosts.c index 1e0c65c..47b06bd 100644 --- a/parsehosts.c +++ b/parsehosts.c @@ -25,27 +25,30 @@ void update_network(char *look_for, struct IP* ip); void TheIP(char *ipaddr, int is_network) { create(ip,IP); - ip->name = ""; - ip->addr = ipaddr; - ip->sharing = NULL; - ip->prio = highest_priority+1; - ip->lmsid = -1; - ip->fixedprio = \ - ip->mark = \ - ip->min = \ - ip->max = \ - ip->desired = \ - ip->credit = \ - ip->upload = \ - ip->proxy = \ - ip->direct = \ - ip->traffic = \ - ip->pktsup = \ - ip->pps_limit = \ - ip->pktsdown = 0; - ip->keyword = keywords; - ip->v6 = (strchr(ip->addr,':')!=NULL); - ip->mask = ((ip->v6)?64:32); + ip->name = ""; + ip->addr = ipaddr; + ip->sharing = NULL; + ip->prio = highest_priority+1; + ip->lmsid = -1; + ip->fixedprio = \ + ip->aggregated = \ + ip->mark = \ + ip->min = \ + ip->max = \ + ip->desired = \ + ip->credit = \ + ip->upload = \ + ip->proxy = \ + ip->direct = \ + ip->traffic = \ + ip->traffic_down = \ + ip->traffic_up = \ + ip->pktsup = \ + ip->pps_limit = \ + ip->pktsdown = 0; + ip->keyword = keywords; + ip->v6 = (strchr(ip->addr,':')!=NULL); + ip->mask = ((ip->v6)?64:32); if(is_network) { push(ip, networks); diff --git a/parseiptables.c b/parseiptables.c index eca2ced..8544df7 100644 --- a/parseiptables.c +++ b/parseiptables.c @@ -178,6 +178,7 @@ void get_traffic_statistics(const char *whichiptables, int ipv6) else {*/ ip->traffic += traffic; + ip->traffic_down += traffic; /* } */ ip->direct += traffic; /*-ip->proxy;*/ ip->pktsdown += pkts; @@ -185,6 +186,7 @@ void get_traffic_statistics(const char *whichiptables, int ipv6) else { ip->upload += traffic; + ip->traffic_up += traffic; ip->pktsup += pkts; if(include_upload) { diff --git a/prometheus.c b/prometheus.c index 3139419..2b9b605 100644 --- a/prometheus.c +++ b/prometheus.c @@ -7,7 +7,7 @@ /* Credit: CZFree.Net,Martin Devera,Netdave,Aquarius,Gandalf */ /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ -/* Modified by: xChaos, 20150315 +/* Modified by: xChaos, 20150331 ludva, 20080415 Prometheus QoS is free software; you can redistribute it and/or @@ -605,6 +605,8 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version); for_each(sharedip, ips) if(eq(sharedip->name, ip->sharing)) { sharedip->traffic += ip->traffic; + sharedip->traffic_down += ip->direct; + sharedip->traffic_up += ip->upload; ip->traffic = 0; ip->mark = sharedip->mark; ip->lmsid = sharedip->lmsid; @@ -1051,8 +1053,8 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version); if_exists(ip,ips,eq(ip->addr,_)) { int unshape_this_ip = stop_shaping; - long avg_mbps_down = ip->direct * 8 / how_much_seconds; - long avg_mbps_up = ip->upload * 8 / how_much_seconds; + long avg_mbps_down = ip->traffic_down * 8 / how_much_seconds; + long avg_mbps_up = ip->traffic_up * 8 / how_much_seconds; int min_mbps = ip->min>>10; int agreg = 1, print_stats = 1; @@ -1066,7 +1068,7 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version); if(min_mbps <= avg_mbps_down) { unshape_this_ip = 0; - agreg = (avg_mbps_down+1)/min_mbps; + agreg = (int)((float)(avg_mbps_down+1)/min_mbps+.5); ip->max /= agreg; printf("Download aggregation 1:%d for %s (min: %lu Mbps avg: %ld Mbps)\n", agreg, ip->name, min_mbps, avg_mbps_down); } @@ -1080,7 +1082,7 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version); if(min_mbps <= avg_mbps_up) { unshape_this_ip = 0; - agreg = (avg_mbps_up+1)/min_mbps; + agreg = (int)((float)(avg_mbps_up+1)/min_mbps+.5); ip->max /= agreg; printf("Upload aggregation 1:%d for %s: (min: %lu Mbps avg: %ld Mbps)\n", agreg, ip->name, min_mbps, avg_mbps_up); } @@ -1089,7 +1091,8 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version); unshape_this_ip = 1; } } - ip->mark=atoi(ptr); + ip->aggregated = agreg; + ip->mark = atoi(ptr); if(ip->max < ip->desired || unshape_this_ip || reduce_ceil) /* apply or disable FUP limit immediately.... */ { if(unshape_this_ip) -- 2.30.2