LCOV - code coverage report
Current view: top level - src/stats - client.h (source / functions) Hit Total Coverage
Test: total_coverage.info Lines: 6 13 46.2 %
Date: 2026-06-25 07:23:43 Functions: 10 17 58.8 %

          Line data    Source code
       1             : // Copyright (c) 2014-2017 Statoshi Developers
       2             : // Copyright (c) 2017-2023 Vincent Thiery
       3             : // Copyright (c) 2020-2025 The Dash Core developers
       4             : // Distributed under the MIT software license, see the accompanying
       5             : // file COPYING or http://www.opensource.org/licenses/mit-license.php.
       6             : 
       7             : #ifndef BITCOIN_STATS_CLIENT_H
       8             : #define BITCOIN_STATS_CLIENT_H
       9             : 
      10             : #include <util/result.h>
      11             : 
      12             : #include <cstdint>
      13             : #include <memory>
      14             : #include <string>
      15             : #include <string_view>
      16             : 
      17             : class ArgsManager;
      18             : 
      19             : /** Default host assumed to be running a Statsd server */
      20             : static const std::string DEFAULT_STATSD_HOST{};
      21             : /** Default prefix prepended to Statsd message keys */
      22             : static const std::string DEFAULT_STATSD_PREFIX{};
      23             : /** Default suffix appended to Statsd message keys */
      24             : static const std::string DEFAULT_STATSD_SUFFIX{};
      25             : 
      26             : /** Default number of milliseconds between flushing a queue of messages */
      27             : static constexpr int DEFAULT_STATSD_DURATION{1000};
      28             : /** Default number of seconds between recording periodic stats */
      29             : static constexpr int DEFAULT_STATSD_PERIOD{60};
      30             : /** Default size in bytes of a batch of messages */
      31             : static constexpr int DEFAULT_STATSD_BATCH_SIZE{1024};
      32             : /** Minimum number of seconds between recording periodic stats */
      33             : static constexpr int MIN_STATSD_PERIOD{5};
      34             : /** Maximum number of seconds between recording periodic stats */
      35             : static constexpr int MAX_STATSD_PERIOD{60 * 60};
      36             : 
      37             : class StatsdClient
      38             : {
      39             : public:
      40             :     static util::Result<std::unique_ptr<StatsdClient>> make(const ArgsManager& args);
      41       10676 :     virtual ~StatsdClient() = default;
      42             : 
      43             :     /* Statsd-defined APIs */
      44           0 :     virtual bool dec(std::string_view key, float sample_rate = 1.f) { return false; }
      45     1907709 :     virtual bool inc(std::string_view key, float sample_rate = 1.f) { return false; }
      46     3441815 :     virtual bool count(std::string_view key, int64_t delta, float sample_rate = 1.f) { return false; }
      47     2909242 :     virtual bool gauge(std::string_view key, int64_t value, float sample_rate = 1.f) { return false; }
      48           0 :     virtual bool gaugeDouble(std::string_view key, double value, float sample_rate = 1.f) { return false; }
      49     1964845 :     virtual bool timing(std::string_view key, uint64_t ms, float sample_rate = 1.f) { return false; }
      50             : 
      51             :     /* Statsd-compatible APIs */
      52           0 :     virtual bool send(std::string_view key, double value, std::string_view type, float sample_rate = 1.f) { return false; }
      53           0 :     virtual bool send(std::string_view key, int32_t value, std::string_view type, float sample_rate = 1.f) { return false; }
      54           0 :     virtual bool send(std::string_view key, int64_t value, std::string_view type, float sample_rate = 1.f) { return false; }
      55           0 :     virtual bool send(std::string_view key, uint32_t value, std::string_view type, float sample_rate = 1.f) { return false; }
      56           0 :     virtual bool send(std::string_view key, uint64_t value, std::string_view type, float sample_rate = 1.f) { return false; }
      57             : 
      58             :     /* Check if a StatsdClient instance is ready to send messages */
      59      149584 :     virtual bool active() const { return false; }
      60             : };
      61             : 
      62             : /** Global smart pointer containing StatsdClient instance */
      63             : extern std::unique_ptr<StatsdClient> g_stats_client;
      64             : 
      65             : #endif // BITCOIN_STATS_CLIENT_H

Generated by: LCOV version 1.16