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