]> source.dussan.org Git - rspamd.git/commitdiff
[Feature] Add frequency and time display to webui
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 1 Nov 2016 12:26:43 +0000 (12:26 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 1 Nov 2016 12:26:43 +0000 (12:26 +0000)
src/controller.c
src/libserver/symbols_cache.c
src/libserver/symbols_cache.h

index 219ee04eddd395a88d5f18ec67731a81f16e09b5..d19ab22601b6694398cee41a798717fc84cc81cd 100644 (file)
@@ -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);
                }
 
index 1313f0840fdf704cdadea74aa9d533e657aa7f2a..68b4ffa84f3872925185a3509a9d8d33a6731182 100644 (file)
@@ -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)
index 0b5ed3cb168b9a61c8d0a8397d4189dcdecc7b40..c9877a83015100fd00173a2ff9d7ebc0683b0507 100644 (file)
@@ -119,6 +119,18 @@ gboolean rspamd_symbols_cache_add_condition_delayed (struct symbols_cache *cache
 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