rippled
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 <ripple/basics/safe_cast.h>
24 #include <ripple/protocol/messages.h>
25 
26 #include <array>
27 #include <atomic>
28 #include <cstdint>
29 
30 namespace ripple {
31 
33 {
34 public:
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  shards, // shard-related traffic
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
166  categorize(
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  assert(cat <= category::unknown);
176 
177  if (inbound)
178  {
179  counts_[cat].bytesIn += bytes;
180  ++counts_[cat].messagesIn;
181  }
182  else
183  {
184  counts_[cat].bytesOut += bytes;
185  ++counts_[cat].messagesOut;
186  }
187  }
188 
189  TrafficCount() = default;
190 
195  auto const&
196  getCounts() const
197  {
198  return counts_;
199  }
200 
201 protected:
203  {"overhead"}, // category::base
204  {"overhead_cluster"}, // category::cluster
205  {"overhead_overlay"}, // category::overlay
206  {"overhead_manifest"}, // category::manifests
207  {"transactions"}, // category::transaction
208  {"proposals"}, // category::proposal
209  {"validations"}, // category::validation
210  {"validator_lists"}, // category::validatorlist
211  {"shards"}, // category::shards
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
ripple::TrafficCount::counts_
std::array< TrafficStats, category::unknown+1 > counts_
Definition: TrafficCount.h:202
ripple::TrafficCount::TrafficStats::messagesIn
std::atomic< std::uint64_t > messagesIn
Definition: TrafficCount.h:42
ripple::TrafficCount::share_hash_asnode
@ share_hash_asnode
Definition: TrafficCount.h:128
ripple::TrafficCount::categorize
static category categorize(::google::protobuf::Message const &message, int type, bool inbound)
Given a protocol message, determine which traffic category it belongs to.
Definition: TrafficCount.cpp:25
ripple::TrafficCount::gl_txn_share
@ gl_txn_share
Definition: TrafficCount.h:104
ripple::TrafficCount::getCounts
auto const & getCounts() const
An up-to-date copy of all the counters.
Definition: TrafficCount.h:196
ripple::TrafficCount
Definition: TrafficCount.h:32
ripple::TrafficCount::share_hash
@ share_hash
Definition: TrafficCount.h:143
ripple::TrafficCount::ld_tsc_get
@ ld_tsc_get
Definition: TrafficCount.h:84
ripple::TrafficCount::unknown
@ unknown
Definition: TrafficCount.h:160
ripple::TrafficCount::have_transactions
@ have_transactions
Definition: TrafficCount.h:155
ripple::TrafficCount::get_hash
@ get_hash
Definition: TrafficCount.h:144
ripple::TrafficCount::replay_delta_request
@ replay_delta_request
Definition: TrafficCount.h:151
ripple::TrafficCount::TrafficStats::TrafficStats
TrafficStats(char const *n)
Definition: TrafficCount.h:45
ripple::TrafficCount::get_hash_txnode
@ get_hash_txnode
Definition: TrafficCount.h:125
ripple::TrafficCount::gl_share
@ gl_share
Definition: TrafficCount.h:112
ripple::TrafficCount::gl_asn_share
@ gl_asn_share
Definition: TrafficCount.h:108
ripple::TrafficCount::TrafficStats
Definition: TrafficCount.h:35
ripple::TrafficCount::get_fetch_pack
@ get_fetch_pack
Definition: TrafficCount.h:137
ripple::TrafficCount::ld_share
@ ld_share
Definition: TrafficCount.h:97
ripple::TrafficCount::TrafficStats::name
char const * name
Definition: TrafficCount.h:38
ripple::TrafficCount::gl_tsc_share
@ gl_tsc_share
Definition: TrafficCount.h:100
ripple::TrafficCount::category
category
Definition: TrafficCount.h:67
ripple::TrafficCount::validation
@ validation
Definition: TrafficCount.h:75
ripple::TrafficCount::get_hash_ledger
@ get_hash_ledger
Definition: TrafficCount.h:117
ripple::TrafficCount::proof_path_request
@ proof_path_request
Definition: TrafficCount.h:147
ripple::TrafficCount::share_fetch_pack
@ share_fetch_pack
Definition: TrafficCount.h:136
ripple::TrafficCount::TrafficStats::TrafficStats
TrafficStats(TrafficStats const &ts)
Definition: TrafficCount.h:49
ripple::TrafficCount::get_hash_asnode
@ get_hash_asnode
Definition: TrafficCount.h:129
ripple::TrafficCount::ld_asn_share
@ ld_asn_share
Definition: TrafficCount.h:93
array
ripple::TrafficCount::share_hash_ledger
@ share_hash_ledger
Definition: TrafficCount.h:116
ripple::TrafficCount::TrafficCount
TrafficCount()=default
ripple::TrafficCount::proposal
@ proposal
Definition: TrafficCount.h:74
ripple::TrafficCount::gl_asn_get
@ gl_asn_get
Definition: TrafficCount.h:109
ripple::TrafficCount::gl_get
@ gl_get
Definition: TrafficCount.h:113
ripple::TrafficCount::ld_asn_get
@ ld_asn_get
Definition: TrafficCount.h:92
cstdint
ripple::TrafficCount::get_cas_object
@ get_cas_object
Definition: TrafficCount.h:133
ripple::TrafficCount::share_hash_txnode
@ share_hash_txnode
Definition: TrafficCount.h:124
atomic
ripple::TrafficCount::requested_transactions
@ requested_transactions
Definition: TrafficCount.h:158
ripple::TrafficCount::share_cas_object
@ share_cas_object
Definition: TrafficCount.h:132
ripple::TrafficCount::proof_path_response
@ proof_path_response
Definition: TrafficCount.h:148
ripple::TrafficCount::manifests
@ manifests
Definition: TrafficCount.h:72
ripple::TrafficCount::base
@ base
Definition: TrafficCount.h:68
ripple::TrafficCount::TrafficStats::bytesOut
std::atomic< std::uint64_t > bytesOut
Definition: TrafficCount.h:41
ripple::TrafficCount::cluster
@ cluster
Definition: TrafficCount.h:70
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::TrafficCount::share_hash_tx
@ share_hash_tx
Definition: TrafficCount.h:120
ripple::TrafficCount::share_set
@ share_set
Definition: TrafficCount.h:81
ripple::TrafficCount::gl_tsc_get
@ gl_tsc_get
Definition: TrafficCount.h:101
ripple::TrafficCount::transaction
@ transaction
Definition: TrafficCount.h:73
ripple::TrafficCount::TrafficStats::bytesIn
std::atomic< std::uint64_t > bytesIn
Definition: TrafficCount.h:40
ripple::TrafficCount::get_hash_tx
@ get_hash_tx
Definition: TrafficCount.h:121
ripple::TrafficCount::validatorlist
@ validatorlist
Definition: TrafficCount.h:76
ripple::TrafficCount::get_transactions
@ get_transactions
Definition: TrafficCount.h:140
ripple::TrafficCount::TrafficStats::messagesOut
std::atomic< std::uint64_t > messagesOut
Definition: TrafficCount.h:43
std::size_t
ripple::TrafficCount::shards
@ shards
Definition: TrafficCount.h:77
ripple::TrafficCount::ld_get
@ ld_get
Definition: TrafficCount.h:96
ripple::TrafficCount::replay_delta_response
@ replay_delta_response
Definition: TrafficCount.h:152
ripple::TrafficCount::ld_txn_get
@ ld_txn_get
Definition: TrafficCount.h:88
ripple::TrafficCount::overlay
@ overlay
Definition: TrafficCount.h:71
ripple::TrafficCount::addCount
void addCount(category cat, bool inbound, int bytes)
Account for traffic associated with the given category.
Definition: TrafficCount.h:173
ripple::TrafficCount::ld_txn_share
@ ld_txn_share
Definition: TrafficCount.h:89
ripple::TrafficCount::ld_tsc_share
@ ld_tsc_share
Definition: TrafficCount.h:85
ripple::TrafficCount::gl_txn_get
@ gl_txn_get
Definition: TrafficCount.h:105
ripple::TrafficCount::get_set
@ get_set
Definition: TrafficCount.h:80