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  unknown // must be last
144  };
145 
148  static category
149  categorize(
150  ::google::protobuf::Message const& message,
151  int type,
152  bool inbound);
153 
155  void
156  addCount(category cat, bool inbound, int bytes)
157  {
158  assert(cat <= category::unknown);
159 
160  if (inbound)
161  {
162  counts_[cat].bytesIn += bytes;
163  ++counts_[cat].messagesIn;
164  }
165  else
166  {
167  counts_[cat].bytesOut += bytes;
168  ++counts_[cat].messagesOut;
169  }
170  }
171 
172  TrafficCount() = default;
173 
178  auto const&
179  getCounts() const
180  {
181  return counts_;
182  }
183 
184 protected:
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 } // namespace ripple
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: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:179
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:143
ripple::TrafficCount::get_hash
@ get_hash
Definition: TrafficCount.h:141
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::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::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::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:156
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