diff options
Diffstat (limited to 'src/libstat')
-rw-r--r-- | src/libstat/backends/backends.h | 5 | ||||
-rw-r--r-- | src/libstat/backends/mmaped_file.c | 31 | ||||
-rw-r--r-- | src/libstat/stat_config.c | 3 |
3 files changed, 37 insertions, 2 deletions
diff --git a/src/libstat/backends/backends.h b/src/libstat/backends/backends.h index a3042e8a4..c7c4210fb 100644 --- a/src/libstat/backends/backends.h +++ b/src/libstat/backends/backends.h @@ -26,7 +26,7 @@ #define BACKENDS_H_ #include "config.h" - +#include "ucl.h" #define RSPAMD_DEFAULT_BACKEND "mmap" @@ -49,6 +49,7 @@ struct rspamd_stat_backend { struct rspamd_token_result *res, gpointer ctx); gulong (*total_learns)(struct rspamd_statfile_runtime *runtime, gpointer ctx); gulong (*inc_learns)(struct rspamd_statfile_runtime *runtime, gpointer ctx); + ucl_object_t* (*get_stat)(struct rspamd_statfile_runtime *runtime, gpointer ctx); gpointer ctx; }; @@ -65,5 +66,7 @@ gulong rspamd_mmaped_file_total_learns (struct rspamd_statfile_runtime *runtime, gpointer ctx); gulong rspamd_mmaped_file_inc_learns (struct rspamd_statfile_runtime *runtime, gpointer ctx); +ucl_object_t * rspamd_mmaped_file_get_stat (struct rspamd_statfile_runtime *runtime, + gpointer ctx); #endif /* BACKENDS_H_ */ diff --git a/src/libstat/backends/mmaped_file.c b/src/libstat/backends/mmaped_file.c index e85db248b..aa99b0902 100644 --- a/src/libstat/backends/mmaped_file.c +++ b/src/libstat/backends/mmaped_file.c @@ -972,3 +972,34 @@ rspamd_mmaped_file_inc_learns (struct rspamd_statfile_runtime *runtime, return rev; } + +ucl_object_t * +rspamd_mmaped_file_get_stat (struct rspamd_statfile_runtime *runtime, + gpointer ctx) +{ + ucl_object_t *res = NULL; + rspamd_mmaped_file_t *mf = (rspamd_mmaped_file_t *)runtime; + + if (mf != NULL) { + res = ucl_object_typed_new (UCL_OBJECT); + + ucl_object_insert_key (res, ucl_object_fromint ( + rspamd_mmaped_file_get_revision (mf, NULL, NULL)), "revision", + 0, false); + ucl_object_insert_key (res, ucl_object_fromint (mf->len), "size", + 0, false); + ucl_object_insert_key (res, ucl_object_fromint ( + rspamd_mmaped_file_get_total (mf)), "total", 0, false); + ucl_object_insert_key (res, ucl_object_fromint ( + rspamd_mmaped_file_get_used (mf)), "used", 0, false); + ucl_object_insert_key (res, ucl_object_fromstring (mf->cf->symbol), + "symbol", 0, false); + + if (mf->cf->label) { + ucl_object_insert_key (res, ucl_object_fromstring (mf->cf->label), + "label", 0, false); + } + } + + return res; +} diff --git a/src/libstat/stat_config.c b/src/libstat/stat_config.c index 7d24be267..53eff3ecb 100644 --- a/src/libstat/stat_config.c +++ b/src/libstat/stat_config.c @@ -52,7 +52,8 @@ struct rspamd_stat_backend stat_backends[] = { .process_token = rspamd_mmaped_file_process_token, .learn_token = rspamd_mmaped_file_learn_token, .total_learns = rspamd_mmaped_file_total_learns, - .inc_learns = rspamd_mmaped_file_inc_learns + .inc_learns = rspamd_mmaped_file_inc_learns, + .get_stat = rspamd_mmaped_file_get_stat } }; |