mirror of
https://github.com/XRPLF/clio.git
synced 2025-12-06 17:27:58 +00:00
@@ -28,10 +28,16 @@
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace RPC {
|
||||
namespace rpc {
|
||||
|
||||
/**
|
||||
* @brief Holds information about successful, failed, forwarded, etc. RPC handler calls.
|
||||
*/
|
||||
class Counters
|
||||
{
|
||||
/**
|
||||
* @brief All counters the system keeps track of for each RPC method.
|
||||
*/
|
||||
struct MethodInfo
|
||||
{
|
||||
std::uint64_t started = 0u;
|
||||
@@ -57,49 +63,92 @@ class Counters
|
||||
std::chrono::time_point<std::chrono::system_clock> startupTime_;
|
||||
|
||||
public:
|
||||
/**
|
||||
* @brief Creates a new counters instance that operates on the given WorkQueue.
|
||||
*
|
||||
* @param wq The work queue to operate on
|
||||
*/
|
||||
Counters(WorkQueue const& wq) : workQueue_(std::cref(wq)), startupTime_{std::chrono::system_clock::now()} {};
|
||||
|
||||
/**
|
||||
* @brief A factory function that creates a new counters instance.
|
||||
*
|
||||
* @param wq The work queue to operate on
|
||||
* @return The new instance
|
||||
*/
|
||||
static Counters
|
||||
make_Counters(WorkQueue const& wq)
|
||||
{
|
||||
return Counters{wq};
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Increments the failed count for a particular RPC method.
|
||||
*
|
||||
* @param method The method to increment the count for
|
||||
*/
|
||||
void
|
||||
rpcFailed(std::string const& method);
|
||||
|
||||
/**
|
||||
* @brief Increments the errored count for a particular RPC method.
|
||||
*
|
||||
* @param method The method to increment the count for
|
||||
*/
|
||||
void
|
||||
rpcErrored(std::string const& method);
|
||||
|
||||
/**
|
||||
* @brief Increments the completed count for a particular RPC method.
|
||||
*
|
||||
* @param method The method to increment the count for
|
||||
*/
|
||||
void
|
||||
rpcComplete(std::string const& method, std::chrono::microseconds const& rpcDuration);
|
||||
|
||||
/**
|
||||
* @brief Increments the forwarded count for a particular RPC method.
|
||||
*
|
||||
* @param method The method to increment the count for
|
||||
*/
|
||||
void
|
||||
rpcForwarded(std::string const& method);
|
||||
|
||||
/**
|
||||
* @brief Increments the failed to forward count for a particular RPC method.
|
||||
*
|
||||
* @param method The method to increment the count for
|
||||
*/
|
||||
void
|
||||
rpcFailedToForward(std::string const& method);
|
||||
|
||||
/** @brief Increments the global too busy counter. */
|
||||
void
|
||||
onTooBusy();
|
||||
|
||||
/** @brief Increments the global not ready counter. */
|
||||
void
|
||||
onNotReady();
|
||||
|
||||
/** @brief Increments the global bad syntax counter. */
|
||||
void
|
||||
onBadSyntax();
|
||||
|
||||
/** @brief Increments the global unknown command/method counter. */
|
||||
void
|
||||
onUnknownCommand();
|
||||
|
||||
/** @brief Increments the global internal error counter. */
|
||||
void
|
||||
onInternalError();
|
||||
|
||||
/** @return Uptime of this instance in seconds. */
|
||||
std::chrono::seconds
|
||||
uptime() const;
|
||||
|
||||
/** @return A JSON report with current state of all counters for every method. */
|
||||
boost::json::object
|
||||
report() const;
|
||||
};
|
||||
|
||||
} // namespace RPC
|
||||
} // namespace rpc
|
||||
|
||||
Reference in New Issue
Block a user