Skip to content

Commit 95e9b9d

Browse files
ZadamsaDamir Zainullin
authored andcommitted
Top ports - update input plugin base class
1 parent fde3a5f commit 95e9b9d

File tree

4 files changed

+33
-3
lines changed

4 files changed

+33
-3
lines changed

include/ipfixprobe/inputPlugin.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class IPXP_API InputPlugin
9696
};
9797

9898
/// Statistics related to packet parsing.
99-
ParserStats m_parser_stats = {};
99+
ParserStats m_parser_stats{10};
100100

101101
private:
102102
void create_parser_stats_telemetry(

include/ipfixprobe/parser-stats.hpp

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,14 @@
2525

2626
#pragma once
2727

28-
#include <array>
2928
#include <cstdint>
3029
#include <string>
31-
30+
#include <array>
3231
#include <ipfixprobe/packet.hpp>
3332
#include <telemetry.hpp>
3433

34+
#include "../../src/plugins/input/parser/topPorts.hpp"
35+
3536
namespace ipxp {
3637

3738
static constexpr std::size_t MAX_VLAN_ID = 4096;
@@ -162,6 +163,22 @@ struct VlanStats {
162163
* \brief Structure for storing parser statistics.
163164
*/
164165
struct ParserStats {
166+
167+
ParserStats(size_t top_ports_count)
168+
: top_ports(top_ports_count)
169+
, mpls_packets(0)
170+
, vlan_packets(0)
171+
, pppoe_packets(0)
172+
, trill_packets(0)
173+
, ipv4_packets(0)
174+
, ipv6_packets(0)
175+
, tcp_packets(0)
176+
, udp_packets(0)
177+
, seen_packets(0)
178+
, unknown_packets(0) {}
179+
180+
TopPorts top_ports;
181+
165182
uint64_t mpls_packets;
166183
uint64_t vlan_packets;
167184
uint64_t pppoe_packets;

src/core/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ target_link_libraries(ipfixprobe-core
3232
atomic::atomic
3333
unwind::unwind
3434
${CMAKE_DL_LIBS}
35+
top-ports
3536
)
3637

3738
add_executable(ipfixprobe main.cpp)

src/core/inputPlugin.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
* SPDX-License-Identifier: BSD-3-Clause
1414
*/
1515

16+
#include <numeric>
17+
1618
#include <ipfixprobe/inputPlugin.hpp>
1719

1820
namespace ipxp {
@@ -35,6 +37,16 @@ static telemetry::Content get_parser_stats_content(const ParserStats& parserStat
3537

3638
dict["seen_packets"] = parserStats.seen_packets;
3739
dict["unknown_packets"] = parserStats.unknown_packets;
40+
const std::vector<TopPorts::PortStats>& ports = parserStats.top_ports.get_top_ports();
41+
if (ports.empty()) {
42+
dict["top_10_ports"] = "";
43+
} else {
44+
std::string top_ports = ports[0].to_string();
45+
dict["top_10_ports"] = std::accumulate(ports.begin() + 1, ports.end(), top_ports,
46+
[](std::string acc, const TopPorts::PortStats& port_frequency) {
47+
return acc + ", " + port_frequency.to_string();
48+
});
49+
}
3850
return dict;
3951
}
4052

0 commit comments

Comments
 (0)