Skip to content

Commit

Permalink
update(metrics): always refresh ifinfo
Browse files Browse the repository at this point in the history
Because libs constantly refreshes them, it's fine to re-create the JSON
each time

Signed-off-by: Melissa Kilby <[email protected]>
  • Loading branch information
incertum committed Aug 26, 2024
1 parent 5792e06 commit f43b4df
Showing 1 changed file with 20 additions and 23 deletions.
43 changes: 20 additions & 23 deletions userspace/falco/stats_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,40 +358,37 @@ void stats_writer::collector::get_metrics_output_fields_wrapper(
output_fields[metric_name_file_sha256] = item.second;
}

if (stats_snapshot_time_delta_sec == 0)
auto ipv4list = inspector->get_ifaddr_list().get_ipv4_list();
auto ipv6list = inspector->get_ifaddr_list().get_ipv6_list();
nlohmann::json ipv4_json;
nlohmann::json ipv6_json;
if(ipv4list)
{
auto ipv4list = inspector->get_ifaddr_list().get_ipv4_list();
auto ipv6list = inspector->get_ifaddr_list().get_ipv6_list();
nlohmann::json ipv4_json;
nlohmann::json ipv6_json;
if(ipv4list)
for (const auto& item : *ipv4list)
{
for (const auto& item : *ipv4list)
if(item.m_name == "lo")
{
if(item.m_name == "lo")
{
continue;
}
ipv4_json[item.m_name] = item.addr_to_string();
continue;
}
ipv4_json[item.m_name] = item.addr_to_string();
}
}

if(ipv6list)
if(ipv6list)
{
for (const auto& item : *ipv6list)
{
for (const auto& item : *ipv6list)
if(item.m_name == "lo")
{
if(item.m_name == "lo")
{
continue;
}
ipv6_json[item.m_name] = item.addr_to_string();
continue;
}
ipv6_json[item.m_name] = item.addr_to_string();
}
nlohmann::json ifinfo_json;
ifinfo_json["ipv4"] = ipv4_json;
ifinfo_json["ipv6"] = ipv6_json;
m_ifinfo_json_escaped = ifinfo_json.dump();
}
nlohmann::json ifinfo_json;
ifinfo_json["ipv4"] = ipv4_json;
ifinfo_json["ipv6"] = ipv6_json;
m_ifinfo_json_escaped = ifinfo_json.dump();
output_fields["falco.host_ifinfo_json"] = m_ifinfo_json_escaped;

#endif
Expand Down

0 comments on commit f43b4df

Please sign in to comment.