Clio  develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
Metrics.hpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of clio: https://github.com/XRPLF/clio
4 Copyright (c) 2025, the clio developers.
5
6 Permission to use, copy, modify, and distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#pragma once
21
22#include "cluster/Backend.hpp"
23#include "cluster/ClioNode.hpp"
24#include "util/prometheus/Bool.hpp"
25#include "util/prometheus/Gauge.hpp"
26#include "util/prometheus/Prometheus.hpp"
27
28#include <memory>
29
30namespace cluster {
31
39class Metrics {
41 util::prometheus::GaugeInt& nodesInClusterMetric_ = PrometheusService::gaugeInt(
42 "cluster_nodes_total_number",
43 {},
44 "Total number of nodes this node can detect in the cluster."
45 );
46
48 util::prometheus::Bool isHealthy_ = PrometheusService::boolMetric(
49 "cluster_communication_is_healthy",
50 {},
51 "Whether cluster communication service is operating healthy (1 - healthy, 0 - we have a problem)"
52 );
53
54public:
60 Metrics();
61
72 void
73 onNewState(ClioNode::CUuid uuid, std::shared_ptr<Backend::ClusterData const> clusterData);
74};
75
76} // namespace cluster
static util::prometheus::Bool boolMetric(std::string name, util::prometheus::Labels labels, std::optional< std::string > description=std::nullopt)
Get a bool based metric. It will be created if it doesn't exist.
Definition Prometheus.cpp:194
static util::prometheus::GaugeInt & gaugeInt(std::string name, util::prometheus::Labels labels, std::optional< std::string > description=std::nullopt)
Get an integer based gauge metric. It will be created if it doesn't exist.
Definition Prometheus.cpp:216
Metrics()
Constructs a Metrics instance and initializes metrics.
Definition Metrics.cpp:29
void onNewState(ClioNode::CUuid uuid, std::shared_ptr< Backend::ClusterData const > clusterData)
Updates metrics based on new cluster state.
Definition Metrics.cpp:36