diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-11-01 12:26:43 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-11-01 12:26:43 +0000 |
commit | c1a32980153a8f90ce6e25fdf8ec7c8c769cd38a (patch) | |
tree | 4b7e998aa1bcb56e32c28a90201384313477b50c /src | |
parent | 31e9ec3a264940b74d05e1dd29758264039d224b (diff) | |
download | rspamd-c1a32980153a8f90ce6e25fdf8ec7c8c769cd38a.tar.gz rspamd-c1a32980153a8f90ce6e25fdf8ec7c8c769cd38a.zip |
[Feature] Add frequency and time display to webui
Diffstat (limited to 'src')
-rw-r--r-- | src/controller.c | 13 | ||||
-rw-r--r-- | src/libserver/symbols_cache.c | 26 | ||||
-rw-r--r-- | src/libserver/symbols_cache.h | 12 |
3 files changed, 51 insertions, 0 deletions
diff --git a/src/controller.c b/src/controller.c index 219ee04ed..d19ab2260 100644 --- a/src/controller.c +++ b/src/controller.c @@ -734,6 +734,9 @@ rspamd_controller_handle_symbols (struct rspamd_http_connection_entry *conn_ent, group_symbols = ucl_object_typed_new (UCL_ARRAY); while (g_hash_table_iter_next (&sit, &k, &v)) { + guint freq = 0; + gdouble tm = 0.0; + sym = v; sym_obj = ucl_object_typed_new (UCL_OBJECT); @@ -748,6 +751,16 @@ rspamd_controller_handle_symbols (struct rspamd_http_connection_entry *conn_ent, "description", 0, false); } + if (rspamd_symbols_cache_stat_symbol (session->ctx->cfg->cache, + sym->name, &freq, &tm)) { + ucl_object_insert_key (sym_obj, + ucl_object_fromint (freq), + "frequency", 0, false); + ucl_object_insert_key (sym_obj, + ucl_object_fromdouble (tm), + "time", 0, false); + } + ucl_array_append (group_symbols, sym_obj); } diff --git a/src/libserver/symbols_cache.c b/src/libserver/symbols_cache.c index 1313f0840..68b4ffa84 100644 --- a/src/libserver/symbols_cache.c +++ b/src/libserver/symbols_cache.c @@ -1934,6 +1934,32 @@ rspamd_symbols_cache_find_symbol (struct symbols_cache *cache, const gchar *name return -1; } +gboolean +rspamd_symbols_cache_stat_symbol (struct symbols_cache *cache, + const gchar *name, + guint *frequency, + gdouble *tm) +{ + struct cache_item *item; + + g_assert (cache != NULL); + + if (name == NULL) { + return FALSE; + } + + item = g_hash_table_lookup (cache->items_by_symbol, name); + + if (item != NULL) { + *frequency = item->frequency; + *tm = item->avg_time; + + return TRUE; + } + + return FALSE; +} + static gint rspamd_symbols_cache_find_symbol_parent (struct symbols_cache *cache, const gchar *name) diff --git a/src/libserver/symbols_cache.h b/src/libserver/symbols_cache.h index 0b5ed3cb1..c9877a830 100644 --- a/src/libserver/symbols_cache.h +++ b/src/libserver/symbols_cache.h @@ -120,6 +120,18 @@ gint rspamd_symbols_cache_find_symbol (struct symbols_cache *cache, const gchar *name); /** + * Get statistics for a specific symbol + * @param cache + * @param name + * @param frequency + * @param tm + * @return + */ +gboolean rspamd_symbols_cache_stat_symbol (struct symbols_cache *cache, + const gchar *name, + guint *frequency, + gdouble *tm); +/** * Find symbol in cache by its id * @param cache * @param id |