rippled
Loading...
Searching...
No Matches
TxMetrics.cpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2012, 2020 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or 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#include <xrpld/overlay/detail/TxMetrics.h>
21#include <xrpl/protocol/jss.h>
22
23#include <numeric>
24
25namespace ripple {
26
27namespace metrics {
28
29void
30TxMetrics::addMetrics(protocol::MessageType type, std::uint32_t val)
31{
32 auto add = [&](auto& m, std::uint32_t val) {
34 m.addMetrics(val);
35 };
36
37 switch (type)
38 {
39 case protocol::MessageType::mtTRANSACTION:
40 add(tx, val);
41 break;
42 case protocol::MessageType::mtHAVE_TRANSACTIONS:
43 add(haveTx, val);
44 break;
45 case protocol::MessageType::mtGET_LEDGER:
46 add(getLedger, val);
47 break;
48 case protocol::MessageType::mtLEDGER_DATA:
49 add(ledgerData, val);
50 break;
51 case protocol::MessageType::mtTRANSACTIONS:
52 add(transactions, val);
53 break;
54 default:
55 return;
56 }
57}
58
59void
61 std::uint32_t selected,
62 std::uint32_t suppressed,
63 std::uint32_t notenabled)
64{
66 selectedPeers.addMetrics(selected);
67 suppressedPeers.addMetrics(suppressed);
68 notEnabled.addMetrics(notenabled);
69}
70
71void
73{
75 missingTx.addMetrics(missing);
76}
77
78void
80{
81 addMetrics(1, val2);
82}
83
84void
86{
87 m1.addMetrics(val1);
88 m2.addMetrics(val2);
89}
90
91void
93{
94 using namespace std::chrono_literals;
95 accum += val;
96 N++;
97 auto const timeElapsed = clock_type::now() - intervalStart;
98 auto const timeElapsedInSecs =
99 std::chrono::duration_cast<std::chrono::seconds>(timeElapsed);
100
101 if (timeElapsedInSecs >= 1s)
102 {
103 auto const avg = accum / (perTimeUnit ? timeElapsedInSecs.count() : N);
104 rollingAvgAggreg.push_back(avg);
105
106 auto const total = std::accumulate(
107 rollingAvgAggreg.begin(), rollingAvgAggreg.end(), 0ull);
108 rollingAvg = total / rollingAvgAggreg.size();
109
111 accum = 0;
112 N = 0;
113 }
114}
115
118{
120
122
123 ret[jss::txr_tx_cnt] = std::to_string(tx.m1.rollingAvg);
124 ret[jss::txr_tx_sz] = std::to_string(tx.m2.rollingAvg);
125
126 ret[jss::txr_have_txs_cnt] = std::to_string(haveTx.m1.rollingAvg);
127 ret[jss::txr_have_txs_sz] = std::to_string(haveTx.m2.rollingAvg);
128
129 ret[jss::txr_get_ledger_cnt] = std::to_string(getLedger.m1.rollingAvg);
130 ret[jss::txr_get_ledger_sz] = std::to_string(getLedger.m2.rollingAvg);
131
132 ret[jss::txr_ledger_data_cnt] = std::to_string(ledgerData.m1.rollingAvg);
133 ret[jss::txr_ledger_data_sz] = std::to_string(ledgerData.m2.rollingAvg);
134
135 ret[jss::txr_transactions_cnt] = std::to_string(transactions.m1.rollingAvg);
136 ret[jss::txr_transactions_sz] = std::to_string(transactions.m2.rollingAvg);
137
138 ret[jss::txr_selected_cnt] = std::to_string(selectedPeers.rollingAvg);
139
140 ret[jss::txr_suppressed_cnt] = std::to_string(suppressedPeers.rollingAvg);
141
142 ret[jss::txr_not_enabled_cnt] = std::to_string(notEnabled.rollingAvg);
143
144 ret[jss::txr_missing_tx_freq] = std::to_string(missingTx.rollingAvg);
145
146 return ret;
147}
148
149} // namespace metrics
150
151} // namespace ripple
T accumulate(T... args)
Represents a JSON value.
Definition: json_value.h:147
@ objectValue
object value (collection of name/value pairs).
Definition: json_value.h:43
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26
void addMetrics(std::uint32_t val2)
Add metrics to m2.
Definition: TxMetrics.cpp:79
boost::circular_buffer< std::uint64_t > rollingAvgAggreg
Definition: TxMetrics.h:56
clock_type::time_point intervalStart
Definition: TxMetrics.h:51
void addMetrics(std::uint32_t val)
Add metrics value.
Definition: TxMetrics.cpp:92
SingleMetrics missingTx
Definition: TxMetrics.h:108
SingleMetrics suppressedPeers
Definition: TxMetrics.h:104
MultipleMetrics tx
Definition: TxMetrics.h:92
MultipleMetrics haveTx
Definition: TxMetrics.h:94
MultipleMetrics transactions
Definition: TxMetrics.h:100
MultipleMetrics getLedger
Definition: TxMetrics.h:96
void addMetrics(protocol::MessageType type, std::uint32_t val)
Add protocol message metrics.
Definition: TxMetrics.cpp:30
SingleMetrics selectedPeers
Definition: TxMetrics.h:102
MultipleMetrics ledgerData
Definition: TxMetrics.h:98
SingleMetrics notEnabled
Definition: TxMetrics.h:106
Json::Value json() const
Get json representation of the metrics.
Definition: TxMetrics.cpp:117
T to_string(T... args)