aboutsummaryrefslogtreecommitdiffstats
path: root/src/libstat
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2015-02-01 22:08:20 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2015-02-01 22:08:20 +0000
commit65892d6abe7d054499bd6cbfe36d991885466ec0 (patch)
tree31c50bb2bb2a89db77f7c489b3c497c073de5105 /src/libstat
parentb21bad88bbe7ee27a38ec0ffb0225fe998eaf2ab (diff)
downloadrspamd-65892d6abe7d054499bd6cbfe36d991885466ec0.tar.gz
rspamd-65892d6abe7d054499bd6cbfe36d991885466ec0.zip
Implement statistics for mmaped statfiles.
Diffstat (limited to 'src/libstat')
-rw-r--r--src/libstat/backends/backends.h5
-rw-r--r--src/libstat/backends/mmaped_file.c31
-rw-r--r--src/libstat/stat_config.c3
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
}
};