EventHandler: Use telemetry framework for EventHandler.call_count

Put the IntCounter into a std::optional rather than initializing
it at EventHandler construction time as that will currently expose
a time series per event handler through the Prometheus API.
This commit is contained in:
Arne Welzel 2023-02-15 18:04:21 +01:00
parent a40025b82d
commit 56a8b99965
4 changed files with 42 additions and 3 deletions

View file

@ -9,6 +9,7 @@
#include "zeek/Var.h"
#include "zeek/broker/Data.h"
#include "zeek/broker/Manager.h"
#include "zeek/telemetry/Manager.h"
namespace zeek
{
@ -53,7 +54,16 @@ void EventHandler::SetFunc(FuncPtr f)
void EventHandler::Call(Args* vl, bool no_remote)
{
call_count++;
if ( ! call_count )
{
static auto eh_invocations_family = telemetry_mgr->CounterFamily(
"zeek", "event-handler-invocations", {"name"},
"Number of times the given event handler was called", "1", true);
call_count = eh_invocations_family.GetOrAdd({{"name", name}});
}
call_count->Inc();
if ( new_event )
NewEvent(vl);