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 <array>
27#include <atomic>
28#include <cstdint>
29
30namespace ripple {
31
33{
34public:
36 {
37 public:
38 char const* name;
39
44
45 TrafficStats(char const* n) : name(n)
46 {
47 }
48
50 : name(ts.name)
51 , bytesIn(ts.bytesIn.load())
52 , bytesOut(ts.bytesOut.load())
53 , messagesIn(ts.messagesIn.load())
54 , messagesOut(ts.messagesOut.load())
55 {
56 }
57
58 operator bool() const
59 {
60 return messagesIn || messagesOut;
61 }
62 };
63
64 // If you add entries to this enum, you need to update the initialization
65 // of the arrays at the bottom of this file which map array numbers to
66 // human-readable, monitoring-tool friendly names.
68 base, // basic peer overhead, must be first
69
70 cluster, // cluster overhead
71 overlay, // overlay management
72 manifests, // manifest management
77
78 // TMHaveSet message:
79 get_set, // transaction sets we try to get
80 share_set, // transaction sets we get
81
82 // TMLedgerData: transaction set candidate
85
86 // TMLedgerData: transaction node
89
90 // TMLedgerData: account state node
93
94 // TMLedgerData: generic
97
98 // TMGetLedger: transaction set candidate
101
102 // TMGetLedger: transaction node
105
106 // TMGetLedger: account state node
109
110 // TMGetLedger: generic
113
114 // TMGetObjectByHash:
117
118 // TMGetObjectByHash:
121
122 // TMGetObjectByHash: transaction node
125
126 // TMGetObjectByHash: account state node
129
130 // TMGetObjectByHash: CAS
133
134 // TMGetObjectByHash: fetch packs
137
138 // TMGetObjectByHash: transactions
140
141 // TMGetObjectByHash: generic
144
145 // TMProofPathRequest and TMProofPathResponse
148
149 // TMReplayDeltaRequest and TMReplayDeltaResponse
152
153 // TMHaveTransactions
155
156 // TMTransactions
158
159 unknown // must be last
160 };
161
164 static category
166 ::google::protobuf::Message const& message,
167 int type,
168 bool inbound);
169
171 void
172 addCount(category cat, bool inbound, int bytes)
173 {
174 XRPL_ASSERT(
175 cat <= category::unknown,
176 "ripple::TrafficCount::addCount : valid category input");
177
178 if (inbound)
179 {
180 counts_[cat].bytesIn += bytes;
181 ++counts_[cat].messagesIn;
182 }
183 else
184 {
185 counts_[cat].bytesOut += bytes;
186 ++counts_[cat].messagesOut;
187 }
188 }
189
190 TrafficCount() = default;
191
196 auto const&
197 getCounts() const
198 {
199 return counts_;
200 }
201
202protected:
204 {"overhead"}, // category::base
205 {"overhead_cluster"}, // category::cluster
206 {"overhead_overlay"}, // category::overlay
207 {"overhead_manifest"}, // category::manifests
208 {"transactions"}, // category::transaction
209 {"proposals"}, // category::proposal
210 {"validations"}, // category::validation
211 {"validator_lists"}, // category::validatorlist
212 {"set_get"}, // category::get_set
213 {"set_share"}, // category::share_set
214 {"ledger_data_Transaction_Set_candidate_get"}, // category::ld_tsc_get
215 {"ledger_data_Transaction_Set_candidate_share"}, // category::ld_tsc_share
216 {"ledger_data_Transaction_Node_get"}, // category::ld_txn_get
217 {"ledger_data_Transaction_Node_share"}, // category::ld_txn_share
218 {"ledger_data_Account_State_Node_get"}, // category::ld_asn_get
219 {"ledger_data_Account_State_Node_share"}, // category::ld_asn_share
220 {"ledger_data_get"}, // category::ld_get
221 {"ledger_data_share"}, // category::ld_share
222 {"ledger_Transaction_Set_candidate_share"}, // category::gl_tsc_share
223 {"ledger_Transaction_Set_candidate_get"}, // category::gl_tsc_get
224 {"ledger_Transaction_node_share"}, // category::gl_txn_share
225 {"ledger_Transaction_node_get"}, // category::gl_txn_get
226 {"ledger_Account_State_node_share"}, // category::gl_asn_share
227 {"ledger_Account_State_node_get"}, // category::gl_asn_get
228 {"ledger_share"}, // category::gl_share
229 {"ledger_get"}, // category::gl_get
230 {"getobject_Ledger_share"}, // category::share_hash_ledger
231 {"getobject_Ledger_get"}, // category::get_hash_ledger
232 {"getobject_Transaction_share"}, // category::share_hash_tx
233 {"getobject_Transaction_get"}, // category::get_hash_tx
234 {"getobject_Transaction_node_share"}, // category::share_hash_txnode
235 {"getobject_Transaction_node_get"}, // category::get_hash_txnode
236 {"getobject_Account_State_node_share"}, // category::share_hash_asnode
237 {"getobject_Account_State_node_get"}, // category::get_hash_asnode
238 {"getobject_CAS_share"}, // category::share_cas_object
239 {"getobject_CAS_get"}, // category::get_cas_object
240 {"getobject_Fetch_Pack_share"}, // category::share_fetch_pack
241 {"getobject_Fetch Pack_get"}, // category::get_fetch_pack
242 {"getobject_Transactions_get"}, // category::get_transactions
243 {"getobject_share"}, // category::share_hash
244 {"getobject_get"}, // category::get_hash
245 {"proof_path_request"}, // category::proof_path_request
246 {"proof_path_response"}, // category::proof_path_response
247 {"replay_delta_request"}, // category::replay_delta_request
248 {"replay_delta_response"}, // category::replay_delta_response
249 {"have_transactions"}, // category::have_transactions
250 {"requested_transactions"}, // category::transactions
251 {"unknown"} // category::unknown
252 }};
253};
254
255} // namespace ripple
256#endif
TrafficStats(TrafficStats const &ts)
Definition: TrafficCount.h:49
std::atomic< std::uint64_t > bytesOut
Definition: TrafficCount.h:41
std::atomic< std::uint64_t > messagesOut
Definition: TrafficCount.h:43
std::atomic< std::uint64_t > messagesIn
Definition: TrafficCount.h:42
std::atomic< std::uint64_t > bytesIn
Definition: TrafficCount.h:40
auto const & getCounts() const
An up-to-date copy of all the counters.
Definition: TrafficCount.h:197
std::array< TrafficStats, category::unknown+1 > counts_
Definition: TrafficCount.h:203
static category categorize(::google::protobuf::Message const &message, int type, bool inbound)
Given a protocol message, determine which traffic category it belongs to.
void addCount(category cat, bool inbound, int bytes)
Account for traffic associated with the given category.
Definition: TrafficCount.h:172
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26