rippled
Loading...
Searching...
No Matches
TrafficCount.h
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2012, 2013 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#ifndef RIPPLE_OVERLAY_TRAFFIC_H_INCLUDED
21#define RIPPLE_OVERLAY_TRAFFIC_H_INCLUDED
22
23#include <xrpl/beast/utility/instrumentation.h>
24#include <xrpl/protocol/messages.h>
25
26#include <atomic>
27#include <cstdint>
28
29namespace ripple {
30
50{
51public:
52 enum category : std::size_t;
53
55 {
56 public:
58
63
66 {
67 }
68
70 : name(ts.name)
71 , bytesIn(ts.bytesIn.load())
72 , bytesOut(ts.bytesOut.load())
73 , messagesIn(ts.messagesIn.load())
74 , messagesOut(ts.messagesOut.load())
75 {
76 }
77
78 operator bool() const
79 {
80 return messagesIn || messagesOut;
81 }
82 };
83
84 // If you add entries to this enum, you need to update the initialization
85 // of the arrays at the bottom of this file which map array numbers to
86 // human-readable, monitoring-tool friendly names.
88 base, // basic peer overhead, must be first
89
90 cluster, // cluster overhead
91 overlay, // overlay management
92 manifests, // manifest management
93
94 transaction, // transaction messages
95 // The following categories breakdown transaction message type
96 transaction_duplicate, // duplicate transaction messages
97
98 proposal, // proposal messages
99 // The following categories breakdown proposal message type
100 proposal_untrusted, // proposals from untrusted validators
101 proposal_duplicate, // proposals seen previously
102
103 validation, // validation messages
104 // The following categories breakdown validation message type
105 validation_untrusted, // validations from untrusted validators
106 validation_duplicate, // validations seen previously
107
109
111 squelch_suppressed, // egress traffic amount suppressed by squelching
112
113 // TMHaveSet message:
114 get_set, // transaction sets we try to get
115 share_set, // transaction sets we get
116
117 // TMLedgerData: transaction set candidate
120
121 // TMLedgerData: transaction node
124
125 // TMLedgerData: account state node
128
129 // TMLedgerData: generic
132
133 // TMGetLedger: transaction set candidate
136
137 // TMGetLedger: transaction node
140
141 // TMGetLedger: account state node
144
145 // TMGetLedger: generic
148
149 // TMGetObjectByHash:
152
153 // TMGetObjectByHash:
156
157 // TMGetObjectByHash: transaction node
160
161 // TMGetObjectByHash: account state node
164
165 // TMGetObjectByHash: CAS
168
169 // TMGetObjectByHash: fetch packs
172
173 // TMGetObjectByHash: transactions
175
176 // TMGetObjectByHash: generic
179
180 // TMProofPathRequest and TMProofPathResponse
183
184 // TMReplayDeltaRequest and TMReplayDeltaResponse
187
188 // TMHaveTransactions
190
191 // TMTransactions
193
194 // The total p2p bytes sent and received on the wire
196
197 unknown // must be last
198 };
199
200 TrafficCount() = default;
201
204 static category
206 ::google::protobuf::Message const& message,
207 protocol::MessageType type,
208 bool inbound);
209
211 void
212 addCount(category cat, bool inbound, int bytes)
213 {
214 XRPL_ASSERT(
215 cat <= category::unknown,
216 "ripple::TrafficCount::addCount : valid category input");
217
218 auto it = counts_.find(cat);
219
220 // nothing to do, the category does not exist
221 if (it == counts_.end())
222 return;
223
224 if (inbound)
225 {
226 it->second.bytesIn += bytes;
227 ++it->second.messagesIn;
228 }
229 else
230 {
231 it->second.bytesOut += bytes;
232 ++it->second.messagesOut;
233 }
234 }
235
240 auto const&
241 getCounts() const
242 {
243 return counts_;
244 }
245
246 static std::string
248 {
249 static std::unordered_map<category, std::string> const category_map = {
250 {base, "overhead"},
251 {cluster, "overhead_cluster"},
252 {overlay, "overhead_overlay"},
253 {manifests, "overhead_manifest"},
254 {transaction, "transactions"},
255 {transaction_duplicate, "transactions_duplicate"},
256 {proposal, "proposals"},
257 {proposal_untrusted, "proposals_untrusted"},
258 {proposal_duplicate, "proposals_duplicate"},
259 {validation, "validations"},
260 {validation_untrusted, "validations_untrusted"},
261 {validation_duplicate, "validations_duplicate"},
262 {validatorlist, "validator_lists"},
263 {squelch, "squelch"},
264 {squelch_suppressed, "squelch_suppressed"},
265 {get_set, "set_get"},
266 {share_set, "set_share"},
267 {ld_tsc_get, "ledger_data_Transaction_Set_candidate_get"},
268 {ld_tsc_share, "ledger_data_Transaction_Set_candidate_share"},
269 {ld_txn_get, "ledger_data_Transaction_Node_get"},
270 {ld_txn_share, "ledger_data_Transaction_Node_share"},
271 {ld_asn_get, "ledger_data_Account_State_Node_get"},
272 {ld_asn_share, "ledger_data_Account_State_Node_share"},
273 {ld_get, "ledger_data_get"},
274 {ld_share, "ledger_data_share"},
275 {gl_tsc_share, "ledger_Transaction_Set_candidate_share"},
276 {gl_tsc_get, "ledger_Transaction_Set_candidate_get"},
277 {gl_txn_share, "ledger_Transaction_node_share"},
278 {gl_txn_get, "ledger_Transaction_node_get"},
279 {gl_asn_share, "ledger_Account_State_node_share"},
280 {gl_asn_get, "ledger_Account_State_node_get"},
281 {gl_share, "ledger_share"},
282 {gl_get, "ledger_get"},
283 {share_hash_ledger, "getobject_Ledger_share"},
284 {get_hash_ledger, "getobject_Ledger_get"},
285 {share_hash_tx, "getobject_Transaction_share"},
286 {get_hash_tx, "getobject_Transaction_get"},
287 {share_hash_txnode, "getobject_Transaction_node_share"},
288 {get_hash_txnode, "getobject_Transaction_node_get"},
289 {share_hash_asnode, "getobject_Account_State_node_share"},
290 {get_hash_asnode, "getobject_Account_State_node_get"},
291 {share_cas_object, "getobject_CAS_share"},
292 {get_cas_object, "getobject_CAS_get"},
293 {share_fetch_pack, "getobject_Fetch_Pack_share"},
294 {get_fetch_pack, "getobject_Fetch Pack_get"},
295 {get_transactions, "getobject_Transactions_get"},
296 {share_hash, "getobject_share"},
297 {get_hash, "getobject_get"},
298 {proof_path_request, "proof_path_request"},
299 {proof_path_response, "proof_path_response"},
300 {replay_delta_request, "replay_delta_request"},
301 {replay_delta_response, "replay_delta_response"},
302 {have_transactions, "have_transactions"},
303 {requested_transactions, "requested_transactions"},
304 {total, "total"}};
305
306 if (auto it = category_map.find(cat); it != category_map.end())
307 return it->second;
308
309 return "unknown";
310 }
311
312protected:
314 {base, {base}},
315 {cluster, {cluster}},
316 {overlay, {overlay}},
317 {manifests, {manifests}},
320 {proposal, {proposal}},
327 {squelch, {squelch}},
329 {get_set, {get_set}},
330 {share_set, {share_set}},
337 {ld_get, {ld_get}},
338 {ld_share, {ld_share}},
345 {gl_share, {gl_share}},
346 {gl_get, {gl_get}},
361 {get_hash, {get_hash}},
368 {total, {total}},
369 {unknown, {unknown}},
370 };
371};
372
373} // namespace ripple
374#endif
TrafficStats(TrafficStats const &ts)
Definition: TrafficCount.h:69
std::atomic< std::uint64_t > bytesOut
Definition: TrafficCount.h:60
TrafficStats(TrafficCount::category cat)
Definition: TrafficCount.h:64
std::atomic< std::uint64_t > messagesOut
Definition: TrafficCount.h:62
std::atomic< std::uint64_t > messagesIn
Definition: TrafficCount.h:61
std::atomic< std::uint64_t > bytesIn
Definition: TrafficCount.h:59
TrafficCount is used to count ingress and egress wire bytes and number of messages.
Definition: TrafficCount.h:50
auto const & getCounts() const
An up-to-date copy of all the counters.
Definition: TrafficCount.h:241
std::unordered_map< category, TrafficStats > counts_
Definition: TrafficCount.h:313
static category categorize(::google::protobuf::Message const &message, protocol::MessageType type, bool inbound)
Given a protocol message, determine which traffic category it belongs to.
static std::string to_string(category cat)
Definition: TrafficCount.h:247
void addCount(category cat, bool inbound, int bytes)
Account for traffic associated with the given category.
Definition: TrafficCount.h:212
T end(T... args)
T find(T... args)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26