Skip to content

Commit e00febd

Browse files
committed
Top ports - update input plugin base class
1 parent 37fdac2 commit e00febd

File tree

4 files changed

+32
-1
lines changed

4 files changed

+32
-1
lines changed

include/ipfixprobe/inputPlugin.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ class IPXP_API InputPlugin
9292
};
9393

9494
/// Statistics related to packet parsing.
95-
ParserStats m_parser_stats = {};
95+
ParserStats m_parser_stats{10};
9696

9797
private:
9898
void create_parser_stats_telemetry(std::shared_ptr<telemetry::Directory> queues_dir);

include/ipfixprobe/parser-stats.hpp

Lines changed: 18 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 <cstdint>
2931

3032
namespace ipxp {
@@ -33,6 +35,22 @@ namespace ipxp {
3335
* \brief Structure for storing parser statistics.
3436
*/
3537
struct ParserStats {
38+
39+
ParserStats(size_t top_ports_count)
40+
: top_ports(top_ports_count)
41+
, mpls_packets(0)
42+
, vlan_packets(0)
43+
, pppoe_packets(0)
44+
, trill_packets(0)
45+
, ipv4_packets(0)
46+
, ipv6_packets(0)
47+
, tcp_packets(0)
48+
, udp_packets(0)
49+
, seen_packets(0)
50+
, unknown_packets(0) {}
51+
52+
TopPorts top_ports;
53+
3654
uint64_t mpls_packets;
3755
uint64_t vlan_packets;
3856
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 {
@@ -34,6 +36,16 @@ static telemetry::Content get_parser_stats_content(const ParserStats& parserStat
3436
dict["seen_packets"] = parserStats.seen_packets;
3537
dict["unknown_packets"] = parserStats.unknown_packets;
3638

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

0 commit comments

Comments
 (0)