rspamd_printf_gstring (out, "Statfile: %s ", symbol); | rspamd_printf_gstring (out, "Statfile: %s ", symbol); | ||||
} | } | ||||
rspamd_printf_gstring (out, "length: %HL; free blocks: %HL; total blocks: %HL; " | 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 | static void | ||||
rspamc_stat_statfile (cur, out); | 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); | rspamd_fprintf (stdout, "%v", out); | ||||
} | } |
#include "libserver/dynamic_cfg.h" | #include "libserver/dynamic_cfg.h" | ||||
#include "libutil/rrd.h" | #include "libutil/rrd.h" | ||||
#include "libutil/map.h" | #include "libutil/map.h" | ||||
#include "libstat/stat_api.h" | |||||
#include "main.h" | #include "main.h" | ||||
#ifdef WITH_GPERF_TOOLS | #ifdef WITH_GPERF_TOOLS | ||||
struct rspamd_controller_session *session = conn_ent->ud; | struct rspamd_controller_session *session = conn_ent->ud; | ||||
ucl_object_t *top, *sub; | ucl_object_t *top, *sub; | ||||
gint i; | gint i; | ||||
guint64 used, total, rev, ham = 0, spam = 0; | |||||
time_t ti; | |||||
guint64 learned = 0, spam, ham; | |||||
rspamd_mempool_stat_t mem_st; | 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; | struct rspamd_stat *stat, stat_copy; | ||||
rspamd_mempool_stat (&mem_st); | rspamd_mempool_stat (&mem_st); | ||||
spam), "spam_count", 0, false); | spam), "spam_count", 0, false); | ||||
ucl_object_insert_key (top, ucl_object_fromint ( | ucl_object_insert_key (top, ucl_object_fromint ( | ||||
ham), "ham_count", 0, false); | 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_insert_key (top, | ||||
ucl_object_fromint (stat->connections_count), "connections", 0, false); | ucl_object_fromint (stat->connections_count), "connections", 0, false); | ||||
ucl_object_insert_key (top, | ucl_object_insert_key (top, | ||||
stat->fuzzy_hashes_expired), "fuzzy_expired", 0, false); | stat->fuzzy_hashes_expired), "fuzzy_expired", 0, false); | ||||
/* Now write statistics for each statfile */ | /* 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, sub, "statfiles", 0, false); | ||||
ucl_object_insert_key (top, | |||||
ucl_object_fromint (learned), "total_learns", 0, false); | |||||
if (do_reset) { | if (do_reset) { | ||||
session->ctx->srv->stat->messages_scanned = 0; | session->ctx->srv->stat->messages_scanned = 0; |
gboolean rspamd_stat_learn (struct rspamd_task *task, gboolean spam, lua_State *L, | gboolean rspamd_stat_learn (struct rspamd_task *task, gboolean spam, lua_State *L, | ||||
GError **err); | 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); | void rspamd_stat_unload (void); | ||||
return ret; | 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; | |||||
} |