diff --git a/collector/lib/CollectorStatsExporter.cpp b/collector/lib/CollectorStatsExporter.cpp index ee628c8eb6..324d3f2231 100644 --- a/collector/lib/CollectorStatsExporter.cpp +++ b/collector/lib/CollectorStatsExporter.cpp @@ -58,6 +58,21 @@ void CollectorStatsExporter::run() { auto& preemptions = collectorEventCounters.Add({{"type", "preemptions"}}); auto& grpcSendFailures = collectorEventCounters.Add({{"type", "grpcSendFailures"}}); auto& threadTableSize = collectorEventCounters.Add({{"type", "threadCacheSize"}}); + auto& procLookups = collectorEventCounters.Add({{"type", "procLookups"}}); + auto& mainThreadLookups = collectorEventCounters.Add({{"type", "mainThreadLookups"}}); + auto& procLookupsDurationNs = collectorEventCounters.Add({{"type", "procLookupsDurationNs"}}); + + auto& fdCacheHits = collectorEventCounters.Add({{"type", "fdCacheHits"}}); + auto& fdCacheMisses = collectorEventCounters.Add({{"type", "fdCacheMisses"}}); + auto& fdLookupFailures = collectorEventCounters.Add({{"type", "fdLookupFailures"}}); + auto& fdsAdded = collectorEventCounters.Add({{"type", "fdsAdded"}}); + auto& fdsRemoved = collectorEventCounters.Add({{"type", "fdsRemoved"}}); + + auto& threadCacheHits = collectorEventCounters.Add({{"type", "threadCacheHits"}}); + auto& threadCacheMisses = collectorEventCounters.Add({{"type", "threadCacheMisses"}}); + auto& threadLookupFailures = collectorEventCounters.Add({{"type", "threadLookupFailures"}}); + auto& threadsAdded = collectorEventCounters.Add({{"type", "threadsAdded"}}); + auto& threadsRemoved = collectorEventCounters.Add({{"type", "threadsRemoved"}}); auto& processSent = collectorEventCounters.Add({{"type", "processSent"}}); auto& processSendFailures = collectorEventCounters.Add({{"type", "processSendFailures"}}); @@ -170,6 +185,21 @@ void CollectorStatsExporter::run() { ringbufferDrops.Set(stats.nDropsBuffer); preemptions.Set(stats.nPreemptions); threadTableSize.Set(stats.nThreadCacheSize); + procLookups.Set(stats.nProcLookups); + mainThreadLookups.Set(stats.nMainThreadLookups); + procLookupsDurationNs.Set(stats.nProcLookupsDurationNs); + + fdCacheHits.Set(stats.nFdCacheHits); + fdCacheMisses.Set(stats.nFdCacheMisses); + fdLookupFailures.Set(stats.nFdLookupFailures); + fdsAdded.Set(stats.nFdsAdded); + fdsRemoved.Set(stats.nFdsRemoved); + + threadCacheHits.Set(stats.nThreadCacheHits); + threadCacheMisses.Set(stats.nThreadCacheMisses); + threadLookupFailures.Set(stats.nThreadLookupFailures); + threadsAdded.Set(stats.nThreadsAdded); + threadsRemoved.Set(stats.nThreadsRemoved); if (config_->EnableDetailedMetrics()) { uint64_t nUserspace = 0; diff --git a/collector/lib/system-inspector/Service.cpp b/collector/lib/system-inspector/Service.cpp index 95c0394416..f874467f4f 100644 --- a/collector/lib/system-inspector/Service.cpp +++ b/collector/lib/system-inspector/Service.cpp @@ -357,9 +357,24 @@ bool Service::GetStats(system_inspector::Stats* stats) const { stats->nDropsBuffer = kernel_stats.n_drops_buffer; stats->nPreemptions = kernel_stats.n_preemptions; stats->nThreadCacheSize = inspector_->m_thread_manager->get_thread_count(); + stats->nProcLookups = inspector_->m_thread_manager->get_m_n_proc_lookups(); + stats->nMainThreadLookups = inspector_->m_thread_manager->get_m_n_main_thread_lookups(); + stats->nProcLookupsDurationNs = inspector_->m_thread_manager->get_m_n_proc_lookups_duration_ns(); if (userspace_stats != nullptr) { stats->nDropsThreadCache = userspace_stats->m_n_drops_full_threadtable; + + stats->nFdCacheHits = userspace_stats->m_n_cached_fd_lookups; + stats->nFdCacheMisses = userspace_stats->m_n_noncached_fd_lookups; + stats->nFdLookupFailures = userspace_stats->m_n_failed_fd_lookups; + stats->nFdsAdded = userspace_stats->m_n_added_fds; + stats->nFdsRemoved = userspace_stats->m_n_removed_fds; + + stats->nThreadCacheHits = userspace_stats->m_n_cached_thread_lookups; + stats->nThreadCacheMisses = userspace_stats->m_n_noncached_thread_lookups; + stats->nThreadLookupFailures = userspace_stats->m_n_failed_thread_lookups; + stats->nThreadsAdded = userspace_stats->m_n_added_threads; + stats->nThreadsRemoved = userspace_stats->m_n_removed_threads; } return true; diff --git a/collector/lib/system-inspector/SystemInspector.h b/collector/lib/system-inspector/SystemInspector.h index 247da3f223..0883d1b127 100644 --- a/collector/lib/system-inspector/SystemInspector.h +++ b/collector/lib/system-inspector/SystemInspector.h @@ -25,6 +25,24 @@ struct Stats { volatile uint64_t nThreadCacheSize = 0; // number of thread-info entries stored in the cache volatile uint64_t nDropsThreadCache = 0; // the number of drops due to full thread cache + // libsinsp fdtable/threadtable state counters (from sinsp_stats_v2) + volatile uint64_t nFdCacheHits = 0; // cached fd lookups + volatile uint64_t nFdCacheMisses = 0; // non-cached fd lookups + volatile uint64_t nFdLookupFailures = 0; // failed fd lookups + volatile uint64_t nFdsAdded = 0; // fds added to fdtables + volatile uint64_t nFdsRemoved = 0; // fds removed from fdtables + + volatile uint64_t nThreadCacheHits = 0; // cached thread lookups + volatile uint64_t nThreadCacheMisses = 0; // non-cached thread lookups + volatile uint64_t nThreadLookupFailures = 0; // failed thread lookups + volatile uint64_t nThreadsAdded = 0; // threads added to the thread table + volatile uint64_t nThreadsRemoved = 0; // threads removed from the thread table + + // number of times a thread lookup fell back to a direct /proc scan (sinsp_thread_manager) + volatile uint64_t nProcLookups = 0; // total /proc lookups performed + volatile uint64_t nMainThreadLookups = 0; // /proc lookups performed specifically for main threads + volatile uint64_t nProcLookupsDurationNs = 0; // total time spent performing /proc lookups + // process related metrics volatile uint64_t nProcessSent = 0; // number of process signals sent volatile uint64_t nProcessSendFailures = 0; // number of process signals failed to send