@@ -679,8 +679,8 @@ rspamc_stat_statfile (const ucl_object_t *obj, GString *out) | |||
rspamd_printf_gstring (out, "Statfile: %s ", symbol); | |||
} | |||
rspamd_printf_gstring (out, "length: %HL; free blocks: %HL; total blocks: %HL; " | |||
"free: %.2f%%\n", size, blocks - used_blocks, blocks, | |||
(blocks - used_blocks) * 100.0 / (gdouble)blocks); | |||
"free: %.2f%%; learned: %L\n", size, blocks - used_blocks, blocks, | |||
(blocks - used_blocks) * 100.0 / (gdouble)blocks, version); | |||
} | |||
static void | |||
@@ -734,6 +734,8 @@ rspamc_stat_output (ucl_object_t *obj) | |||
rspamc_stat_statfile (cur, out); | |||
} | |||
} | |||
rspamd_printf_gstring (out, "Total learns: %L\n", | |||
ucl_object_toint (ucl_object_find_key (obj, "total_learns"))); | |||
rspamd_fprintf (stdout, "%v", out); | |||
} |
@@ -26,6 +26,7 @@ | |||
#include "libserver/dynamic_cfg.h" | |||
#include "libutil/rrd.h" | |||
#include "libutil/map.h" | |||
#include "libstat/stat_api.h" | |||
#include "main.h" | |||
#ifdef WITH_GPERF_TOOLS | |||
@@ -1255,12 +1256,8 @@ rspamd_controller_handle_stat_common ( | |||
struct rspamd_controller_session *session = conn_ent->ud; | |||
ucl_object_t *top, *sub; | |||
gint i; | |||
guint64 used, total, rev, ham = 0, spam = 0; | |||
time_t ti; | |||
guint64 learned = 0, spam, ham; | |||
rspamd_mempool_stat_t mem_st; | |||
struct rspamd_classifier_config *ccf; | |||
struct rspamd_statfile_config *st; | |||
GList *cur_cl, *cur_st; | |||
struct rspamd_stat *stat, stat_copy; | |||
rspamd_mempool_stat (&mem_st); | |||
@@ -1293,8 +1290,6 @@ rspamd_controller_handle_stat_common ( | |||
spam), "spam_count", 0, false); | |||
ucl_object_insert_key (top, ucl_object_fromint ( | |||
ham), "ham_count", 0, false); | |||
ucl_object_insert_key (top, | |||
ucl_object_fromint (stat->messages_learned), "learned", 0, false); | |||
ucl_object_insert_key (top, | |||
ucl_object_fromint (stat->connections_count), "connections", 0, false); | |||
ucl_object_insert_key (top, | |||
@@ -1327,15 +1322,11 @@ rspamd_controller_handle_stat_common ( | |||
stat->fuzzy_hashes_expired), "fuzzy_expired", 0, false); | |||
/* Now write statistics for each statfile */ | |||
cur_cl = g_list_first (session->ctx->cfg->classifiers); | |||
sub = ucl_object_typed_new (UCL_ARRAY); | |||
while (cur_cl) { | |||
ccf = cur_cl->data; | |||
/* XXX: add statistics for the modern system */ | |||
cur_cl = g_list_next (cur_cl); | |||
} | |||
sub = rspamd_stat_statistics (session->ctx->cfg, &learned); | |||
ucl_object_insert_key (top, sub, "statfiles", 0, false); | |||
ucl_object_insert_key (top, | |||
ucl_object_fromint (learned), "total_learns", 0, false); | |||
if (do_reset) { | |||
session->ctx->srv->stat->messages_scanned = 0; |
@@ -55,6 +55,14 @@ gboolean rspamd_stat_classify (struct rspamd_task *task, lua_State *L, GError ** | |||
gboolean rspamd_stat_learn (struct rspamd_task *task, gboolean spam, lua_State *L, | |||
GError **err); | |||
/** | |||
* Get the overall statistics for all statfile backends | |||
* @param cfg configuration | |||
* @param total_learns the total number of learns is stored here | |||
* @return array of statistical information | |||
*/ | |||
ucl_object_t * rspamd_stat_statistics (struct rspamd_config *cfg, | |||
guint64 *total_learns); | |||
void rspamd_stat_unload (void); | |||
@@ -536,3 +536,60 @@ rspamd_stat_learn (struct rspamd_task *task, gboolean spam, lua_State *L, | |||
return ret; | |||
} | |||
ucl_object_t * | |||
rspamd_stat_statistics (struct rspamd_config *cfg, guint64 *total_learns) | |||
{ | |||
struct rspamd_classifier_config *clcf; | |||
struct rspamd_statfile_config *stcf; | |||
struct rspamd_stat_backend *bk; | |||
gpointer backend_runtime; | |||
GList *cur, *st_list = NULL, *curst; | |||
ucl_object_t *res = NULL, *elt; | |||
guint64 learns = 0; | |||
if (cfg != NULL && cfg->classifiers != NULL) { | |||
res = ucl_object_typed_new (UCL_ARRAY); | |||
cur = g_list_first (cfg->classifiers); | |||
while (cur) { | |||
clcf = (struct rspamd_classifier_config *)cur->data; | |||
st_list = clcf->statfiles; | |||
curst = st_list; | |||
while (curst != NULL) { | |||
stcf = (struct rspamd_statfile_config *)curst->data; | |||
bk = rspamd_stat_get_backend (stcf->backend); | |||
if (bk == NULL) { | |||
msg_warn ("backend of type %s is not defined", stcf->backend); | |||
curst = g_list_next (curst); | |||
continue; | |||
} | |||
backend_runtime = bk->runtime (stcf, FALSE, bk->ctx); | |||
learns += bk->total_learns (backend_runtime, bk->ctx); | |||
elt = bk->get_stat (backend_runtime, bk->ctx); | |||
if (elt != NULL) { | |||
ucl_array_append (res, elt); | |||
} | |||
curst = g_list_next (curst); | |||
} | |||
/* Next classifier */ | |||
cur = g_list_next (cur); | |||
} | |||
if (total_learns != NULL) { | |||
*total_learns = learns; | |||
} | |||
} | |||
return res; | |||
} |