-/* @(#) $Id: stats.c,v 1.30 2009/06/24 17:06:22 dcid Exp $ */
-
+/* @(#) $Id: ./src/analysisd/stats.c, 2011/09/08 dcid Exp $
+ */
+
/* Copyright (C) 2009 Trend Micro Inc.
* All right reserved.
*
* This program is a free software; you can redistribute it
* and/or modify it under the terms of the GNU General Public
- * License (version 3) as published by the FSF - Free Software
+ * License (version 2) as published by the FSF - Free Software
* Foundation
*/
"Friday","Saturday"};
char *(l_month[])={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug",
"Sep","Oct","Nov","Dec"};
-
+
/* Global vars */
char logfile[OS_FLSIZE +1];
FILE *flog;
-
+
/* Creating the path for the logs */
snprintf(logfile, OS_FLSIZE,"%s/%d/", STATSAVED, prev_year);
if(IsDir(logfile) == -1)
merror(FOPEN_ERROR, ARGV0, logfile);
return;
}
-
+
/* Printing the hourly stats */
for(i=0;i<=23;i++)
{
totals+=_CHour[i];
}
fprintf(flog,"Total events for day:%d\n", totals);
-
+
fclose(flog);
}
/* gethour: v0.2
* Return the parameter (event_number + 20 % of it)
* If event_number < mindiff, return mindiff
- * If event_number > maxdiff, return maxdiff
+ * If event_number > maxdiff, return maxdiff
*/
int gethour(int event_number)
{
event_diff = (event_number * percent_diff)/100;
event_diff++;
-
+
if(event_diff < mindiff)
return(event_number + mindiff);
else if(event_diff > maxdiff)
return(event_number + maxdiff);
-
+
return(event_number + event_diff);
}
{
int i,j;
int inter;
-
-
+
+
/* Print total number of logs received per hour */
print_totals();
-
-
+
+
/* Hourly update */
_RHour[24]++;
inter = _RHour[24];
if(inter > 7)
inter = 7;
-
+
for(i=0;i<=24;i++)
{
char _hourly[128]; /* _hourly file */
-
+
FILE *fp;
-
+
if(i != 24)
{
/* If saved hourly = 0, just copy the current hourly rate */
{
_RHour[i]=(((3*_CHour[i])+(inter*_RHour[i]))/(inter+3))+25;
}
-
+
else
{
/* The average is going to be the number of interactions +
}
}
}
-
+
snprintf(_hourly,128,"%s/%d",STATQUEUE,i);
fp = fopen(_hourly, "w");
if(fp)
{
merror(FOPEN_ERROR, "logstats", _hourly);
}
-
+
_CHour[i] = 0; /* Zeroing the currently hour */
}
inter = _CWHour[i][24];
if(inter > 7)
inter = 7;
-
+
for(j=0;j<=24;j++)
{
if(j != 24)
}
}
}
-
+
snprintf(_weekly,128,"%s/%d/%d",STATWQUEUE,i,j);
fp = fopen(_weekly, "w");
if(fp)
{
merror(FOPEN_ERROR, "logstats", _weekly);
}
-
+
_CWHour[i][j] = 0;
- }
+ }
}
_daily_errors = 0;
" between %d:00 and %d:00 is %d. We "
"reached %d.",__crt_hour,__crt_hour+1,
_RHour[__crt_hour],_CHour[__crt_hour]);
-
-
+
+
_fired = 1;
_daily_errors++;
return(1);
/* We need to have at least 3 days of stats */
if(_RWHour[__crt_wday][24] <= 2)
return(0);
-
+
/* checking for the hour during a specific day of the week */
if(_RWHour[__crt_wday][__crt_hour] != 0)
{
if(_CWHour[__crt_wday][__crt_hour] > _RWHour[__crt_wday][__crt_hour])
{
- if(_CWHour[__crt_wday][__crt_hour] >
+ if(_CWHour[__crt_wday][__crt_hour] >
gethour(_RWHour[__crt_wday][__crt_hour]))
{
snprintf(__stats_comment, 191,
weekdays[__crt_wday],
_RWHour[__crt_wday][__crt_hour],
_CWHour[__crt_wday][__crt_hour]);
-
-
+
+
_fired = 1;
_daily_errors++;
return(1);
maxdiff = getDefine_Int("analysisd",
"stats_maxdiff",
10, 99999);
-
+
mindiff = getDefine_Int("analysisd",
"stats_mindiff",
10, 99999);
_lastmsg = NULL;
_prevlast = NULL;
_pprevlast = NULL;
-
-
+
+
/* They should not be null */
os_strdup(" ", _lastmsg);
os_strdup(" ", _prevlast);
os_strdup(" ", _pprevlast);
-
-
- /* Creating the stat queue directories */
+
+
+ /* Creating the stat queue directories */
if(IsDir(STATWQUEUE) == -1)
if(mkdir(STATWQUEUE,0770) == -1)
{
merror("%s: logstat: Unable to create stat queue: %s",
ARGV0, STATWQUEUE);
return(-1);
- }
+ }
if(IsDir(STATQUEUE) == -1)
if(mkdir(STATQUEUE,0770) == -1)
merror("%s: logstat: Unable to create stat queue: %s",
ARGV0, STATQUEUE);
return(-1);
- }
+ }
/* Creating store dir */
if(IsDir(STATSAVED) == -1)
_CHour[i]=0;
if(File_DateofChange(_hourly) < 0)
_RHour[i] = 0;
-
+
else
{
FILE *fp;
_RHour[i] = 0;
if(_RHour[i] < 0)
- _RHour[i] = 0;
+ _RHour[i] = 0;
fclose(fp);
}
}
_RWHour[i][j] = 0;
if(_RWHour[i][j] < 0)
- _RWHour[i][j] = 0;
+ _RWHour[i][j] = 0;
fclose(fp);
}
}
/* LastMsg_Change: v0.3: 2006/03/21
* v0.3: 2006/03/21: Some performance fixes.
- * v0.2: 2005/03/17
+ * v0.2: 2005/03/17
* If the message is not repeated, rearrange the last
* received messages
*/
{
/* Removing the last one */
free(_pprevlast);
-
+
/* Moving the second to third and the last to second */
_pprevlast = _prevlast;
-
+
_prevlast = _lastmsg;
-
+
os_strdup(log, _lastmsg);
return;