1
0
mirror of https://github.com/pavel-odintsov/fastnetmon synced 2024-11-22 20:42:03 +01:00

Migrates Graphtie metrics plugin to new configuration struicture and adjusted it to new total counters format

This commit is contained in:
Pavel Odintsov 2024-07-13 13:41:53 +03:00
parent 6da2de9691
commit 2d478918e7
3 changed files with 47 additions and 40 deletions

@ -446,15 +446,6 @@ std::string exabgp_community_host = "";
std::string exabgp_next_hop = "";
// Graphite monitoring
bool graphite_enabled = false;
std::string graphite_host = "127.0.0.1";
unsigned short int graphite_port = 2003;
unsigned int graphite_push_period = 1;
// Default graphite namespace
std::string graphite_prefix = "fastnetmon";
std::string influxdb_writes_total_desc = "Total number of InfluxDB writes";
uint64_t influxdb_writes_total = 0;
@ -687,7 +678,7 @@ bool load_configuration_file() {
}
if (configuration_map.count("graphite_prefix") != 0) {
graphite_prefix = configuration_map["graphite_prefix"];
fastnetmon_global_configuration.graphite_prefix = configuration_map["graphite_prefix"];
}
if (configuration_map.count("average_calculation_time") != 0) {
@ -813,19 +804,19 @@ bool load_configuration_file() {
// Graphite
if (configuration_map.count("graphite") != 0) {
graphite_enabled = configuration_map["graphite"] == "on" ? true : false;
fastnetmon_global_configuration.graphite = configuration_map["graphite"] == "on" ? true : false;
}
if (configuration_map.count("graphite_host") != 0) {
graphite_host = configuration_map["graphite_host"];
fastnetmon_global_configuration.graphite_host = configuration_map["graphite_host"];
}
if (configuration_map.count("graphite_port") != 0) {
graphite_port = convert_string_to_integer(configuration_map["graphite_port"]);
fastnetmon_global_configuration.graphite_port = convert_string_to_integer(configuration_map["graphite_port"]);
}
if (configuration_map.count("graphite_push_period") != 0) {
graphite_push_period = convert_string_to_integer(configuration_map["graphite_push_period"]);
fastnetmon_global_configuration.graphite_push_period = convert_string_to_integer(configuration_map["graphite_push_period"]);
}
// InfluxDB

@ -9,6 +9,7 @@
class fastnetmon_configuration_t {
public:
// Clickhouse metrics
bool clickhouse_metrics{ false };
std::string clickhouse_metrics_database{ "fastnetmon" };
std::string clickhouse_metrics_username{ "default" };
@ -16,5 +17,23 @@ class fastnetmon_configuration_t {
std::string clickhouse_metrics_host{ "127.0.0.1" };
unsigned int clickhouse_metrics_port{ 9000 };
unsigned int clickhouse_metrics_push_period{ 1 };
// InfluxDB metrics
bool influxdb{ false };
std::string influxdb_database{ "fastnetmon" };
std::string influxdb_host{ "127.0.0.1" };
unsigned int influxdb_port{ 8086 };
bool influxdb_skip_host_counters{ false };
std::string influxdb_user{ "fastnetmon" };
std::string influxdb_password{ "fastnetmon" };
bool influxdb_auth{ false };
unsigned int influxdb_push_period{ 1 };
// Graphtie metrics
bool graphite{ false };
std::string graphite_host{ "127.0.0.1" };
unsigned int graphite_port{ 2003 };
std::string graphite_prefix{ "fastnetmon" };
unsigned int graphite_push_period{ 1 };
};

@ -3,6 +3,7 @@
#include "../fast_library.hpp"
#include "../fastnetmon_types.hpp"
#include "../fastnetmon_configuration_scheme.hpp"
#include <vector>
@ -11,17 +12,8 @@
#include "../abstract_subnet_counters.hpp"
extern log4cpp::Category& logger;
extern uint64_t incoming_total_flows_speed;
extern uint64_t outgoing_total_flows_speed;
extern abstract_subnet_counters_t<subnet_cidr_mask_t, subnet_counter_t> ipv4_network_counters;
extern total_speed_counters_t total_counters_ipv4;
extern total_speed_counters_t total_counters_ipv6;
extern bool graphite_enabled;
extern std::string graphite_host;
extern unsigned short int graphite_port;
extern std::string graphite_prefix;
extern unsigned int graphite_push_period;
extern fastnetmon_configuration_t fastnetmon_global_configuration;
// Push host traffic to Graphite
bool push_hosts_traffic_counters_to_graphite() {
@ -57,7 +49,7 @@ bool push_hosts_traffic_counters_to_graphite() {
direction_as_string = "outgoing";
}
std::string graphite_current_prefix = graphite_prefix + ".hosts." +
std::string graphite_current_prefix = fastnetmon_global_configuration.graphite_prefix + ".hosts." +
ip_as_string_with_dash_delimiters + "." + direction_as_string;
@ -96,11 +88,11 @@ bool push_hosts_traffic_counters_to_graphite() {
}
}
bool graphite_put_result = store_data_to_graphite(graphite_port, graphite_host, graphite_data);
bool graphite_put_result = store_data_to_graphite(fastnetmon_global_configuration.graphite_port, fastnetmon_global_configuration.graphite_host, graphite_data);
if (!graphite_put_result) {
logger << log4cpp::Priority::ERROR << "Can't store host load data to Graphite server "
<< graphite_host << " port: " << graphite_port;
<< fastnetmon_global_configuration.graphite_host << " port: " << fastnetmon_global_configuration.graphite_port;
return false;
}
@ -110,11 +102,15 @@ bool push_hosts_traffic_counters_to_graphite() {
// Push total counters to graphite
bool push_total_traffic_counters_to_graphite() {
extern total_speed_counters_t total_counters_ipv4;
extern uint64_t incoming_total_flows_speed;
extern uint64_t outgoing_total_flows_speed;
std::vector<direction_t> directions = { INCOMING, OUTGOING, INTERNAL, OTHER };
for (auto packet_direction : directions) {
uint64_t speed_in_pps = total_counters_ipv4.total_speed_average_counters[packet_direction].packets;
uint64_t speed_in_bps = total_counters_ipv4.total_speed_average_counters[packet_direction].bytes;
uint64_t speed_in_pps = total_counters_ipv4.total_speed_average_counters[packet_direction].total.packets;
uint64_t speed_in_bps = total_counters_ipv4.total_speed_average_counters[packet_direction].total.bytes;
graphite_data_t graphite_data;
@ -130,17 +126,17 @@ bool push_total_traffic_counters_to_graphite() {
flow_counter_for_this_direction = outgoing_total_flows_speed;
}
graphite_data[graphite_prefix + ".total." + direction_as_string + ".flows"] = flow_counter_for_this_direction;
graphite_data[fastnetmon_global_configuration.graphite_prefix + ".total." + direction_as_string + ".flows"] = flow_counter_for_this_direction;
}
graphite_data[graphite_prefix + ".total." + direction_as_string + ".pps"] = speed_in_pps;
graphite_data[graphite_prefix + ".total." + direction_as_string + ".bps"] = speed_in_bps * 8;
graphite_data[fastnetmon_global_configuration.graphite_prefix + ".total." + direction_as_string + ".pps"] = speed_in_pps;
graphite_data[fastnetmon_global_configuration.graphite_prefix + ".total." + direction_as_string + ".bps"] = speed_in_bps * 8;
bool graphite_put_result = store_data_to_graphite(graphite_port, graphite_host, graphite_data);
bool graphite_put_result = store_data_to_graphite(fastnetmon_global_configuration.graphite_port, fastnetmon_global_configuration.graphite_host, graphite_data);
if (!graphite_put_result) {
logger << log4cpp::Priority::ERROR << "Can't store total load data to Graphite server " << graphite_host
<< " port: " << graphite_port;
logger << log4cpp::Priority::ERROR << "Can't store total load data to Graphite server " << fastnetmon_global_configuration.graphite_host
<< " port: " << fastnetmon_global_configuration.graphite_port;
;
return false;
}
@ -151,6 +147,7 @@ bool push_total_traffic_counters_to_graphite() {
// Push per subnet traffic counters to graphite
bool push_network_traffic_counters_to_graphite() {
extern abstract_subnet_counters_t<subnet_cidr_mask_t, subnet_counter_t> ipv4_network_counters;
graphite_data_t graphite_data;
std::vector<std::pair<subnet_cidr_mask_t, subnet_counter_t>> speed_elements;
@ -166,7 +163,7 @@ bool push_network_traffic_counters_to_graphite() {
// Replace / by dashes too
std::replace(subnet_as_string_as_dash_delimiters.begin(), subnet_as_string_as_dash_delimiters.end(), '/', '_');
std::string current_prefix = graphite_prefix + ".networks." + subnet_as_string_as_dash_delimiters + ".";
std::string current_prefix = fastnetmon_global_configuration.graphite_prefix + ".networks." + subnet_as_string_as_dash_delimiters + ".";
graphite_data[current_prefix + "incoming.pps"] = speed->total.in_packets;
graphite_data[current_prefix + "outgoing.pps"] = speed->total.out_packets;
@ -175,11 +172,11 @@ bool push_network_traffic_counters_to_graphite() {
}
bool graphite_put_result = store_data_to_graphite(graphite_port, graphite_host, graphite_data);
bool graphite_put_result = store_data_to_graphite(fastnetmon_global_configuration.graphite_port, fastnetmon_global_configuration.graphite_host, graphite_data);
if (!graphite_put_result) {
logger << log4cpp::Priority::ERROR << "Can't store network load data to Graphite server " << graphite_host
<< " port: " << graphite_port;
logger << log4cpp::Priority::ERROR << "Can't store network load data to Graphite server " << fastnetmon_global_configuration.graphite_host
<< " port: " << fastnetmon_global_configuration.graphite_port;
return false;
}
@ -194,7 +191,7 @@ void graphite_push_thread() {
boost::this_thread::sleep(boost::posix_time::milliseconds(500));
while (true) {
boost::this_thread::sleep(boost::posix_time::seconds(graphite_push_period));
boost::this_thread::sleep(boost::posix_time::seconds(fastnetmon_global_configuration.graphite_push_period));
std::chrono::steady_clock::time_point start_time = std::chrono::steady_clock::now();