mirror of
https://github.com/zeek/zeek.git
synced 2025-10-07 17:18:20 +00:00
Checkpoint
This commit is contained in:
parent
09cbaa7ccc
commit
8778761c07
30 changed files with 833 additions and 848 deletions
35
scripts/base/frameworks/measurement/plugins/average.bro
Normal file
35
scripts/base/frameworks/measurement/plugins/average.bro
Normal file
|
@ -0,0 +1,35 @@
|
|||
|
||||
module Metrics;
|
||||
|
||||
export {
|
||||
redef enum Calculation += {
|
||||
## Calculate the average of the values.
|
||||
AVERAGE
|
||||
};
|
||||
|
||||
redef record ResultVal += {
|
||||
## For numeric data, this calculates the average of all values.
|
||||
average: double &log &optional;
|
||||
};
|
||||
}
|
||||
|
||||
hook add_to_calculation(filter: Filter, val: double, data: DataPoint, result: ResultVal)
|
||||
{
|
||||
if ( AVERAGE in filter$measure )
|
||||
{
|
||||
if ( ! result?$average )
|
||||
result$average = val;
|
||||
else
|
||||
result$average += (val - result$average) / result$num;
|
||||
}
|
||||
}
|
||||
|
||||
hook plugin_merge_measurements(result: ResultVal, rv1: ResultVal, rv2: ResultVal)
|
||||
{
|
||||
if ( rv1?$average && rv2?$average )
|
||||
result$average = ((rv1$average*rv1$num) + (rv2$average*rv2$num))/(rv1$num+rv2$num);
|
||||
else if ( rv1?$average )
|
||||
result$average = rv1$average;
|
||||
else if ( rv2?$average )
|
||||
result$average = rv2$average;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue