Statistics.hpp

1. Overview

Statistics interface. Declares counters, grouped aggregates and a bounded recent-event log.

The original source path is:

include/bsc/stats/Statistics.hpp

2. Role in the Daemon

This file participates in the privileged BastionGuard Secure Connection daemon. It uses the shared bsc models and follows the daemon-wide fallback strategy: optional high-fidelity backends are used when available, while portable polling or stub behavior preserves service startup.


3. Namespaces

  • bsc::stats

4. Dependencies and Included Interfaces

  • bsc/model/Connection.hpp
  • cstdint
  • deque
  • map
  • mutex
  • string

5. Declared Types

  • struct Event
  • class Statistics

6. State and Data Members

The interface declares the following relevant state members:

  • std::string time
  • bsc::model::Connection connection
  • std::string rule_name
  • mutable std::mutex mutex_
  • std::size_t max_events_
  • std::map<std::string, std::uint64_t> by_proto_
  • std::map<std::string, std::uint64_t> by_address_
  • std::map<std::string, std::uint64_t> by_host_
  • std::map<std::string, std::uint64_t> by_port_
  • std::map<std::string, std::uint64_t> by_uid_
  • std::map<std::string, std::uint64_t> by_executable_
  • std::deque<Event> events_

7. API and Functions

The file declares or implements the following callable entry points:

  • public: explicit Statistics(std::size_t max_events = 250)
  • void record(const bsc::model::Connection& conn, const std::string& action, const std::string& rule_name)
  • void note_dns_response()
  • explicit Statistics(std::size_t max_events = 250)

8. Recorded Metrics

  • Total connections and accepted/dropped/ignored verdicts.
  • Rule hit and miss counts and DNS response count.
  • Aggregates by protocol, address, hostname, destination port, UID and executable.
  • A bounded deque of recent detailed events.

9. External Resources and Protocol Values

Relevant paths, endpoints, command names or policy values referenced by this file include:

  • bsc/model/Connection.hpp

10. Concurrency and Lifecycle

  • Protects mutable shared data with std::mutex.

11. Implementation Considerations

  • Shared state is protected by mutexes; callers should avoid holding external locks while invoking callbacks.

12. Source Metrics

MetricValue
File size2131 bytes
Lines58
Detected API entries4
Detected types2