-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
54 lines (45 loc) · 1.73 KB
/
Copy pathmain.cpp
File metadata and controls
54 lines (45 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include "MetricsCollector.cpp"
#include <random>
#include <chrono>
// Пример метрики CPU
void simulateCPUMetrics(MetricsCollector& collector) {
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_real_distribution<> dis(0.0, 4.0); // Для 4-ядерного процессора
for (int i = 0; i < 10; ++i) {
double cpuUsage = dis(gen);
collector.addMetric("CPU usage", cpuUsage);
std::this_thread::sleep_for(std::chrono::seconds(1));
}
}
// Пример метрики HTTP запросов
void simulateHTTPMetrics(MetricsCollector& collector) {
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_int_distribution<> dis(0, 1000);
for (int i = 0; i < 10; ++i) {
int requests = dis(gen);
collector.addMetric("HTTP requests RPS", requests);
std::this_thread::sleep_for(std::chrono::seconds(1));
}
}
// Пользовательская метрика
void simulateCustomMetrics(MetricsCollector& collector) {
for (int i = 0; i < 5; ++i) {
collector.addMetric("Active connections", i * 10);
collector.addMetric("Memory usage (MB)", 512 + i * 50);
collector.addMetric("Status", std::string("OK"));
std::this_thread::sleep_for(std::chrono::milliseconds(1500));
}
}
int main() {
MetricsCollector collector("metrics.log");
// Запускаем сбор метрик в разных потоках
std::thread cpuThread(simulateCPUMetrics, std::ref(collector));
std::thread httpThread(simulateHTTPMetrics, std::ref(collector));
std::thread customThread(simulateCustomMetrics, std::ref(collector));
cpuThread.join();
httpThread.join();
customThread.join();
return 0;
}