mirror of
https://bitbucket.org/jsuto/piler.git
synced 2024-12-24 19:20:12 +01:00
pilerstats shows the delta between now and the last archived email
Signed-off-by: Janos SUTO <sj@acts.hu>
This commit is contained in:
parent
c5959f79c4
commit
5d31891f87
39
src/stats.c
39
src/stats.c
@ -33,7 +33,7 @@ struct stats {
|
|||||||
uint64 disk_bytes;
|
uint64 disk_bytes;
|
||||||
|
|
||||||
uint64 error_emails;
|
uint64 error_emails;
|
||||||
|
long last_email;
|
||||||
float smtp_response_time;
|
float smtp_response_time;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -66,6 +66,39 @@ int query_counters(struct session_data *sdata, struct stats *stats){
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int get_last_email_archived_timestamp(struct session_data *sdata, struct stats *stats){
|
||||||
|
int rc=ERR;
|
||||||
|
unsigned long arrived=86400;
|
||||||
|
struct sql sql;
|
||||||
|
|
||||||
|
// By default we haven't archived a mail a day ago, and this value should represent an error
|
||||||
|
time(&(sdata->now));
|
||||||
|
arrived = sdata->now - 86400;
|
||||||
|
|
||||||
|
if(prepare_sql_statement(sdata, &sql, "select arrived from metadata order by id desc limit 1") == ERR) return rc;
|
||||||
|
|
||||||
|
p_bind_init(&sql);
|
||||||
|
|
||||||
|
if(p_exec_stmt(sdata, &sql) == OK){
|
||||||
|
p_bind_init(&sql);
|
||||||
|
|
||||||
|
sql.sql[sql.pos] = (char *)&arrived; sql.type[sql.pos] = TYPE_LONG; sql.len[sql.pos] = sizeof(arrived); sql.pos++;
|
||||||
|
|
||||||
|
p_store_results(&sql);
|
||||||
|
|
||||||
|
if(p_fetch_results(&sql) == OK) rc = OK;
|
||||||
|
|
||||||
|
p_free_results(&sql);
|
||||||
|
}
|
||||||
|
|
||||||
|
close_prepared_statement(&sql);
|
||||||
|
|
||||||
|
stats->last_email = sdata->now - arrived;
|
||||||
|
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void sphinx_queries(struct session_data *sdata, struct stats *stats){
|
void sphinx_queries(struct session_data *sdata, struct stats *stats){
|
||||||
MYSQL_RES *result;
|
MYSQL_RES *result;
|
||||||
MYSQL_ROW row;
|
MYSQL_ROW row;
|
||||||
@ -182,6 +215,7 @@ void print_json_results(struct stats *stats){
|
|||||||
printf("\t\"ram_bytes\": %llu,\n", stats->ram_bytes);
|
printf("\t\"ram_bytes\": %llu,\n", stats->ram_bytes);
|
||||||
printf("\t\"disk_bytes\": %llu,\n", stats->disk_bytes);
|
printf("\t\"disk_bytes\": %llu,\n", stats->disk_bytes);
|
||||||
printf("\t\"error_emails\": %llu,\n", stats->error_emails);
|
printf("\t\"error_emails\": %llu,\n", stats->error_emails);
|
||||||
|
printf("\t\"last_email\": %ld,\n", stats->last_email);
|
||||||
printf("\t\"smtp_response\": %.2f\n", stats->smtp_response_time);
|
printf("\t\"smtp_response\": %.2f\n", stats->smtp_response_time);
|
||||||
|
|
||||||
printf("}\n");
|
printf("}\n");
|
||||||
@ -205,6 +239,7 @@ int main(int argc, char **argv){
|
|||||||
if(open_database(&sdata, &cfg) == ERR) return 0;
|
if(open_database(&sdata, &cfg) == ERR) return 0;
|
||||||
|
|
||||||
query_counters(&sdata, &stats);
|
query_counters(&sdata, &stats);
|
||||||
|
get_last_email_archived_timestamp(&sdata, &stats);
|
||||||
|
|
||||||
close_database(&sdata);
|
close_database(&sdata);
|
||||||
|
|
||||||
@ -216,7 +251,7 @@ int main(int argc, char **argv){
|
|||||||
if(open_database(&sdata, &cfg) == ERR) return 0;
|
if(open_database(&sdata, &cfg) == ERR) return 0;
|
||||||
|
|
||||||
sphinx_queries(&sdata, &stats);
|
sphinx_queries(&sdata, &stats);
|
||||||
|
|
||||||
close_database(&sdata);
|
close_database(&sdata);
|
||||||
|
|
||||||
count_error_emails(&stats);
|
count_error_emails(&stats);
|
||||||
|
Loading…
Reference in New Issue
Block a user