mirror of
https://bitbucket.org/jsuto/piler.git
synced 2024-12-25 06:40:12 +01:00
added size counter
This commit is contained in:
parent
1211e9a39c
commit
cd68dd1f1a
@ -54,6 +54,7 @@
|
|||||||
#define MEMCACHED_MSGS_VIRUS MEMCACHED_CLAPF_PREFIX ":virus"
|
#define MEMCACHED_MSGS_VIRUS MEMCACHED_CLAPF_PREFIX ":virus"
|
||||||
#define MEMCACHED_MSGS_DUPLICATE MEMCACHED_CLAPF_PREFIX ":duplicate"
|
#define MEMCACHED_MSGS_DUPLICATE MEMCACHED_CLAPF_PREFIX ":duplicate"
|
||||||
#define MEMCACHED_MSGS_IGNORE MEMCACHED_CLAPF_PREFIX ":ignore"
|
#define MEMCACHED_MSGS_IGNORE MEMCACHED_CLAPF_PREFIX ":ignore"
|
||||||
|
#define MEMCACHED_MSGS_SIZE MEMCACHED_CLAPF_PREFIX ":size"
|
||||||
|
|
||||||
|
|
||||||
#define LOG_PRIORITY LOG_INFO
|
#define LOG_PRIORITY LOG_INFO
|
||||||
|
@ -16,7 +16,7 @@ struct __counters loadCounters(struct session_data *sdata, struct __config *cfg)
|
|||||||
|
|
||||||
bzero(&counters, sizeof(counters));
|
bzero(&counters, sizeof(counters));
|
||||||
|
|
||||||
snprintf(buf, SMALLBUFSIZE-1, "SELECT `rcvd`, `virus`, `duplicate`, `ignore` FROM `%s`", SQL_COUNTER_TABLE);
|
snprintf(buf, SMALLBUFSIZE-1, "SELECT `rcvd`, `virus`, `duplicate`, `ignore`, `size` FROM `%s`", SQL_COUNTER_TABLE);
|
||||||
|
|
||||||
#ifdef NEED_MYSQL
|
#ifdef NEED_MYSQL
|
||||||
MYSQL_RES *res;
|
MYSQL_RES *res;
|
||||||
@ -31,6 +31,7 @@ struct __counters loadCounters(struct session_data *sdata, struct __config *cfg)
|
|||||||
counters.c_virus = strtoull(row[1], NULL, 10);
|
counters.c_virus = strtoull(row[1], NULL, 10);
|
||||||
counters.c_duplicate = strtoull(row[2], NULL, 10);
|
counters.c_duplicate = strtoull(row[2], NULL, 10);
|
||||||
counters.c_ignore = strtoull(row[3], NULL, 10);
|
counters.c_ignore = strtoull(row[3], NULL, 10);
|
||||||
|
counters.c_size = strtoull(row[4], NULL, 10);
|
||||||
}
|
}
|
||||||
mysql_free_result(res);
|
mysql_free_result(res);
|
||||||
}
|
}
|
||||||
@ -60,11 +61,12 @@ void update_counters(struct session_data *sdata, struct __data *data, struct __c
|
|||||||
if(counters->c_virus > 0) memcached_increment(&(data->memc), MEMCACHED_MSGS_VIRUS, strlen(MEMCACHED_MSGS_VIRUS), counters->c_virus, &mc);
|
if(counters->c_virus > 0) memcached_increment(&(data->memc), MEMCACHED_MSGS_VIRUS, strlen(MEMCACHED_MSGS_VIRUS), counters->c_virus, &mc);
|
||||||
if(counters->c_duplicate > 0) memcached_increment(&(data->memc), MEMCACHED_MSGS_DUPLICATE, strlen(MEMCACHED_MSGS_DUPLICATE), counters->c_duplicate, &mc);
|
if(counters->c_duplicate > 0) memcached_increment(&(data->memc), MEMCACHED_MSGS_DUPLICATE, strlen(MEMCACHED_MSGS_DUPLICATE), counters->c_duplicate, &mc);
|
||||||
if(counters->c_ignore > 0) memcached_increment(&(data->memc), MEMCACHED_MSGS_IGNORE, strlen(MEMCACHED_MSGS_IGNORE), counters->c_ignore, &mc);
|
if(counters->c_ignore > 0) memcached_increment(&(data->memc), MEMCACHED_MSGS_IGNORE, strlen(MEMCACHED_MSGS_IGNORE), counters->c_ignore, &mc);
|
||||||
|
if(counters->c_size > 0) memcached_increment(&(data->memc), MEMCACHED_MSGS_SIZE, strlen(MEMCACHED_MSGS_SIZE), counters->c_size, &mc);
|
||||||
|
|
||||||
|
|
||||||
bzero(&c, sizeof(c));
|
bzero(&c, sizeof(c));
|
||||||
|
|
||||||
snprintf(buf, MAXBUFSIZE-1, "%s %s %s %s %s", MEMCACHED_MSGS_RCVD, MEMCACHED_MSGS_VIRUS, MEMCACHED_MSGS_DUPLICATE, MEMCACHED_MSGS_IGNORE, MEMCACHED_COUNTERS_LAST_UPDATE);
|
snprintf(buf, MAXBUFSIZE-1, "%s %s %s %s %s %s", MEMCACHED_MSGS_RCVD, MEMCACHED_MSGS_VIRUS, MEMCACHED_MSGS_DUPLICATE, MEMCACHED_MSGS_IGNORE, MEMCACHED_MSGS_SIZE, MEMCACHED_COUNTERS_LAST_UPDATE);
|
||||||
|
|
||||||
if(memcached_mget(&(data->memc), buf) == MEMCACHED_SUCCESS){
|
if(memcached_mget(&(data->memc), buf) == MEMCACHED_SUCCESS){
|
||||||
while((memcached_fetch_result(&(data->memc), &key[0], &buf[0], &flags))){
|
while((memcached_fetch_result(&(data->memc), &key[0], &buf[0], &flags))){
|
||||||
@ -72,6 +74,7 @@ void update_counters(struct session_data *sdata, struct __data *data, struct __c
|
|||||||
else if(!strcmp(key, MEMCACHED_MSGS_VIRUS)) c.c_virus = strtoull(buf, NULL, 10);
|
else if(!strcmp(key, MEMCACHED_MSGS_VIRUS)) c.c_virus = strtoull(buf, NULL, 10);
|
||||||
else if(!strcmp(key, MEMCACHED_MSGS_DUPLICATE)) c.c_duplicate = strtoull(buf, NULL, 10);
|
else if(!strcmp(key, MEMCACHED_MSGS_DUPLICATE)) c.c_duplicate = strtoull(buf, NULL, 10);
|
||||||
else if(!strcmp(key, MEMCACHED_MSGS_IGNORE)) c.c_ignore = strtoull(buf, NULL, 10);
|
else if(!strcmp(key, MEMCACHED_MSGS_IGNORE)) c.c_ignore = strtoull(buf, NULL, 10);
|
||||||
|
else if(!strcmp(key, MEMCACHED_MSGS_SIZE)) c.c_size = strtoull(buf, NULL, 10);
|
||||||
else if(!strcmp(key, MEMCACHED_COUNTERS_LAST_UPDATE)) mc = strtoull(buf, NULL, 10);
|
else if(!strcmp(key, MEMCACHED_COUNTERS_LAST_UPDATE)) mc = strtoull(buf, NULL, 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,7 +82,7 @@ void update_counters(struct session_data *sdata, struct __data *data, struct __c
|
|||||||
if(sdata->now - mc > cfg->memcached_to_db_interval && c.c_rcvd > 0 && c.c_rcvd >= rcvd){
|
if(sdata->now - mc > cfg->memcached_to_db_interval && c.c_rcvd > 0 && c.c_rcvd >= rcvd){
|
||||||
snprintf(buf, SMALLBUFSIZE-1, "%ld", sdata->now); memcached_set(&(data->memc), MEMCACHED_COUNTERS_LAST_UPDATE, strlen(MEMCACHED_COUNTERS_LAST_UPDATE), buf, strlen(buf), 0, 0);
|
snprintf(buf, SMALLBUFSIZE-1, "%ld", sdata->now); memcached_set(&(data->memc), MEMCACHED_COUNTERS_LAST_UPDATE, strlen(MEMCACHED_COUNTERS_LAST_UPDATE), buf, strlen(buf), 0, 0);
|
||||||
|
|
||||||
snprintf(buf, SMALLBUFSIZE-1, "UPDATE `%s` SET `rcvd`=%llu, `virus`=%llu, `duplicate`=%llu, `ignore`=%llu", SQL_COUNTER_TABLE, c.c_rcvd, c.c_virus, c.c_duplicate, c.c_ignore);
|
snprintf(buf, SMALLBUFSIZE-1, "UPDATE `%s` SET `rcvd`=%llu, `virus`=%llu, `duplicate`=%llu, `ignore`=%llu, `size`=%llu", SQL_COUNTER_TABLE, c.c_rcvd, c.c_virus, c.c_duplicate, c.c_ignore, c.c_size);
|
||||||
|
|
||||||
//if(cfg->verbosity >= _LOG_DEBUG) syslog(LOG_PRIORITY, "%s: update counters: %s", sdata->ttmpfile, buf);
|
//if(cfg->verbosity >= _LOG_DEBUG) syslog(LOG_PRIORITY, "%s: update counters: %s", sdata->ttmpfile, buf);
|
||||||
|
|
||||||
@ -98,12 +101,13 @@ void update_counters(struct session_data *sdata, struct __data *data, struct __c
|
|||||||
snprintf(buf, SMALLBUFSIZE-1, "%llu", c.c_rcvd + counters->c_rcvd); memcached_add(&(data->memc), MEMCACHED_MSGS_RCVD, strlen(MEMCACHED_MSGS_RCVD), buf, strlen(buf), 0, 0);
|
snprintf(buf, SMALLBUFSIZE-1, "%llu", c.c_rcvd + counters->c_rcvd); memcached_add(&(data->memc), MEMCACHED_MSGS_RCVD, strlen(MEMCACHED_MSGS_RCVD), buf, strlen(buf), 0, 0);
|
||||||
snprintf(buf, SMALLBUFSIZE-1, "%llu", c.c_duplicate + counters->c_duplicate); memcached_add(&(data->memc), MEMCACHED_MSGS_DUPLICATE, strlen(MEMCACHED_MSGS_DUPLICATE), buf, strlen(buf), 0, 0);
|
snprintf(buf, SMALLBUFSIZE-1, "%llu", c.c_duplicate + counters->c_duplicate); memcached_add(&(data->memc), MEMCACHED_MSGS_DUPLICATE, strlen(MEMCACHED_MSGS_DUPLICATE), buf, strlen(buf), 0, 0);
|
||||||
snprintf(buf, SMALLBUFSIZE-1, "%llu", c.c_ignore + counters->c_ignore); memcached_add(&(data->memc), MEMCACHED_MSGS_IGNORE, strlen(MEMCACHED_MSGS_IGNORE), buf, strlen(buf), 0, 0);
|
snprintf(buf, SMALLBUFSIZE-1, "%llu", c.c_ignore + counters->c_ignore); memcached_add(&(data->memc), MEMCACHED_MSGS_IGNORE, strlen(MEMCACHED_MSGS_IGNORE), buf, strlen(buf), 0, 0);
|
||||||
|
snprintf(buf, SMALLBUFSIZE-1, "%llu", c.c_size + counters->c_size); memcached_add(&(data->memc), MEMCACHED_MSGS_SIZE, strlen(MEMCACHED_MSGS_SIZE), buf, strlen(buf), 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
#endif
|
#endif
|
||||||
snprintf(buf, SMALLBUFSIZE-1, "UPDATE `%s` SET `rcvd`=`rcvd`+%llu, `virus`=`virus`+%llu, `duplicate`=`duplicate`+%llu, `ignore`=`ignore`+%llu", SQL_COUNTER_TABLE, counters->c_rcvd, counters->c_virus, counters->c_duplicate, counters->c_ignore);
|
snprintf(buf, SMALLBUFSIZE-1, "UPDATE `%s` SET `rcvd`=`rcvd`+%llu, `virus`=`virus`+%llu, `duplicate`=`duplicate`+%llu, `ignore`=`ignore`+%llu, `size`=`size`+%llu", SQL_COUNTER_TABLE, counters->c_rcvd, counters->c_virus, counters->c_duplicate, counters->c_ignore, counters->c_size);
|
||||||
|
|
||||||
//if(cfg->verbosity >= _LOG_DEBUG) syslog(LOG_PRIORITY, "%s: update counters: %s", sdata->ttmpfile, buf);
|
//if(cfg->verbosity >= _LOG_DEBUG) syslog(LOG_PRIORITY, "%s: update counters: %s", sdata->ttmpfile, buf);
|
||||||
|
|
||||||
|
@ -232,6 +232,7 @@ struct __counters {
|
|||||||
unsigned long long c_virus;
|
unsigned long long c_virus;
|
||||||
unsigned long long c_duplicate;
|
unsigned long long c_duplicate;
|
||||||
unsigned long long c_ignore;
|
unsigned long long c_ignore;
|
||||||
|
unsigned long long c_size;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* _DEFS_H */
|
#endif /* _DEFS_H */
|
||||||
|
@ -25,6 +25,7 @@ int import_message(char *filename, struct session_data *sdata, struct __data *da
|
|||||||
char *rule;
|
char *rule;
|
||||||
struct stat st;
|
struct stat st;
|
||||||
struct _state state;
|
struct _state state;
|
||||||
|
struct __counters counters;
|
||||||
|
|
||||||
if(stat(filename, &st) != 0){
|
if(stat(filename, &st) != 0){
|
||||||
printf("cannot read: %s\n", filename);
|
printf("cannot read: %s\n", filename);
|
||||||
@ -67,6 +68,11 @@ ENDE:
|
|||||||
switch(rc) {
|
switch(rc) {
|
||||||
case OK:
|
case OK:
|
||||||
printf("imported: %s\n", filename);
|
printf("imported: %s\n", filename);
|
||||||
|
|
||||||
|
bzero(&counters, sizeof(counters));
|
||||||
|
counters.c_size += sdata->tot_len;
|
||||||
|
update_counters(sdata, data, &counters, cfg);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ERR_EXISTS:
|
case ERR_EXISTS:
|
||||||
|
@ -202,6 +202,7 @@ int handle_smtp_session(int new_sd, struct __data *data, struct __config *cfg){
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
inj = process_message(&sdata, &sstate, data, cfg);
|
inj = process_message(&sdata, &sstate, data, cfg);
|
||||||
|
counters.c_size += sdata.tot_len;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,7 @@ create table if not exists `metadata` (
|
|||||||
`attachments` int default 0,
|
`attachments` int default 0,
|
||||||
`piler_id` char(36) not null,
|
`piler_id` char(36) not null,
|
||||||
`message_id` char(128) character set 'latin1' not null,
|
`message_id` char(128) character set 'latin1' not null,
|
||||||
`reference` char(128) character set 'latin1' not null,
|
`reference` char(64) character set 'latin1' not null,
|
||||||
`digest` char(64) not null,
|
`digest` char(64) not null,
|
||||||
`bodydigest` char(64) not null,
|
`bodydigest` char(64) not null,
|
||||||
`vcode` char(64) default null,
|
`vcode` char(64) default null,
|
||||||
@ -137,9 +137,10 @@ create table if not exists `counter` (
|
|||||||
`virus` bigint unsigned default 0,
|
`virus` bigint unsigned default 0,
|
||||||
`duplicate` bigint unsigned default 0,
|
`duplicate` bigint unsigned default 0,
|
||||||
`ignore` bigint unsigned default 0
|
`ignore` bigint unsigned default 0
|
||||||
|
`size` bigint unsigned default 0
|
||||||
) Engine=InnoDB;
|
) Engine=InnoDB;
|
||||||
|
|
||||||
insert into `counter` values(0, 0, 0, 0);
|
insert into `counter` values(0, 0, 0, 0, 0);
|
||||||
|
|
||||||
|
|
||||||
drop table if exists `search`;
|
drop table if exists `search`;
|
||||||
|
Loading…
Reference in New Issue
Block a user