rippled
Loading...
Searching...
No Matches
TxMetrics.cpp
1#include <xrpld/overlay/detail/TxMetrics.h>
2
3#include <xrpl/protocol/jss.h>
4
5#include <numeric>
6
7namespace ripple {
8
9namespace metrics {
10
11void
12TxMetrics::addMetrics(protocol::MessageType type, std::uint32_t val)
13{
14 auto add = [&](auto& m, std::uint32_t val) {
16 m.addMetrics(val);
17 };
18
19 switch (type)
20 {
21 case protocol::MessageType::mtTRANSACTION:
22 add(tx, val);
23 break;
24 case protocol::MessageType::mtHAVE_TRANSACTIONS:
25 add(haveTx, val);
26 break;
27 case protocol::MessageType::mtGET_LEDGER:
28 add(getLedger, val);
29 break;
30 case protocol::MessageType::mtLEDGER_DATA:
31 add(ledgerData, val);
32 break;
33 case protocol::MessageType::mtTRANSACTIONS:
34 add(transactions, val);
35 break;
36 default:
37 return;
38 }
39}
40
41void
43 std::uint32_t selected,
44 std::uint32_t suppressed,
45 std::uint32_t notenabled)
46{
48 selectedPeers.addMetrics(selected);
49 suppressedPeers.addMetrics(suppressed);
50 notEnabled.addMetrics(notenabled);
51}
52
53void
59
60void
65
66void
72
73void
75{
76 using namespace std::chrono_literals;
77 accum += val;
78 N++;
79 auto const timeElapsed = clock_type::now() - intervalStart;
80 auto const timeElapsedInSecs =
81 std::chrono::duration_cast<std::chrono::seconds>(timeElapsed);
82
83 if (timeElapsedInSecs >= 1s)
84 {
85 auto const avg = accum / (perTimeUnit ? timeElapsedInSecs.count() : N);
86 rollingAvgAggreg.push_back(avg);
87
88 auto const total = std::accumulate(
89 rollingAvgAggreg.begin(), rollingAvgAggreg.end(), 0ull);
90 rollingAvg = total / rollingAvgAggreg.size();
91
93 accum = 0;
94 N = 0;
95 }
96}
97
100{
102
104
105 ret[jss::txr_tx_cnt] = std::to_string(tx.m1.rollingAvg);
106 ret[jss::txr_tx_sz] = std::to_string(tx.m2.rollingAvg);
107
108 ret[jss::txr_have_txs_cnt] = std::to_string(haveTx.m1.rollingAvg);
109 ret[jss::txr_have_txs_sz] = std::to_string(haveTx.m2.rollingAvg);
110
111 ret[jss::txr_get_ledger_cnt] = std::to_string(getLedger.m1.rollingAvg);
112 ret[jss::txr_get_ledger_sz] = std::to_string(getLedger.m2.rollingAvg);
113
114 ret[jss::txr_ledger_data_cnt] = std::to_string(ledgerData.m1.rollingAvg);
115 ret[jss::txr_ledger_data_sz] = std::to_string(ledgerData.m2.rollingAvg);
116
117 ret[jss::txr_transactions_cnt] = std::to_string(transactions.m1.rollingAvg);
118 ret[jss::txr_transactions_sz] = std::to_string(transactions.m2.rollingAvg);
119
120 ret[jss::txr_selected_cnt] = std::to_string(selectedPeers.rollingAvg);
121
122 ret[jss::txr_suppressed_cnt] = std::to_string(suppressedPeers.rollingAvg);
123
124 ret[jss::txr_not_enabled_cnt] = std::to_string(notEnabled.rollingAvg);
125
126 ret[jss::txr_missing_tx_freq] = std::to_string(missingTx.rollingAvg);
127
128 return ret;
129}
130
131} // namespace metrics
132
133} // namespace ripple
T accumulate(T... args)
Represents a JSON value.
Definition json_value.h:130
@ objectValue
object value (collection of name/value pairs).
Definition json_value.h:26
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
void addMetrics(std::uint32_t val2)
Add metrics to m2.
Definition TxMetrics.cpp:61
boost::circular_buffer< std::uint64_t > rollingAvgAggreg
Definition TxMetrics.h:37
clock_type::time_point intervalStart
Definition TxMetrics.h:32
void addMetrics(std::uint32_t val)
Add metrics value.
Definition TxMetrics.cpp:74
SingleMetrics missingTx
Definition TxMetrics.h:89
SingleMetrics suppressedPeers
Definition TxMetrics.h:85
MultipleMetrics haveTx
Definition TxMetrics.h:75
MultipleMetrics transactions
Definition TxMetrics.h:81
MultipleMetrics getLedger
Definition TxMetrics.h:77
void addMetrics(protocol::MessageType type, std::uint32_t val)
Add protocol message metrics.
Definition TxMetrics.cpp:12
SingleMetrics selectedPeers
Definition TxMetrics.h:83
MultipleMetrics ledgerData
Definition TxMetrics.h:79
SingleMetrics notEnabled
Definition TxMetrics.h:87
Json::Value json() const
Get json representation of the metrics.
Definition TxMetrics.cpp:99
T to_string(T... args)