mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
Add extra metrics to session_mgr
- Sessions killed by activity - Current number of sessions across all types
This commit is contained in:
parent
d1f7999f61
commit
a81f6ab9a6
6 changed files with 29 additions and 7 deletions
|
@ -119,7 +119,7 @@ void ProfileLogger::Log() {
|
|||
|
||||
// TODO: This previously output the number of connections, but now that we're storing
|
||||
// sessions as well as connections, this might need to be renamed.
|
||||
file->Write(util::fmt("%.06f Conns: total=%" PRIu64 " current=%" PRIu64 "/%u\n", run_state::network_time,
|
||||
file->Write(util::fmt("%.06f Conns: total=%" PRIu64 " current=%" PRIu64 "/%zu\n", run_state::network_time,
|
||||
Connection::TotalConnections(), Connection::CurrentConnections(),
|
||||
session_mgr->CurrentSessions()));
|
||||
|
||||
|
|
|
@ -46,9 +46,9 @@ public:
|
|||
|
||||
ProtocolMap::iterator InitCounters(const std::string& protocol) {
|
||||
auto active_family =
|
||||
telemetry_mgr->GaugeFamily("zeek", "active-sessions", {"protocol"}, "Active Zeek Sessions");
|
||||
telemetry_mgr->GaugeFamily("zeek", "active_sessions", {"protocol"}, "Active Zeek Sessions");
|
||||
auto total_family =
|
||||
telemetry_mgr->CounterFamily("zeek", "total-sessions", {"protocol"}, "Total number of sessions");
|
||||
telemetry_mgr->CounterFamily("zeek", "total_sessions", {"protocol"}, "Total number of sessions");
|
||||
|
||||
auto [it, inserted] = entries.insert({protocol, Protocol{active_family, total_family, protocol}});
|
||||
|
||||
|
@ -75,7 +75,17 @@ private:
|
|||
|
||||
} // namespace detail
|
||||
|
||||
Manager::Manager() { stats = new detail::ProtocolStats(); }
|
||||
Manager::Manager() {
|
||||
stats = new detail::ProtocolStats();
|
||||
ended_sessions_metric_family = telemetry_mgr->CounterFamily("zeek", "ended_sessions", {"reason"},
|
||||
"Number of sessions ended for specific reasons");
|
||||
ended_by_inactivity_metric =
|
||||
ended_sessions_metric_family->GetOrAdd({{"reason", "inactivity"}}, []() -> prometheus::ClientMetric {
|
||||
prometheus::ClientMetric metric;
|
||||
metric.counter.value = static_cast<double>(zeek::detail::killed_by_inactivity);
|
||||
return metric;
|
||||
});
|
||||
}
|
||||
|
||||
Manager::~Manager() {
|
||||
Clear();
|
||||
|
|
|
@ -13,6 +13,13 @@
|
|||
|
||||
namespace zeek {
|
||||
|
||||
namespace telemetry {
|
||||
class CounterFamily;
|
||||
using CounterFamilyPtr = std::shared_ptr<CounterFamily>;
|
||||
class Counter;
|
||||
using CounterPtr = std::shared_ptr<Counter>;
|
||||
} // namespace telemetry
|
||||
|
||||
namespace detail {
|
||||
class PacketFilter;
|
||||
}
|
||||
|
@ -82,7 +89,7 @@ public:
|
|||
void Weird(const char* name, const Packet* pkt, const char* addl = "", const char* source = "");
|
||||
void Weird(const char* name, const IP_Hdr* ip, const char* addl = "");
|
||||
|
||||
unsigned int CurrentSessions() { return session_map.size(); }
|
||||
size_t CurrentSessions() { return session_map.size(); }
|
||||
|
||||
private:
|
||||
using SessionMap = std::unordered_map<detail::Key, Session*, detail::KeyHash>;
|
||||
|
@ -96,6 +103,8 @@ private:
|
|||
|
||||
SessionMap session_map;
|
||||
detail::ProtocolStats* stats;
|
||||
telemetry::CounterFamilyPtr ended_sessions_metric_family;
|
||||
telemetry::CounterPtr ended_by_inactivity_metric;
|
||||
};
|
||||
|
||||
} // namespace session
|
||||
|
|
|
@ -83,7 +83,7 @@ function get_conn_stats%(%): ConnStats
|
|||
|
||||
r->Assign(n++, Connection::TotalConnections());
|
||||
r->Assign(n++, Connection::CurrentConnections());
|
||||
r->Assign(n++, session_mgr->CurrentSessions());
|
||||
r->Assign(n++, static_cast<uint64_t>(session_mgr->CurrentSessions()));
|
||||
|
||||
session::Stats s;
|
||||
if ( session_mgr )
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
||||
### zeek_session_metrics |2|
|
||||
### zeek_session_metrics |3|
|
||||
Telemetry::COUNTER, zeek, zeek_ended_sessions_total, [reason], [inactivity], 0.0
|
||||
Telemetry::COUNTER, zeek, zeek_total_sessions_total, [protocol], [tcp], 500.0
|
||||
Telemetry::GAUGE, zeek, zeek_active_sessions, [protocol], [tcp], 500.0
|
||||
### bt* metrics |5|
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
||||
XXXXXXXXXX.XXXXXX zeek counter zeek_ended_sessions_total reason inactivity 0.0
|
||||
XXXXXXXXXX.XXXXXX zeek counter zeek_total_sessions_total protocol tcp 1.0
|
||||
XXXXXXXXXX.XXXXXX zeek gauge zeek_active_sessions protocol tcp 1.0
|
||||
XXXXXXXXXX.XXXXXX zeek counter zeek_ended_sessions_total reason inactivity 0.0
|
||||
XXXXXXXXXX.XXXXXX zeek counter zeek_total_sessions_total protocol tcp 500.0
|
||||
XXXXXXXXXX.XXXXXX zeek gauge zeek_active_sessions protocol tcp 500.0
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue