-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add metrics #163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add metrics #163
Changes from all commits
767cc95
f155a86
8672009
fd6914e
0107726
c2a3b3d
052c32a
218a5c7
74e6658
397a0cd
aaab892
896ad1e
98ebcd9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,29 @@ | ||
| #ifndef METRICS_COLLECTOR_HPP | ||
| #define METRICS_COLLECTOR_HPP | ||
|
|
||
| #include <atomic> | ||
| #include <chrono> | ||
| #include <prometheus/counter.h> | ||
| #include <prometheus/gateway.h> | ||
| #include <prometheus/gauge.h> | ||
| #include <prometheus/histogram.h> | ||
| #include <prometheus/registry.h> | ||
| #include <sstream> | ||
| #include <string> | ||
| #include <thread> | ||
| #include <unordered_map> | ||
|
|
||
| class MetricsCollector { | ||
| prometheus::Gateway gateway; | ||
| std::shared_ptr<prometheus::Registry> registry; | ||
| public: | ||
| MetricsCollector(const char *gateway_address, const char *gateway_port, | ||
| const char *worker_name); | ||
|
Comment on lines
+18
to
+19
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. а вы это где-то используете? |
||
| ~MetricsCollector(); | ||
|
|
||
| void IncrementPacketsReceived(uint64_t count = 1); | ||
| void IncrementPacketsPassed(uint64_t count = 1); | ||
| void IncrementPacketsDropped(uint64_t count = 1); | ||
|
|
||
| private: | ||
| struct CPUInfo { | ||
| prometheus::Gauge *gauge; | ||
|
|
||
|
|
@@ -21,29 +35,29 @@ class MetricsCollector { | |
| }; | ||
|
|
||
| Time time; | ||
| }; | ||
|
|
||
| std::unordered_map<std::string, CPUInfo> cpu_usage; | ||
| uint64_t last_total{0}; | ||
| uint64_t last_non_idle{0}; | ||
| }; | ||
|
|
||
| prometheus::Gauge *memory_used_gauge; | ||
| prometheus::Gauge *task_processing_time_gauge; | ||
| void GetCPUUsage(); | ||
| void MainLoop(); | ||
| void PushMetrics(); | ||
|
|
||
| std::atomic<bool> is_running{true}; | ||
| std::thread thread; | ||
| prometheus::Gateway gateway; | ||
| std::shared_ptr<prometheus::Registry> registry; | ||
|
|
||
| std::atomic<bool> is_task_running; | ||
| std::chrono::time_point<std::chrono::high_resolution_clock> task_start; | ||
| std::unordered_map<std::string, CPUInfo> cpu_usage; | ||
| prometheus::Gauge *memory_used_gauge; | ||
|
|
||
| void GetCPUUsage(); | ||
| void MainLoop(); | ||
| prometheus::Counter *packets_received_counter; | ||
| prometheus::Counter *packets_passed_counter; | ||
| prometheus::Counter *packets_dropped_counter; | ||
|
|
||
| public: | ||
| MetricsCollector(const char *gateway_address, const char *gateway_port, | ||
| const char *worker_name); | ||
| ~MetricsCollector(); | ||
| prometheus::Counter *push_errors_total; | ||
|
|
||
| void StartTask(); | ||
| void StopTask(); | ||
| std::atomic<bool> is_running{true}; | ||
| std::thread thread; | ||
| }; | ||
|
|
||
| #endif | ||
| #endif | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,12 @@ | |
| #include "domain_cache.h" | ||
| #include "ip_cache.h" | ||
| #include <stdatomic.h> | ||
| #include <stdbool.h> | ||
| #include <stdint.h> | ||
|
|
||
| extern void record_packet_received(); | ||
| extern void record_packet_passed(); | ||
| extern void record_packet_dropped(); | ||
|
|
||
| extern bool worker_classify(const char *type, const char *target, | ||
| struct requested_classification *out_req); | ||
|
|
@@ -17,11 +23,17 @@ void package_sending_decision(bool solution_is_send, struct rte_mbuf *pkt, | |
|
|
||
| if (ret < 1) { | ||
| LOG_ERROR("Failed to send packet"); | ||
| // PLUG (to be added later) - need to add processing for this case | ||
| record_packet_dropped(); | ||
| rte_pktmbuf_free(pkt); | ||
| return; | ||
| } | ||
|
|
||
| record_packet_passed(); | ||
|
|
||
| return; | ||
| } | ||
|
|
||
| record_packet_dropped(); | ||
| rte_pktmbuf_free(pkt); | ||
| } | ||
|
|
||
|
|
@@ -48,18 +60,22 @@ void pakage_processing(struct net_port *port_in, struct net_port *port_out, | |
| } | ||
| if (atomic_load(&filtring_is_turned_off)) { | ||
| for (int i = 0; i < nb_rx; i++) { | ||
| record_packet_received(); | ||
| package_sending_decision(true, pkts[i], port_out, queue_number); | ||
| } | ||
| return; | ||
| } | ||
|
|
||
| for (int i = 0; i < nb_rx; i++) { | ||
|
|
||
| record_packet_received(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. вы тут считает пакет, а дальше идут логические ветки, которые ловят ошибки, например, |
||
|
|
||
| struct info_of_pakage info_pac; | ||
| memset(&info_pac, 0, sizeof(info_pac)); | ||
|
|
||
| parsing_pakage(pkts[i], &info_pac); | ||
| LOG_INFO("[PKT] port = %hu", ntohs(info_pac.number_port)); | ||
|
|
||
| if (info_pac.domain[0] == '\0') { | ||
| LOG_INFO("Packet without dns request"); | ||
| struct node_cache_ip *cached_node_ip = NULL; | ||
|
|
@@ -91,7 +107,7 @@ void pakage_processing(struct net_port *port_in, struct net_port *port_out, | |
| } else if (ret == -ENOENT) { | ||
| LOG_INFO("IP cache miss, applying filter"); | ||
|
|
||
| struct requested_classification req_clas; // query to ip controller | ||
| struct requested_classification req_clas; | ||
|
|
||
| bool solution_is_send; | ||
|
|
||
|
|
@@ -142,6 +158,8 @@ void pakage_processing(struct net_port *port_in, struct net_port *port_out, | |
| } else { | ||
| LOG_ERROR("Failed to search a key-value pair in the hash table: %s", | ||
| strerror(-ret)); | ||
| record_packet_dropped(); | ||
| rte_pktmbuf_free(pkts[i]); | ||
| } | ||
| } else { | ||
| LOG_INFO("[INFO] Packet with dns request"); | ||
|
|
@@ -165,7 +183,7 @@ void pakage_processing(struct net_port *port_in, struct net_port *port_out, | |
| LOG_INFO("Domain cache miss for '%s', applying filter", | ||
| info_pac.domain); | ||
|
|
||
| struct requested_classification req_clas; // query to domain controller | ||
| struct requested_classification req_clas; | ||
|
|
||
| bool solution_is_send; | ||
| bool classification_success = | ||
|
|
@@ -179,6 +197,9 @@ void pakage_processing(struct net_port *port_in, struct net_port *port_out, | |
| LOG_WARNING("Classification failed for %s", info_pac.domain); | ||
| } | ||
|
|
||
| package_sending_decision(solution_is_send, pkts[i], port_out, | ||
| queue_number); | ||
|
|
||
| struct node_cache_domain *new_node = | ||
| rte_calloc("struct_node_cache", 1, sizeof(struct node_cache_domain), | ||
| RTE_CACHE_LINE_SIZE); | ||
|
|
@@ -193,7 +214,9 @@ void pakage_processing(struct net_port *port_in, struct net_port *port_out, | |
| } else { | ||
| LOG_ERROR("Failed to search a key-value pair in the hash table: %s", | ||
| strerror(-ret)); | ||
| record_packet_dropped(); | ||
| rte_pktmbuf_free(pkts[i]); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Вы тестировали код?
у вам в env переменных нет METRICS_GATEWAY_ADDRESS, а в
worker\src\main.cpp:Оно как будто бы должно грохнуться из-за несогласованности переменных...
Сразу проверил, что дело не в отствании версии базовой ветки, если ее смержить, то там не меняются проблемный файлы:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Потому что тестовый стенд не использует dockerfile, а запускает виртуальные машины, для которых уже прописаны переменные окружения. А там они есть.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ну вот хорошо, вы PR подготваливаете разве так, чтобы он работал только на тестовом стенде?
Нужно согласовывать переменные, чтобы не ломать сборку
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Поправлю