Report RPC counts in server_info (#72)

This commit is contained in:
Nathan Nichols
2022-01-05 11:58:17 -06:00
committed by GitHub
parent 2f0b3235ee
commit 41e412302b
13 changed files with 240 additions and 18 deletions

53
src/rpc/Counters.h Normal file
View File

@@ -0,0 +1,53 @@
#ifndef RPC_COUNTERS_H
#define RPC_COUNTERS_H
#include <chrono>
#include <cstdint>
#include <string>
#include <shared_mutex>
#include <boost/json.hpp>
namespace RPC
{
class Counters
{
private:
struct MethodInfo
{
MethodInfo() = default;
std::atomic_uint started{0};
std::atomic_uint finished{0};
std::atomic_uint errored{0};
std::atomic_uint forwarded{0};
std::atomic_uint duration{0};
};
void
initializeCounter(std::string const& method);
std::shared_mutex mutex_;
std::unordered_map<std::string, MethodInfo> methodInfo_;
public:
Counters() = default;
void
rpcErrored(std::string const& method);
void
rpcComplete(
std::string const& method,
std::chrono::microseconds const& rpcDuration);
void
rpcForwarded(std::string const& method);
boost::json::object
report();
};
} // namespace RPCs
#endif // RPC_COUNTERS_H