Skip to content

Commit 8917316

Browse files
ZadamsaDamir Zainullin
authored andcommitted
Top ports - update input plugin base class
1 parent 2b7fcab commit 8917316

File tree

4 files changed

+36
-1
lines changed

4 files changed

+36
-1
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 & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525

2626
#pragma once
2727

28+
#include "../../src/plugins/input/parser/topPorts.hpp"
29+
2830
#include <array>
2931
#include <cstdint>
3032
#include <string>
@@ -162,6 +164,23 @@ struct VlanStats {
162164
* \brief Structure for storing parser statistics.
163165
*/
164166
struct ParserStats {
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+
}
181+
182+
TopPorts top_ports;
183+
165184
uint64_t mpls_packets;
166185
uint64_t vlan_packets;
167186
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: 15 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,19 @@ 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(
46+
ports.begin() + 1,
47+
ports.end(),
48+
top_ports,
49+
[](std::string acc, const TopPorts::PortStats& port_frequency) {
50+
return acc + ", " + port_frequency.to_string();
51+
});
52+
}
3853
return dict;
3954
}
4055

0 commit comments

Comments
 (0)