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)
46  : 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  {
70  base, // basic peer overhead, must be first
71 
72  cluster, // cluster overhead
73  overlay, // overlay management
74  manifests, // manifest management
79  shards, // shard-related traffic
80 
81  // TMHaveSet message:
82  get_set, // transaction sets we try to get
83  share_set, // transaction sets we get
84 
85  // TMLedgerData: transaction set candidate
88 
89  // TMLedgerData: transaction node
92 
93  // TMLedgerData: account state node
96 
97  // TMLedgerData: generic
100 
101  // TMGetLedger: transaction set candidate
104 
105  // TMGetLedger: transaction node
108 
109  // TMGetLedger: account state node
112 
113  // TMGetLedger: generic
116 
117  // TMGetObjectByHash:
120 
121  // TMGetObjectByHash:
124 
125  // TMGetObjectByHash: transaction node
128 
129  // TMGetObjectByHash: account state node
132 
133  // TMGetObjectByHash: CAS
136 
137  // TMGetObjectByHash: fetch packs
140 
141  // TMGetObjectByHash: generic
144 
145  unknown // must be last
146  };
147 
149  static category categorize (
150  ::google::protobuf::Message const& message,
151  int type, bool inbound);
152 
154  void addCount (category cat, bool inbound, int bytes)
155  {
156  assert (cat <= category::unknown);
157 
158  if (inbound)
159  {
160  counts_[cat].bytesIn += bytes;
161  ++counts_[cat].messagesIn;
162  }
163  else
164  {
165  counts_[cat].bytesOut += bytes;
166  ++counts_[cat].messagesOut;
167  }
168  }
169 
170  TrafficCount() = default;
171 
176  auto const&
177  getCounts () const
178  {
179  return counts_;
180  }
181 
182 
183 protected:
185  {{
186  {"overhead"}, // category::base
187  {"overhead_cluster"}, // category::cluster
188  {"overhead_overlay"}, // category::overlay
189  {"overhead_manifest"}, // category::manifests
190  {"transactions"}, // category::transaction
191  {"proposals"}, // category::proposal
192  {"validations"}, // category::validation
193  {"validator_lists"}, // category::validatorlist
194  {"shards"}, // category::shards
195  {"set_get"}, // category::get_set
196  {"set_share"}, // category::share_set
197  {"ledger_data_Transaction_Set_candidate_get"}, // category::ld_tsc_get
198  {"ledger_data_Transaction_Set_candidate_share"}, // category::ld_tsc_share
199  {"ledger_data_Transaction_Node_get"}, // category::ld_txn_get
200  {"ledger_data_Transaction_Node_share"}, // category::ld_txn_share
201  {"ledger_data_Account_State_Node_get"}, // category::ld_asn_get
202  {"ledger_data_Account_State_Node_share"}, // category::ld_asn_share
203  {"ledger_data_get"}, // category::ld_get
204  {"ledger_data_share"}, // category::ld_share
205  {"ledger_Transaction_Set_candidate_share"}, // category::gl_tsc_share
206  {"ledger_Transaction_Set_candidate_get"}, // category::gl_tsc_get
207  {"ledger_Transaction_node_share"}, // category::gl_txn_share
208  {"ledger_Transaction_node_get"}, // category::gl_txn_get
209  {"ledger_Account_State_node_share"}, // category::gl_asn_share
210  {"ledger_Account_State_node_get"}, // category::gl_asn_get
211  {"ledger_share"}, // category::gl_share
212  {"ledger_get"}, // category::gl_get
213  {"getobject_Ledger_share"}, // category::share_hash_ledger
214  {"getobject_Ledger_get"}, // category::get_hash_ledger
215  {"getobject_Transaction_share"}, // category::share_hash_tx
216  {"getobject_Transaction_get"}, // category::get_hash_tx
217  {"getobject_Transaction_node_share"}, // category::share_hash_txnode
218  {"getobject_Transaction_node_get"}, // category::get_hash_txnode
219  {"getobject_Account_State_node_share"}, // category::share_hash_asnode
220  {"getobject_Account_State_node_get"}, // category::get_hash_asnode
221  {"getobject_CAS_share"}, // category::share_cas_object
222  {"getobject_CAS_get"}, // category::get_cas_object
223  {"getobject_Fetch_Pack_share"}, // category::share_fetch_pack
224  {"getobject_Fetch Pack_get"}, // category::get_fetch_pack
225  {"getobject_share"}, // category::share_hash
226  {"getobject_get"}, // category::get_hash
227  {"unknown"} // category::unknown
228  }};
229 };
230 
231 }
232 #endif
ripple::TrafficCount::counts_
std::array< TrafficStats, category::unknown+1 > counts_
Definition: TrafficCount.h:185
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:130
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:24
ripple::TrafficCount::gl_txn_share
@ gl_txn_share
Definition: TrafficCount.h:106
ripple::TrafficCount::getCounts
auto const & getCounts() const
An up-to-date copy of all the counters.
Definition: TrafficCount.h:177
ripple::TrafficCount
Definition: TrafficCount.h:32
ripple::TrafficCount::share_hash
@ share_hash
Definition: TrafficCount.h:142
ripple::TrafficCount::ld_tsc_get
@ ld_tsc_get
Definition: TrafficCount.h:86
ripple::TrafficCount::unknown
@ unknown
Definition: TrafficCount.h:145
ripple::TrafficCount::get_hash
@ get_hash
Definition: TrafficCount.h:143
ripple::TrafficCount::TrafficStats::TrafficStats
TrafficStats(char const *n)
Definition: TrafficCount.h:45
ripple::TrafficCount::get_hash_txnode
@ get_hash_txnode
Definition: TrafficCount.h:127
ripple::TrafficCount::gl_share
@ gl_share
Definition: TrafficCount.h:114
ripple::TrafficCount::gl_asn_share
@ gl_asn_share
Definition: TrafficCount.h:110
ripple::TrafficCount::TrafficStats
Definition: TrafficCount.h:35
ripple::TrafficCount::get_fetch_pack
@ get_fetch_pack
Definition: TrafficCount.h:139
ripple::TrafficCount::ld_share
@ ld_share
Definition: TrafficCount.h:99
ripple::TrafficCount::TrafficStats::name
char const * name
Definition: TrafficCount.h:38
ripple::TrafficCount::gl_tsc_share
@ gl_tsc_share
Definition: TrafficCount.h:102
ripple::TrafficCount::category
category
Definition: TrafficCount.h:68
ripple::TrafficCount::validation
@ validation
Definition: TrafficCount.h:77
ripple::TrafficCount::get_hash_ledger
@ get_hash_ledger
Definition: TrafficCount.h:119
ripple::TrafficCount::share_fetch_pack
@ share_fetch_pack
Definition: TrafficCount.h:138
ripple::TrafficCount::TrafficStats::TrafficStats
TrafficStats(TrafficStats const &ts)
Definition: TrafficCount.h:50
ripple::TrafficCount::get_hash_asnode
@ get_hash_asnode
Definition: TrafficCount.h:131
ripple::TrafficCount::ld_asn_share
@ ld_asn_share
Definition: TrafficCount.h:95
array
ripple::TrafficCount::share_hash_ledger
@ share_hash_ledger
Definition: TrafficCount.h:118
ripple::TrafficCount::TrafficCount
TrafficCount()=default
ripple::TrafficCount::proposal
@ proposal
Definition: TrafficCount.h:76
ripple::TrafficCount::gl_asn_get
@ gl_asn_get
Definition: TrafficCount.h:111
ripple::TrafficCount::gl_get
@ gl_get
Definition: TrafficCount.h:115
ripple::TrafficCount::ld_asn_get
@ ld_asn_get
Definition: TrafficCount.h:94
cstdint
ripple::TrafficCount::get_cas_object
@ get_cas_object
Definition: TrafficCount.h:135
ripple::TrafficCount::share_hash_txnode
@ share_hash_txnode
Definition: TrafficCount.h:126
atomic
ripple::TrafficCount::share_cas_object
@ share_cas_object
Definition: TrafficCount.h:134
ripple::TrafficCount::manifests
@ manifests
Definition: TrafficCount.h:74
ripple::TrafficCount::base
@ base
Definition: TrafficCount.h:70
ripple::TrafficCount::TrafficStats::bytesOut
std::atomic< std::uint64_t > bytesOut
Definition: TrafficCount.h:41
ripple::TrafficCount::cluster
@ cluster
Definition: TrafficCount.h:72
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:122
ripple::TrafficCount::share_set
@ share_set
Definition: TrafficCount.h:83
ripple::TrafficCount::gl_tsc_get
@ gl_tsc_get
Definition: TrafficCount.h:103
ripple::TrafficCount::transaction
@ transaction
Definition: TrafficCount.h:75
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:123
ripple::TrafficCount::validatorlist
@ validatorlist
Definition: TrafficCount.h:78
ripple::TrafficCount::TrafficStats::messagesOut
std::atomic< std::uint64_t > messagesOut
Definition: TrafficCount.h:43
std::size_t
ripple::TrafficCount::shards
@ shards
Definition: TrafficCount.h:79
ripple::TrafficCount::ld_get
@ ld_get
Definition: TrafficCount.h:98
ripple::TrafficCount::ld_txn_get
@ ld_txn_get
Definition: TrafficCount.h:90
ripple::TrafficCount::overlay
@ overlay
Definition: TrafficCount.h:73
ripple::TrafficCount::addCount
void addCount(category cat, bool inbound, int bytes)
Account for traffic associated with the given category.
Definition: TrafficCount.h:154
ripple::TrafficCount::ld_txn_share
@ ld_txn_share
Definition: TrafficCount.h:91
ripple::TrafficCount::ld_tsc_share
@ ld_tsc_share
Definition: TrafficCount.h:87
ripple::TrafficCount::gl_txn_get
@ gl_txn_get
Definition: TrafficCount.h:107
ripple::TrafficCount::get_set
@ get_set
Definition: TrafficCount.h:82