mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00

- On-demand access to sumstats results through "return from" functions named SumStats::request and Sumstats::request_key. Both functions are tested in standalone and clustered modes. - $name field has returned to SumStats which simplifies cluster code and makes the on-demand access stuff possible. - Clustered results can only be collected for 1 minute from their time of creation now instead of time of last read. - Thresholds use doubles instead of counts everywhere now. - Calculation dependency resolution occurs at start up time now instead of doing it at observation time which provide a minor cpu performance improvement. A new plugin registration mechanism was created to support this change. - AppStats now has a minimal doc string and is broken into hook-based plugins. - AppStats and traceroute detection added to local.bro
93 lines
2.6 KiB
Text
93 lines
2.6 KiB
Text
# @TEST-SERIALIZE: comm
|
|
#
|
|
# @TEST-EXEC: btest-bg-run manager-1 BROPATH=$BROPATH:.. CLUSTER_NODE=manager-1 bro %INPUT
|
|
# @TEST-EXEC: sleep 1
|
|
# @TEST-EXEC: btest-bg-run worker-1 BROPATH=$BROPATH:.. CLUSTER_NODE=worker-1 bro %INPUT
|
|
# @TEST-EXEC: btest-bg-run worker-2 BROPATH=$BROPATH:.. CLUSTER_NODE=worker-2 bro %INPUT
|
|
# @TEST-EXEC: btest-bg-wait 15
|
|
|
|
# @TEST-EXEC: btest-diff manager-1/.stdout
|
|
|
|
@TEST-START-FILE cluster-layout.bro
|
|
redef Cluster::nodes = {
|
|
["manager-1"] = [$node_type=Cluster::MANAGER, $ip=127.0.0.1, $p=37757/tcp, $workers=set("worker-1", "worker-2")],
|
|
["worker-1"] = [$node_type=Cluster::WORKER, $ip=127.0.0.1, $p=37760/tcp, $manager="manager-1", $interface="eth0"],
|
|
["worker-2"] = [$node_type=Cluster::WORKER, $ip=127.0.0.1, $p=37761/tcp, $manager="manager-1", $interface="eth1"],
|
|
};
|
|
@TEST-END-FILE
|
|
|
|
redef Log::default_rotation_interval = 0secs;
|
|
|
|
global n = 0;
|
|
|
|
event bro_init() &priority=5
|
|
{
|
|
local r1: SumStats::Reducer = [$stream="test", $apply=set(SumStats::SUM, SumStats::MIN, SumStats::MAX, SumStats::AVERAGE, SumStats::STD_DEV, SumStats::VARIANCE, SumStats::UNIQUE)];
|
|
SumStats::create([$name="test sumstat",
|
|
$epoch=1hr,
|
|
$reducers=set(r1)]);
|
|
}
|
|
|
|
event remote_connection_closed(p: event_peer)
|
|
{
|
|
terminate();
|
|
}
|
|
|
|
global ready_for_data: event();
|
|
redef Cluster::manager2worker_events += /^ready_for_data$/;
|
|
|
|
event ready_for_data()
|
|
{
|
|
if ( Cluster::node == "worker-1" )
|
|
{
|
|
SumStats::observe("test", [$host=1.2.3.4], [$num=34]);
|
|
SumStats::observe("test", [$host=1.2.3.4], [$num=30]);
|
|
SumStats::observe("test", [$host=6.5.4.3], [$num=1]);
|
|
SumStats::observe("test", [$host=7.2.1.5], [$num=54]);
|
|
}
|
|
if ( Cluster::node == "worker-2" )
|
|
{
|
|
SumStats::observe("test", [$host=1.2.3.4], [$num=75]);
|
|
SumStats::observe("test", [$host=1.2.3.4], [$num=30]);
|
|
SumStats::observe("test", [$host=7.2.1.5], [$num=91]);
|
|
SumStats::observe("test", [$host=10.10.10.10], [$num=5]);
|
|
}
|
|
}
|
|
|
|
|
|
event on_demand2()
|
|
{
|
|
local host = 7.2.1.5;
|
|
when ( local result = SumStats::request_key("test sumstat", [$host=host]) )
|
|
{
|
|
print "SumStat key request";
|
|
print fmt(" Host: %s -> %.0f", host, result["test"]$sum);
|
|
terminate();
|
|
}
|
|
}
|
|
|
|
event on_demand()
|
|
{
|
|
when ( local results = SumStats::request("test sumstat") )
|
|
{
|
|
print "Complete SumStat request";
|
|
for ( key in results )
|
|
print fmt(" Host: %s -> %.0f", key$host, results[key]["test"]$sum);
|
|
|
|
event on_demand2();
|
|
}
|
|
}
|
|
|
|
global peer_count = 0;
|
|
event remote_connection_handshake_done(p: event_peer) &priority=-5
|
|
{
|
|
++peer_count;
|
|
if ( peer_count == 2 )
|
|
{
|
|
if ( Cluster::local_node_type() == Cluster::MANAGER )
|
|
event ready_for_data();
|
|
|
|
schedule 1sec { on_demand() };
|
|
}
|
|
}
|
|
|