Add Query Types over Time data structure

This commit is contained in:
DL6ER
2017-03-28 22:45:16 +01:00
parent b426ced9f2
commit cabc6800d6
6 changed files with 36 additions and 3 deletions
+2
View File
@@ -144,6 +144,7 @@ typedef struct {
int blocked;
int forwardnum;
int *forwarddata;
int *querytypedata;
} overTimeDataStruct;
typedef struct {
@@ -154,6 +155,7 @@ typedef struct {
int forwardedips;
int forwardednames;
int forwarddata;
int querytypedata;
} memoryStruct;
enum { QUERIES, FORWARDED, CLIENTS, DOMAINS, OVERTIME };
+2
View File
@@ -60,10 +60,12 @@ void pihole_log_flushed(bool message)
for(i=0;i<counters.overTime;i++)
{
free(overTime[i].forwarddata);
free(overTime[i].querytypedata);
}
free(overTime);
overTime = NULL;
memory.forwarddata = 0;
memory.querytypedata = 0;
// Reset all counters (except clients and forwards, because they need PTRs) to zero
int counters_bck = counters.clients;
+2 -2
View File
@@ -56,8 +56,8 @@ void *GC_thread(void *val)
switch(queries[i].type)
{
case 1: counters.IPv4--; break;
case 2: counters.IPv6--; break;
case 1: counters.IPv4--; overTime[queries[i].timeidx].querytypedata[0]--; break;
case 2: counters.IPv6--; overTime[queries[i].timeidx].querytypedata[1]--; break;
default: /* some other query, but neither A nor AAAA */ break;
}
+1 -1
View File
@@ -114,7 +114,7 @@ void logg_struct_resize(const char* str, int to, int step)
get_timestr();
unsigned long int structbytes = sizeof(countersStruct) + sizeof(ConfigStruct) + counters.queries_MAX*sizeof(queriesDataStruct) + counters.forwarded_MAX*sizeof(forwardedDataStruct) + counters.clients_MAX*sizeof(clientsDataStruct) + counters.domains_MAX*sizeof(domainsDataStruct) + counters.overTime_MAX*sizeof(overTimeDataStruct) + (counters.wildcarddomains)*sizeof(*wildcarddomains);
unsigned long int dynamicbytes = memory.wildcarddomains + memory.domainnames + memory.clientips + memory.clientnames + memory.forwardedips + memory.forwardednames + memory.forwarddata;
unsigned long int dynamicbytes = memory.wildcarddomains + memory.domainnames + memory.clientips + memory.clientnames + memory.forwardedips + memory.forwardednames + memory.forwarddata + memory.querytypedata;
unsigned long int bytes = structbytes + dynamicbytes;
char *prefix = calloc(2, sizeof(char));
+6
View File
@@ -165,6 +165,8 @@ void process_pihole_log(int file)
overTime[timeidx].blocked = 0;
overTime[timeidx].forwardnum = 0;
overTime[timeidx].forwarddata = NULL;
overTime[timeidx].querytypedata = calloc(2, sizeof(int));
memory.querytypedata += 2*sizeof(int);
counters.overTime++;
}
@@ -213,11 +215,13 @@ void process_pihole_log(int file)
{
type = 1;
counters.IPv4++;
overTime[timeidx].querytypedata[0]++;
}
else if(strstr(readbuffer,"query[AAAA]") != NULL)
{
type = 2;
counters.IPv6++;
overTime[timeidx].querytypedata[1]++;
}
// Save current file pointer position
@@ -431,6 +435,8 @@ void process_pihole_log(int file)
overTime[timeidx].blocked = 0;
overTime[timeidx].forwardnum = 0;
overTime[timeidx].forwarddata = NULL;
overTime[timeidx].querytypedata = calloc(2, sizeof(int));
memory.querytypedata += 2*sizeof(int);
counters.overTime++;
}
// Determine if there is enough space for saving the current
+23
View File
@@ -527,6 +527,29 @@ void process_request(char *client_message, int *sock)
if(debugclients)
logg_int("Sent overTime forwarded data to client, ID: ", *sock);
}
else if(command(client_message, ">QueryTypesoverTime"))
{
processed = true;
int i, sendit = -1;
for(i = 0; i < counters.overTime; i++)
{
if((overTime[i].total > 0 || overTime[i].blocked > 0))
{
sendit = i;
break;
}
}
if(sendit > -1)
{
for(i = sendit; i < counters.overTime; i++)
{
sprintf(server_message, "%i %i %i\n", overTime[i].timestamp,overTime[i].querytypedata[0],overTime[i].querytypedata[1]);
swrite(server_message, *sock);
}
}
if(debugclients)
logg_int("Sent overTime query types data to client, ID: ", *sock);
}
else if(command(client_message, ">version"))
{
processed = true;