Skip to content

Commit

Permalink
fix(userspace/metric): minor fixes in new libsinsp state metrics hand…
Browse files Browse the repository at this point in the history
…ling

Signed-off-by: Melissa Kilby <[email protected]>
  • Loading branch information
incertum authored and poiana committed Jan 24, 2024
1 parent 8143a19 commit 2dc8d45
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion userspace/falco/stats_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,16 +366,29 @@ void stats_writer::collector::get_metrics_output_fields_additional(
sinsp_thread_manager* thread_manager = inspector->m_thread_manager;
const scap_stats_v2* sinsp_stats_v2_snapshot = libsinsp::stats::get_sinsp_stats_v2(flags, agent_info, thread_manager, sinsp_stats_v2, buffer, &nstats, &rc);

uint32_t base_stat = 0;
// todo @incertum this needs to become better with the next proper stats refactor in libs 0.15.0
if ((flags & PPM_SCAP_STATS_STATE_COUNTERS) && !(flags & PPM_SCAP_STATS_RESOURCE_UTILIZATION))
{
base_stat = SINSP_STATS_V2_N_THREADS;
}

if (sinsp_stats_v2_snapshot && rc == 0 && nstats > 0)
{
for(uint32_t stat = 0; stat < nstats; stat++)
for(uint32_t stat = base_stat; stat < nstats; stat++)
{
if (sinsp_stats_v2_snapshot[stat].name[0] == '\0')
{
break;
}
char metric_name[STATS_NAME_MAX] = "falco.";
strlcat(metric_name, sinsp_stats_v2_snapshot[stat].name, sizeof(metric_name));
// todo @incertum temporary fix for n_fds and n_threads, type assignment was missed in libs, will be fixed in libs 0.15.0
if (strncmp(sinsp_stats_v2_snapshot[stat].name, "n_fds", 6) == 0 || strncmp(sinsp_stats_v2_snapshot[stat].name, "n_threads", 10) == 0)
{
output_fields[metric_name] = sinsp_stats_v2_snapshot[stat].value.u64;
}

switch(sinsp_stats_v2_snapshot[stat].type)
{
case STATS_VALUE_TYPE_U64:
Expand Down

0 comments on commit 2dc8d45

Please sign in to comment.