Clio  develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
SystemState.hpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of clio: https://github.com/XRPLF/clio
4 Copyright (c) 2023, 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 "util/config/ConfigDefinition.hpp"
23#include "util/log/Logger.hpp"
24#include "util/prometheus/Bool.hpp"
25#include "util/prometheus/Label.hpp"
26#include "util/prometheus/Prometheus.hpp"
27
28#include <boost/signals2/signal.hpp>
29#include <boost/signals2/variadic_signal.hpp>
30
31#include <memory>
32
33namespace etl {
34
38struct SystemState {
39 SystemState()
40 {
41 isLoadingCache = true;
42 }
43
50 static std::shared_ptr<SystemState>
52 {
53 auto state = std::make_shared<SystemState>();
54 state->isStrictReadonly = config.get<bool>("read_only");
55 return state;
56 }
57
65 "read_only",
67 "Whether the process is in strict read-only mode"
68 );
69
71 util::prometheus::Bool isWriting = PrometheusService::boolMetric(
72 "etl_writing",
74 "Whether the process is writing to the database"
75 );
76
79 "etl_loading_cache",
81 "Whether etl is loading cache after clio startup"
82 );
83
93
101 boost::signals2::signal<void(WriteCommand)> writeCommandSignal;
102
111 "etl_amendment_blocked",
113 "Whether clio detected an amendment block"
114 );
115
123 "etl_corruption_detected",
125 "Whether clio detected a corruption that needs manual attention"
126 );
127
141 "etl_writing_deciding_fallback",
143 "Whether the cluster is using the fallback writer decision mechanism"
144 );
145};
146
147} // namespace etl
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
All the config data will be stored and extracted from this class.
Definition ConfigDefinition.hpp:50
T get(std::string_view fullKey) const
Returns the specified value of given string if value exists.
Definition ConfigDefinition.hpp:104
Class representing a collection of Prometheus labels.
Definition Label.hpp:59
static std::shared_ptr< SystemState > makeSystemState(util::config::ClioConfigDefinition const &config)
Factory method to create a SystemState instance.
Definition SystemState.hpp:51
util::prometheus::Bool isAmendmentBlocked
Whether clio detected an amendment block.
Definition SystemState.hpp:110
WriteCommand
Commands for controlling the ETL writer state.
Definition SystemState.hpp:89
@ StopWriting
Definition SystemState.hpp:91
@ StartWriting
Definition SystemState.hpp:90
util::prometheus::Bool isCorruptionDetected
Whether clio detected a corruption that needs manual attention.
Definition SystemState.hpp:122
boost::signals2::signal< void(WriteCommand)> writeCommandSignal
Signal for coordinating ETL writer state transitions.
Definition SystemState.hpp:101
util::prometheus::Bool isStrictReadonly
Whether the process is in strict read-only mode.
Definition SystemState.hpp:64
util::prometheus::Bool isWriting
Whether the process is writing to the database.
Definition SystemState.hpp:71
util::prometheus::Bool isWriterDecidingFallback
Whether the cluster is using the fallback writer decision mechanism.
Definition SystemState.hpp:140
util::prometheus::Bool isLoadingCache
Whether the process is still loading cache after startup.
Definition SystemState.hpp:78