This is a work in progress, all comments and review are welcome and appreciated.
TL;DR: We add a new network RPC call, getnetworkrpcinfo, that returns metrics about JSON RPC HTTP server.
INTRODUCTION
As part of constructing Service Level Agreements (SLAs) around the uptime of Bitcoin nodes, it is useful to measure such things as requests processed per second or average request processing time. While the getnetworkinfo RPC call provides a lot information and many useful metrics about the P2P layer of Bitcoin, it does not provide any metrics about the JSON RPC layer. Since many services interact with Bitcoin almost entirely through its JSON RPC interface, it would be useful to collect and provide metrics about this interface.
OVERVIEW OF CHANGES
This PR contains two major changes: Collecting HTTP server metrics and Adding a new RPC method.
Collect HTTP Server Metrics (httpserver.h, httpserver.cpp)
This change is the first part of adding a new RPC call to report stats from the HTTP server. It modifies the HTTP server functionality to collect and report the gathered statistics.
httpserver.h:
- Add private member variable
receivedAtTimeMicrostoHTTPRequestto record the time at which the request was started. - Add data-type,
RPCServerStats, that holds all gathered HTTP server stats. - Add function,
GetRPCServerStats, that returns the current RPC server stats via the provider pointer.
httpserver.cpp:
- Add static global
g_rpcserverstatsto hold HTTP server stats across all requests. - Add static global
g_rpcserverstats_mutexto serialize writes tog_rpcserverstats. - Modify several functions to collect the RPC server stats.
- Implement
GetRPCServerStats.
Add getnetworkrpcinfo RPC Method (rpc/net.cpp)
Add a new RPC command, getnetworkrpcinfo, that returns an object containing various state information about the HTTP server providing a JSON RPC interface. This information can be used to derive information such as requests per second and average request processing time.
The information is provided in a raw form leaving the clients to derive such useful metrics, this is intentional and allows this RPC call to avoid issues around floating point accuracy and floating point error accumulation. Instead, these issues are left to the consumers of the response object to handle in whatever fashion they like.