mirror of
https://github.com/falcosecurity/falco.git
synced 2025-08-09 01:58:13 +00:00
update(userspace): introduce nlohmann json library
Signed-off-by: Andrea Terzolo <andrea.terzolo@polito.it>
This commit is contained in:
parent
1bf5f864bc
commit
b57a2d5a5f
@ -16,6 +16,7 @@ limitations under the License.
|
|||||||
|
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
#include "statsfilewriter.h"
|
#include "statsfilewriter.h"
|
||||||
#include "banned.h" // This raises a compilation error when certain functions are used
|
#include "banned.h" // This raises a compilation error when certain functions are used
|
||||||
@ -100,6 +101,7 @@ void StatsFileWriter::handle()
|
|||||||
{
|
{
|
||||||
scap_stats cstats;
|
scap_stats cstats;
|
||||||
scap_stats delta;
|
scap_stats delta;
|
||||||
|
nlohmann::json jmsg;
|
||||||
|
|
||||||
g_save_stats = false;
|
g_save_stats = false;
|
||||||
m_num_stats++;
|
m_num_stats++;
|
||||||
@ -116,21 +118,19 @@ void StatsFileWriter::handle()
|
|||||||
delta.n_preemptions = cstats.n_preemptions - m_last_stats.n_preemptions;
|
delta.n_preemptions = cstats.n_preemptions - m_last_stats.n_preemptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_output << "{\"sample\": " << m_num_stats;
|
jmsg["sample"] = m_num_stats;
|
||||||
if(m_extra != "")
|
if(m_extra != "")
|
||||||
{
|
{
|
||||||
m_output << ", " << m_extra;
|
jmsg["extra"] = m_extra;
|
||||||
}
|
}
|
||||||
m_output << ", \"cur\": {" <<
|
jmsg["cur"]["events"] = cstats.n_evts;
|
||||||
"\"events\": " << cstats.n_evts <<
|
jmsg["cur"]["drops"] = cstats.n_drops;
|
||||||
", \"drops\": " << cstats.n_drops <<
|
jmsg["cur"]["preemptions"] = cstats.n_preemptions;
|
||||||
", \"preemptions\": " << cstats.n_preemptions <<
|
jmsg["delta"]["events"] = delta.n_evts;
|
||||||
"}, \"delta\": {" <<
|
jmsg["delta"]["drops"] = delta.n_drops;
|
||||||
"\"events\": " << delta.n_evts <<
|
jmsg["delta"]["preemptions"] = delta.n_preemptions;
|
||||||
", \"drops\": " << delta.n_drops <<
|
jmsg["drop_pct"] = (delta.n_evts == 0 ? 0 : (100.0*delta.n_drops/delta.n_evts));
|
||||||
", \"preemptions\": " << delta.n_preemptions <<
|
m_output << jmsg.dump() << endl;
|
||||||
"}, \"drop_pct\": " << (delta.n_evts == 0 ? 0 : (100.0*delta.n_drops/delta.n_evts)) <<
|
|
||||||
"}," << endl;
|
|
||||||
|
|
||||||
m_last_stats = cstats;
|
m_last_stats = cstats;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user