From: xchaos Date: Mon, 16 Mar 2015 00:13:21 +0000 (+0000) Subject: average speed calculation when analysing logs X-Git-Url: http://git.harvie.cz/?p=svn%2FPrometheus-QoS%2F.git;a=commitdiff_plain;h=3856be6ab5f6ada6c64a059a61da74d65122592e;ds=sidebyside average speed calculation when analysing logs git-svn-id: https://dev.arachne.cz/repos/prometheus/trunk@248 251d49ef-1d17-4917-a970-b30cf55b089b --- diff --git a/htmlandlogs.c b/htmlandlogs.c index 3820ae4..2cb7898 100644 --- a/htmlandlogs.c +++ b/htmlandlogs.c @@ -259,7 +259,7 @@ style=\"cursor: pointer;\">+%d]", } else if(ip->lmsid == 0) { - fputs("-------",f); + fputs("------",f); } fputs("\n",f); } diff --git a/parselogs.c b/parselogs.c index a5c2acf..ffd82a1 100644 --- a/parselogs.c +++ b/parselogs.c @@ -20,6 +20,8 @@ struct IpLog char *name; long traffic; long guaranted; + long avg; + time_t logged_time; int i; int lmsid; long l; @@ -32,6 +34,7 @@ void parse_ip_log(int argc, char **argv) long traffic=0l, traffic_month, total=0, guaranted; int col, col2, y_ok, m_ok, accept_month, i=1, any_month=0, lmsid; char mstr[4], ystr[5]; + long log_timestamp, log_started = 0, log_ended = 0; FILE *f; string(str,STRLEN); string(filename,STRLEN); @@ -75,14 +78,15 @@ void parse_ip_log(int argc, char **argv) /* sorry... next release of C<<1 header file will include for_path_files(name,path) { } macro */ sprintf(str,"%s %s/",ls,log_dir); shell(str); + /* for_each(file, str, dir, log_dir) */ input(str,STRLEN) { if(strstr(str,".log")) { ptr=strrchr(str,'\n'); if(ptr) *ptr='\0'; - sprintf(filename,"%s/%s",log_dir,str); - printf("Parsing %s ...",filename); + sprintf(filename,"%s/%s", log_dir,str); + printf("Parsing %s ...", filename); accept_month=0; traffic_month=0; guaranted=0; @@ -92,6 +96,7 @@ void parse_ip_log(int argc, char **argv) y_ok=m_ok=0; valid_columns(ptr,_,'\t',col) switch(col) { + case 1: log_timestamp = atol(ptr); break; case 2: name = ptr;break; case 3: traffic = atol(ptr);break; /* column number - was 7, now 11...*/ @@ -117,17 +122,32 @@ void parse_ip_log(int argc, char **argv) if(y_ok && m_ok) { traffic_month += traffic; + if(log_started == 0) + { + log_started = log_timestamp; + } accept_month = 1; } + else if (log_started != 0 && log_ended == 0) + { + log_ended = log_timestamp; + } } done; /* ugly macro end */ if(accept_month) { + if(log_ended == 0) + { + log_ended = time(NULL); + } + create(iplog,IpLog); iplog->name = name; iplog->guaranted = guaranted; - iplog->traffic = traffic_month; + iplog->avg = traffic_month * 8 / (log_ended - log_started); /* Mbps */ + iplog->logged_time = (log_ended - log_started); + iplog->traffic = traffic_month; /* MB */ iplog->lmsid = lmsid; insert(iplog,iplogs,desc_order_by,traffic); printf(" %ld MB\n",iplog->traffic); @@ -143,23 +163,33 @@ void parse_ip_log(int argc, char **argv) f=fopen(str,"w"); if(f > 0) { + time_t max_logged_time = 0; + fprintf(f, "\n\ \n\ \n\ \n\ \n\ +\n\ \n ", month, year); row_odd_even = 0; for_each(iplog, iplogs) { + if(iplog->logged_time > max_logged_time) + { + max_logged_time = iplog->logged_time; + } + if(iplog->traffic) { fprintf(f, "%s\n\ -\n\ +\n\ \n\ - \n\ - \n", - iplog->traffic, iplog->traffic>>10, iplog->guaranted); +\n\ +\n", + iplog->traffic, iplog->traffic>>10, iplog->guaranted, iplog->avg); total+=iplog->traffic>>10; iplog->i=i; iplog->l=total; } } fprintf(f,"\ - \ - \ - \n", total, line); +\ +\ +\ +\ +\n", total, line, (8*(total<<20))/max_logged_time/i); fputs("
%s %slmsData transfersMin.speedAvg.speed
%d%s\ +%s", tr_odd_even(), i++, log_url, iplog->name, iplog->name); + if(iplog->lmsid > 0) { /*base URL will be configurable soon ... */ @@ -167,21 +197,25 @@ void parse_ip_log(int argc, char **argv) } else if(iplog->lmsid == 0) { - fputs("-------",f); + fputs("------",f); } fprintf(f, "%ld MB%ld GB%ld kb/s
%ld GB%ld kb/s\ +%ld Mb/s\ +
Total:%ld GB%Ld kb/s
Total:%ld GB%Ld kb/s%Ld kb/s
\n", f); row_odd_even = 0; diff --git a/prometheus.c b/prometheus.c index 03b7554..75162f3 100644 --- a/prometheus.c +++ b/prometheus.c @@ -2,12 +2,12 @@ /* Prometheus QoS - you can "steal fire" from your ISP */ /* "fair-per-IP" quality of service (QoS) utility */ /* requires Linux 2.4.x or 2.6.x with HTB support */ -/* Copyright(C) 2005-2014 Michael Polak, Arachne Aerospace */ +/* Copyright(C) 2005-2015 Michael Polak, Arachne Aerospace */ /* iptables-restore support Copyright(C) 2007-2008 ludva */ /* Credit: CZFree.Net,Martin Devera,Netdave,Aquarius,Gandalf */ /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ -/* Modified by: xChaos, 20140812 +/* Modified by: xChaos, 20150315 ludva, 20080415 Prometheus QoS is free software; you can redistribute it and/or @@ -29,7 +29,7 @@ #include "cll1-0.6.2.h" #include "ipstruct.h" -const char *version = "0.8.5-b"; +const char *version = "0.8.5-c"; /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ /* Versions: 0.8.3 is development release, 0.8.4 will be "stable" */ @@ -40,7 +40,7 @@ const char *version = "0.8.5-b"; /* Warning: unofficial Github mirror is not supported by author! */ /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ -const char *stats_html_signature = "Statistics generated by Prometheus QoS version %s
GPL+Copyright(C)2005-2014 Michael Polak, Arachne Labs
\n"; +const char *stats_html_signature = "Statistics generated by Prometheus QoS version %s
GPL+Copyright(C)2005-2015 Michael Polak, Arachne Labs
\n"; #define STRLEN 512 #undef DEBUG @@ -503,7 +503,7 @@ program printf("\n\ Prometheus QoS - \"fair-per-IP\" Quality of Service setup utility.\n\ -Version %s - Copyright (C)2005-2014 Michael Polak, Arachne Labs\n\ +Version %s - Copyright (C)2005-2015 Michael Polak, Arachne Labs\n\ iptables-restore & burst tunning & classify modification by Ludva\n\ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);