mirror of
https://github.com/XRPLF/clio.git
synced 2025-12-06 17:27:58 +00:00
Report RPC counts in server_info (#72)
This commit is contained in:
53
src/rpc/Counters.h
Normal file
53
src/rpc/Counters.h
Normal 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
|
||||
Reference in New Issue
Block a user