mirror of
https://github.com/pi-hole/FTL.git
synced 2024-10-26 16:52:18 +02:00
Add Query Types over Time data structure
This commit is contained in:
@@ -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 };
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user