1
0
Fork 0
mirror of https://github.com/pavel-odintsov/fastnetmon synced 2024-05-21 23:46:27 +02:00

Added logic to export AF_PACKET counters from Prometheus

This commit is contained in:
Pavel Odintsov 2023-03-10 12:25:00 +01:00
parent 7aa3b19849
commit ddc4f5eaf3
4 changed files with 29 additions and 7 deletions

View File

@ -313,10 +313,27 @@ void start_af_packet_capture(std::string interface_name, bool enable_fanout, int
setup_socket(interface_name, enable_fanout, fanout_group_id);
}
void get_af_packet_stats() {
// getsockopt PACKET_STATISTICS
std::vector<system_counter_t> get_af_packet_stats() {
std::vector<system_counter_t> system_counter;
system_counter.push_back(system_counter_t("af_packet_socket_received_packets", socket_received_packets,
metric_type_t::counter, socket_received_packets_desc));
system_counter.push_back(system_counter_t("af_packet_socket_dropped_packets", socket_dropped_packets,
metric_type_t::counter, socket_dropped_packets_desc));
system_counter.push_back(system_counter_t("af_packet_blocks_read", blocks_read, metric_type_t::counter, blocks_read_desc));
system_counter.push_back(system_counter_t("af_packet_packets_raw", af_packet_packets_raw, metric_type_t::counter,
af_packet_packets_raw_desc));
system_counter.push_back(system_counter_t("af_packet_packets_parsed", af_packet_packets_parsed,
metric_type_t::counter, af_packet_packets_parsed_desc));
system_counter.push_back(system_counter_t("af_packet_packets_unparsed", af_packet_packets_unparsed,
metric_type_t::counter, af_packet_packets_unparsed_desc));
return system_counter;
}
// Could get some speed up on NUMA servers
bool afpacket_execute_strict_cpu_affinity = false;

View File

@ -1,9 +1,7 @@
#ifndef AFPACKET_PLUGIN_H
#define AFPACKET_PLUGIN_H
#pragma once
#include "../fastnetmon_types.hpp"
void start_afpacket_collection(process_packet_pointer func_ptr);
void start_af_packet_capture_for_interface(std::string capture_interface, int fanout_group_id, unsigned int num_cpus);
#endif
std::vector<system_counter_t> get_af_packet_stats();

View File

@ -3192,6 +3192,14 @@ bool get_statistics(std::vector<system_counter_t>& system_counters) {
system_counters.insert(system_counters.end(), netflow_stats.begin(), netflow_stats.end());
}
#ifdef FASTNETMON_ENABLE_AFPACKET
if (enable_afpacket_collection) {
auto af_packet_counters = get_af_packet_stats();
system_counters.insert(system_counters.end(), af_packet_counters.begin(), af_packet_counters.end());
}
#endif
return true;
}

View File

@ -1,5 +1,4 @@
#pragma once
/* netflow plugin header */
#include "../fastnetmon_types.hpp"