Statistics.cpp

1. Overview

Statistics implementation. Records verdicts, rule hit/miss counters, DNS responses and grouped metrics by protocol, address, host, port, UID and executable under a mutex.

The original source path is:

src/stats/Statistics.cpp

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/stats/Statistics.hpp
  • chrono
  • ctime
  • iomanip
  • sstream

5. API and Functions

The file declares or implements the following callable entry points:

  • now_string()
  • Statistics::Statistics(std::size_t max_events) : max_events_(max_events)
  • Statistics::record(const bsc::model::Connection& conn, const std::string& action, const std::string& rule_name)
  • Statistics::connections()
  • Statistics::accepted()
  • Statistics::dropped()
  • Statistics::ignored()
  • Statistics::rules()
  • Statistics::note_dns_response()
  • Statistics::dns_responses()
  • Statistics::rule_hits()
  • Statistics::rule_misses()
  • Statistics::by_proto()
  • Statistics::by_address()
  • Statistics::by_host()
  • Statistics::by_port()
  • Statistics::by_uid()
  • Statistics::by_executable()
  • Statistics::events()

6. External Resources and Protocol Values

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

  • bsc/stats/Statistics.hpp
  • allow

7. Implementation Considerations

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

8. Source Metrics

MetricValue
File size3089 bytes
Lines56
Detected API entries19
Detected types0