@@ -32,6 +32,10 @@ limitations under the License.
32
32
#include < libscap/strl.h>
33
33
#include < libscap/scap_vtable.h>
34
34
35
+ #ifdef HAS_JEMALLOC
36
+ #include < jemalloc.h>
37
+ #endif
38
+
35
39
namespace fs = std::filesystem;
36
40
37
41
// note: ticker_t is an uint16_t, which is enough because we don't care about
@@ -434,6 +438,43 @@ void stats_writer::collector::get_metrics_output_fields_additional(
434
438
}
435
439
}
436
440
441
+ #ifdef HAS_JEMALLOC
442
+ if (m_writer->m_config ->m_metrics_flags & METRICS_V2_JEMALLOC_STATS) {
443
+ nlohmann::json j;
444
+ malloc_stats_print (
445
+ [](void * to, const char * from) {
446
+ nlohmann::json* j = (nlohmann::json*)to;
447
+ *j = nlohmann::json::parse (from);
448
+ },
449
+ &j,
450
+ " Jmdablxeg" );
451
+ const auto & j_stats = j[" jemalloc" ][" stats" ];
452
+ for (auto it = j_stats.begin (); it != j_stats.end (); ++it) {
453
+ if (it.value ().is_number_unsigned ()) {
454
+ std::uint64_t val = it.value ().template get <std::uint64_t >();
455
+ if (m_writer->m_config ->m_metrics_include_empty_values || val != 0 ) {
456
+ std::string key = " falco.jemalloc." + it.key () + " _bytes" ;
457
+ auto metric = libs::metrics::libsinsp_metrics::new_metric (
458
+ key.c_str (),
459
+ METRICS_V2_JEMALLOC_STATS,
460
+ METRIC_VALUE_TYPE_U64,
461
+ METRIC_VALUE_UNIT_MEMORY_BYTES,
462
+ METRIC_VALUE_METRIC_TYPE_MONOTONIC,
463
+ val);
464
+ if (m_writer->m_config ->m_metrics_convert_memory_to_mb &&
465
+ m_writer->m_output_rule_metrics_converter ) {
466
+ m_writer->m_output_rule_metrics_converter
467
+ ->convert_metric_to_unit_convention (metric);
468
+ output_fields[metric.name ] = metric.value .d ;
469
+ } else {
470
+ output_fields[metric.name ] = metric.value .u64 ;
471
+ }
472
+ }
473
+ }
474
+ }
475
+ }
476
+ #endif
477
+
437
478
#if defined(__linux__) and !defined(MINIMAL_BUILD) and !defined(__EMSCRIPTEN__)
438
479
if (m_writer->m_libs_metrics_collector && m_writer->m_output_rule_metrics_converter ) {
439
480
// Libs metrics categories
0 commit comments