Skip to content
API Documentation
BastionGuard™
Statistics.hpp
Go to the documentation of this file.
1#pragma once
3#include <cstdint>
4#include <deque>
5#include <map>
6#include <mutex>
7#include <string>
8
9namespace bsc::stats {
10
11struct Event {
12 std::string time;
14 std::string rule_name;
15 std::int64_t unixnano{0};
16};
17
19 public:
20 explicit Statistics(std::size_t max_events = 250);
21 void record(const bsc::model::Connection& conn, const std::string& action, const std::string& rule_name);
22 void note_dns_response();
23 [[nodiscard]] std::uint64_t connections() const;
24 [[nodiscard]] std::uint64_t accepted() const;
25 [[nodiscard]] std::uint64_t dropped() const;
26 [[nodiscard]] std::uint64_t ignored() const;
27 [[nodiscard]] std::uint64_t rules() const;
28 [[nodiscard]] std::uint64_t dns_responses() const;
29 [[nodiscard]] std::uint64_t rule_hits() const;
30 [[nodiscard]] std::uint64_t rule_misses() const;
31 [[nodiscard]] std::map<std::string, std::uint64_t> by_proto() const;
32 [[nodiscard]] std::map<std::string, std::uint64_t> by_address() const;
33 [[nodiscard]] std::map<std::string, std::uint64_t> by_host() const;
34 [[nodiscard]] std::map<std::string, std::uint64_t> by_port() const;
35 [[nodiscard]] std::map<std::string, std::uint64_t> by_uid() const;
36 [[nodiscard]] std::map<std::string, std::uint64_t> by_executable() const;
37 [[nodiscard]] std::deque<Event> events() const;
38 private:
39 mutable std::mutex mutex_;
40 std::size_t max_events_;
41 std::uint64_t rules_{0};
42 std::uint64_t connections_{0};
43 std::uint64_t ignored_{0};
44 std::uint64_t accepted_{0};
45 std::uint64_t dropped_{0};
46 std::uint64_t dns_responses_{0};
47 std::uint64_t rule_hits_{0};
48 std::uint64_t rule_misses_{0};
49 std::map<std::string, std::uint64_t> by_proto_;
50 std::map<std::string, std::uint64_t> by_address_;
51 std::map<std::string, std::uint64_t> by_host_;
52 std::map<std::string, std::uint64_t> by_port_;
53 std::map<std::string, std::uint64_t> by_uid_;
54 std::map<std::string, std::uint64_t> by_executable_;
55 std::deque<Event> events_;
56};
57
58} // namespace bsc::stats
std::map< std::string, std::uint64_t > by_uid_
std::uint64_t rule_hits_
std::map< std::string, std::uint64_t > by_port() const
std::uint64_t dropped_
std::map< std::string, std::uint64_t > by_executable() const
std::uint64_t connections_
std::deque< Event > events() const
std::uint64_t rule_misses_
std::uint64_t ignored() const
std::map< std::string, std::uint64_t > by_address() const
std::uint64_t rule_misses() const
void record(const bsc::model::Connection &conn, const std::string &action, const std::string &rule_name)
std::map< std::string, std::uint64_t > by_port_
std::map< std::string, std::uint64_t > by_host() const
std::map< std::string, std::uint64_t > by_host_
std::uint64_t accepted_
std::map< std::string, std::uint64_t > by_address_
std::map< std::string, std::uint64_t > by_executable_
std::uint64_t dns_responses() const
Statistics(std::size_t max_events=250)
std::uint64_t dropped() const
std::uint64_t connections() const
std::uint64_t rule_hits() const
std::uint64_t accepted() const
std::uint64_t rules() const
std::map< std::string, std::uint64_t > by_proto() const
std::uint64_t ignored_
std::map< std::string, std::uint64_t > by_proto_
std::deque< Event > events_
std::map< std::string, std::uint64_t > by_uid() const
std::uint64_t dns_responses_
std::int64_t unixnano
std::string rule_name
bsc::model::Connection connection
std::string time