Skip to content

Commit

Permalink
new(libsinsp): expose crucial container cache stats via hijacking the…
Browse files Browse the repository at this point in the history
… periodic container cache flush functionality

Signed-off-by: Melissa Kilby <[email protected]>
  • Loading branch information
incertum committed Oct 21, 2023
1 parent e644cca commit 9e79c35
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 73 deletions.
11 changes: 10 additions & 1 deletion userspace/libsinsp/container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,16 @@ bool sinsp_container_manager::remove_inactive_containers()
});

auto containers = m_containers.lock();
if (m_inspector != nullptr)
{
m_inspector->m_sinsp_stats_v2.m_n_containers = containers->size();
m_inspector->m_sinsp_stats_v2.m_n_missing_container_images = 0;
}
for(auto it = containers->begin(); it != containers->end();)
{
sinsp_container_info::ptr_t container = it->second;
if(containers_in_use.find(it->first) == containers_in_use.end())
{
sinsp_container_info::ptr_t container = it->second;
for(const auto &remove_cb : m_remove_callbacks)
{
remove_cb(*container);
Expand All @@ -101,6 +106,10 @@ bool sinsp_container_manager::remove_inactive_containers()
}
else
{
if (container.get()->m_image.empty() && m_inspector != nullptr)
{
m_inspector->m_sinsp_stats_v2.m_n_missing_container_images++;
}
++it;
}
}
Expand Down
2 changes: 2 additions & 0 deletions userspace/libsinsp/sinsp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,8 @@ void sinsp::init()
m_sinsp_stats_v2.m_n_failed_thread_lookups = 0;
m_sinsp_stats_v2.m_n_added_threads = 0;
m_sinsp_stats_v2.m_n_removed_threads = 0;
m_sinsp_stats_v2.m_n_missing_container_images = 0;
m_sinsp_stats_v2.m_n_containers = 0;

m_nevts = 0;
m_tid_to_remove = -1;
Expand Down
126 changes: 64 additions & 62 deletions userspace/libsinsp/stats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ static const char *const sinsp_stats_v2_resource_utilization_names[] = {
[SINSP_STATS_V2_ADDED_THREADS] = "n_added_threads",
[SINSP_STATS_V2_REMOVED_THREADS] = "n_removed_threads",
[SINSP_STATS_V2_N_DROPS_FULL_THREADTABLE] = "n_drops_full_threadtable",
[SINSP_STATS_V2_N_MISSING_CONTAINER_IMAGES] = "n_missing_container_images",
[SINSP_STATS_V2_N_CONTAINERS] = "n_containers",
};

Expand Down Expand Up @@ -300,9 +301,9 @@ uint64_t get_container_memory_usage()
return memory_used;
}

const scap_stats_v2* libsinsp::stats::get_sinsp_stats_v2(uint32_t flags, const scap_agent_info* agent_info, sinsp_thread_manager* thread_manager, sinsp_stats_v2 sinsp_stats_v2_counters, scap_stats_v2* stats, uint32_t n_containers, uint32_t* nstats, int32_t* rc)
const scap_stats_v2* libsinsp::stats::get_sinsp_stats_v2(uint32_t flags, const scap_agent_info* agent_info, sinsp_thread_manager* thread_manager, sinsp_stats_v2 stats_v2, scap_stats_v2* buffer, uint32_t* nstats, int32_t* rc)
{
if (!stats)
if (!buffer)
{
*nstats = 0;
*rc = SCAP_FAILURE;
Expand All @@ -320,105 +321,106 @@ const scap_stats_v2* libsinsp::stats::get_sinsp_stats_v2(uint32_t flags, const s
double cpu_usage_perc_total_host = 0.0;
uint32_t procs_running_host = 0;

if(stats[SINSP_RESOURCE_UTILIZATION_CPU_PERC].name != nullptr && strncmp(stats[SINSP_RESOURCE_UTILIZATION_CPU_PERC].name, sinsp_stats_v2_resource_utilization_names[SINSP_RESOURCE_UTILIZATION_CPU_PERC], 15) != 0)
if(buffer[SINSP_RESOURCE_UTILIZATION_CPU_PERC].name != nullptr && strncmp(buffer[SINSP_RESOURCE_UTILIZATION_CPU_PERC].name, sinsp_stats_v2_resource_utilization_names[SINSP_RESOURCE_UTILIZATION_CPU_PERC], 15) != 0)
{
// Init
for(uint32_t i = SINSP_RESOURCE_UTILIZATION_CPU_PERC; i < SINSP_RESOURCE_UTILIZATION_FDS_TOTAL_HOST + 1; i++)
{
stats[i].flags = PPM_SCAP_STATS_RESOURCE_UTILIZATION;
strlcpy(stats[i].name, sinsp_stats_v2_resource_utilization_names[i], STATS_NAME_MAX);
buffer[i].flags = PPM_SCAP_STATS_RESOURCE_UTILIZATION;
strlcpy(buffer[i].name, sinsp_stats_v2_resource_utilization_names[i], STATS_NAME_MAX);
}

stats[SINSP_RESOURCE_UTILIZATION_CPU_PERC].type = STATS_VALUE_TYPE_D;
stats[SINSP_RESOURCE_UTILIZATION_MEMORY_RSS].type = STATS_VALUE_TYPE_U32;
stats[SINSP_RESOURCE_UTILIZATION_MEMORY_VSZ].type = STATS_VALUE_TYPE_U32;
stats[SINSP_RESOURCE_UTILIZATION_MEMORY_PSS].type = STATS_VALUE_TYPE_U32;
stats[SINSP_RESOURCE_UTILIZATION_CONTAINER_MEMORY].type = STATS_VALUE_TYPE_U64;
stats[SINSP_RESOURCE_UTILIZATION_CPU_PERC_TOTAL_HOST].type = STATS_VALUE_TYPE_D;
stats[SINSP_RESOURCE_UTILIZATION_PROCS_HOST].type = STATS_VALUE_TYPE_U32;
stats[SINSP_RESOURCE_UTILIZATION_MEMORY_TOTAL_HOST].type = STATS_VALUE_TYPE_U64;
stats[SINSP_RESOURCE_UTILIZATION_FDS_TOTAL_HOST].type = STATS_VALUE_TYPE_U64;
buffer[SINSP_RESOURCE_UTILIZATION_CPU_PERC].type = STATS_VALUE_TYPE_D;
buffer[SINSP_RESOURCE_UTILIZATION_MEMORY_RSS].type = STATS_VALUE_TYPE_U32;
buffer[SINSP_RESOURCE_UTILIZATION_MEMORY_VSZ].type = STATS_VALUE_TYPE_U32;
buffer[SINSP_RESOURCE_UTILIZATION_MEMORY_PSS].type = STATS_VALUE_TYPE_U32;
buffer[SINSP_RESOURCE_UTILIZATION_CONTAINER_MEMORY].type = STATS_VALUE_TYPE_U64;
buffer[SINSP_RESOURCE_UTILIZATION_CPU_PERC_TOTAL_HOST].type = STATS_VALUE_TYPE_D;
buffer[SINSP_RESOURCE_UTILIZATION_PROCS_HOST].type = STATS_VALUE_TYPE_U32;
buffer[SINSP_RESOURCE_UTILIZATION_MEMORY_TOTAL_HOST].type = STATS_VALUE_TYPE_U64;
buffer[SINSP_RESOURCE_UTILIZATION_FDS_TOTAL_HOST].type = STATS_VALUE_TYPE_U64;
}

// Get stats / metrics snapshot

get_cpu_usage_and_total_procs(agent_info->start_time, cpu_usage_perc, cpu_usage_perc_total_host, procs_running_host);
get_rss_vsz_pss_total_memory_and_open_fds(rss, vsz, pss, memory_used_host, open_fds_host);

stats[SINSP_RESOURCE_UTILIZATION_CPU_PERC].value.d = cpu_usage_perc;
stats[SINSP_RESOURCE_UTILIZATION_MEMORY_RSS].value.u32 = rss;
stats[SINSP_RESOURCE_UTILIZATION_MEMORY_VSZ].value.u32 = vsz;
stats[SINSP_RESOURCE_UTILIZATION_MEMORY_PSS].value.u32 = pss;
stats[SINSP_RESOURCE_UTILIZATION_CONTAINER_MEMORY].value.u64 = get_container_memory_usage();
stats[SINSP_RESOURCE_UTILIZATION_CPU_PERC_TOTAL_HOST].value.d = cpu_usage_perc_total_host;
stats[SINSP_RESOURCE_UTILIZATION_PROCS_HOST].value.u32 = procs_running_host;
stats[SINSP_RESOURCE_UTILIZATION_MEMORY_TOTAL_HOST].value.u64 = memory_used_host;
stats[SINSP_RESOURCE_UTILIZATION_FDS_TOTAL_HOST].value.u64 = open_fds_host;
buffer[SINSP_RESOURCE_UTILIZATION_CPU_PERC].value.d = cpu_usage_perc;
buffer[SINSP_RESOURCE_UTILIZATION_MEMORY_RSS].value.u32 = rss;
buffer[SINSP_RESOURCE_UTILIZATION_MEMORY_VSZ].value.u32 = vsz;
buffer[SINSP_RESOURCE_UTILIZATION_MEMORY_PSS].value.u32 = pss;
buffer[SINSP_RESOURCE_UTILIZATION_CONTAINER_MEMORY].value.u64 = get_container_memory_usage();
buffer[SINSP_RESOURCE_UTILIZATION_CPU_PERC_TOTAL_HOST].value.d = cpu_usage_perc_total_host;
buffer[SINSP_RESOURCE_UTILIZATION_PROCS_HOST].value.u32 = procs_running_host;
buffer[SINSP_RESOURCE_UTILIZATION_MEMORY_TOTAL_HOST].value.u64 = memory_used_host;
buffer[SINSP_RESOURCE_UTILIZATION_FDS_TOTAL_HOST].value.u64 = open_fds_host;

*nstats = SINSP_RESOURCE_UTILIZATION_FDS_TOTAL_HOST + 1;

}

if((flags & PPM_SCAP_STATS_STATE_COUNTERS))
{
if(stats[SINSP_STATS_V2_N_THREADS].name != nullptr && strncmp(stats[SINSP_STATS_V2_N_THREADS].name, sinsp_stats_v2_resource_utilization_names[SINSP_STATS_V2_N_THREADS], 10) != 0)
if(buffer[SINSP_STATS_V2_N_THREADS].name != nullptr && strncmp(buffer[SINSP_STATS_V2_N_THREADS].name, sinsp_stats_v2_resource_utilization_names[SINSP_STATS_V2_N_THREADS], 10) != 0)
{
// Init
for(uint32_t i = SINSP_STATS_V2_N_THREADS; i < SINSP_MAX_STATS_V2; i++)
{
stats[i].flags = PPM_SCAP_STATS_STATE_COUNTERS;
strlcpy(stats[i].name, sinsp_stats_v2_resource_utilization_names[i], STATS_NAME_MAX);
buffer[i].flags = PPM_SCAP_STATS_STATE_COUNTERS;
strlcpy(buffer[i].name, sinsp_stats_v2_resource_utilization_names[i], STATS_NAME_MAX);
}

stats[SINSP_STATS_V2_NONCACHED_FD_LOOKUPS].type = STATS_VALUE_TYPE_U64;
stats[SINSP_STATS_V2_CACHED_FD_LOOKUPS].type = STATS_VALUE_TYPE_U64;
stats[SINSP_STATS_V2_FAILED_FD_LOOKUPS].type = STATS_VALUE_TYPE_U64;
stats[SINSP_STATS_V2_ADDED_FDS].type = STATS_VALUE_TYPE_U64;
stats[SINSP_STATS_V2_REMOVED_FDS].type = STATS_VALUE_TYPE_U64;
stats[SINSP_STATS_V2_STORED_EVTS].type = STATS_VALUE_TYPE_U64;
stats[SINSP_STATS_V2_STORE_EVTS_DROPS].type = STATS_VALUE_TYPE_U64;
stats[SINSP_STATS_V2_RETRIEVED_EVTS].type = STATS_VALUE_TYPE_U64;
stats[SINSP_STATS_V2_RETRIEVE_EVTS_DROPS].type = STATS_VALUE_TYPE_U64;
stats[SINSP_STATS_V2_NONCACHED_THREAD_LOOKUPS].type = STATS_VALUE_TYPE_U64;
stats[SINSP_STATS_V2_CACHED_THREAD_LOOKUPS].type = STATS_VALUE_TYPE_U64;
stats[SINSP_STATS_V2_FAILED_THREAD_LOOKUPS].type = STATS_VALUE_TYPE_U64;
stats[SINSP_STATS_V2_ADDED_THREADS].type = STATS_VALUE_TYPE_U64;
stats[SINSP_STATS_V2_REMOVED_THREADS].type = STATS_VALUE_TYPE_U64;
stats[SINSP_STATS_V2_N_DROPS_FULL_THREADTABLE].type = STATS_VALUE_TYPE_U32;
stats[SINSP_STATS_V2_N_CONTAINERS].type = STATS_VALUE_TYPE_U32;
buffer[SINSP_STATS_V2_NONCACHED_FD_LOOKUPS].type = STATS_VALUE_TYPE_U64;
buffer[SINSP_STATS_V2_CACHED_FD_LOOKUPS].type = STATS_VALUE_TYPE_U64;
buffer[SINSP_STATS_V2_FAILED_FD_LOOKUPS].type = STATS_VALUE_TYPE_U64;
buffer[SINSP_STATS_V2_ADDED_FDS].type = STATS_VALUE_TYPE_U64;
buffer[SINSP_STATS_V2_REMOVED_FDS].type = STATS_VALUE_TYPE_U64;
buffer[SINSP_STATS_V2_STORED_EVTS].type = STATS_VALUE_TYPE_U64;
buffer[SINSP_STATS_V2_STORE_EVTS_DROPS].type = STATS_VALUE_TYPE_U64;
buffer[SINSP_STATS_V2_RETRIEVED_EVTS].type = STATS_VALUE_TYPE_U64;
buffer[SINSP_STATS_V2_RETRIEVE_EVTS_DROPS].type = STATS_VALUE_TYPE_U64;
buffer[SINSP_STATS_V2_NONCACHED_THREAD_LOOKUPS].type = STATS_VALUE_TYPE_U64;
buffer[SINSP_STATS_V2_CACHED_THREAD_LOOKUPS].type = STATS_VALUE_TYPE_U64;
buffer[SINSP_STATS_V2_FAILED_THREAD_LOOKUPS].type = STATS_VALUE_TYPE_U64;
buffer[SINSP_STATS_V2_ADDED_THREADS].type = STATS_VALUE_TYPE_U64;
buffer[SINSP_STATS_V2_REMOVED_THREADS].type = STATS_VALUE_TYPE_U64;
buffer[SINSP_STATS_V2_N_DROPS_FULL_THREADTABLE].type = STATS_VALUE_TYPE_U32;
buffer[SINSP_STATS_V2_N_CONTAINERS].type = STATS_VALUE_TYPE_U32;

}

// Get stats / metrics snapshot
stats[SINSP_STATS_V2_N_THREADS].value.u64 = thread_manager->get_thread_count();
stats[SINSP_STATS_V2_N_FDS].value.u64 = 0;
buffer[SINSP_STATS_V2_N_THREADS].value.u64 = thread_manager->get_thread_count();
buffer[SINSP_STATS_V2_N_FDS].value.u64 = 0;
threadinfo_map_t* threadtable = thread_manager->get_threads();
threadtable->loop([&] (sinsp_threadinfo& tinfo) {
sinsp_fdtable* fdtable = tinfo.get_fd_table();
stats[SINSP_STATS_V2_N_FDS].value.u64 += fdtable->size();
buffer[SINSP_STATS_V2_N_FDS].value.u64 += fdtable->size();
return true;
});
stats[SINSP_STATS_V2_NONCACHED_FD_LOOKUPS].value.u64 = sinsp_stats_v2_counters.m_n_noncached_fd_lookups;
stats[SINSP_STATS_V2_CACHED_FD_LOOKUPS].value.u64 = sinsp_stats_v2_counters.m_n_cached_fd_lookups;
stats[SINSP_STATS_V2_FAILED_FD_LOOKUPS].value.u64 = sinsp_stats_v2_counters.m_n_failed_fd_lookups;
stats[SINSP_STATS_V2_ADDED_FDS].value.u64 = sinsp_stats_v2_counters.m_n_added_fds;
stats[SINSP_STATS_V2_REMOVED_FDS].value.u64 = sinsp_stats_v2_counters.m_n_removed_fds;
stats[SINSP_STATS_V2_STORED_EVTS].value.u64 = sinsp_stats_v2_counters.m_n_stored_evts;
stats[SINSP_STATS_V2_STORE_EVTS_DROPS].value.u64 = sinsp_stats_v2_counters.m_n_store_evts_drops;
stats[SINSP_STATS_V2_RETRIEVED_EVTS].value.u64 = sinsp_stats_v2_counters.m_n_retrieved_evts;
stats[SINSP_STATS_V2_RETRIEVE_EVTS_DROPS].value.u64 = sinsp_stats_v2_counters.m_n_retrieve_evts_drops;
stats[SINSP_STATS_V2_NONCACHED_THREAD_LOOKUPS].value.u64 = sinsp_stats_v2_counters.m_n_noncached_thread_lookups;
stats[SINSP_STATS_V2_CACHED_THREAD_LOOKUPS].value.u64 = sinsp_stats_v2_counters.m_n_cached_thread_lookups;
stats[SINSP_STATS_V2_FAILED_THREAD_LOOKUPS].value.u64 = sinsp_stats_v2_counters.m_n_failed_thread_lookups;
stats[SINSP_STATS_V2_ADDED_THREADS].value.u64 = sinsp_stats_v2_counters.m_n_added_threads;
stats[SINSP_STATS_V2_REMOVED_THREADS].value.u64 = sinsp_stats_v2_counters.m_n_removed_threads;
stats[SINSP_STATS_V2_N_DROPS_FULL_THREADTABLE].value.u32 = thread_manager->get_m_n_drops();
stats[SINSP_STATS_V2_N_CONTAINERS].value.u32 = n_containers;
buffer[SINSP_STATS_V2_NONCACHED_FD_LOOKUPS].value.u64 = stats_v2.m_n_noncached_fd_lookups;
buffer[SINSP_STATS_V2_CACHED_FD_LOOKUPS].value.u64 = stats_v2.m_n_cached_fd_lookups;
buffer[SINSP_STATS_V2_FAILED_FD_LOOKUPS].value.u64 = stats_v2.m_n_failed_fd_lookups;
buffer[SINSP_STATS_V2_ADDED_FDS].value.u64 = stats_v2.m_n_added_fds;
buffer[SINSP_STATS_V2_REMOVED_FDS].value.u64 = stats_v2.m_n_removed_fds;
buffer[SINSP_STATS_V2_STORED_EVTS].value.u64 = stats_v2.m_n_stored_evts;
buffer[SINSP_STATS_V2_STORE_EVTS_DROPS].value.u64 = stats_v2.m_n_store_evts_drops;
buffer[SINSP_STATS_V2_RETRIEVED_EVTS].value.u64 = stats_v2.m_n_retrieved_evts;
buffer[SINSP_STATS_V2_RETRIEVE_EVTS_DROPS].value.u64 = stats_v2.m_n_retrieve_evts_drops;
buffer[SINSP_STATS_V2_NONCACHED_THREAD_LOOKUPS].value.u64 = stats_v2.m_n_noncached_thread_lookups;
buffer[SINSP_STATS_V2_CACHED_THREAD_LOOKUPS].value.u64 = stats_v2.m_n_cached_thread_lookups;
buffer[SINSP_STATS_V2_FAILED_THREAD_LOOKUPS].value.u64 = stats_v2.m_n_failed_thread_lookups;
buffer[SINSP_STATS_V2_ADDED_THREADS].value.u64 = stats_v2.m_n_added_threads;
buffer[SINSP_STATS_V2_REMOVED_THREADS].value.u64 = stats_v2.m_n_removed_threads;
buffer[SINSP_STATS_V2_N_DROPS_FULL_THREADTABLE].value.u32 = thread_manager->get_m_n_drops();
buffer[SINSP_STATS_V2_N_MISSING_CONTAINER_IMAGES].value.u32 = stats_v2.m_n_missing_container_images;
buffer[SINSP_STATS_V2_N_CONTAINERS].value.u32 = stats_v2.m_n_containers;

*nstats = SINSP_MAX_STATS_V2;
}

*rc = SCAP_SUCCESS;

return stats;
return buffer;
}
12 changes: 7 additions & 5 deletions userspace/libsinsp/stats.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ typedef struct sinsp_stats_v2
uint64_t m_n_failed_thread_lookups;
uint64_t m_n_added_threads;
uint64_t m_n_removed_threads;
uint64_t m_n_missing_container_images;
uint64_t m_n_containers;
}sinsp_stats_v2;

typedef enum sinsp_stats_v2_resource_utilization {
Expand Down Expand Up @@ -66,7 +68,8 @@ typedef enum sinsp_stats_v2_resource_utilization {
SINSP_STATS_V2_ADDED_THREADS, ///< threadtable state related counters, unit: count.
SINSP_STATS_V2_REMOVED_THREADS, ///< threadtable state related counters, unit: count.
SINSP_STATS_V2_N_DROPS_FULL_THREADTABLE, ///< Number of drops due to full threadtable, unit: count.
SINSP_STATS_V2_N_CONTAINERS, ///< Number of containers currently cached by sinsp_container_manager, unit: count.
SINSP_STATS_V2_N_MISSING_CONTAINER_IMAGES, ///< Number of cached containers (cgroups) without container info such as image, hijacked sinsp_container_manager::remove_inactive_containers() -> every flush snapshot update, unit: count.
SINSP_STATS_V2_N_CONTAINERS, ///< Number of containers (cgroups) currently cached by sinsp_container_manager, hijacked sinsp_container_manager::remove_inactive_containers() -> every flush snapshot update, unit: count.
SINSP_MAX_STATS_V2
}sinsp_stats_v2_resource_utilization;

Expand All @@ -77,16 +80,15 @@ namespace stats {
\brief Retrieve current sinsp stats v2 including resource utilization metrics.
\param agent_info Pointer to a \ref scap_agent_info containing relevant constants from the agent start up moment.
\param thread_manager Pointer to a \ref thread_manager to access threadtable properties.
\param sinsp_stats_v2_counters sinsp_stats_v2 struct containing counters related to the sinsp state tables (e.g. adding, removing, storing, failed lookup activities).
\param stats Pointer to a \ref scap_stats_v2 pre-allocated sinsp_stats_v2_buffer (aka scap_stats_v2 schema).
\param n_containers Number of containers currently cached by sinsp_container_manager.
\param stats_v2 sinsp_stats_v2 struct containing counters related to the sinsp state tables (e.g. adding, removing, storing, failed lookup activities).
\param buffer Pointer to a \ref scap_stats_v2 pre-allocated sinsp_stats_v2_buffer (aka scap_stats_v2 schema).
\param nstats Pointer reflecting number of statistics in returned buffer
\param rc Pointer to return code
\note Intended to be called once every x hours.
\return Pointer to a \ref scap_stats_v2 buffer filled with the current sinsp stats v2 including resource utilization metrics.
*/
const scap_stats_v2* get_sinsp_stats_v2(uint32_t flags, const scap_agent_info* agent_info, sinsp_thread_manager* thread_manager, sinsp_stats_v2 sinsp_stats_v2_counters, scap_stats_v2* stats, uint32_t n_containers, uint32_t* nstats, int32_t* rc);
const scap_stats_v2* get_sinsp_stats_v2(uint32_t flags, const scap_agent_info* agent_info, sinsp_thread_manager* thread_manager, sinsp_stats_v2 stats_v2, scap_stats_v2* buffer, uint32_t* nstats, int32_t* rc);

}
}
10 changes: 5 additions & 5 deletions userspace/libsinsp/test/sinsp_stats.ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ limitations under the License.
#include "sinsp_with_test_input.h"
#include "test_utils.h"
#include "scap_stats_v2.h"
#include "stats.h"
#include <test/helpers/threads_helpers.h>

TEST_F(sinsp_with_test_input, sinsp_stats_v2_resource_utilization)
Expand All @@ -42,16 +43,15 @@ TEST_F(sinsp_with_test_input, sinsp_stats_v2_resource_utilization)
auto buffer = m_inspector.get_sinsp_stats_v2_buffer();
sinsp_stats_v2 sinsp_stats_v2_counters = m_inspector.get_sinsp_stats_v2();
sinsp_thread_manager* thread_manager = m_inspector.m_thread_manager;
uint32_t n_containers = m_inspector.m_container_manager.get_containers()->size();
uint32_t flags = PPM_SCAP_STATS_RESOURCE_UTILIZATION;
sinsp_stats_v2_snapshot = libsinsp::stats::get_sinsp_stats_v2(flags, agent_info, thread_manager, sinsp_stats_v2_counters, buffer, n_containers, &nstats, &rc);
sinsp_stats_v2_snapshot = libsinsp::stats::get_sinsp_stats_v2(flags, agent_info, thread_manager, sinsp_stats_v2_counters, buffer, &nstats, &rc);
/* Extra call */
sinsp_stats_v2_snapshot = libsinsp::stats::get_sinsp_stats_v2(flags, agent_info, thread_manager, sinsp_stats_v2_counters, buffer, n_containers, &nstats, &rc);
sinsp_stats_v2_snapshot = libsinsp::stats::get_sinsp_stats_v2(flags, agent_info, thread_manager, sinsp_stats_v2_counters, buffer, &nstats, &rc);
ASSERT_EQ(nstats, SINSP_RESOURCE_UTILIZATION_FDS_TOTAL_HOST + 1);
ASSERT_EQ(rc, SCAP_SUCCESS);

flags = (PPM_SCAP_STATS_RESOURCE_UTILIZATION | PPM_SCAP_STATS_STATE_COUNTERS);
sinsp_stats_v2_snapshot = libsinsp::stats::get_sinsp_stats_v2(flags, agent_info, thread_manager, sinsp_stats_v2_counters, buffer, n_containers, &nstats, &rc);
sinsp_stats_v2_snapshot = libsinsp::stats::get_sinsp_stats_v2(flags, agent_info, thread_manager, sinsp_stats_v2_counters, buffer, &nstats, &rc);
ASSERT_EQ(nstats, SINSP_MAX_STATS_V2);
ASSERT_EQ(rc, SCAP_SUCCESS);

Expand Down Expand Up @@ -90,7 +90,7 @@ TEST_F(sinsp_with_test_input, sinsp_stats_v2_resource_utilization)
/* Empty call */
nstats = 0;
flags = 0;
sinsp_stats_v2_snapshot = libsinsp::stats::get_sinsp_stats_v2(flags, agent_info, thread_manager, sinsp_stats_v2_counters, buffer, n_containers, &nstats, &rc);
sinsp_stats_v2_snapshot = libsinsp::stats::get_sinsp_stats_v2(flags, agent_info, thread_manager, sinsp_stats_v2_counters, buffer, &nstats, &rc);
ASSERT_EQ(nstats, 0);
ASSERT_EQ(rc, SCAP_SUCCESS);

Expand Down

0 comments on commit 9e79c35

Please sign in to comment.