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: generic
142 
143  // TMProofPathRequest and TMProofPathResponse
146 
147  // TMReplayDeltaRequest and TMReplayDeltaResponse
150 
151  unknown // must be last
152  };
153 
156  static category
157  categorize(
158  ::google::protobuf::Message const& message,
159  int type,
160  bool inbound);
161 
163  void
164  addCount(category cat, bool inbound, int bytes)
165  {
166  assert(cat <= category::unknown);
167 
168  if (inbound)
169  {
170  counts_[cat].bytesIn += bytes;
171  ++counts_[cat].messagesIn;
172  }
173  else
174  {
175  counts_[cat].bytesOut += bytes;
176  ++counts_[cat].messagesOut;
177  }
178  }
179 
180  TrafficCount() = default;
181 
186  auto const&
187  getCounts() const
188  {
189  return counts_;
190  }
191 
192 protected:
194  {"overhead"}, // category::base
195  {"overhead_cluster"}, // category::cluster
196  {"overhead_overlay"}, // category::overlay
197  {"overhead_manifest"}, // category::manifests
198  {"transactions"}, // category::transaction
199  {"proposals"}, // category::proposal
200  {"validations"}, // category::validation
201  {"validator_lists"}, // category::validatorlist
202  {"shards"}, // category::shards
203  {"set_get"}, // category::get_set
204  {"set_share"}, // category::share_set
205  {"ledger_data_Transaction_Set_candidate_get"}, // category::ld_tsc_get
206  {"ledger_data_Transaction_Set_candidate_share"}, // category::ld_tsc_share
207  {"ledger_data_Transaction_Node_get"}, // category::ld_txn_get
208  {"ledger_data_Transaction_Node_share"}, // category::ld_txn_share
209  {"ledger_data_Account_State_Node_get"}, // category::ld_asn_get
210  {"ledger_data_Account_State_Node_share"}, // category::ld_asn_share
211  {"ledger_data_get"}, // category::ld_get
212  {"ledger_data_share"}, // category::ld_share
213  {"ledger_Transaction_Set_candidate_share"}, // category::gl_tsc_share
214  {"ledger_Transaction_Set_candidate_get"}, // category::gl_tsc_get
215  {"ledger_Transaction_node_share"}, // category::gl_txn_share
216  {"ledger_Transaction_node_get"}, // category::gl_txn_get
217  {"ledger_Account_State_node_share"}, // category::gl_asn_share
218  {"ledger_Account_State_node_get"}, // category::gl_asn_get
219  {"ledger_share"}, // category::gl_share
220  {"ledger_get"}, // category::gl_get
221  {"getobject_Ledger_share"}, // category::share_hash_ledger
222  {"getobject_Ledger_get"}, // category::get_hash_ledger
223  {"getobject_Transaction_share"}, // category::share_hash_tx
224  {"getobject_Transaction_get"}, // category::get_hash_tx
225  {"getobject_Transaction_node_share"}, // category::share_hash_txnode
226  {"getobject_Transaction_node_get"}, // category::get_hash_txnode
227  {"getobject_Account_State_node_share"}, // category::share_hash_asnode
228  {"getobject_Account_State_node_get"}, // category::get_hash_asnode
229  {"getobject_CAS_share"}, // category::share_cas_object
230  {"getobject_CAS_get"}, // category::get_cas_object
231  {"getobject_Fetch_Pack_share"}, // category::share_fetch_pack
232  {"getobject_Fetch Pack_get"}, // category::get_fetch_pack
233  {"getobject_share"}, // category::share_hash
234  {"getobject_get"}, // category::get_hash
235  {"proof_path_request"}, // category::proof_path_request
236  {"proof_path_response"}, // category::proof_path_response
237  {"replay_delta_request"}, // category::replay_delta_request
238  {"replay_delta_response"}, // category::replay_delta_response
239  {"unknown"} // category::unknown
240  }};
241 };
242 
243 } // namespace ripple
244 #endif
ripple::TrafficCount::counts_
std::array< TrafficStats, category::unknown+1 > counts_
Definition: TrafficCount.h:193
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:187
ripple::TrafficCount
Definition: TrafficCount.h:32
ripple::TrafficCount::share_hash
@ share_hash
Definition: TrafficCount.h:140
ripple::TrafficCount::ld_tsc_get
@ ld_tsc_get
Definition: TrafficCount.h:84
ripple::TrafficCount::unknown
@ unknown
Definition: TrafficCount.h:151
ripple::TrafficCount::get_hash
@ get_hash
Definition: TrafficCount.h:141
ripple::TrafficCount::replay_delta_request
@ replay_delta_request
Definition: TrafficCount.h:148
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:144
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::share_cas_object
@ share_cas_object
Definition: TrafficCount.h:132
ripple::TrafficCount::proof_path_response
@ proof_path_response
Definition: TrafficCount.h:145
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::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:149
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:164
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