|
2 | 2 |
|
3 | 3 | #include <filesystem>
|
4 | 4 | #include <optional>
|
| 5 | +#include <sstream> |
5 | 6 |
|
6 | 7 | #include <libsinsp/sinsp.h>
|
7 | 8 |
|
@@ -256,7 +257,7 @@ void CollectorConfig::HandleTls(const Json::Value& config, const CollectorArgs*
|
256 | 257 | }
|
257 | 258 |
|
258 | 259 | void CollectorConfig::HandleNetworkConfig() {
|
259 |
| - auto filler = [](std::vector<IPNet>& output, const std::vector<std::string>& input, const std::string& error_message, const std::string& notification_message) { |
| 260 | + auto filler = [](std::vector<IPNet>& output, const std::vector<std::string>& input, const std::string& notification_message, const std::string& error_message) { |
260 | 261 | for (const std::string& str : input) {
|
261 | 262 | if (str.empty()) {
|
262 | 263 | continue;
|
@@ -383,19 +384,86 @@ std::string CollectorConfig::LogLevel() {
|
383 | 384 | return logging::GetLogLevelName(logging::GetLogLevel());
|
384 | 385 | }
|
385 | 386 |
|
| 387 | +namespace { |
| 388 | + |
| 389 | +template <typename T> |
| 390 | +std::string VectorToYamlList(const std::vector<T>& v, size_t indent_level, bool compressed = false) { |
| 391 | + std::stringstream ss; |
| 392 | + if (compressed) { |
| 393 | + bool first = true; |
| 394 | + ss << "[ "; |
| 395 | + |
| 396 | + for (const auto& item : v) { |
| 397 | + if (first) { |
| 398 | + first = false; |
| 399 | + } else { |
| 400 | + ss << ", "; |
| 401 | + } |
| 402 | + |
| 403 | + ss << '"' << item << '"'; |
| 404 | + } |
| 405 | + |
| 406 | + ss << " ]"; |
| 407 | + } else { |
| 408 | + std::string indent(indent_level * 2, ' '); |
| 409 | + for (const auto& item : v) { |
| 410 | + ss << indent << "- " << item << '\n'; |
| 411 | + } |
| 412 | + } |
| 413 | + return ss.str(); |
| 414 | +} |
| 415 | + |
| 416 | +std::string UnorderedSetToYamlList(const UnorderedSet<L4ProtoPortPair>& p, size_t indent_level) { |
| 417 | + std::stringstream ss; |
| 418 | + std::string indent(indent_level * 2, ' '); |
| 419 | + for (const auto& [k, v] : p) { |
| 420 | + ss << indent << k << ": " << v << '\n'; |
| 421 | + } |
| 422 | + return ss.str(); |
| 423 | +} |
| 424 | + |
| 425 | +} // namespace |
| 426 | + |
386 | 427 | std::ostream& operator<<(std::ostream& os, const CollectorConfig& c) {
|
387 | 428 | return os
|
388 |
| - << "collection_method:" << c.GetCollectionMethod() |
389 |
| - << ", scrape_interval:" << c.ScrapeInterval() |
390 |
| - << ", turn_off_scrape:" << c.TurnOffScrape() |
391 |
| - << ", hostname:" << c.Hostname() |
392 |
| - << ", processesListeningOnPorts:" << c.IsProcessesListeningOnPortsEnabled() |
393 |
| - << ", logLevel:" << CollectorConfig::LogLevel() |
394 |
| - << ", set_import_users:" << c.ImportUsers() |
395 |
| - << ", collect_connection_status:" << c.CollectConnectionStatus() |
396 |
| - << ", enable_detailed_metrics:" << c.EnableDetailedMetrics() |
397 |
| - << ", enable_external_ips:" << c.EnableExternalIPs() |
398 |
| - << ", track_send_recv:" << c.TrackingSendRecv(); |
| 429 | + << std::boolalpha << "\n" |
| 430 | + << " collection_method: " << c.GetCollectionMethod() << "\n" |
| 431 | + << " scrape_interval: " << c.ScrapeInterval() << "\n" |
| 432 | + << " turn_off_scrape: " << c.TurnOffScrape() << "\n" |
| 433 | + << " scrape_listen_endpoints: " << c.ScrapeListenEndpoints() << "\n" |
| 434 | + << " syscalls: " << VectorToYamlList(c.Syscalls(), 1, true) << "\n" |
| 435 | + << " hostname: " << c.Hostname() << "\n" |
| 436 | + << " disable_network_flows: " << c.DisableNetworkFlows() << "\n" |
| 437 | + << " ignored_l4proto_port_pairs: \n" |
| 438 | + << UnorderedSetToYamlList(c.IgnoredL4ProtoPortPairs(), 2) |
| 439 | + << " ignored_networks: \n" |
| 440 | + << VectorToYamlList(c.IgnoredNetworks(), 1) |
| 441 | + << " non_aggregated_networks: \n" |
| 442 | + << VectorToYamlList(c.NonAggregatedNetworks(), 1) |
| 443 | + << " enable_afterglow: " << c.EnableAfterglow() << "\n" |
| 444 | + << " afterglow_period_micros: " << c.AfterglowPeriod() << "\n" |
| 445 | + << " enable_core_dump: " << c.IsCoreDumpEnabled() << "\n" |
| 446 | + << " processesListeningOnPorts: " << c.IsProcessesListeningOnPortsEnabled() << "\n" |
| 447 | + << " logLevel: " << CollectorConfig::LogLevel() << "\n" |
| 448 | + << " set_import_users: " << c.ImportUsers() << "\n" |
| 449 | + << " collect_connection_status: " << c.CollectConnectionStatus() << "\n" |
| 450 | + << " enable_detailed_metrics: " << c.EnableDetailedMetrics() << "\n" |
| 451 | + << " enable_runtime_config: " << c.EnableRuntimeConfig() << "\n" |
| 452 | + << " use_docker_ce: " << c.UseDockerCe() << "\n" |
| 453 | + << " use_podman_ce: " << c.UsePodmanCe() << "\n" |
| 454 | + << " enable_introspection: " << c.IsIntrospectionEnabled() << "\n" |
| 455 | + << " enable_external_ips: " << c.EnableExternalIPs() << "\n" |
| 456 | + << " track_send_recv: " << c.TrackingSendRecv() << "\n" |
| 457 | + << " connection_stats:\n" |
| 458 | + << " error: " << c.GetConnectionStatsError() << "\n" |
| 459 | + << " window: " << c.GetConnectionStatsWindow() << "\n" |
| 460 | + << " quantiles:\n" |
| 461 | + << VectorToYamlList(c.GetConnectionStatsQuantiles(), 2) |
| 462 | + << " system_inspector:\n" |
| 463 | + << " cpu_buffer_size: " << c.GetSinspCpuPerBuffer() << "\n" |
| 464 | + << " buffer_size: " << c.GetSinspBufferSize() << "\n" |
| 465 | + << " total_buffer_size: " << c.GetSinspTotalBufferSize() << "\n" |
| 466 | + << " thread_cache_size: " << c.GetSinspThreadCacheSize() << "\n"; |
399 | 467 | }
|
400 | 468 |
|
401 | 469 | // Returns size of ring buffers to be allocated.
|
|
0 commit comments