diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-02-01 22:33:59 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-02-01 22:33:59 +0000 |
commit | 526afdf95a5ab8a12a96c3095501265077ff24f2 (patch) | |
tree | 0594fb88c9da773c1d465fab7a4e56c2c1a1d91a /src/libstat | |
parent | 65892d6abe7d054499bd6cbfe36d991885466ec0 (diff) | |
download | rspamd-526afdf95a5ab8a12a96c3095501265077ff24f2.tar.gz rspamd-526afdf95a5ab8a12a96c3095501265077ff24f2.zip |
Return statfiles stats from controller.
Diffstat (limited to 'src/libstat')
-rw-r--r-- | src/libstat/stat_api.h | 8 | ||||
-rw-r--r-- | src/libstat/stat_process.c | 57 |
2 files changed, 65 insertions, 0 deletions
diff --git a/src/libstat/stat_api.h b/src/libstat/stat_api.h index 2dbf19372..c0023ffbd 100644 --- a/src/libstat/stat_api.h +++ b/src/libstat/stat_api.h @@ -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); diff --git a/src/libstat/stat_process.c b/src/libstat/stat_process.c index 022edde7d..dc58e0ac4 100644 --- a/src/libstat/stat_process.c +++ b/src/libstat/stat_process.c @@ -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; +} |