1 //--------------------------------------------------------------------------
2 // Copyright (C) 2014-2021 Cisco and/or its affiliates. All rights reserved.
3 // Copyright (C) 2013-2013 Sourcefire, Inc.
4 //
5 // This program is free software; you can redistribute it and/or modify it
6 // under the terms of the GNU General Public License Version 2 as published
7 // by the Free Software Foundation. You may not use, modify or distribute
8 // this program under any other version of the GNU General Public License.
9 //
10 // This program is distributed in the hope that it will be useful, but
11 // WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License along
16 // with this program; if not, write to the Free Software Foundation, Inc.,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 //--------------------------------------------------------------------------
19
20 #ifndef STATS_H
21 #define STATS_H
22
23 // Provides facilities for displaying Snort exit stats
24
25 #include <daq_common.h>
26 #include <vector>
27
28 #include "framework/counts.h"
29 #include "main/snort_types.h"
30 #include "main/thread.h"
31
32 using IndexVec = std::vector<unsigned>;
33
34 class ControlConn;
35
36 // FIXIT-L split this out into appropriate modules
37 struct PacketCount
38 {
39 PegCount analyzed_pkts;
40 PegCount hard_evals;
41 PegCount raw_searches;
42 PegCount cooked_searches;
43 PegCount pkt_searches;
44 PegCount alt_searches;
45 PegCount key_searches;
46 PegCount header_searches;
47 PegCount body_searches;
48 PegCount file_searches;
49 PegCount raw_key_searches;
50 PegCount raw_header_searches;
51 PegCount method_searches;
52 PegCount stat_code_searches;
53 PegCount stat_msg_searches;
54 PegCount cookie_searches;
55 PegCount js_data_searches;
56 PegCount vba_searches;
57 PegCount offloads;
58 PegCount alert_pkts;
59 PegCount total_alert_pkts;
60 PegCount log_pkts;
61 PegCount pass_pkts;
62 PegCount match_limit;
63 PegCount queue_limit;
64 PegCount log_limit;
65 PegCount event_limit;
66 PegCount alert_limit;
67 PegCount context_stalls;
68 PegCount offload_busy;
69 PegCount onload_waits;
70 PegCount offload_fallback;
71 PegCount offload_failures;
72 PegCount offload_suspends;
73 PegCount pcre_match_limit;
74 PegCount pcre_recursion_limit;
75 PegCount pcre_error;
76 };
77
78 struct ProcessCount
79 {
80 PegCount local_commands;
81 PegCount remote_commands;
82 PegCount signals;
83 PegCount conf_reloads;
84 PegCount policy_reloads;
85 PegCount inspector_deletions;
86 PegCount daq_reloads;
87 PegCount attribute_table_reloads;
88 PegCount attribute_table_hosts; // FIXIT-D - remove when host attribute pegs updated
89 PegCount attribute_table_overflow; // FIXIT-D - remove when host attribute pegs updated
90 };
91
92 extern ProcessCount proc_stats;
93
94 extern const PegInfo daq_names[];
95 extern const PegInfo pc_names[];
96 extern const PegInfo proc_names[];
97
98 namespace snort
99 {
100 extern SO_PUBLIC THREAD_LOCAL PacketCount pc;
101
get_packet_number()102 SO_PUBLIC inline PegCount get_packet_number() { return pc.analyzed_pkts; }
103
104 SO_PUBLIC void LogLabel(const char*, FILE* = stdout);
105 SO_PUBLIC void LogText(const char*, FILE* = stdout);
106 SO_PUBLIC void LogValue(const char*, const char*, FILE* = stdout);
107 SO_PUBLIC void LogCount(const char*, uint64_t, FILE* = stdout);
108
109 SO_PUBLIC void LogStat(const char*, uint64_t n, uint64_t tot, FILE* = stdout);
110 SO_PUBLIC void LogStat(const char*, double, FILE* = stdout);
111 }
112
113 void sum_stats(PegCount* sums, PegCount* counts, unsigned n);
114 void show_stats(PegCount*, const PegInfo*, const char* module_name = nullptr);
115 void show_stats(PegCount*, const PegInfo*, unsigned n, const char* module_name = nullptr);
116 void show_stats(PegCount*, const PegInfo*, const IndexVec&, const char* module_name, FILE*);
117 void show_percent_stats(PegCount*, const char*[], unsigned n, const char* module_name = nullptr);
118
119 void sum_stats(SimpleStats* sums, SimpleStats* counts);
120 void show_stats(SimpleStats*, const char* module_name);
121
122 double CalcPct(uint64_t, uint64_t);
123 void DropStats(ControlConn* ctrlcon = nullptr);
124 void PrintStatistics();
125 void TimeStart();
126 void TimeStop();
127
128 #endif
129