From 33bf99fa74b873d2e850412b2a7f578185750d83 Mon Sep 17 00:00:00 2001 From: Gabriel Moise Date: Thu, 13 Jun 2024 16:33:17 +0300 Subject: [PATCH 1/2] RPC_process: Add metrics for external RPC calls --- src/lib_rpc_process/main.ml | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/lib_rpc_process/main.ml b/src/lib_rpc_process/main.ml index 491f324dcd53..ffa3ffbbc82a 100644 --- a/src/lib_rpc_process/main.ml +++ b/src/lib_rpc_process/main.ml @@ -59,6 +59,16 @@ let () = (function Missing_socket_dir -> Some () | _ -> None) (fun () -> Missing_socket_dir) +let rpc_metrics = + Prometheus.Summary.v_labels + ~label_names:["endpoint"; "method"] + ~help:"External RPC endpoint call counts and sum of execution times." + ~namespace:Tezos_version.Octez_node_version.namespace + ~subsystem:"external_rpc_process" + "calls" + +module Metrics_server = Prometheus_app.Cohttp (Cohttp_lwt_unix.Server) + (* Add default accepted CORS headers *) let sanitize_cors_headers ~default headers = List.map String.lowercase_ascii headers @@ -116,8 +126,25 @@ let launch_rpc_server dynamic_store (params : Parameters.t) (addr, port) ~media_types:(Media_type.Command_line.of_command_line media_types) dir in + let callback (conn : Cohttp_lwt_unix.Server.conn) req body = + let path = Cohttp.Request.uri req |> Uri.path in + if path = "/metrics" then + let*! response = Metrics_server.callback conn req body in + Lwt.return (`Response response) + else + Forward_handler.callback + ~acl + server + params.rpc_comm_socket_path + conn + req + body + in + let update_metrics uri meth callback = + Prometheus.Summary.(time (labels rpc_metrics [uri; meth]) Sys.time) callback + in let callback = - Forward_handler.callback ~acl server params.rpc_comm_socket_path + RPC_middleware.rpc_metrics_transform_callback ~update_metrics dir callback in let* callback = if params.config.rpc.enable_http_cache_headers then -- GitLab From b2d50291e6a2b3f55048c80cfcf8378dd77d3323 Mon Sep 17 00:00:00 2001 From: Gabriel Moise Date: Thu, 11 Jul 2024 10:52:40 +0100 Subject: [PATCH 2/2] Docs: Add clarification to metrics gathering in docs --- docs/user/node-monitoring.rst | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/docs/user/node-monitoring.rst b/docs/user/node-monitoring.rst index faad0936b5fe..22aa61a92f61 100644 --- a/docs/user/node-monitoring.rst +++ b/docs/user/node-monitoring.rst @@ -15,8 +15,16 @@ So now you can configure and launch your node with a metrics exporter. Starting a node with monitoring ------------------------------- -Start -~~~~~ +Metrics for the node are always available on the ``/metrics`` endpoint of the address and port of the ``--rpc-addr`` (or ``--external-rpc-addr``) argument. One can query this using: + +.. code-block:: shell + + curl http://:/metrics + +Alternatively, the user has an option to gather metrics when no RPC server is setup at all, or when they want a dedicated server for this process. + +Starting metrics server manually +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The node can be started with its metrics exporter with the option ``--metrics-addr`` which takes as a parameter ``:`` or ```` or ``:``. @@ -29,9 +37,6 @@ By default, ```` is ``localhost`` and ```` is ``9932``. Note that it is possible to serve metrics on several addresses by using the option more than once. -Configure -~~~~~~~~~ - You can also add this configuration to your persistent configuration file through the command line: .. code-block:: shell @@ -49,6 +54,9 @@ A correct setup should write an entry in the logs similar to: - node.main: starting metrics server on : +As some metrics (i.e. node internal metrics) are issued by the node only, some metrics accessible on the external RPC process metrics server may lack some data. +It is therefore the duty of the user to aggregate both metrics if needed. + Gathering data -------------- -- GitLab