mirror of
https://github.com/zeek/zeek.git
synced 2025-10-07 09:08:20 +00:00
Add timer counts as telemetry metrics
This commit is contained in:
parent
4face43462
commit
44860676a2
2 changed files with 42 additions and 4 deletions
29
src/Timer.cc
29
src/Timer.cc
|
@ -10,6 +10,7 @@
|
||||||
#include "zeek/broker/Manager.h"
|
#include "zeek/broker/Manager.h"
|
||||||
#include "zeek/iosource/Manager.h"
|
#include "zeek/iosource/Manager.h"
|
||||||
#include "zeek/iosource/PktSrc.h"
|
#include "zeek/iosource/PktSrc.h"
|
||||||
|
#include "zeek/telemetry/Manager.h"
|
||||||
#include "zeek/util.h"
|
#include "zeek/util.h"
|
||||||
|
|
||||||
namespace zeek::detail {
|
namespace zeek::detail {
|
||||||
|
@ -97,6 +98,34 @@ void TimerMgr::InitPostScript() {
|
||||||
iosource_mgr->Register(this, true);
|
iosource_mgr->Register(this, true);
|
||||||
|
|
||||||
dispatch_all_expired = zeek::detail::max_timer_expires == 0;
|
dispatch_all_expired = zeek::detail::max_timer_expires == 0;
|
||||||
|
|
||||||
|
cumulative_num_metric = telemetry_mgr->CounterInstance("zeek", "timers", {}, "Cumulative number of timers", "",
|
||||||
|
[]() -> prometheus::ClientMetric {
|
||||||
|
prometheus::ClientMetric metric;
|
||||||
|
metric.counter.value =
|
||||||
|
static_cast<double>(timer_mgr->CumulativeNum());
|
||||||
|
return metric;
|
||||||
|
});
|
||||||
|
|
||||||
|
lag_time_metric = telemetry_mgr->GaugeInstance("zeek", "timers_lag_time", {},
|
||||||
|
"Lag between current network time and last expired timer", "seconds",
|
||||||
|
[]() -> prometheus::ClientMetric {
|
||||||
|
prometheus::ClientMetric metric;
|
||||||
|
metric.gauge.value =
|
||||||
|
run_state::network_time - timer_mgr->last_timestamp;
|
||||||
|
return metric;
|
||||||
|
});
|
||||||
|
|
||||||
|
std::shared_ptr<telemetry::GaugeFamily> family =
|
||||||
|
telemetry_mgr->GaugeFamily("zeek", "timers_pending", {"type"}, "Number of timers for a certain type");
|
||||||
|
for ( int i = 0; i < NUM_TIMER_TYPES; i++ ) {
|
||||||
|
current_timer_metrics[i] = family->GetOrAdd({{"type", timer_type_to_string(static_cast<TimerType>(i))}},
|
||||||
|
[i]() -> prometheus::ClientMetric {
|
||||||
|
prometheus::ClientMetric metric;
|
||||||
|
metric.gauge.value = TimerMgr::CurrentTimers()[i];
|
||||||
|
return metric;
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TimerMgr::Add(Timer* timer) {
|
void TimerMgr::Add(Timer* timer) {
|
||||||
|
|
17
src/Timer.h
17
src/Timer.h
|
@ -10,7 +10,14 @@
|
||||||
|
|
||||||
namespace zeek {
|
namespace zeek {
|
||||||
class ODesc;
|
class ODesc;
|
||||||
}
|
|
||||||
|
namespace telemetry {
|
||||||
|
class Gauge;
|
||||||
|
class Counter;
|
||||||
|
using GaugePtr = std::shared_ptr<Gauge>;
|
||||||
|
using CounterPtr = std::shared_ptr<Counter>;
|
||||||
|
} // namespace telemetry
|
||||||
|
} // namespace zeek
|
||||||
|
|
||||||
namespace zeek::detail {
|
namespace zeek::detail {
|
||||||
|
|
||||||
|
@ -153,10 +160,12 @@ private:
|
||||||
// for the max_timer_expires=0 case.
|
// for the max_timer_expires=0 case.
|
||||||
bool dispatch_all_expired = false;
|
bool dispatch_all_expired = false;
|
||||||
|
|
||||||
size_t peak_size = 0;
|
|
||||||
size_t cumulative_num = 0;
|
|
||||||
|
|
||||||
static unsigned int current_timers[NUM_TIMER_TYPES];
|
static unsigned int current_timers[NUM_TIMER_TYPES];
|
||||||
|
|
||||||
|
telemetry::CounterPtr cumulative_num_metric;
|
||||||
|
telemetry::GaugePtr lag_time_metric;
|
||||||
|
telemetry::GaugePtr current_timer_metrics[NUM_TIMER_TYPES];
|
||||||
|
|
||||||
std::unique_ptr<PriorityQueue> q;
|
std::unique_ptr<PriorityQueue> q;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue