ApplicationNetworkStats.cpp
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5 *
6 * ArmarX is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * ArmarX is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * @package ArmarXCore::core
19 * @author Manfred Kroehnert (manfred dot kroehnert at kit dot edu)
20 * @date 2015
21 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22 * GNU General Public License
23 */
24
26
27#include <atomic>
28
29#include <Ice/Connection.h>
30#include <Ice/Endpoint.h>
31#include <IceSSL/EndpointInfo.h>
32
35
37{
38 struct ArmarXConnectionObserver : public Ice::Instrumentation::ConnectionObserver
39 {
41 {
42 }
43
44 void
45 attach() override
46 {
47 }
48
49 void
50 detach() override
51 {
52 }
53
54 void
55 failed(const std::string&) override
56 {
57 }
58
59 void
60 sentBytes(int num) override
61 {
62 sent += num;
63 }
64
65 void
66 receivedBytes(int num) override
67 {
68 received += num;
69 }
70
71 void
72 report(ProfilerListenerPrx& profiler, const std::string& applicationName)
73 {
74 profiler->reportNetworkTraffic(
75 applicationName, protocol, received.exchange(0), sent.exchange(0));
76 }
77
78 const std::string protocol;
79 std::atomic<Ice::Int> sent{0};
80 std::atomic<Ice::Int> received{0};
81 };
82} // namespace armarx::detail
83
84namespace armarx
85{
87 {
88 observerTCP = new detail::ArmarXConnectionObserver{"tcp"};
89 observerUDP = new detail::ArmarXConnectionObserver{"udp"};
90 observerSSL = new detail::ArmarXConnectionObserver{"ssl"};
91 observerUnknown = new detail::ArmarXConnectionObserver{"Unknown"};
92 }
93
94 void
95 ApplicationNetworkStats::start(ProfilerListenerPrx profiler, const std::string& applicationName)
96 {
97 ARMARX_CHECK_EXPRESSION(!applicationName.empty());
99 reportNetworkTrafficTask =
100 new SimplePeriodicTask<>{[this, profiler, applicationName]() mutable
101 {
102 observerTCP->report(profiler, applicationName);
103 observerUDP->report(profiler, applicationName);
104 observerSSL->report(profiler, applicationName);
105 observerUnknown->report(profiler, applicationName);
106 },
107 REPORT_TIME_MS};
108 reportNetworkTrafficTask->start();
109 }
110
111 void
113 {
114 reportNetworkTrafficTask->stop();
115 }
116
121
122 Ice::Instrumentation::ConnectionObserverPtr
124 const Ice::ConnectionInfoPtr& /*c*/,
125 const Ice::EndpointPtr& e,
126 Ice::Instrumentation::ConnectionState /*s*/,
127 const Ice::Instrumentation::ConnectionObserverPtr& /*previous*/)
128 {
129 const auto protocol = e->getInfo()->type();
130 switch (protocol)
131 {
132 case Ice::TCPEndpointType:
133 return observerTCP;
134 case Ice::UDPEndpointType:
135 return observerUDP;
136 case Ice::SSLEndpointType:
137 return observerSSL;
138 //TODO maybe implement more endpointypes introduced in ice3.7
139 default:
140 ARMARX_WARNING << deactivateSpam(10, to_string(protocol))
141 << "Unknown protocol with type " << protocol;
142 return observerUnknown;
143 }
144 }
145
146 Ice::Instrumentation::ObserverPtr
148 const std::string&)
149 {
150 return {};
151 }
152
153 Ice::Instrumentation::ObserverPtr
155 {
156 return {};
157 }
158
159 Ice::Instrumentation::ThreadObserverPtr
161 const std::string&,
162 Ice::Instrumentation::ThreadState,
163 const Ice::Instrumentation::ThreadObserverPtr&)
164 {
165 return {};
166 }
167
168 Ice::Instrumentation::InvocationObserverPtr
170 const std::string&,
171 const Ice::Context&)
172 {
173 return {};
174 }
175
176 Ice::Instrumentation::DispatchObserverPtr
177 ApplicationNetworkStats::getDispatchObserver(const Ice::Current&, Ice::Int)
178 {
179 return {};
180 }
181
182 void
183 ApplicationNetworkStats::setObserverUpdater(const Ice::Instrumentation::ObserverUpdaterPtr& upd)
184 {
185 }
186} // namespace armarx
SpamFilterDataPtr deactivateSpam(SpamFilterDataPtr const &spamFilter, float deactivationDurationSec, const std::string &identifier, bool deactivate)
Definition Logging.cpp:75
void start(ProfilerListenerPrx profiler, const std::string &applicationName)
Ice::Instrumentation::DispatchObserverPtr getDispatchObserver(const Ice::Current &, Ice::Int) override
Ice::Instrumentation::ThreadObserverPtr getThreadObserver(const std::string &, const std::string &, Ice::Instrumentation::ThreadState, const Ice::Instrumentation::ThreadObserverPtr &) override
Ice::Instrumentation::InvocationObserverPtr getInvocationObserver(const Ice::ObjectPrx &, const std::string &, const Ice::Context &) override
Ice::Instrumentation::ObserverPtr getConnectionEstablishmentObserver(const Ice::EndpointPtr &, const std::string &) override
Ice::Instrumentation::ConnectionObserverPtr getConnectionObserver(const Ice::ConnectionInfoPtr &c, const Ice::EndpointPtr &e, Ice::Instrumentation::ConnectionState s, const Ice::Instrumentation::ConnectionObserverPtr &previous) override
Ice::Instrumentation::ObserverPtr getEndpointLookupObserver(const Ice::EndpointPtr &) override
void setObserverUpdater(const Ice::Instrumentation::ObserverUpdaterPtr &upd) override
void start()
Starts the thread.
#define ARMARX_CHECK_EXPRESSION(expression)
This macro evaluates the expression and if it turns out to be false it will throw an ExpressionExcept...
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
Definition Logging.h:193
This file offers overloads of toIce() and fromIce() functions for STL container types.
const std::string & to_string(const std::string &s)
void failed(const std::string &) override
void report(ProfilerListenerPrx &profiler, const std::string &applicationName)