]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
stats: print alert count at shutdown 2826/head
authorVictor Julien <victor@inliniac.net>
Fri, 7 Jul 2017 11:34:21 +0000 (13:34 +0200)
committerVictor Julien <victor@inliniac.net>
Fri, 7 Jul 2017 11:58:06 +0000 (13:58 +0200)
Bug #1855.

src/counters.c

index e1780e9fbb48a1f75996bece6aaff3037899d7b4..910116081109fbf635ccabe37aa1d60e1dd0d500 100644 (file)
@@ -802,6 +802,25 @@ TmEcode StatsOutputCounterSocket(json_t *cmd,
 }
 #endif /* BUILD_UNIX_SOCKET */
 
+static void StatsLogSummary(void)
+{
+    uint64_t alerts = 0;
+    SCMutexLock(&stats_table_mutex);
+    if (stats_table.start_time != 0) {
+        const StatsTable *st = &stats_table;
+        uint32_t u = 0;
+        for (u = 0; u < st->nstats; u++) {
+            const char *name = st->stats[u].name;
+            if (name == NULL || strcmp(name, "detect.alert") != 0)
+                continue;
+            alerts = st->stats[u].value;
+            break;
+        }
+    }
+    SCMutexUnlock(&stats_table_mutex);
+    SCLogInfo("Alerts: %"PRIu64, alerts);
+}
+
 /**
  * \brief Initializes the perf counter api.  Things are hard coded currently.
  *        More work to be done when we implement multiple interfaces
@@ -1208,6 +1227,7 @@ uint64_t StatsGetLocalCounterValue(ThreadVars *tv, uint16_t id)
  */
 void StatsReleaseResources()
 {
+    StatsLogSummary();
     StatsReleaseCtx();
 
     return;