mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
Change all instruments to only handle doubles
This commit is contained in:
parent
6eab954fd2
commit
46ff48c29a
35 changed files with 635 additions and 1148 deletions
|
@ -19,7 +19,7 @@ export {
|
||||||
## :zeek:see:`Telemetry::counter_with`. To modify counters directly
|
## :zeek:see:`Telemetry::counter_with`. To modify counters directly
|
||||||
## use :zeek:see:`Telemetry::counter_family_inc`.
|
## use :zeek:see:`Telemetry::counter_family_inc`.
|
||||||
type CounterFamily: record {
|
type CounterFamily: record {
|
||||||
__family: opaque of dbl_counter_metric_family;
|
__family: opaque of counter_metric_family;
|
||||||
__labels: vector of string;
|
__labels: vector of string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ export {
|
||||||
## per :zeek:see:`Log::Stream` or number connections broken down
|
## per :zeek:see:`Log::Stream` or number connections broken down
|
||||||
## by protocol and service.
|
## by protocol and service.
|
||||||
type Counter: record {
|
type Counter: record {
|
||||||
__metric: opaque of dbl_counter_metric;
|
__metric: opaque of counter_metric;
|
||||||
};
|
};
|
||||||
|
|
||||||
## Register a counter family.
|
## Register a counter family.
|
||||||
|
@ -103,7 +103,7 @@ export {
|
||||||
## :zeek:see:`Telemetry::gauge_family_inc` or
|
## :zeek:see:`Telemetry::gauge_family_inc` or
|
||||||
## :zeek:see:`Telemetry::gauge_family_set` directly.
|
## :zeek:see:`Telemetry::gauge_family_set` directly.
|
||||||
type GaugeFamily: record {
|
type GaugeFamily: record {
|
||||||
__family: opaque of dbl_gauge_metric_family;
|
__family: opaque of gauge_metric_family;
|
||||||
__labels: vector of string;
|
__labels: vector of string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -115,7 +115,7 @@ export {
|
||||||
## or footprints of long-lived values as determined by
|
## or footprints of long-lived values as determined by
|
||||||
## :zeek:see:`val_footprint`.
|
## :zeek:see:`val_footprint`.
|
||||||
type Gauge: record {
|
type Gauge: record {
|
||||||
__metric: opaque of dbl_gauge_metric;
|
__metric: opaque of gauge_metric;
|
||||||
};
|
};
|
||||||
|
|
||||||
## Register a gauge family.
|
## Register a gauge family.
|
||||||
|
@ -204,14 +204,14 @@ export {
|
||||||
## :zeek:see:`Telemetry::histogram_with` or use
|
## :zeek:see:`Telemetry::histogram_with` or use
|
||||||
## :zeek:see:`Telemetry::histogram_family_observe` directly.
|
## :zeek:see:`Telemetry::histogram_family_observe` directly.
|
||||||
type HistogramFamily: record {
|
type HistogramFamily: record {
|
||||||
__family: opaque of dbl_histogram_metric_family;
|
__family: opaque of histogram_metric_family;
|
||||||
__labels: vector of string;
|
__labels: vector of string;
|
||||||
};
|
};
|
||||||
|
|
||||||
## Type representing a histogram metric with initialized label values.
|
## Type representing a histogram metric with initialized label values.
|
||||||
## Use :zeek:see:`Telemetry::histogram_observe` to make observations.
|
## Use :zeek:see:`Telemetry::histogram_observe` to make observations.
|
||||||
type Histogram: record {
|
type Histogram: record {
|
||||||
__metric: opaque of dbl_histogram_metric;
|
__metric: opaque of histogram_metric;
|
||||||
};
|
};
|
||||||
|
|
||||||
## Register a histogram family.
|
## Register a histogram family.
|
||||||
|
@ -292,7 +292,7 @@ function make_labels(keys: vector of string, values: labels_vector): table[strin
|
||||||
|
|
||||||
function register_counter_family(opts: MetricOpts): CounterFamily
|
function register_counter_family(opts: MetricOpts): CounterFamily
|
||||||
{
|
{
|
||||||
local f = Telemetry::__dbl_counter_family(
|
local f = Telemetry::__counter_family(
|
||||||
opts$prefix,
|
opts$prefix,
|
||||||
opts$name,
|
opts$name,
|
||||||
opts$labels,
|
opts$labels,
|
||||||
|
@ -320,24 +320,24 @@ function counter_with(cf: CounterFamily, label_values: labels_vector): Counter
|
||||||
}
|
}
|
||||||
|
|
||||||
local labels = make_labels(cf$__labels, label_values);
|
local labels = make_labels(cf$__labels, label_values);
|
||||||
local m = Telemetry::__dbl_counter_metric_get_or_add(cf$__family, labels);
|
local m = Telemetry::__counter_metric_get_or_add(cf$__family, labels);
|
||||||
return Counter($__metric=m);
|
return Counter($__metric=m);
|
||||||
}
|
}
|
||||||
|
|
||||||
function counter_inc(c: Counter, amount: double): bool
|
function counter_inc(c: Counter, amount: double): bool
|
||||||
{
|
{
|
||||||
return Telemetry::__dbl_counter_inc(c$__metric, amount);
|
return Telemetry::__counter_inc(c$__metric, amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
function counter_set(c: Counter, value: double): bool
|
function counter_set(c: Counter, value: double): bool
|
||||||
{
|
{
|
||||||
local cur_value: double = Telemetry::__dbl_counter_value(c$__metric);
|
local cur_value: double = Telemetry::__counter_value(c$__metric);
|
||||||
if (value < cur_value)
|
if (value < cur_value)
|
||||||
{
|
{
|
||||||
Reporter::error(fmt("Attempted to set lower counter value=%s cur_value=%s", value, cur_value));
|
Reporter::error(fmt("Attempted to set lower counter value=%s cur_value=%s", value, cur_value));
|
||||||
return F;
|
return F;
|
||||||
}
|
}
|
||||||
return Telemetry::__dbl_counter_inc(c$__metric, value - cur_value);
|
return Telemetry::__counter_inc(c$__metric, value - cur_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
function counter_family_inc(cf: CounterFamily, label_values: labels_vector, amount: double): bool
|
function counter_family_inc(cf: CounterFamily, label_values: labels_vector, amount: double): bool
|
||||||
|
@ -352,7 +352,7 @@ function counter_family_set(cf: CounterFamily, label_values: labels_vector, valu
|
||||||
|
|
||||||
function register_gauge_family(opts: MetricOpts): GaugeFamily
|
function register_gauge_family(opts: MetricOpts): GaugeFamily
|
||||||
{
|
{
|
||||||
local f = Telemetry::__dbl_gauge_family(
|
local f = Telemetry::__gauge_family(
|
||||||
opts$prefix,
|
opts$prefix,
|
||||||
opts$name,
|
opts$name,
|
||||||
opts$labels,
|
opts$labels,
|
||||||
|
@ -379,29 +379,29 @@ function gauge_with(gf: GaugeFamily, label_values: labels_vector): Gauge
|
||||||
return gauge_with(error_gauge_cf);
|
return gauge_with(error_gauge_cf);
|
||||||
}
|
}
|
||||||
local labels = make_labels(gf$__labels, label_values);
|
local labels = make_labels(gf$__labels, label_values);
|
||||||
local m = Telemetry::__dbl_gauge_metric_get_or_add(gf$__family, labels);
|
local m = Telemetry::__gauge_metric_get_or_add(gf$__family, labels);
|
||||||
return Gauge($__metric=m);
|
return Gauge($__metric=m);
|
||||||
}
|
}
|
||||||
|
|
||||||
function gauge_inc(g: Gauge, amount: double &default=1.0): bool
|
function gauge_inc(g: Gauge, amount: double &default=1.0): bool
|
||||||
{
|
{
|
||||||
return Telemetry::__dbl_gauge_inc(g$__metric, amount);
|
return Telemetry::__gauge_inc(g$__metric, amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
function gauge_dec(g: Gauge, amount: double &default=1.0): bool
|
function gauge_dec(g: Gauge, amount: double &default=1.0): bool
|
||||||
{
|
{
|
||||||
return Telemetry::__dbl_gauge_dec(g$__metric, amount);
|
return Telemetry::__gauge_dec(g$__metric, amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
function gauge_set(g: Gauge, value: double): bool
|
function gauge_set(g: Gauge, value: double): bool
|
||||||
{
|
{
|
||||||
# Telemetry currently does not implement __dbl_gauge_set(), do
|
# Telemetry currently does not implement __gauge_set(), do
|
||||||
# it by hand here.
|
# it by hand here.
|
||||||
local cur_value: double = Telemetry::__dbl_gauge_value(g$__metric);
|
local cur_value: double = Telemetry::__gauge_value(g$__metric);
|
||||||
if (value > cur_value)
|
if (value > cur_value)
|
||||||
return Telemetry::__dbl_gauge_inc(g$__metric, value - cur_value);
|
return Telemetry::__gauge_inc(g$__metric, value - cur_value);
|
||||||
|
|
||||||
return Telemetry::__dbl_gauge_dec(g$__metric, cur_value - value);
|
return Telemetry::__gauge_dec(g$__metric, cur_value - value);
|
||||||
}
|
}
|
||||||
|
|
||||||
function gauge_family_inc(gf: GaugeFamily, label_values: labels_vector, value: double): bool
|
function gauge_family_inc(gf: GaugeFamily, label_values: labels_vector, value: double): bool
|
||||||
|
@ -421,7 +421,7 @@ function gauge_family_set(gf: GaugeFamily, label_values: labels_vector, value: d
|
||||||
|
|
||||||
function register_histogram_family(opts: MetricOpts): HistogramFamily
|
function register_histogram_family(opts: MetricOpts): HistogramFamily
|
||||||
{
|
{
|
||||||
local f = Telemetry::__dbl_histogram_family(
|
local f = Telemetry::__histogram_family(
|
||||||
opts$prefix,
|
opts$prefix,
|
||||||
opts$name,
|
opts$name,
|
||||||
opts$labels,
|
opts$labels,
|
||||||
|
@ -450,13 +450,13 @@ function histogram_with(hf: HistogramFamily, label_values: labels_vector): Histo
|
||||||
}
|
}
|
||||||
|
|
||||||
local labels = make_labels(hf$__labels, label_values);
|
local labels = make_labels(hf$__labels, label_values);
|
||||||
local m = Telemetry::__dbl_histogram_metric_get_or_add(hf$__family, labels);
|
local m = Telemetry::__histogram_metric_get_or_add(hf$__family, labels);
|
||||||
return Histogram($__metric=m);
|
return Histogram($__metric=m);
|
||||||
}
|
}
|
||||||
|
|
||||||
function histogram_observe(h: Histogram, measurement: double): bool
|
function histogram_observe(h: Histogram, measurement: double): bool
|
||||||
{
|
{
|
||||||
return Telemetry::__dbl_histogram_observe(h$__metric, measurement);
|
return Telemetry::__histogram_observe(h$__metric, measurement);
|
||||||
}
|
}
|
||||||
|
|
||||||
function histogram_family_observe(hf: HistogramFamily, label_values: labels_vector, measurement: double): bool
|
function histogram_family_observe(hf: HistogramFamily, label_values: labels_vector, measurement: double): bool
|
||||||
|
|
|
@ -5775,12 +5775,9 @@ module Telemetry;
|
||||||
export {
|
export {
|
||||||
|
|
||||||
type MetricType: enum {
|
type MetricType: enum {
|
||||||
DOUBLE_COUNTER,
|
COUNTER,
|
||||||
INT_COUNTER,
|
GAUGE,
|
||||||
DOUBLE_GAUGE,
|
HISTOGRAM,
|
||||||
INT_GAUGE,
|
|
||||||
DOUBLE_HISTOGRAM,
|
|
||||||
INT_HISTOGRAM,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
## Type that captures options used to create metrics.
|
## Type that captures options used to create metrics.
|
||||||
|
@ -5822,13 +5819,6 @@ export {
|
||||||
## describes the number and bounds of the individual buckets.
|
## describes the number and bounds of the individual buckets.
|
||||||
bounds: vector of double &optional;
|
bounds: vector of double &optional;
|
||||||
|
|
||||||
## The same meaning as *bounds*, but as :zeek:type:`count`.
|
|
||||||
## Only set in the return value of
|
|
||||||
## :zeek:see:`Telemetry::collect_histogram_metrics`.
|
|
||||||
## for histograms when the underlying type is ``int64_t``,
|
|
||||||
## otherwise ignored.
|
|
||||||
count_bounds: vector of count &optional;
|
|
||||||
|
|
||||||
## Describes the underlying metric type.
|
## Describes the underlying metric type.
|
||||||
## Only set in the return value of
|
## Only set in the return value of
|
||||||
## :zeek:see:`Telemetry::collect_metrics` or
|
## :zeek:see:`Telemetry::collect_metrics` or
|
||||||
|
@ -5850,11 +5840,6 @@ export {
|
||||||
## This value is set for all counter and gauge metrics,
|
## This value is set for all counter and gauge metrics,
|
||||||
## it is unset for histograms.
|
## it is unset for histograms.
|
||||||
value: double &optional;
|
value: double &optional;
|
||||||
|
|
||||||
## The integer value of underlying instrument if the metric type
|
|
||||||
## is INT_COUNTER or INT_GAUGE. This will be unset if the type
|
|
||||||
## is DOUBLE_COUNTER or DOUBLE_GAUGE.
|
|
||||||
count_value: count &optional;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
## Histograms returned by the :zeek:see:`Telemetry::collect_histogram_metrics` function.
|
## Histograms returned by the :zeek:see:`Telemetry::collect_histogram_metrics` function.
|
||||||
|
@ -5869,26 +5854,11 @@ export {
|
||||||
## described by the *bounds* field in *opts*;
|
## described by the *bounds* field in *opts*;
|
||||||
values: vector of double;
|
values: vector of double;
|
||||||
|
|
||||||
## Integer values for the individual counters for each of the
|
|
||||||
## bckets as described in the ``bounds`` field in ``opts``. This
|
|
||||||
## value will be unset if the metric type is DOUBLE_HISTOGRAM.
|
|
||||||
count_values: vector of count &optional;
|
|
||||||
|
|
||||||
## The number of observations made for this histogram.
|
## The number of observations made for this histogram.
|
||||||
observations: double;
|
observations: double;
|
||||||
|
|
||||||
## The sum of all observations for this histogram.
|
## The sum of all observations for this histogram.
|
||||||
sum: double;
|
sum: double;
|
||||||
|
|
||||||
## The integer value of the number of observations made for this
|
|
||||||
## histogram. This value will be unset if the metric type is
|
|
||||||
## DOUBLE_HISTOGRAM.
|
|
||||||
count_observations: count &optional;
|
|
||||||
|
|
||||||
## The integer value of the sum of all observations for this
|
|
||||||
## histogram. This value will be unset if the metric type is
|
|
||||||
## DOUBLE_HISTOGRAM.
|
|
||||||
count_sum: count &optional;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
type MetricVector : vector of Metric;
|
type MetricVector : vector of Metric;
|
||||||
|
|
|
@ -119,17 +119,17 @@ function do_log()
|
||||||
local m = metrics[i];
|
local m = metrics[i];
|
||||||
|
|
||||||
# Histograms don't have single values, skip over them.
|
# Histograms don't have single values, skip over them.
|
||||||
if ( m$opts$metric_type == DOUBLE_HISTOGRAM || m$opts$metric_type == INT_HISTOGRAM )
|
if ( m$opts$metric_type == HISTOGRAM )
|
||||||
next;
|
next;
|
||||||
|
|
||||||
# Render the metric_type as a short string. Unknown
|
# Render the metric_type as a short string. Unknown
|
||||||
# shouldn't really happen, but lets have a fallback.
|
# shouldn't really happen, but lets have a fallback.
|
||||||
local metric_type = "unknown";
|
local metric_type = "unknown";
|
||||||
switch ( m$opts$metric_type ) {
|
switch ( m$opts$metric_type ) {
|
||||||
case DOUBLE_COUNTER, INT_COUNTER:
|
case COUNTER:
|
||||||
metric_type = "counter";
|
metric_type = "counter";
|
||||||
break;
|
break;
|
||||||
case DOUBLE_GAUGE, INT_GAUGE:
|
case GAUGE:
|
||||||
metric_type = "gauge";
|
metric_type = "gauge";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ extern double network_time;
|
||||||
} // namespace run_state
|
} // namespace run_state
|
||||||
|
|
||||||
namespace telemetry {
|
namespace telemetry {
|
||||||
class IntCounter;
|
class Counter;
|
||||||
}
|
}
|
||||||
|
|
||||||
class Func;
|
class Func;
|
||||||
|
@ -78,7 +78,7 @@ private:
|
||||||
bool generate_always;
|
bool generate_always;
|
||||||
|
|
||||||
// Initialize this lazy, so we don't expose metrics for 0 values.
|
// Initialize this lazy, so we don't expose metrics for 0 values.
|
||||||
std::shared_ptr<zeek::telemetry::IntCounter> call_count;
|
std::shared_ptr<zeek::telemetry::Counter> call_count;
|
||||||
|
|
||||||
std::unordered_set<std::string> auto_publish;
|
std::unordered_set<std::string> auto_publish;
|
||||||
};
|
};
|
||||||
|
|
18
src/Type.h
18
src/Type.h
|
@ -1042,15 +1042,9 @@ extern zeek::OpaqueTypePtr bloomfilter_type;
|
||||||
extern zeek::OpaqueTypePtr x509_opaque_type;
|
extern zeek::OpaqueTypePtr x509_opaque_type;
|
||||||
extern zeek::OpaqueTypePtr ocsp_resp_opaque_type;
|
extern zeek::OpaqueTypePtr ocsp_resp_opaque_type;
|
||||||
extern zeek::OpaqueTypePtr paraglob_type;
|
extern zeek::OpaqueTypePtr paraglob_type;
|
||||||
extern zeek::OpaqueTypePtr int_counter_metric_type;
|
extern zeek::OpaqueTypePtr counter_metric_type;
|
||||||
extern zeek::OpaqueTypePtr int_counter_metric_family_type;
|
extern zeek::OpaqueTypePtr counter_metric_family_type;
|
||||||
extern zeek::OpaqueTypePtr dbl_counter_metric_type;
|
extern zeek::OpaqueTypePtr gauge_metric_type;
|
||||||
extern zeek::OpaqueTypePtr dbl_counter_metric_family_type;
|
extern zeek::OpaqueTypePtr gauge_metric_family_type;
|
||||||
extern zeek::OpaqueTypePtr int_gauge_metric_type;
|
extern zeek::OpaqueTypePtr histogram_metric_type;
|
||||||
extern zeek::OpaqueTypePtr int_gauge_metric_family_type;
|
extern zeek::OpaqueTypePtr histogram_metric_family_type;
|
||||||
extern zeek::OpaqueTypePtr dbl_gauge_metric_type;
|
|
||||||
extern zeek::OpaqueTypePtr dbl_gauge_metric_family_type;
|
|
||||||
extern zeek::OpaqueTypePtr int_histogram_metric_type;
|
|
||||||
extern zeek::OpaqueTypePtr int_histogram_metric_family_type;
|
|
||||||
extern zeek::OpaqueTypePtr dbl_histogram_metric_type;
|
|
||||||
extern zeek::OpaqueTypePtr dbl_histogram_metric_family_type;
|
|
||||||
|
|
|
@ -223,9 +223,9 @@ struct Manager::WriterInfo {
|
||||||
bool hook_initialized = false;
|
bool hook_initialized = false;
|
||||||
string instantiating_filter;
|
string instantiating_filter;
|
||||||
|
|
||||||
std::shared_ptr<telemetry::IntCounter> total_writes;
|
std::shared_ptr<telemetry::Counter> total_writes;
|
||||||
|
|
||||||
WriterInfo(std::shared_ptr<telemetry::IntCounter> total_writes) : total_writes(std::move(total_writes)) {}
|
WriterInfo(std::shared_ptr<telemetry::Counter> total_writes) : total_writes(std::move(total_writes)) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Manager::Stream {
|
struct Manager::Stream {
|
||||||
|
@ -244,7 +244,7 @@ struct Manager::Stream {
|
||||||
|
|
||||||
bool enable_remote = false;
|
bool enable_remote = false;
|
||||||
|
|
||||||
std::shared_ptr<telemetry::IntCounter> total_writes; // Initialized on first write.
|
std::shared_ptr<telemetry::Counter> total_writes; // Initialized on first write.
|
||||||
|
|
||||||
// State about delayed writes for this Stream.
|
// State about delayed writes for this Stream.
|
||||||
detail::DelayQueue delay_queue;
|
detail::DelayQueue delay_queue;
|
||||||
|
|
|
@ -403,8 +403,8 @@ private:
|
||||||
FuncPtr rotation_format_func;
|
FuncPtr rotation_format_func;
|
||||||
FuncPtr log_stream_policy_hook;
|
FuncPtr log_stream_policy_hook;
|
||||||
|
|
||||||
std::shared_ptr<telemetry::IntCounterFamily> total_log_stream_writes_family;
|
std::shared_ptr<telemetry::CounterFamily> total_log_stream_writes_family;
|
||||||
std::shared_ptr<telemetry::IntCounterFamily> total_log_writer_writes_family;
|
std::shared_ptr<telemetry::CounterFamily> total_log_writer_writes_family;
|
||||||
|
|
||||||
zeek_uint_t last_delay_token = 0;
|
zeek_uint_t last_delay_token = 0;
|
||||||
std::vector<detail::WriteContext> active_writes;
|
std::vector<detail::WriteContext> active_writes;
|
||||||
|
|
|
@ -151,32 +151,19 @@ static std::unordered_map<std::string, unsigned int> func_attrs = {
|
||||||
{"Supervisor::__stem_pid", ATTR_NO_SCRIPT_SIDE_EFFECTS},
|
{"Supervisor::__stem_pid", ATTR_NO_SCRIPT_SIDE_EFFECTS},
|
||||||
{"Telemetry::__collect_histogram_metrics", ATTR_NO_SCRIPT_SIDE_EFFECTS},
|
{"Telemetry::__collect_histogram_metrics", ATTR_NO_SCRIPT_SIDE_EFFECTS},
|
||||||
{"Telemetry::__collect_metrics", ATTR_NO_SCRIPT_SIDE_EFFECTS},
|
{"Telemetry::__collect_metrics", ATTR_NO_SCRIPT_SIDE_EFFECTS},
|
||||||
{"Telemetry::__dbl_counter_family", ATTR_NO_SCRIPT_SIDE_EFFECTS},
|
{"Telemetry::__counter_family", ATTR_NO_SCRIPT_SIDE_EFFECTS},
|
||||||
{"Telemetry::__dbl_counter_inc", ATTR_NO_SCRIPT_SIDE_EFFECTS},
|
{"Telemetry::__counter_inc", ATTR_NO_SCRIPT_SIDE_EFFECTS},
|
||||||
{"Telemetry::__dbl_counter_metric_get_or_add", ATTR_NO_SCRIPT_SIDE_EFFECTS},
|
{"Telemetry::__counter_metric_get_or_add", ATTR_NO_SCRIPT_SIDE_EFFECTS},
|
||||||
{"Telemetry::__dbl_counter_value", ATTR_NO_SCRIPT_SIDE_EFFECTS},
|
{"Telemetry::__counter_value", ATTR_NO_SCRIPT_SIDE_EFFECTS},
|
||||||
{"Telemetry::__dbl_gauge_dec", ATTR_NO_SCRIPT_SIDE_EFFECTS},
|
{"Telemetry::__gauge_dec", ATTR_NO_SCRIPT_SIDE_EFFECTS},
|
||||||
{"Telemetry::__dbl_gauge_family", ATTR_NO_SCRIPT_SIDE_EFFECTS},
|
{"Telemetry::__gauge_family", ATTR_NO_SCRIPT_SIDE_EFFECTS},
|
||||||
{"Telemetry::__dbl_gauge_inc", ATTR_NO_SCRIPT_SIDE_EFFECTS},
|
{"Telemetry::__gauge_inc", ATTR_NO_SCRIPT_SIDE_EFFECTS},
|
||||||
{"Telemetry::__dbl_gauge_metric_get_or_add", ATTR_NO_SCRIPT_SIDE_EFFECTS},
|
{"Telemetry::__gauge_metric_get_or_add", ATTR_NO_SCRIPT_SIDE_EFFECTS},
|
||||||
{"Telemetry::__dbl_gauge_value", ATTR_NO_SCRIPT_SIDE_EFFECTS},
|
{"Telemetry::__gauge_value", ATTR_NO_SCRIPT_SIDE_EFFECTS},
|
||||||
{"Telemetry::__dbl_histogram_family", ATTR_NO_SCRIPT_SIDE_EFFECTS},
|
{"Telemetry::__histogram_family", ATTR_NO_SCRIPT_SIDE_EFFECTS},
|
||||||
{"Telemetry::__dbl_histogram_metric_get_or_add", ATTR_NO_SCRIPT_SIDE_EFFECTS},
|
{"Telemetry::__histogram_metric_get_or_add", ATTR_NO_SCRIPT_SIDE_EFFECTS},
|
||||||
{"Telemetry::__dbl_histogram_observe", ATTR_NO_SCRIPT_SIDE_EFFECTS},
|
{"Telemetry::__histogram_observe", ATTR_NO_SCRIPT_SIDE_EFFECTS},
|
||||||
{"Telemetry::__dbl_histogram_sum", ATTR_NO_SCRIPT_SIDE_EFFECTS},
|
{"Telemetry::__histogram_sum", ATTR_NO_SCRIPT_SIDE_EFFECTS},
|
||||||
{"Telemetry::__int_counter_family", ATTR_NO_SCRIPT_SIDE_EFFECTS},
|
|
||||||
{"Telemetry::__int_counter_inc", ATTR_NO_SCRIPT_SIDE_EFFECTS},
|
|
||||||
{"Telemetry::__int_counter_metric_get_or_add", ATTR_NO_SCRIPT_SIDE_EFFECTS},
|
|
||||||
{"Telemetry::__int_counter_value", ATTR_NO_SCRIPT_SIDE_EFFECTS},
|
|
||||||
{"Telemetry::__int_gauge_dec", ATTR_NO_SCRIPT_SIDE_EFFECTS},
|
|
||||||
{"Telemetry::__int_gauge_family", ATTR_NO_SCRIPT_SIDE_EFFECTS},
|
|
||||||
{"Telemetry::__int_gauge_inc", ATTR_NO_SCRIPT_SIDE_EFFECTS},
|
|
||||||
{"Telemetry::__int_gauge_metric_get_or_add", ATTR_NO_SCRIPT_SIDE_EFFECTS},
|
|
||||||
{"Telemetry::__int_gauge_value", ATTR_NO_SCRIPT_SIDE_EFFECTS},
|
|
||||||
{"Telemetry::__int_histogram_family", ATTR_NO_SCRIPT_SIDE_EFFECTS},
|
|
||||||
{"Telemetry::__int_histogram_metric_get_or_add", ATTR_NO_SCRIPT_SIDE_EFFECTS},
|
|
||||||
{"Telemetry::__int_histogram_observe", ATTR_NO_SCRIPT_SIDE_EFFECTS},
|
|
||||||
{"Telemetry::__int_histogram_sum", ATTR_NO_SCRIPT_SIDE_EFFECTS},
|
|
||||||
{"WebSocket::__configure_analyzer", ATTR_NO_SCRIPT_SIDE_EFFECTS},
|
{"WebSocket::__configure_analyzer", ATTR_NO_SCRIPT_SIDE_EFFECTS},
|
||||||
{"__init_primary_bifs", ATTR_NO_SCRIPT_SIDE_EFFECTS},
|
{"__init_primary_bifs", ATTR_NO_SCRIPT_SIDE_EFFECTS},
|
||||||
{"__init_secondary_bifs", ATTR_NO_SCRIPT_SIDE_EFFECTS},
|
{"__init_secondary_bifs", ATTR_NO_SCRIPT_SIDE_EFFECTS},
|
||||||
|
|
|
@ -32,12 +32,12 @@ namespace detail {
|
||||||
class ProtocolStats {
|
class ProtocolStats {
|
||||||
public:
|
public:
|
||||||
struct Protocol {
|
struct Protocol {
|
||||||
std::shared_ptr<telemetry::IntGauge> active;
|
std::shared_ptr<telemetry::Gauge> active;
|
||||||
std::shared_ptr<telemetry::IntCounter> total;
|
std::shared_ptr<telemetry::Counter> total;
|
||||||
ssize_t max = 0;
|
ssize_t max = 0;
|
||||||
|
|
||||||
Protocol(const std::shared_ptr<telemetry::IntGaugeFamily>& active_family,
|
Protocol(const std::shared_ptr<telemetry::GaugeFamily>& active_family,
|
||||||
const std::shared_ptr<telemetry::IntCounterFamily>& total_family, std::string protocol)
|
const std::shared_ptr<telemetry::CounterFamily>& total_family, std::string protocol)
|
||||||
: active(active_family->GetOrAdd({{"protocol", protocol}})),
|
: active(active_family->GetOrAdd({{"protocol", protocol}})),
|
||||||
total(total_family->GetOrAdd({{"protocol", protocol}})) {}
|
total(total_family->GetOrAdd({{"protocol", protocol}})) {}
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
zeek_add_subdir_library(
|
zeek_add_subdir_library(
|
||||||
telemetry
|
telemetry
|
||||||
SOURCES
|
SOURCES
|
||||||
|
Counter.cc
|
||||||
|
Gauge.cc
|
||||||
|
Histogram.cc
|
||||||
Manager.cc
|
Manager.cc
|
||||||
Opaques.cc
|
Opaques.cc
|
||||||
ProcessStats.cc
|
ProcessStats.cc
|
||||||
|
|
41
src/telemetry/Counter.cc
Normal file
41
src/telemetry/Counter.cc
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
#include "zeek/telemetry/Counter.h"
|
||||||
|
|
||||||
|
using namespace zeek::telemetry;
|
||||||
|
|
||||||
|
Counter::Counter(FamilyType* family, const prometheus::Labels& labels, prometheus::CollectCallbackPtr callback) noexcept
|
||||||
|
: handle(family->Add(labels)), labels(labels) {
|
||||||
|
if ( callback ) {
|
||||||
|
handle.AddCollectCallback(callback);
|
||||||
|
has_callback = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
double Counter::Value() const noexcept {
|
||||||
|
if ( has_callback ) {
|
||||||
|
// Use Collect() here instead of Value() to correctly handle metrics with
|
||||||
|
// callbacks.
|
||||||
|
auto metric = handle.Collect();
|
||||||
|
return metric.counter.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return handle.Value();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<Counter> CounterFamily::GetOrAdd(Span<const LabelView> labels,
|
||||||
|
prometheus::CollectCallbackPtr callback) {
|
||||||
|
prometheus::Labels p_labels = detail::BuildPrometheusLabels(labels);
|
||||||
|
|
||||||
|
auto check = [&](const std::shared_ptr<Counter>& counter) { return counter->CompareLabels(p_labels); };
|
||||||
|
|
||||||
|
if ( auto it = std::find_if(counters.begin(), counters.end(), check); it != counters.end() )
|
||||||
|
return *it;
|
||||||
|
|
||||||
|
auto counter = std::make_shared<Counter>(family, p_labels, callback);
|
||||||
|
counters.push_back(counter);
|
||||||
|
return counter;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<Counter> CounterFamily::GetOrAdd(std::initializer_list<LabelView> labels,
|
||||||
|
prometheus::CollectCallbackPtr callback) {
|
||||||
|
return GetOrAdd(Span{labels.begin(), labels.size()}, callback);
|
||||||
|
}
|
|
@ -15,12 +15,19 @@
|
||||||
|
|
||||||
namespace zeek::telemetry {
|
namespace zeek::telemetry {
|
||||||
|
|
||||||
template<typename BaseType>
|
/**
|
||||||
class BaseCounter {
|
* A handle to a metric that can only go up.
|
||||||
|
*/
|
||||||
|
class Counter {
|
||||||
public:
|
public:
|
||||||
|
static inline const char* OpaqueName = "CounterMetricVal";
|
||||||
|
|
||||||
using Handle = prometheus::Counter;
|
using Handle = prometheus::Counter;
|
||||||
using FamilyType = prometheus::Family<Handle>;
|
using FamilyType = prometheus::Family<Handle>;
|
||||||
|
|
||||||
|
explicit Counter(FamilyType* family, const prometheus::Labels& labels,
|
||||||
|
prometheus::CollectCallbackPtr callback = nullptr) noexcept;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Increments the value by 1.
|
* Increments the value by 1.
|
||||||
*/
|
*/
|
||||||
|
@ -30,151 +37,54 @@ public:
|
||||||
* Increments the value by @p amount.
|
* Increments the value by @p amount.
|
||||||
* @pre `amount >= 0`
|
* @pre `amount >= 0`
|
||||||
*/
|
*/
|
||||||
void Inc(BaseType amount) noexcept { handle.Increment(amount); }
|
void Inc(double amount) noexcept { handle.Increment(amount); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Increments the value by 1.
|
* Increments the value by 1.
|
||||||
* @return The new value.
|
* @return The new value.
|
||||||
*/
|
*/
|
||||||
BaseType operator++() noexcept {
|
double operator++() noexcept {
|
||||||
Inc(1);
|
Inc(1);
|
||||||
return Value();
|
return Value();
|
||||||
}
|
}
|
||||||
|
|
||||||
BaseType Value() const noexcept {
|
double Value() const noexcept;
|
||||||
if ( has_callback ) {
|
|
||||||
// Use Collect() here instead of Value() to correctly handle metrics with
|
|
||||||
// callbacks.
|
|
||||||
auto metric = handle.Collect();
|
|
||||||
return static_cast<BaseType>(metric.counter.value);
|
|
||||||
}
|
|
||||||
|
|
||||||
return handle.Value();
|
bool operator==(const Counter& rhs) const noexcept { return &handle == &rhs.handle; }
|
||||||
}
|
bool operator!=(const Counter& rhs) const noexcept { return &handle != &rhs.handle; }
|
||||||
|
|
||||||
bool operator==(const BaseCounter<BaseType>& rhs) const noexcept { return &handle == &rhs.handle; }
|
|
||||||
bool operator!=(const BaseCounter<BaseType>& rhs) const noexcept { return &handle != &rhs.handle; }
|
|
||||||
|
|
||||||
bool CompareLabels(const prometheus::Labels& lbls) const { return labels == lbls; }
|
bool CompareLabels(const prometheus::Labels& lbls) const { return labels == lbls; }
|
||||||
|
|
||||||
protected:
|
private:
|
||||||
explicit BaseCounter(FamilyType* family, const prometheus::Labels& labels,
|
|
||||||
prometheus::CollectCallbackPtr callback = nullptr) noexcept
|
|
||||||
: handle(family->Add(labels)), labels(labels) {
|
|
||||||
if ( callback ) {
|
|
||||||
handle.AddCollectCallback(callback);
|
|
||||||
has_callback = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Handle& handle;
|
Handle& handle;
|
||||||
prometheus::Labels labels;
|
prometheus::Labels labels;
|
||||||
bool has_callback = false;
|
bool has_callback = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
class CounterFamily : public MetricFamily, public std::enable_shared_from_this<CounterFamily> {
|
||||||
* A handle to a metric that represents an integer value that can only go up.
|
|
||||||
*/
|
|
||||||
class IntCounter final : public BaseCounter<uint64_t> {
|
|
||||||
public:
|
public:
|
||||||
static inline const char* OpaqueName = "IntCounterMetricVal";
|
static inline const char* OpaqueName = "CounterMetricFamilyVal";
|
||||||
explicit IntCounter(FamilyType* family, const prometheus::Labels& labels,
|
|
||||||
prometheus::CollectCallbackPtr callback = nullptr) noexcept
|
|
||||||
: BaseCounter(family, labels, callback) {}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
CounterFamily(prometheus::Family<prometheus::Counter>* family, Span<const std::string_view> labels)
|
||||||
* A handle to a metric that represents a double value that can only go up.
|
: MetricFamily(labels), family(family) {}
|
||||||
*/
|
|
||||||
class DblCounter final : public BaseCounter<double> {
|
|
||||||
public:
|
|
||||||
static inline const char* OpaqueName = "DblCounterMetricVal";
|
|
||||||
explicit DblCounter(FamilyType* family, const prometheus::Labels& labels,
|
|
||||||
prometheus::CollectCallbackPtr callback = nullptr) noexcept
|
|
||||||
: BaseCounter(family, labels, callback) {}
|
|
||||||
};
|
|
||||||
|
|
||||||
template<class CounterType, typename BaseType>
|
|
||||||
class BaseCounterFamily : public MetricFamily,
|
|
||||||
public std::enable_shared_from_this<BaseCounterFamily<CounterType, BaseType>> {
|
|
||||||
public:
|
|
||||||
/**
|
/**
|
||||||
* Returns the metrics handle for given labels, creating a new instance
|
* Returns the metrics handle for given labels, creating a new instance
|
||||||
* lazily if necessary.
|
* lazily if necessary.
|
||||||
*/
|
*/
|
||||||
std::shared_ptr<CounterType> GetOrAdd(Span<const LabelView> labels,
|
std::shared_ptr<Counter> GetOrAdd(Span<const LabelView> labels, prometheus::CollectCallbackPtr callback = nullptr);
|
||||||
prometheus::CollectCallbackPtr callback = nullptr) {
|
|
||||||
prometheus::Labels p_labels = detail::BuildPrometheusLabels(labels);
|
|
||||||
|
|
||||||
auto check = [&](const std::shared_ptr<CounterType>& counter) { return counter->CompareLabels(p_labels); };
|
|
||||||
|
|
||||||
if ( auto it = std::find_if(counters.begin(), counters.end(), check); it != counters.end() )
|
|
||||||
return *it;
|
|
||||||
|
|
||||||
auto counter = std::make_shared<CounterType>(family, p_labels, callback);
|
|
||||||
counters.push_back(counter);
|
|
||||||
return counter;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @copydoc GetOrAdd
|
* @copydoc GetOrAdd
|
||||||
*/
|
*/
|
||||||
std::shared_ptr<CounterType> GetOrAdd(std::initializer_list<LabelView> labels,
|
std::shared_ptr<Counter> GetOrAdd(std::initializer_list<LabelView> labels,
|
||||||
prometheus::CollectCallbackPtr callback = nullptr) {
|
prometheus::CollectCallbackPtr callback = nullptr);
|
||||||
return GetOrAdd(Span{labels.begin(), labels.size()}, callback);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
zeek_int_t MetricType() const noexcept override { return BifEnum::Telemetry::MetricType::COUNTER; }
|
||||||
BaseCounterFamily(prometheus::Family<prometheus::Counter>* family, Span<const std::string_view> labels)
|
|
||||||
: MetricFamily(labels), family(family) {}
|
|
||||||
|
|
||||||
|
private:
|
||||||
prometheus::Family<prometheus::Counter>* family;
|
prometheus::Family<prometheus::Counter>* family;
|
||||||
std::vector<std::shared_ptr<CounterType>> counters;
|
std::vector<std::shared_ptr<Counter>> counters;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Manages a collection of IntCounter metrics.
|
|
||||||
*/
|
|
||||||
class IntCounterFamily final : public BaseCounterFamily<IntCounter, uint64_t> {
|
|
||||||
public:
|
|
||||||
static inline const char* OpaqueName = "IntCounterMetricFamilyVal";
|
|
||||||
|
|
||||||
explicit IntCounterFamily(prometheus::Family<prometheus::Counter>* family, Span<const std::string_view> labels)
|
|
||||||
: BaseCounterFamily(family, labels) {}
|
|
||||||
|
|
||||||
zeek_int_t MetricType() const noexcept override { return BifEnum::Telemetry::MetricType::INT_COUNTER; }
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Manages a collection of DblCounter metrics.
|
|
||||||
*/
|
|
||||||
class DblCounterFamily final : public BaseCounterFamily<DblCounter, double> {
|
|
||||||
public:
|
|
||||||
static inline const char* OpaqueName = "DblCounterMetricFamilyVal";
|
|
||||||
|
|
||||||
explicit DblCounterFamily(prometheus::Family<prometheus::Counter>* family, Span<const std::string_view> labels)
|
|
||||||
: BaseCounterFamily(family, labels) {}
|
|
||||||
|
|
||||||
zeek_int_t MetricType() const noexcept override { return BifEnum::Telemetry::MetricType::DOUBLE_COUNTER; }
|
|
||||||
};
|
|
||||||
|
|
||||||
namespace detail {
|
|
||||||
|
|
||||||
template<class T>
|
|
||||||
struct CounterOracle {
|
|
||||||
static_assert(std::is_same<T, int64_t>::value, "Counter<T> only supports int64_t and double");
|
|
||||||
|
|
||||||
using type = IntCounter;
|
|
||||||
};
|
|
||||||
|
|
||||||
template<>
|
|
||||||
struct CounterOracle<double> {
|
|
||||||
using type = DblCounter;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace detail
|
|
||||||
|
|
||||||
template<class T>
|
|
||||||
using Counter = typename detail::CounterOracle<T>::type;
|
|
||||||
|
|
||||||
} // namespace zeek::telemetry
|
} // namespace zeek::telemetry
|
||||||
|
|
41
src/telemetry/Gauge.cc
Normal file
41
src/telemetry/Gauge.cc
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
#include "zeek/telemetry/Gauge.h"
|
||||||
|
|
||||||
|
using namespace zeek::telemetry;
|
||||||
|
|
||||||
|
double Gauge::Value() const noexcept {
|
||||||
|
if ( has_callback ) {
|
||||||
|
// Use Collect() here instead of Value() to correctly handle metrics
|
||||||
|
// with callbacks.
|
||||||
|
auto metric = handle.Collect();
|
||||||
|
return metric.gauge.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return handle.Value();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Gauge::Gauge(FamilyType* family, const prometheus::Labels& labels, prometheus::CollectCallbackPtr callback) noexcept
|
||||||
|
: handle(family->Add(labels)), labels(labels) {
|
||||||
|
if ( callback ) {
|
||||||
|
handle.AddCollectCallback(callback);
|
||||||
|
has_callback = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<Gauge> GaugeFamily::GetOrAdd(Span<const LabelView> labels, prometheus::CollectCallbackPtr callback) {
|
||||||
|
prometheus::Labels p_labels = detail::BuildPrometheusLabels(labels);
|
||||||
|
|
||||||
|
auto check = [&](const std::shared_ptr<Gauge>& gauge) { return gauge->CompareLabels(p_labels); };
|
||||||
|
|
||||||
|
if ( auto it = std::find_if(gauges.begin(), gauges.end(), check); it != gauges.end() )
|
||||||
|
return *it;
|
||||||
|
|
||||||
|
auto gauge = std::make_shared<Gauge>(family, p_labels, callback);
|
||||||
|
gauges.push_back(gauge);
|
||||||
|
return gauge;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<Gauge> GaugeFamily::GetOrAdd(std::initializer_list<LabelView> labels,
|
||||||
|
prometheus::CollectCallbackPtr callback) {
|
||||||
|
return GetOrAdd(Span{labels.begin(), labels.size()}, callback);
|
||||||
|
}
|
|
@ -15,12 +15,19 @@
|
||||||
|
|
||||||
namespace zeek::telemetry {
|
namespace zeek::telemetry {
|
||||||
|
|
||||||
template<typename BaseType>
|
/**
|
||||||
class BaseGauge {
|
* A handle to a metric that can count up and down.
|
||||||
|
*/
|
||||||
|
class Gauge {
|
||||||
public:
|
public:
|
||||||
|
static inline const char* OpaqueName = "GaugeMetricVal";
|
||||||
|
|
||||||
using Handle = prometheus::Gauge;
|
using Handle = prometheus::Gauge;
|
||||||
using FamilyType = prometheus::Family<Handle>;
|
using FamilyType = prometheus::Family<Handle>;
|
||||||
|
|
||||||
|
explicit Gauge(FamilyType* family, const prometheus::Labels& labels,
|
||||||
|
prometheus::CollectCallbackPtr callback = nullptr) noexcept;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Increments the value by 1.
|
* Increments the value by 1.
|
||||||
*/
|
*/
|
||||||
|
@ -29,13 +36,13 @@ public:
|
||||||
/**
|
/**
|
||||||
* Increments the value by @p amount.
|
* Increments the value by @p amount.
|
||||||
*/
|
*/
|
||||||
void Inc(BaseType amount) noexcept { handle.Increment(amount); }
|
void Inc(double amount) noexcept { handle.Increment(amount); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Increments the value by 1.
|
* Increments the value by 1.
|
||||||
* @return The new value.
|
* @return The new value.
|
||||||
*/
|
*/
|
||||||
BaseType operator++() noexcept {
|
double operator++() noexcept {
|
||||||
Inc(1);
|
Inc(1);
|
||||||
return Value();
|
return Value();
|
||||||
}
|
}
|
||||||
|
@ -48,164 +55,54 @@ public:
|
||||||
/**
|
/**
|
||||||
* Decrements the value by @p amount.
|
* Decrements the value by @p amount.
|
||||||
*/
|
*/
|
||||||
void Dec(BaseType amount) noexcept { handle.Decrement(amount); }
|
void Dec(double amount) noexcept { handle.Decrement(amount); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Decrements the value by 1.
|
* Decrements the value by 1.
|
||||||
* @return The new value.
|
* @return The new value.
|
||||||
*/
|
*/
|
||||||
BaseType operator--() noexcept {
|
double operator--() noexcept {
|
||||||
Dec(1);
|
Dec(1);
|
||||||
return Value();
|
return Value();
|
||||||
}
|
}
|
||||||
|
|
||||||
BaseType Value() const noexcept {
|
double Value() const noexcept;
|
||||||
if ( has_callback ) {
|
|
||||||
// Use Collect() here instead of Value() to correctly handle metrics
|
|
||||||
// with callbacks.
|
|
||||||
auto metric = handle.Collect();
|
|
||||||
return static_cast<BaseType>(metric.gauge.value);
|
|
||||||
}
|
|
||||||
|
|
||||||
return handle.Value();
|
bool operator==(const Gauge& rhs) const noexcept { return &handle == &rhs.handle; }
|
||||||
}
|
bool operator!=(const Gauge& rhs) const noexcept { return &handle != &rhs.handle; }
|
||||||
|
|
||||||
/**
|
|
||||||
* Directly sets the value of the gauge.
|
|
||||||
*/
|
|
||||||
void Set(BaseType v) { handle.Set(v); }
|
|
||||||
|
|
||||||
bool operator==(const BaseGauge<BaseType>& rhs) const noexcept { return &handle == &rhs.handle; }
|
|
||||||
bool operator!=(const BaseGauge<BaseType>& rhs) const noexcept { return &handle != &rhs.handle; }
|
|
||||||
|
|
||||||
bool CompareLabels(const prometheus::Labels& lbls) const { return labels == lbls; }
|
bool CompareLabels(const prometheus::Labels& lbls) const { return labels == lbls; }
|
||||||
|
|
||||||
protected:
|
private:
|
||||||
explicit BaseGauge(FamilyType* family, const prometheus::Labels& labels,
|
|
||||||
prometheus::CollectCallbackPtr callback = nullptr) noexcept
|
|
||||||
: handle(family->Add(labels)), labels(labels) {
|
|
||||||
if ( callback ) {
|
|
||||||
handle.AddCollectCallback(callback);
|
|
||||||
has_callback = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Handle& handle;
|
Handle& handle;
|
||||||
prometheus::Labels labels;
|
prometheus::Labels labels;
|
||||||
bool has_callback = false;
|
bool has_callback = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
class GaugeFamily : public MetricFamily, public std::enable_shared_from_this<GaugeFamily> {
|
||||||
* A handle to a metric that represents an integer value. Gauges are more
|
|
||||||
* permissive than counters and also allow decrementing the value.
|
|
||||||
*/
|
|
||||||
class IntGauge final : public BaseGauge<int64_t> {
|
|
||||||
public:
|
public:
|
||||||
static inline const char* OpaqueName = "IntGaugeMetricVal";
|
static inline const char* OpaqueName = "GaugeMetricFamilyVal";
|
||||||
|
|
||||||
explicit IntGauge(FamilyType* family, const prometheus::Labels& labels,
|
|
||||||
prometheus::CollectCallbackPtr callback = nullptr) noexcept
|
|
||||||
: BaseGauge(family, labels, callback) {}
|
|
||||||
|
|
||||||
IntGauge(const IntGauge&) = delete;
|
|
||||||
IntGauge& operator=(const IntGauge&) = delete;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A handle to a metric that represents a double value. Gauges are more
|
|
||||||
* permissive than counters and also allow decrementing the value.
|
|
||||||
*/
|
|
||||||
class DblGauge final : public BaseGauge<double> {
|
|
||||||
public:
|
|
||||||
static inline const char* OpaqueName = "DblGaugeMetricVal";
|
|
||||||
|
|
||||||
explicit DblGauge(FamilyType* family, const prometheus::Labels& labels,
|
|
||||||
prometheus::CollectCallbackPtr callback = nullptr) noexcept
|
|
||||||
: BaseGauge(family, labels, callback) {}
|
|
||||||
|
|
||||||
DblGauge(const DblGauge&) = delete;
|
|
||||||
DblGauge& operator=(const DblGauge&) = delete;
|
|
||||||
};
|
|
||||||
|
|
||||||
template<class GaugeType, typename BaseType>
|
|
||||||
class BaseGaugeFamily : public MetricFamily, public std::enable_shared_from_this<BaseGaugeFamily<GaugeType, BaseType>> {
|
|
||||||
public:
|
|
||||||
/**
|
/**
|
||||||
* Returns the metrics handle for given labels, creating a new instance
|
* Returns the metrics handle for given labels, creating a new instance
|
||||||
* lazily if necessary.
|
* lazily if necessary.
|
||||||
*/
|
*/
|
||||||
std::shared_ptr<GaugeType> GetOrAdd(Span<const LabelView> labels,
|
std::shared_ptr<Gauge> GetOrAdd(Span<const LabelView> labels, prometheus::CollectCallbackPtr callback = nullptr);
|
||||||
prometheus::CollectCallbackPtr callback = nullptr) {
|
|
||||||
prometheus::Labels p_labels = detail::BuildPrometheusLabels(labels);
|
|
||||||
|
|
||||||
auto check = [&](const std::shared_ptr<GaugeType>& gauge) { return gauge->CompareLabels(p_labels); };
|
|
||||||
|
|
||||||
if ( auto it = std::find_if(gauges.begin(), gauges.end(), check); it != gauges.end() )
|
|
||||||
return *it;
|
|
||||||
|
|
||||||
auto gauge = std::make_shared<GaugeType>(family, p_labels, callback);
|
|
||||||
gauges.push_back(gauge);
|
|
||||||
return gauge;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @copydoc GetOrAdd
|
* @copydoc GetOrAdd
|
||||||
*/
|
*/
|
||||||
std::shared_ptr<GaugeType> GetOrAdd(std::initializer_list<LabelView> labels,
|
std::shared_ptr<Gauge> GetOrAdd(std::initializer_list<LabelView> labels,
|
||||||
prometheus::CollectCallbackPtr callback = nullptr) {
|
prometheus::CollectCallbackPtr callback = nullptr);
|
||||||
return GetOrAdd(Span{labels.begin(), labels.size()}, callback);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
zeek_int_t MetricType() const noexcept override { return BifEnum::Telemetry::MetricType::GAUGE; }
|
||||||
BaseGaugeFamily(prometheus::Family<prometheus::Gauge>* family, Span<const std::string_view> labels)
|
|
||||||
|
GaugeFamily(prometheus::Family<prometheus::Gauge>* family, Span<const std::string_view> labels)
|
||||||
: MetricFamily(labels), family(family) {}
|
: MetricFamily(labels), family(family) {}
|
||||||
|
|
||||||
|
private:
|
||||||
prometheus::Family<prometheus::Gauge>* family;
|
prometheus::Family<prometheus::Gauge>* family;
|
||||||
std::vector<std::shared_ptr<GaugeType>> gauges;
|
std::vector<std::shared_ptr<Gauge>> gauges;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Manages a collection of IntGauge metrics.
|
|
||||||
*/
|
|
||||||
class IntGaugeFamily final : public BaseGaugeFamily<IntGauge, int64_t> {
|
|
||||||
public:
|
|
||||||
static inline const char* OpaqueName = "IntGaugeMetricFamilyVal";
|
|
||||||
|
|
||||||
explicit IntGaugeFamily(prometheus::Family<prometheus::Gauge>* family, Span<const std::string_view> labels)
|
|
||||||
: BaseGaugeFamily(family, labels) {}
|
|
||||||
|
|
||||||
zeek_int_t MetricType() const noexcept override { return BifEnum::Telemetry::MetricType::INT_GAUGE; }
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Manages a collection of DblGauge metrics.
|
|
||||||
*/
|
|
||||||
class DblGaugeFamily final : public BaseGaugeFamily<DblGauge, double> {
|
|
||||||
public:
|
|
||||||
static inline const char* OpaqueName = "DblGaugeMetricFamilyVal";
|
|
||||||
|
|
||||||
explicit DblGaugeFamily(prometheus::Family<prometheus::Gauge>* family, Span<const std::string_view> labels)
|
|
||||||
: BaseGaugeFamily(family, labels) {}
|
|
||||||
|
|
||||||
zeek_int_t MetricType() const noexcept override { return BifEnum::Telemetry::MetricType::DOUBLE_GAUGE; }
|
|
||||||
};
|
|
||||||
|
|
||||||
namespace detail {
|
|
||||||
|
|
||||||
template<class T>
|
|
||||||
struct GaugeOracle {
|
|
||||||
static_assert(std::is_same<T, int64_t>::value, "Gauge<T> only supports int64_t and double");
|
|
||||||
using type = IntGauge;
|
|
||||||
};
|
|
||||||
|
|
||||||
template<>
|
|
||||||
struct GaugeOracle<double> {
|
|
||||||
using type = DblGauge;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace detail
|
|
||||||
|
|
||||||
template<class T>
|
|
||||||
using Gauge = typename detail::GaugeOracle<T>::type;
|
|
||||||
|
|
||||||
} // namespace zeek::telemetry
|
} // namespace zeek::telemetry
|
||||||
|
|
38
src/telemetry/Histogram.cc
Normal file
38
src/telemetry/Histogram.cc
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
#include "zeek/telemetry/Histogram.h"
|
||||||
|
|
||||||
|
using namespace zeek::telemetry;
|
||||||
|
|
||||||
|
double Histogram::Sum() const noexcept {
|
||||||
|
auto metric = handle.Collect();
|
||||||
|
return static_cast<double>(metric.histogram.sample_sum);
|
||||||
|
}
|
||||||
|
|
||||||
|
Histogram::Histogram(FamilyType* family, const prometheus::Labels& labels,
|
||||||
|
prometheus::Histogram::BucketBoundaries bounds) noexcept
|
||||||
|
: handle(family->Add(labels, std::move(bounds))), labels(labels) {}
|
||||||
|
|
||||||
|
std::shared_ptr<Histogram> HistogramFamily::GetOrAdd(Span<const LabelView> labels) {
|
||||||
|
prometheus::Labels p_labels = detail::BuildPrometheusLabels(labels);
|
||||||
|
|
||||||
|
auto check = [&](const std::shared_ptr<Histogram>& histo) { return histo->CompareLabels(p_labels); };
|
||||||
|
|
||||||
|
if ( auto it = std::find_if(histograms.begin(), histograms.end(), check); it != histograms.end() )
|
||||||
|
return *it;
|
||||||
|
|
||||||
|
auto histogram = std::make_shared<Histogram>(family, p_labels, boundaries);
|
||||||
|
histograms.push_back(histogram);
|
||||||
|
return histogram;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @copydoc GetOrAdd
|
||||||
|
*/
|
||||||
|
std::shared_ptr<Histogram> HistogramFamily::GetOrAdd(std::initializer_list<LabelView> labels) {
|
||||||
|
return GetOrAdd(Span{labels.begin(), labels.size()});
|
||||||
|
}
|
||||||
|
|
||||||
|
HistogramFamily::HistogramFamily(prometheus::Family<prometheus::Histogram>* family, Span<const double> bounds,
|
||||||
|
Span<const std::string_view> labels)
|
||||||
|
: MetricFamily(labels), family(family) {
|
||||||
|
std::copy(bounds.begin(), bounds.end(), std::back_inserter(boundaries));
|
||||||
|
}
|
|
@ -15,159 +15,59 @@
|
||||||
|
|
||||||
namespace zeek::telemetry {
|
namespace zeek::telemetry {
|
||||||
|
|
||||||
template<typename BaseType>
|
class Histogram {
|
||||||
class BaseHistogram {
|
|
||||||
public:
|
public:
|
||||||
|
static inline const char* OpaqueName = "HistogramMetricVal";
|
||||||
|
|
||||||
using Handle = prometheus::Histogram;
|
using Handle = prometheus::Histogram;
|
||||||
using FamilyType = prometheus::Family<Handle>;
|
using FamilyType = prometheus::Family<Handle>;
|
||||||
|
|
||||||
|
explicit Histogram(FamilyType* family, const prometheus::Labels& labels,
|
||||||
|
prometheus::Histogram::BucketBoundaries bounds) noexcept;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Increments all buckets with an upper bound less than or equal to @p value
|
* Increments all buckets with an upper bound less than or equal to @p value
|
||||||
* by one and adds @p value to the total sum of all observed values.
|
* by one and adds @p value to the total sum of all observed values.
|
||||||
*/
|
*/
|
||||||
void Observe(BaseType value) noexcept { handle.Observe(value); }
|
void Observe(double value) noexcept { handle.Observe(value); }
|
||||||
|
|
||||||
/// @return The sum of all observed values.
|
/// @return The sum of all observed values.
|
||||||
BaseType Sum() const noexcept {
|
double Sum() const noexcept;
|
||||||
auto metric = handle.Collect();
|
|
||||||
return static_cast<BaseType>(metric.histogram.sample_sum);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool operator==(const BaseHistogram<BaseType>& rhs) const noexcept { return &handle == &rhs.handle; }
|
bool operator==(const Histogram& rhs) const noexcept { return &handle == &rhs.handle; }
|
||||||
bool operator!=(const BaseHistogram<BaseType>& rhs) const noexcept { return &handle != &rhs.handle; }
|
bool operator!=(const Histogram& rhs) const noexcept { return &handle != &rhs.handle; }
|
||||||
|
|
||||||
bool CompareLabels(const prometheus::Labels& lbls) const { return labels == lbls; }
|
bool CompareLabels(const prometheus::Labels& lbls) const { return labels == lbls; }
|
||||||
|
|
||||||
protected:
|
private:
|
||||||
explicit BaseHistogram(FamilyType* family, const prometheus::Labels& labels,
|
|
||||||
prometheus::Histogram::BucketBoundaries bounds) noexcept
|
|
||||||
: handle(family->Add(labels, std::move(bounds))), labels(labels) {}
|
|
||||||
|
|
||||||
Handle& handle;
|
Handle& handle;
|
||||||
prometheus::Labels labels;
|
prometheus::Labels labels;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
class HistogramFamily : public MetricFamily, public std::enable_shared_from_this<HistogramFamily> {
|
||||||
* A handle to a metric that represents an aggregable distribution of observed
|
|
||||||
* measurements with integer precision. Sorts individual measurements into
|
|
||||||
* configurable buckets.
|
|
||||||
*/
|
|
||||||
class IntHistogram final : public BaseHistogram<int64_t> {
|
|
||||||
public:
|
public:
|
||||||
static inline const char* OpaqueName = "IntHistogramMetricVal";
|
static inline const char* OpaqueName = "HistogramMetricFamilyVal";
|
||||||
|
|
||||||
explicit IntHistogram(FamilyType* family, const prometheus::Labels& labels,
|
HistogramFamily(prometheus::Family<prometheus::Histogram>* family, Span<const double> bounds,
|
||||||
prometheus::Histogram::BucketBoundaries bounds) noexcept
|
Span<const std::string_view> labels);
|
||||||
: BaseHistogram(family, labels, std::move(bounds)) {}
|
|
||||||
|
|
||||||
IntHistogram() = delete;
|
|
||||||
IntHistogram(const IntHistogram&) noexcept = delete;
|
|
||||||
IntHistogram& operator=(const IntHistogram&) noexcept = delete;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A handle to a metric that represents an aggregable distribution of observed
|
|
||||||
* measurements with integer precision. Sorts individual measurements into
|
|
||||||
* configurable buckets.
|
|
||||||
*/
|
|
||||||
class DblHistogram final : public BaseHistogram<double> {
|
|
||||||
public:
|
|
||||||
static inline const char* OpaqueName = "DblHistogramMetricVal";
|
|
||||||
|
|
||||||
explicit DblHistogram(FamilyType* family, const prometheus::Labels& labels,
|
|
||||||
prometheus::Histogram::BucketBoundaries bounds) noexcept
|
|
||||||
: BaseHistogram(family, labels, std::move(bounds)) {}
|
|
||||||
|
|
||||||
DblHistogram() = delete;
|
|
||||||
DblHistogram(const DblHistogram&) noexcept = delete;
|
|
||||||
DblHistogram& operator=(const DblHistogram&) noexcept = delete;
|
|
||||||
};
|
|
||||||
|
|
||||||
template<class HistogramType, typename BaseType>
|
|
||||||
class BaseHistogramFamily : public MetricFamily,
|
|
||||||
public std::enable_shared_from_this<BaseHistogramFamily<HistogramType, BaseType>> {
|
|
||||||
public:
|
|
||||||
/**
|
/**
|
||||||
* Returns the metrics handle for given labels, creating a new instance
|
* Returns the metrics handle for given labels, creating a new instance
|
||||||
* lazily if necessary.
|
* lazily if necessary.
|
||||||
*/
|
*/
|
||||||
std::shared_ptr<HistogramType> GetOrAdd(Span<const LabelView> labels) {
|
std::shared_ptr<Histogram> GetOrAdd(Span<const LabelView> labels);
|
||||||
prometheus::Labels p_labels = detail::BuildPrometheusLabels(labels);
|
|
||||||
|
|
||||||
auto check = [&](const std::shared_ptr<HistogramType>& histo) { return histo->CompareLabels(p_labels); };
|
|
||||||
|
|
||||||
if ( auto it = std::find_if(histograms.begin(), histograms.end(), check); it != histograms.end() )
|
|
||||||
return *it;
|
|
||||||
|
|
||||||
auto histogram = std::make_shared<HistogramType>(family, p_labels, boundaries);
|
|
||||||
histograms.push_back(histogram);
|
|
||||||
return histogram;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @copydoc GetOrAdd
|
* @copydoc GetOrAdd
|
||||||
*/
|
*/
|
||||||
std::shared_ptr<HistogramType> GetOrAdd(std::initializer_list<LabelView> labels) {
|
std::shared_ptr<Histogram> GetOrAdd(std::initializer_list<LabelView> labels);
|
||||||
return GetOrAdd(Span{labels.begin(), labels.size()});
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
zeek_int_t MetricType() const noexcept override { return BifEnum::Telemetry::MetricType::HISTOGRAM; }
|
||||||
BaseHistogramFamily(prometheus::Family<prometheus::Histogram>* family, Span<const BaseType> bounds,
|
|
||||||
Span<const std::string_view> labels)
|
|
||||||
: MetricFamily(labels), family(family) {
|
|
||||||
std::copy(bounds.begin(), bounds.end(), std::back_inserter(boundaries));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
private:
|
||||||
prometheus::Family<prometheus::Histogram>* family;
|
prometheus::Family<prometheus::Histogram>* family;
|
||||||
prometheus::Histogram::BucketBoundaries boundaries;
|
prometheus::Histogram::BucketBoundaries boundaries;
|
||||||
std::vector<std::shared_ptr<HistogramType>> histograms;
|
std::vector<std::shared_ptr<Histogram>> histograms;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Manages a collection of IntHistogram metrics.
|
|
||||||
*/
|
|
||||||
class IntHistogramFamily final : public BaseHistogramFamily<IntHistogram, int64_t> {
|
|
||||||
public:
|
|
||||||
static inline const char* OpaqueName = "IntHistogramMetricFamilyVal";
|
|
||||||
|
|
||||||
explicit IntHistogramFamily(prometheus::Family<prometheus::Histogram>* family, Span<const int64_t> bounds,
|
|
||||||
Span<const std::string_view> labels)
|
|
||||||
: BaseHistogramFamily(family, bounds, labels) {}
|
|
||||||
|
|
||||||
zeek_int_t MetricType() const noexcept override { return BifEnum::Telemetry::MetricType::INT_HISTOGRAM; }
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Manages a collection of DblHistogram metrics.
|
|
||||||
*/
|
|
||||||
class DblHistogramFamily final : public BaseHistogramFamily<DblHistogram, double> {
|
|
||||||
public:
|
|
||||||
static inline const char* OpaqueName = "DblHistogramMetricFamilyVal";
|
|
||||||
|
|
||||||
explicit DblHistogramFamily(prometheus::Family<prometheus::Histogram>* family, Span<const double> bounds,
|
|
||||||
Span<const std::string_view> labels)
|
|
||||||
: BaseHistogramFamily(family, bounds, labels) {}
|
|
||||||
|
|
||||||
zeek_int_t MetricType() const noexcept override { return BifEnum::Telemetry::MetricType::DOUBLE_HISTOGRAM; }
|
|
||||||
};
|
|
||||||
|
|
||||||
namespace detail {
|
|
||||||
|
|
||||||
template<class T>
|
|
||||||
struct HistogramOracle {
|
|
||||||
static_assert(std::is_same<T, int64_t>::value, "Histogram<T> only supports int64_t and double");
|
|
||||||
|
|
||||||
using type = IntHistogram;
|
|
||||||
};
|
|
||||||
|
|
||||||
template<>
|
|
||||||
struct HistogramOracle<double> {
|
|
||||||
using type = DblHistogram;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace detail
|
|
||||||
|
|
||||||
template<class T>
|
|
||||||
using Histogram = typename detail::HistogramOracle<T>::type;
|
|
||||||
|
|
||||||
} // namespace zeek::telemetry
|
} // namespace zeek::telemetry
|
||||||
|
|
|
@ -81,37 +81,37 @@ void Manager::InitPostScript() {
|
||||||
|
|
||||||
return &this->current_process_stats;
|
return &this->current_process_stats;
|
||||||
};
|
};
|
||||||
rss_gauge = GaugeInstance<int64_t>("process", "resident_memory", {}, "Resident memory size", "bytes", false,
|
rss_gauge = GaugeInstance("process", "resident_memory", {}, "Resident memory size", "bytes", false,
|
||||||
[]() -> prometheus::ClientMetric {
|
[]() -> prometheus::ClientMetric {
|
||||||
auto* s = get_stats();
|
auto* s = get_stats();
|
||||||
prometheus::ClientMetric metric;
|
prometheus::ClientMetric metric;
|
||||||
metric.gauge.value = static_cast<double>(s->rss);
|
metric.gauge.value = static_cast<double>(s->rss);
|
||||||
return metric;
|
return metric;
|
||||||
});
|
});
|
||||||
|
|
||||||
vms_gauge = GaugeInstance<int64_t>("process", "virtual_memory", {}, "Virtual memory size", "bytes", false,
|
vms_gauge = GaugeInstance("process", "virtual_memory", {}, "Virtual memory size", "bytes", false,
|
||||||
[]() -> prometheus::ClientMetric {
|
[]() -> prometheus::ClientMetric {
|
||||||
auto* s = get_stats();
|
auto* s = get_stats();
|
||||||
prometheus::ClientMetric metric;
|
prometheus::ClientMetric metric;
|
||||||
metric.gauge.value = static_cast<double>(s->vms);
|
metric.gauge.value = static_cast<double>(s->vms);
|
||||||
return metric;
|
return metric;
|
||||||
});
|
});
|
||||||
|
|
||||||
cpu_gauge = GaugeInstance<double>("process", "cpu", {}, "Total user and system CPU time spent", "seconds", false,
|
cpu_gauge = GaugeInstance("process", "cpu", {}, "Total user and system CPU time spent", "seconds", false,
|
||||||
[]() -> prometheus::ClientMetric {
|
[]() -> prometheus::ClientMetric {
|
||||||
auto* s = get_stats();
|
auto* s = get_stats();
|
||||||
prometheus::ClientMetric metric;
|
prometheus::ClientMetric metric;
|
||||||
metric.gauge.value = s->cpu;
|
metric.gauge.value = s->cpu;
|
||||||
return metric;
|
return metric;
|
||||||
});
|
});
|
||||||
|
|
||||||
fds_gauge = GaugeInstance<int64_t>("process", "open_fds", {}, "Number of open file descriptors", "", false,
|
fds_gauge = GaugeInstance("process", "open_fds", {}, "Number of open file descriptors", "", false,
|
||||||
[]() -> prometheus::ClientMetric {
|
[]() -> prometheus::ClientMetric {
|
||||||
auto* s = get_stats();
|
auto* s = get_stats();
|
||||||
prometheus::ClientMetric metric;
|
prometheus::ClientMetric metric;
|
||||||
metric.gauge.value = static_cast<double>(s->fds);
|
metric.gauge.value = static_cast<double>(s->fds);
|
||||||
return metric;
|
return metric;
|
||||||
});
|
});
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -169,13 +169,13 @@ RecordValPtr Manager::GetMetricOptsRecord(const prometheus::MetricFamily& metric
|
||||||
// prom-cpp stores everything internally as doubles
|
// prom-cpp stores everything internally as doubles
|
||||||
if ( metric_family.type == prometheus::MetricType::Counter )
|
if ( metric_family.type == prometheus::MetricType::Counter )
|
||||||
record_val->Assign(metric_type_idx, zeek::BifType::Enum::Telemetry::MetricType->GetEnumVal(
|
record_val->Assign(metric_type_idx, zeek::BifType::Enum::Telemetry::MetricType->GetEnumVal(
|
||||||
BifEnum::Telemetry::MetricType::DOUBLE_COUNTER));
|
BifEnum::Telemetry::MetricType::COUNTER));
|
||||||
if ( metric_family.type == prometheus::MetricType::Gauge )
|
if ( metric_family.type == prometheus::MetricType::Gauge )
|
||||||
record_val->Assign(metric_type_idx, zeek::BifType::Enum::Telemetry::MetricType->GetEnumVal(
|
record_val->Assign(metric_type_idx, zeek::BifType::Enum::Telemetry::MetricType->GetEnumVal(
|
||||||
BifEnum::Telemetry::MetricType::DOUBLE_GAUGE));
|
BifEnum::Telemetry::MetricType::GAUGE));
|
||||||
if ( metric_family.type == prometheus::MetricType::Histogram )
|
if ( metric_family.type == prometheus::MetricType::Histogram )
|
||||||
record_val->Assign(metric_type_idx, zeek::BifType::Enum::Telemetry::MetricType->GetEnumVal(
|
record_val->Assign(metric_type_idx, zeek::BifType::Enum::Telemetry::MetricType->GetEnumVal(
|
||||||
BifEnum::Telemetry::MetricType::DOUBLE_HISTOGRAM));
|
BifEnum::Telemetry::MetricType::HISTOGRAM));
|
||||||
|
|
||||||
// prometheus-cpp doesn't store label names anywhere other than in each
|
// prometheus-cpp doesn't store label names anywhere other than in each
|
||||||
// instrument. this is valid because label names can be different
|
// instrument. this is valid because label names can be different
|
||||||
|
@ -264,7 +264,6 @@ ValPtr Manager::CollectMetrics(std::string_view prefix_pattern, std::string_view
|
||||||
static auto opts_idx = metric_record_type->FieldOffset("opts");
|
static auto opts_idx = metric_record_type->FieldOffset("opts");
|
||||||
static auto labels_idx = metric_record_type->FieldOffset("labels");
|
static auto labels_idx = metric_record_type->FieldOffset("labels");
|
||||||
static auto value_idx = metric_record_type->FieldOffset("value");
|
static auto value_idx = metric_record_type->FieldOffset("value");
|
||||||
static auto count_value_idx = metric_record_type->FieldOffset("count_value");
|
|
||||||
|
|
||||||
static auto metric_opts_type = zeek::id::find_type<zeek::RecordType>("Telemetry::MetricOpts");
|
static auto metric_opts_type = zeek::id::find_type<zeek::RecordType>("Telemetry::MetricOpts");
|
||||||
static auto metric_type_idx = metric_opts_type->FieldOffset("metric_type");
|
static auto metric_type_idx = metric_opts_type->FieldOffset("metric_type");
|
||||||
|
@ -304,17 +303,6 @@ ValPtr Manager::CollectMetrics(std::string_view prefix_pattern, std::string_view
|
||||||
else if ( fam.type == prometheus::MetricType::Gauge )
|
else if ( fam.type == prometheus::MetricType::Gauge )
|
||||||
r->Assign(value_idx, zeek::make_intrusive<DoubleVal>(inst.gauge.value));
|
r->Assign(value_idx, zeek::make_intrusive<DoubleVal>(inst.gauge.value));
|
||||||
|
|
||||||
// Use the information from GetMetaricOptsRecord to check whether we need to add the integer
|
|
||||||
// fields, or if this is a double.
|
|
||||||
if ( opts_record->GetField<EnumVal>(metric_type_idx)->Get() ==
|
|
||||||
BifEnum::Telemetry::MetricType::INT_COUNTER ) {
|
|
||||||
r->Assign(count_value_idx, val_mgr->Count(static_cast<int64_t>(inst.counter.value)));
|
|
||||||
}
|
|
||||||
else if ( opts_record->GetField<EnumVal>(metric_type_idx)->Get() ==
|
|
||||||
BifEnum::Telemetry::MetricType::INT_GAUGE ) {
|
|
||||||
r->Assign(count_value_idx, val_mgr->Count(static_cast<int64_t>(inst.gauge.value)));
|
|
||||||
}
|
|
||||||
|
|
||||||
ret_val->Append(r);
|
ret_val->Append(r);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -339,22 +327,16 @@ ValPtr Manager::CollectHistogramMetrics(std::string_view prefix_pattern, std::st
|
||||||
static auto metrics_vector_type = zeek::id::find_type<VectorType>("Telemetry::HistogramMetricVector");
|
static auto metrics_vector_type = zeek::id::find_type<VectorType>("Telemetry::HistogramMetricVector");
|
||||||
static auto string_vec_type = zeek::id::find_type<zeek::VectorType>("string_vec");
|
static auto string_vec_type = zeek::id::find_type<zeek::VectorType>("string_vec");
|
||||||
static auto double_vec_type = zeek::id::find_type<zeek::VectorType>("double_vec");
|
static auto double_vec_type = zeek::id::find_type<zeek::VectorType>("double_vec");
|
||||||
static auto count_vec_type = zeek::id::find_type<zeek::VectorType>("index_vec");
|
|
||||||
static auto histogram_metric_type = zeek::id::find_type<zeek::RecordType>("Telemetry::HistogramMetric");
|
static auto histogram_metric_type = zeek::id::find_type<zeek::RecordType>("Telemetry::HistogramMetric");
|
||||||
static auto labels_idx = histogram_metric_type->FieldOffset("labels");
|
static auto labels_idx = histogram_metric_type->FieldOffset("labels");
|
||||||
static auto values_idx = histogram_metric_type->FieldOffset("values");
|
static auto values_idx = histogram_metric_type->FieldOffset("values");
|
||||||
static auto count_values_idx = histogram_metric_type->FieldOffset("count_values");
|
|
||||||
|
|
||||||
static auto observations_idx = histogram_metric_type->FieldOffset("observations");
|
static auto observations_idx = histogram_metric_type->FieldOffset("observations");
|
||||||
static auto count_observations_idx = histogram_metric_type->FieldOffset("count_observations");
|
|
||||||
|
|
||||||
static auto sum_idx = histogram_metric_type->FieldOffset("sum");
|
static auto sum_idx = histogram_metric_type->FieldOffset("sum");
|
||||||
static auto count_sum_idx = histogram_metric_type->FieldOffset("count_sum");
|
|
||||||
|
|
||||||
static auto opts_idx = histogram_metric_type->FieldOffset("opts");
|
static auto opts_idx = histogram_metric_type->FieldOffset("opts");
|
||||||
static auto opts_rt = zeek::id::find_type<zeek::RecordType>("Telemetry::MetricOpts");
|
static auto opts_rt = zeek::id::find_type<zeek::RecordType>("Telemetry::MetricOpts");
|
||||||
static auto bounds_idx = opts_rt->FieldOffset("bounds");
|
static auto bounds_idx = opts_rt->FieldOffset("bounds");
|
||||||
static auto count_bounds_idx = opts_rt->FieldOffset("count_bounds");
|
|
||||||
|
|
||||||
static auto metric_opts_type = zeek::id::find_type<zeek::RecordType>("Telemetry::MetricOpts");
|
static auto metric_opts_type = zeek::id::find_type<zeek::RecordType>("Telemetry::MetricOpts");
|
||||||
static auto metric_type_idx = metric_opts_type->FieldOffset("metric_type");
|
static auto metric_type_idx = metric_opts_type->FieldOffset("metric_type");
|
||||||
|
@ -390,32 +372,20 @@ ValPtr Manager::CollectHistogramMetrics(std::string_view prefix_pattern, std::st
|
||||||
r->Assign(opts_idx, opts_record);
|
r->Assign(opts_idx, opts_record);
|
||||||
|
|
||||||
auto double_values_vec = make_intrusive<zeek::VectorVal>(double_vec_type);
|
auto double_values_vec = make_intrusive<zeek::VectorVal>(double_vec_type);
|
||||||
auto count_values_vec = make_intrusive<zeek::VectorVal>(count_vec_type);
|
|
||||||
std::vector<double> boundaries;
|
std::vector<double> boundaries;
|
||||||
uint64_t last = 0.0;
|
uint64_t last = 0.0;
|
||||||
for ( const auto& b : inst.histogram.bucket ) {
|
for ( const auto& b : inst.histogram.bucket ) {
|
||||||
double_values_vec->Append(
|
double_values_vec->Append(
|
||||||
zeek::make_intrusive<DoubleVal>(static_cast<double>(b.cumulative_count - last)));
|
zeek::make_intrusive<DoubleVal>(static_cast<double>(b.cumulative_count - last)));
|
||||||
count_values_vec->Append(val_mgr->Count(b.cumulative_count - last));
|
|
||||||
last = b.cumulative_count;
|
last = b.cumulative_count;
|
||||||
boundaries.push_back(b.upper_bound);
|
boundaries.push_back(b.upper_bound);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: these could be stored somehow to avoid recreating them repeatedly
|
// TODO: these could be stored somehow to avoid recreating them repeatedly
|
||||||
auto bounds_vec = make_intrusive<zeek::VectorVal>(double_vec_type);
|
auto bounds_vec = make_intrusive<zeek::VectorVal>(double_vec_type);
|
||||||
auto count_bounds_vec = make_intrusive<zeek::VectorVal>(count_vec_type);
|
for ( auto b : boundaries )
|
||||||
for ( auto b : boundaries ) {
|
|
||||||
bounds_vec->Append(zeek::make_intrusive<DoubleVal>(b));
|
bounds_vec->Append(zeek::make_intrusive<DoubleVal>(b));
|
||||||
|
|
||||||
// The boundaries from prom-cpp include the infinite boundary in double.
|
|
||||||
// This can't be converted safely to int64_t, so check for that case and
|
|
||||||
// set the int64_t version.
|
|
||||||
if ( b != std::numeric_limits<double>::infinity() )
|
|
||||||
count_bounds_vec->Append(val_mgr->Count(static_cast<int64_t>(b)));
|
|
||||||
else
|
|
||||||
count_bounds_vec->Append(val_mgr->Count(std::numeric_limits<int64_t>::infinity()));
|
|
||||||
}
|
|
||||||
|
|
||||||
r->Assign(values_idx, double_values_vec);
|
r->Assign(values_idx, double_values_vec);
|
||||||
r->Assign(observations_idx,
|
r->Assign(observations_idx,
|
||||||
zeek::make_intrusive<DoubleVal>(static_cast<double>(inst.histogram.sample_count)));
|
zeek::make_intrusive<DoubleVal>(static_cast<double>(inst.histogram.sample_count)));
|
||||||
|
@ -424,16 +394,6 @@ ValPtr Manager::CollectHistogramMetrics(std::string_view prefix_pattern, std::st
|
||||||
RecordValPtr local_opts_record = r->GetField<RecordVal>(opts_idx);
|
RecordValPtr local_opts_record = r->GetField<RecordVal>(opts_idx);
|
||||||
local_opts_record->Assign(bounds_idx, bounds_vec);
|
local_opts_record->Assign(bounds_idx, bounds_vec);
|
||||||
|
|
||||||
// Use the information from GetMetaricOptsRecord to check whether we need to add the integer
|
|
||||||
// fields, or if this is a double.
|
|
||||||
if ( opts_record->GetField<EnumVal>(metric_type_idx)->Get() ==
|
|
||||||
BifEnum::Telemetry::MetricType::INT_HISTOGRAM ) {
|
|
||||||
r->Assign(count_values_idx, count_values_vec);
|
|
||||||
r->Assign(count_observations_idx, val_mgr->Count(inst.histogram.sample_count));
|
|
||||||
r->Assign(count_sum_idx, val_mgr->Count(static_cast<int64_t>(inst.histogram.sample_sum)));
|
|
||||||
local_opts_record->Assign(count_bounds_idx, count_bounds_vec);
|
|
||||||
}
|
|
||||||
|
|
||||||
ret_val->Append(r);
|
ret_val->Append(r);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -483,6 +443,135 @@ std::string Manager::GetClusterJson() const {
|
||||||
return buffer.GetString();
|
return buffer.GetString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<telemetry::CounterFamily> Manager::CounterFamily(std::string_view prefix, std::string_view name,
|
||||||
|
Span<const std::string_view> labels,
|
||||||
|
std::string_view helptext, std::string_view unit,
|
||||||
|
bool is_sum) {
|
||||||
|
auto full_name = detail::BuildFullPrometheusName(prefix, name, unit, is_sum);
|
||||||
|
|
||||||
|
auto& prom_fam =
|
||||||
|
prometheus::BuildCounter().Name(full_name).Help(std::string{helptext}).Register(*prometheus_registry);
|
||||||
|
|
||||||
|
if ( auto it = families.find(prom_fam.GetName()); it != families.end() )
|
||||||
|
return std::static_pointer_cast<telemetry::CounterFamily>(it->second);
|
||||||
|
|
||||||
|
auto fam = std::make_shared<telemetry::CounterFamily>(&prom_fam, labels);
|
||||||
|
families.insert({prom_fam.GetName(), fam});
|
||||||
|
return fam;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<telemetry::CounterFamily> Manager::CounterFamily(std::string_view prefix, std::string_view name,
|
||||||
|
std::initializer_list<std::string_view> labels,
|
||||||
|
std::string_view helptext, std::string_view unit,
|
||||||
|
bool is_sum) {
|
||||||
|
auto lbl_span = Span{labels.begin(), labels.size()};
|
||||||
|
return CounterFamily(prefix, name, lbl_span, helptext, unit, is_sum);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<Counter> Manager::CounterInstance(std::string_view prefix, std::string_view name,
|
||||||
|
Span<const LabelView> labels, std::string_view helptext,
|
||||||
|
std::string_view unit, bool is_sum,
|
||||||
|
prometheus::CollectCallbackPtr callback) {
|
||||||
|
return WithLabelNames(labels, [&, this](auto labelNames) {
|
||||||
|
auto family = CounterFamily(prefix, name, labelNames, helptext, unit, is_sum);
|
||||||
|
return family->GetOrAdd(labels, callback);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<Counter> Manager::CounterInstance(std::string_view prefix, std::string_view name,
|
||||||
|
std::initializer_list<LabelView> labels, std::string_view helptext,
|
||||||
|
std::string_view unit, bool is_sum,
|
||||||
|
prometheus::CollectCallbackPtr callback) {
|
||||||
|
auto lbl_span = Span{labels.begin(), labels.size()};
|
||||||
|
return CounterInstance(prefix, name, lbl_span, helptext, unit, is_sum, std::move(callback));
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<telemetry::GaugeFamily> Manager::GaugeFamily(std::string_view prefix, std::string_view name,
|
||||||
|
Span<const std::string_view> labels,
|
||||||
|
std::string_view helptext, std::string_view unit,
|
||||||
|
bool is_sum) {
|
||||||
|
auto full_name = detail::BuildFullPrometheusName(prefix, name, unit, is_sum);
|
||||||
|
|
||||||
|
auto& prom_fam =
|
||||||
|
prometheus::BuildGauge().Name(full_name).Help(std::string{helptext}).Register(*prometheus_registry);
|
||||||
|
|
||||||
|
if ( auto it = families.find(prom_fam.GetName()); it != families.end() )
|
||||||
|
return std::static_pointer_cast<telemetry::GaugeFamily>(it->second);
|
||||||
|
|
||||||
|
auto fam = std::make_shared<telemetry::GaugeFamily>(&prom_fam, labels);
|
||||||
|
families.insert({prom_fam.GetName(), fam});
|
||||||
|
return fam;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<telemetry::GaugeFamily> Manager::GaugeFamily(std::string_view prefix, std::string_view name,
|
||||||
|
std::initializer_list<std::string_view> labels,
|
||||||
|
std::string_view helptext, std::string_view unit,
|
||||||
|
bool is_sum) {
|
||||||
|
auto lbl_span = Span{labels.begin(), labels.size()};
|
||||||
|
return GaugeFamily(prefix, name, lbl_span, helptext, unit, is_sum);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<Gauge> Manager::GaugeInstance(std::string_view prefix, std::string_view name,
|
||||||
|
Span<const LabelView> labels, std::string_view helptext,
|
||||||
|
std::string_view unit, bool is_sum,
|
||||||
|
prometheus::CollectCallbackPtr callback) {
|
||||||
|
return WithLabelNames(labels, [&, this](auto labelNames) {
|
||||||
|
auto family = GaugeFamily(prefix, name, labelNames, helptext, unit, is_sum);
|
||||||
|
return family->GetOrAdd(labels, callback);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<Gauge> Manager::GaugeInstance(std::string_view prefix, std::string_view name,
|
||||||
|
std::initializer_list<LabelView> labels, std::string_view helptext,
|
||||||
|
std::string_view unit, bool is_sum,
|
||||||
|
prometheus::CollectCallbackPtr callback) {
|
||||||
|
auto lbl_span = Span{labels.begin(), labels.size()};
|
||||||
|
return GaugeInstance(prefix, name, lbl_span, helptext, unit, is_sum, callback);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<telemetry::HistogramFamily> Manager::HistogramFamily(std::string_view prefix, std::string_view name,
|
||||||
|
Span<const std::string_view> labels,
|
||||||
|
ConstSpan<double> bounds,
|
||||||
|
std::string_view helptext, std::string_view unit) {
|
||||||
|
auto full_name = detail::BuildFullPrometheusName(prefix, name, unit);
|
||||||
|
|
||||||
|
auto& prom_fam =
|
||||||
|
prometheus::BuildHistogram().Name(full_name).Help(std::string{helptext}).Register(*prometheus_registry);
|
||||||
|
|
||||||
|
if ( auto it = families.find(prom_fam.GetName()); it != families.end() )
|
||||||
|
return std::static_pointer_cast<telemetry::HistogramFamily>(it->second);
|
||||||
|
|
||||||
|
auto fam = std::make_shared<telemetry::HistogramFamily>(&prom_fam, bounds, labels);
|
||||||
|
families.insert({prom_fam.GetName(), fam});
|
||||||
|
return fam;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<telemetry::HistogramFamily> Manager::HistogramFamily(std::string_view prefix, std::string_view name,
|
||||||
|
std::initializer_list<std::string_view> labels,
|
||||||
|
ConstSpan<double> bounds,
|
||||||
|
std::string_view helptext, std::string_view unit) {
|
||||||
|
auto lbl_span = Span{labels.begin(), labels.size()};
|
||||||
|
return HistogramFamily(prefix, name, lbl_span, bounds, helptext, unit);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<Histogram> Manager::HistogramInstance(std::string_view prefix, std::string_view name,
|
||||||
|
Span<const LabelView> labels, ConstSpan<double> bounds,
|
||||||
|
std::string_view helptext, std::string_view unit) {
|
||||||
|
return WithLabelNames(labels, [&, this](auto labelNames) {
|
||||||
|
auto family = HistogramFamily(prefix, name, labelNames, bounds, helptext, unit);
|
||||||
|
return family->GetOrAdd(labels);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<Histogram> Manager::HistogramInstance(std::string_view prefix, std::string_view name,
|
||||||
|
std::initializer_list<LabelView> labels,
|
||||||
|
std::initializer_list<double> bounds, std::string_view helptext,
|
||||||
|
std::string_view unit) {
|
||||||
|
auto lbls = Span{labels.begin(), labels.size()};
|
||||||
|
auto bounds_span = Span{bounds.begin(), bounds.size()};
|
||||||
|
return HistogramInstance(prefix, name, lbls, bounds_span, helptext, unit);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace zeek::telemetry
|
} // namespace zeek::telemetry
|
||||||
|
|
||||||
// -- unit tests ---------------------------------------------------------------
|
// -- unit tests ---------------------------------------------------------------
|
||||||
|
@ -519,7 +608,7 @@ SCENARIO("telemetry managers provide access to counter families") {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
WHEN("retrieving a DblCounter family") {
|
WHEN("retrieving a DblCounter family") {
|
||||||
auto family = mgr.CounterFamily<double>("zeek", "runtime", {"query"}, "test", "seconds", true);
|
auto family = mgr.CounterFamily("zeek", "runtime", {"query"}, "test", "seconds", true);
|
||||||
THEN("GetOrAdd returns the same metric for the same labels") {
|
THEN("GetOrAdd returns the same metric for the same labels") {
|
||||||
auto first = family->GetOrAdd({{"query", "foo"}});
|
auto first = family->GetOrAdd({{"query", "foo"}});
|
||||||
auto second = family->GetOrAdd({{"query", "foo"}});
|
auto second = family->GetOrAdd({{"query", "foo"}});
|
||||||
|
@ -551,7 +640,7 @@ SCENARIO("telemetry managers provide access to gauge families") {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
WHEN("retrieving a DblGauge family") {
|
WHEN("retrieving a DblGauge family") {
|
||||||
auto family = mgr.GaugeFamily<double>("zeek", "water-level", {"river"}, "test", "meters");
|
auto family = mgr.GaugeFamily("zeek", "water-level", {"river"}, "test", "meters");
|
||||||
THEN("GetOrAdd returns the same metric for the same labels") {
|
THEN("GetOrAdd returns the same metric for the same labels") {
|
||||||
auto first = family->GetOrAdd({{"river", "Sacramento"}});
|
auto first = family->GetOrAdd({{"river", "Sacramento"}});
|
||||||
auto second = family->GetOrAdd({{"river", "Sacramento"}});
|
auto second = family->GetOrAdd({{"river", "Sacramento"}});
|
||||||
|
@ -570,7 +659,7 @@ SCENARIO("telemetry managers provide access to histogram families") {
|
||||||
GIVEN("a telemetry manager") {
|
GIVEN("a telemetry manager") {
|
||||||
Manager mgr;
|
Manager mgr;
|
||||||
WHEN("retrieving an IntHistogram family") {
|
WHEN("retrieving an IntHistogram family") {
|
||||||
int64_t buckets[] = {10, 20};
|
double buckets[] = {10, 20};
|
||||||
auto family = mgr.HistogramFamily("zeek", "payload-size", {"protocol"}, buckets, "test", "bytes");
|
auto family = mgr.HistogramFamily("zeek", "payload-size", {"protocol"}, buckets, "test", "bytes");
|
||||||
THEN("GetOrAdd returns the same metric for the same labels") {
|
THEN("GetOrAdd returns the same metric for the same labels") {
|
||||||
auto first = family->GetOrAdd({{"protocol", "tcp"}});
|
auto first = family->GetOrAdd({{"protocol", "tcp"}});
|
||||||
|
@ -585,7 +674,7 @@ SCENARIO("telemetry managers provide access to histogram families") {
|
||||||
}
|
}
|
||||||
WHEN("retrieving a DblHistogram family") {
|
WHEN("retrieving a DblHistogram family") {
|
||||||
double buckets[] = {10.0, 20.0};
|
double buckets[] = {10.0, 20.0};
|
||||||
auto family = mgr.HistogramFamily<double>("zeek", "parse-time", {"protocol"}, buckets, "test", "seconds");
|
auto family = mgr.HistogramFamily("zeek", "parse-time", {"protocol"}, buckets, "test", "seconds");
|
||||||
THEN("GetOrAdd returns the same metric for the same labels") {
|
THEN("GetOrAdd returns the same metric for the same labels") {
|
||||||
auto first = family->GetOrAdd({{"protocol", "tcp"}});
|
auto first = family->GetOrAdd({{"protocol", "tcp"}});
|
||||||
auto second = family->GetOrAdd({{"protocol", "tcp"}});
|
auto second = family->GetOrAdd({{"protocol", "tcp"}});
|
||||||
|
|
|
@ -70,40 +70,16 @@ public:
|
||||||
* @param unit Unit of measurement.
|
* @param unit Unit of measurement.
|
||||||
* @param is_sum Indicates whether this metric accumulates something, where only the total value is of interest.
|
* @param is_sum Indicates whether this metric accumulates something, where only the total value is of interest.
|
||||||
*/
|
*/
|
||||||
template<class ValueType = int64_t>
|
std::shared_ptr<telemetry::CounterFamily> CounterFamily(std::string_view prefix, std::string_view name,
|
||||||
auto CounterFamily(std::string_view prefix, std::string_view name, Span<const std::string_view> labels,
|
Span<const std::string_view> labels,
|
||||||
std::string_view helptext, std::string_view unit = "", bool is_sum = false) {
|
std::string_view helptext, std::string_view unit = "",
|
||||||
auto full_name = detail::BuildFullPrometheusName(prefix, name, unit, is_sum);
|
bool is_sum = false);
|
||||||
|
|
||||||
auto& prom_fam =
|
|
||||||
prometheus::BuildCounter().Name(full_name).Help(std::string{helptext}).Register(*prometheus_registry);
|
|
||||||
|
|
||||||
if constexpr ( std::is_same<ValueType, int64_t>::value ) {
|
|
||||||
if ( auto it = families.find(prom_fam.GetName()); it != families.end() )
|
|
||||||
return std::static_pointer_cast<IntCounterFamily>(it->second);
|
|
||||||
|
|
||||||
auto fam = std::make_shared<IntCounterFamily>(&prom_fam, labels);
|
|
||||||
families.insert({prom_fam.GetName(), fam});
|
|
||||||
return fam;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
static_assert(std::is_same<ValueType, double>::value, "metrics only support int64_t and double values");
|
|
||||||
if ( auto it = families.find(prom_fam.GetName()); it != families.end() )
|
|
||||||
return std::static_pointer_cast<DblCounterFamily>(it->second);
|
|
||||||
|
|
||||||
auto fam = std::make_shared<DblCounterFamily>(&prom_fam, labels);
|
|
||||||
families.insert({prom_fam.GetName(), fam});
|
|
||||||
return fam;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @copydoc CounterFamily
|
/// @copydoc CounterFamily
|
||||||
template<class ValueType = int64_t>
|
std::shared_ptr<telemetry::CounterFamily> CounterFamily(std::string_view prefix, std::string_view name,
|
||||||
auto CounterFamily(std::string_view prefix, std::string_view name, std::initializer_list<std::string_view> labels,
|
std::initializer_list<std::string_view> labels,
|
||||||
std::string_view helptext, std::string_view unit = "", bool is_sum = false) {
|
std::string_view helptext, std::string_view unit = "",
|
||||||
auto lbl_span = Span{labels.begin(), labels.size()};
|
bool is_sum = false);
|
||||||
return CounterFamily<ValueType>(prefix, name, lbl_span, helptext, unit, is_sum);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Accesses a counter instance. Creates the hosting metric family as well
|
* Accesses a counter instance. Creates the hosting metric family as well
|
||||||
|
@ -117,27 +93,16 @@ public:
|
||||||
* @param callback Passing a callback method will enable asynchronous mode. The callback method will be called by
|
* @param callback Passing a callback method will enable asynchronous mode. The callback method will be called by
|
||||||
* the metrics subsystem whenever data is requested.
|
* the metrics subsystem whenever data is requested.
|
||||||
*/
|
*/
|
||||||
template<class ValueType = int64_t>
|
std::shared_ptr<Counter> CounterInstance(std::string_view prefix, std::string_view name,
|
||||||
std::shared_ptr<Counter<ValueType>> CounterInstance(std::string_view prefix, std::string_view name,
|
Span<const LabelView> labels, std::string_view helptext,
|
||||||
Span<const LabelView> labels, std::string_view helptext,
|
std::string_view unit = "", bool is_sum = false,
|
||||||
std::string_view unit = "", bool is_sum = false,
|
prometheus::CollectCallbackPtr callback = nullptr);
|
||||||
prometheus::CollectCallbackPtr callback = nullptr) {
|
|
||||||
return WithLabelNames(labels, [&, this](auto labelNames) {
|
|
||||||
auto family = CounterFamily<ValueType>(prefix, name, labelNames, helptext, unit, is_sum);
|
|
||||||
return family->GetOrAdd(labels, callback);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @copydoc counterInstance
|
/// @copydoc counterInstance
|
||||||
template<class ValueType = int64_t>
|
std::shared_ptr<Counter> CounterInstance(std::string_view prefix, std::string_view name,
|
||||||
std::shared_ptr<Counter<ValueType>> CounterInstance(std::string_view prefix, std::string_view name,
|
std::initializer_list<LabelView> labels, std::string_view helptext,
|
||||||
std::initializer_list<LabelView> labels,
|
std::string_view unit = "", bool is_sum = false,
|
||||||
std::string_view helptext, std::string_view unit = "",
|
prometheus::CollectCallbackPtr callback = nullptr);
|
||||||
bool is_sum = false,
|
|
||||||
prometheus::CollectCallbackPtr callback = nullptr) {
|
|
||||||
auto lbl_span = Span{labels.begin(), labels.size()};
|
|
||||||
return CounterInstance<ValueType>(prefix, name, lbl_span, helptext, unit, is_sum, callback);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return A gauge metric family. Creates the family lazily if necessary.
|
* @return A gauge metric family. Creates the family lazily if necessary.
|
||||||
|
@ -148,40 +113,15 @@ public:
|
||||||
* @param unit Unit of measurement.
|
* @param unit Unit of measurement.
|
||||||
* @param is_sum Indicates whether this metric accumulates something, where only the total value is of interest.
|
* @param is_sum Indicates whether this metric accumulates something, where only the total value is of interest.
|
||||||
*/
|
*/
|
||||||
template<class ValueType = int64_t>
|
std::shared_ptr<telemetry::GaugeFamily> GaugeFamily(std::string_view prefix, std::string_view name,
|
||||||
auto GaugeFamily(std::string_view prefix, std::string_view name, Span<const std::string_view> labels,
|
Span<const std::string_view> labels, std::string_view helptext,
|
||||||
std::string_view helptext, std::string_view unit = "", bool is_sum = false) {
|
std::string_view unit = "", bool is_sum = false);
|
||||||
auto full_name = detail::BuildFullPrometheusName(prefix, name, unit, is_sum);
|
|
||||||
|
|
||||||
auto& prom_fam =
|
|
||||||
prometheus::BuildGauge().Name(full_name).Help(std::string{helptext}).Register(*prometheus_registry);
|
|
||||||
|
|
||||||
if constexpr ( std::is_same<ValueType, int64_t>::value ) {
|
|
||||||
if ( auto it = families.find(prom_fam.GetName()); it != families.end() )
|
|
||||||
return std::static_pointer_cast<IntGaugeFamily>(it->second);
|
|
||||||
|
|
||||||
auto fam = std::make_shared<IntGaugeFamily>(&prom_fam, labels);
|
|
||||||
families.insert({prom_fam.GetName(), fam});
|
|
||||||
return fam;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
static_assert(std::is_same<ValueType, double>::value, "metrics only support int64_t and double values");
|
|
||||||
if ( auto it = families.find(prom_fam.GetName()); it != families.end() )
|
|
||||||
return std::static_pointer_cast<DblGaugeFamily>(it->second);
|
|
||||||
|
|
||||||
auto fam = std::make_shared<DblGaugeFamily>(&prom_fam, labels);
|
|
||||||
families.insert({prom_fam.GetName(), fam});
|
|
||||||
return fam;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @copydoc GaugeFamily
|
/// @copydoc GaugeFamily
|
||||||
template<class ValueType = int64_t>
|
std::shared_ptr<telemetry::GaugeFamily> GaugeFamily(std::string_view prefix, std::string_view name,
|
||||||
auto GaugeFamily(std::string_view prefix, std::string_view name, std::initializer_list<std::string_view> labels,
|
std::initializer_list<std::string_view> labels,
|
||||||
std::string_view helptext, std::string_view unit = "", bool is_sum = false) {
|
std::string_view helptext, std::string_view unit = "",
|
||||||
auto lbl_span = Span{labels.begin(), labels.size()};
|
bool is_sum = false);
|
||||||
return GaugeFamily<ValueType>(prefix, name, lbl_span, helptext, unit, is_sum);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Accesses a gauge instance. Creates the hosting metric family as well
|
* Accesses a gauge instance. Creates the hosting metric family as well
|
||||||
|
@ -195,26 +135,15 @@ public:
|
||||||
* @param callback Passing a callback method will enable asynchronous mode. The callback method will be called by
|
* @param callback Passing a callback method will enable asynchronous mode. The callback method will be called by
|
||||||
* the metrics subsystem whenever data is requested.
|
* the metrics subsystem whenever data is requested.
|
||||||
*/
|
*/
|
||||||
template<class ValueType = int64_t>
|
std::shared_ptr<Gauge> GaugeInstance(std::string_view prefix, std::string_view name, Span<const LabelView> labels,
|
||||||
std::shared_ptr<Gauge<ValueType>> GaugeInstance(std::string_view prefix, std::string_view name,
|
std::string_view helptext, std::string_view unit = "", bool is_sum = false,
|
||||||
Span<const LabelView> labels, std::string_view helptext,
|
prometheus::CollectCallbackPtr callback = nullptr);
|
||||||
std::string_view unit = "", bool is_sum = false,
|
|
||||||
prometheus::CollectCallbackPtr callback = nullptr) {
|
|
||||||
return WithLabelNames(labels, [&, this](auto labelNames) {
|
|
||||||
auto family = GaugeFamily<ValueType>(prefix, name, labelNames, helptext, unit, is_sum);
|
|
||||||
return family->GetOrAdd(labels, callback);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @copydoc GaugeInstance
|
/// @copydoc GaugeInstance
|
||||||
template<class ValueType = int64_t>
|
std::shared_ptr<Gauge> GaugeInstance(std::string_view prefix, std::string_view name,
|
||||||
std::shared_ptr<Gauge<ValueType>> GaugeInstance(std::string_view prefix, std::string_view name,
|
std::initializer_list<LabelView> labels, std::string_view helptext,
|
||||||
std::initializer_list<LabelView> labels, std::string_view helptext,
|
std::string_view unit = "", bool is_sum = false,
|
||||||
std::string_view unit = "", bool is_sum = false,
|
prometheus::CollectCallbackPtr callback = nullptr);
|
||||||
prometheus::CollectCallbackPtr callback = nullptr) {
|
|
||||||
auto lbl_span = Span{labels.begin(), labels.size()};
|
|
||||||
return GaugeInstance<ValueType>(prefix, name, lbl_span, helptext, unit, is_sum, callback);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Forces the compiler to use the type `Span<const T>` instead of trying to
|
// Forces the compiler to use the type `Span<const T>` instead of trying to
|
||||||
// match parameters to a `span`.
|
// match parameters to a `span`.
|
||||||
|
@ -245,40 +174,16 @@ public:
|
||||||
* different bucket settings. Users may also override
|
* different bucket settings. Users may also override
|
||||||
* @p bounds via run-time configuration.
|
* @p bounds via run-time configuration.
|
||||||
*/
|
*/
|
||||||
template<class ValueType = int64_t>
|
std::shared_ptr<telemetry::HistogramFamily> HistogramFamily(std::string_view prefix, std::string_view name,
|
||||||
auto HistogramFamily(std::string_view prefix, std::string_view name, Span<const std::string_view> labels,
|
Span<const std::string_view> labels,
|
||||||
ConstSpan<ValueType> bounds, std::string_view helptext, std::string_view unit = "") {
|
ConstSpan<double> bounds, std::string_view helptext,
|
||||||
auto full_name = detail::BuildFullPrometheusName(prefix, name, unit);
|
std::string_view unit = "");
|
||||||
|
|
||||||
auto& prom_fam =
|
|
||||||
prometheus::BuildHistogram().Name(full_name).Help(std::string{helptext}).Register(*prometheus_registry);
|
|
||||||
|
|
||||||
if constexpr ( std::is_same<ValueType, int64_t>::value ) {
|
|
||||||
if ( auto it = families.find(prom_fam.GetName()); it != families.end() )
|
|
||||||
return std::static_pointer_cast<IntHistogramFamily>(it->second);
|
|
||||||
|
|
||||||
auto fam = std::make_shared<IntHistogramFamily>(&prom_fam, bounds, labels);
|
|
||||||
families.insert({prom_fam.GetName(), fam});
|
|
||||||
return fam;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
static_assert(std::is_same<ValueType, double>::value, "metrics only support int64_t and double values");
|
|
||||||
if ( auto it = families.find(prom_fam.GetName()); it != families.end() )
|
|
||||||
return std::static_pointer_cast<DblHistogramFamily>(it->second);
|
|
||||||
|
|
||||||
auto fam = std::make_shared<DblHistogramFamily>(&prom_fam, bounds, labels);
|
|
||||||
families.insert({prom_fam.GetName(), fam});
|
|
||||||
return fam;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @copydoc HistogramFamily
|
/// @copydoc HistogramFamily
|
||||||
template<class ValueType = int64_t>
|
std::shared_ptr<telemetry::HistogramFamily> HistogramFamily(std::string_view prefix, std::string_view name,
|
||||||
auto HistogramFamily(std::string_view prefix, std::string_view name, std::initializer_list<std::string_view> labels,
|
std::initializer_list<std::string_view> labels,
|
||||||
ConstSpan<ValueType> bounds, std::string_view helptext, std::string_view unit = "") {
|
ConstSpan<double> bounds, std::string_view helptext,
|
||||||
auto lbl_span = Span{labels.begin(), labels.size()};
|
std::string_view unit = "");
|
||||||
return HistogramFamily<ValueType>(prefix, name, lbl_span, bounds, helptext, unit);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a histogram. Creates the family lazily if necessary.
|
* Returns a histogram. Creates the family lazily if necessary.
|
||||||
|
@ -297,26 +202,15 @@ public:
|
||||||
* different bucket settings. Users may also override
|
* different bucket settings. Users may also override
|
||||||
* @p bounds via run-time configuration.
|
* @p bounds via run-time configuration.
|
||||||
*/
|
*/
|
||||||
template<class ValueType = int64_t>
|
std::shared_ptr<Histogram> HistogramInstance(std::string_view prefix, std::string_view name,
|
||||||
std::shared_ptr<Histogram<ValueType>> HistogramInstance(std::string_view prefix, std::string_view name,
|
Span<const LabelView> labels, ConstSpan<double> bounds,
|
||||||
Span<const LabelView> labels, ConstSpan<ValueType> bounds,
|
std::string_view helptext, std::string_view unit = "");
|
||||||
std::string_view helptext, std::string_view unit = "") {
|
|
||||||
return WithLabelNames(labels, [&, this](auto labelNames) {
|
|
||||||
auto family = HistogramFamily<ValueType>(prefix, name, labelNames, bounds, helptext, unit);
|
|
||||||
return family->GetOrAdd(labels);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @copdoc HistogramInstance
|
/// @copdoc HistogramInstance
|
||||||
template<class ValueType = int64_t>
|
std::shared_ptr<Histogram> HistogramInstance(std::string_view prefix, std::string_view name,
|
||||||
std::shared_ptr<Histogram<ValueType>> HistogramInstance(std::string_view prefix, std::string_view name,
|
std::initializer_list<LabelView> labels,
|
||||||
std::initializer_list<LabelView> labels,
|
std::initializer_list<double> bounds, std::string_view helptext,
|
||||||
std::initializer_list<ValueType> bounds,
|
std::string_view unit = "");
|
||||||
std::string_view helptext, std::string_view unit = "") {
|
|
||||||
auto lbls = Span{labels.begin(), labels.size()};
|
|
||||||
auto bounds_span = Span{bounds.begin(), bounds.size()};
|
|
||||||
return HistogramInstance<ValueType>(prefix, name, lbls, bounds_span, helptext, unit);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return A JSON description of the cluster configuration for reporting
|
* @return A JSON description of the cluster configuration for reporting
|
||||||
|
@ -359,10 +253,10 @@ private:
|
||||||
detail::process_stats current_process_stats;
|
detail::process_stats current_process_stats;
|
||||||
double process_stats_last_updated = 0.0;
|
double process_stats_last_updated = 0.0;
|
||||||
|
|
||||||
std::shared_ptr<IntGauge> rss_gauge;
|
std::shared_ptr<Gauge> rss_gauge;
|
||||||
std::shared_ptr<IntGauge> vms_gauge;
|
std::shared_ptr<Gauge> vms_gauge;
|
||||||
std::shared_ptr<DblGauge> cpu_gauge;
|
std::shared_ptr<Gauge> cpu_gauge;
|
||||||
std::shared_ptr<IntGauge> fds_gauge;
|
std::shared_ptr<Gauge> fds_gauge;
|
||||||
|
|
||||||
std::string endpoint_name;
|
std::string endpoint_name;
|
||||||
std::vector<std::string> export_prefixes;
|
std::vector<std::string> export_prefixes;
|
||||||
|
|
|
@ -2,43 +2,21 @@
|
||||||
|
|
||||||
using namespace zeek;
|
using namespace zeek;
|
||||||
|
|
||||||
TelemetryVal::TelemetryVal(std::shared_ptr<telemetry::IntCounter>) : OpaqueVal(int_counter_metric_type) {}
|
TelemetryVal::TelemetryVal(std::shared_ptr<telemetry::Counter>) : OpaqueVal(counter_metric_type) {}
|
||||||
|
|
||||||
TelemetryVal::TelemetryVal(std::shared_ptr<telemetry::IntCounterFamily>) : OpaqueVal(int_counter_metric_family_type) {}
|
TelemetryVal::TelemetryVal(std::shared_ptr<telemetry::CounterFamily>) : OpaqueVal(counter_metric_family_type) {}
|
||||||
|
|
||||||
TelemetryVal::TelemetryVal(std::shared_ptr<telemetry::DblCounter>) : OpaqueVal(dbl_counter_metric_type) {}
|
TelemetryVal::TelemetryVal(std::shared_ptr<telemetry::Gauge>) : OpaqueVal(gauge_metric_type) {}
|
||||||
|
|
||||||
TelemetryVal::TelemetryVal(std::shared_ptr<telemetry::DblCounterFamily>) : OpaqueVal(dbl_counter_metric_family_type) {}
|
TelemetryVal::TelemetryVal(std::shared_ptr<telemetry::GaugeFamily>) : OpaqueVal(gauge_metric_family_type) {}
|
||||||
|
|
||||||
TelemetryVal::TelemetryVal(std::shared_ptr<telemetry::IntGauge>) : OpaqueVal(int_gauge_metric_type) {}
|
TelemetryVal::TelemetryVal(std::shared_ptr<telemetry::Histogram>) : OpaqueVal(histogram_metric_type) {}
|
||||||
|
|
||||||
TelemetryVal::TelemetryVal(std::shared_ptr<telemetry::IntGaugeFamily>) : OpaqueVal(int_gauge_metric_family_type) {}
|
TelemetryVal::TelemetryVal(std::shared_ptr<telemetry::HistogramFamily>) : OpaqueVal(histogram_metric_family_type) {}
|
||||||
|
|
||||||
TelemetryVal::TelemetryVal(std::shared_ptr<telemetry::DblGauge>) : OpaqueVal(dbl_gauge_metric_type) {}
|
IMPLEMENT_OPAQUE_VALUE(CounterMetricVal)
|
||||||
|
IMPLEMENT_OPAQUE_VALUE(CounterMetricFamilyVal)
|
||||||
TelemetryVal::TelemetryVal(std::shared_ptr<telemetry::DblGaugeFamily>) : OpaqueVal(dbl_gauge_metric_family_type) {}
|
IMPLEMENT_OPAQUE_VALUE(GaugeMetricVal)
|
||||||
|
IMPLEMENT_OPAQUE_VALUE(GaugeMetricFamilyVal)
|
||||||
TelemetryVal::TelemetryVal(std::shared_ptr<telemetry::IntHistogram>) : OpaqueVal(int_histogram_metric_type) {}
|
IMPLEMENT_OPAQUE_VALUE(HistogramMetricVal)
|
||||||
|
IMPLEMENT_OPAQUE_VALUE(HistogramMetricFamilyVal)
|
||||||
TelemetryVal::TelemetryVal(std::shared_ptr<telemetry::IntHistogramFamily>)
|
|
||||||
: OpaqueVal(int_histogram_metric_family_type) {}
|
|
||||||
|
|
||||||
TelemetryVal::TelemetryVal(std::shared_ptr<telemetry::DblHistogram>) : OpaqueVal(dbl_histogram_metric_type) {}
|
|
||||||
|
|
||||||
TelemetryVal::TelemetryVal(std::shared_ptr<telemetry::DblHistogramFamily>)
|
|
||||||
: OpaqueVal(dbl_histogram_metric_family_type) {}
|
|
||||||
|
|
||||||
// TelemetryVal::TelemetryVal(prometheus::Counter&) : OpaqueVal(
|
|
||||||
|
|
||||||
IMPLEMENT_OPAQUE_VALUE(IntCounterMetricVal)
|
|
||||||
IMPLEMENT_OPAQUE_VALUE(IntCounterMetricFamilyVal)
|
|
||||||
IMPLEMENT_OPAQUE_VALUE(DblCounterMetricVal)
|
|
||||||
IMPLEMENT_OPAQUE_VALUE(DblCounterMetricFamilyVal)
|
|
||||||
IMPLEMENT_OPAQUE_VALUE(IntGaugeMetricVal)
|
|
||||||
IMPLEMENT_OPAQUE_VALUE(IntGaugeMetricFamilyVal)
|
|
||||||
IMPLEMENT_OPAQUE_VALUE(DblGaugeMetricVal)
|
|
||||||
IMPLEMENT_OPAQUE_VALUE(DblGaugeMetricFamilyVal)
|
|
||||||
IMPLEMENT_OPAQUE_VALUE(IntHistogramMetricVal)
|
|
||||||
IMPLEMENT_OPAQUE_VALUE(IntHistogramMetricFamilyVal)
|
|
||||||
IMPLEMENT_OPAQUE_VALUE(DblHistogramMetricVal)
|
|
||||||
IMPLEMENT_OPAQUE_VALUE(DblHistogramMetricFamilyVal)
|
|
||||||
|
|
|
@ -15,18 +15,12 @@ namespace zeek {
|
||||||
*/
|
*/
|
||||||
class TelemetryVal : public OpaqueVal {
|
class TelemetryVal : public OpaqueVal {
|
||||||
protected:
|
protected:
|
||||||
explicit TelemetryVal(std::shared_ptr<telemetry::IntCounter>);
|
explicit TelemetryVal(std::shared_ptr<telemetry::Counter>);
|
||||||
explicit TelemetryVal(std::shared_ptr<telemetry::IntCounterFamily>);
|
explicit TelemetryVal(std::shared_ptr<telemetry::CounterFamily>);
|
||||||
explicit TelemetryVal(std::shared_ptr<telemetry::DblCounter>);
|
explicit TelemetryVal(std::shared_ptr<telemetry::Gauge>);
|
||||||
explicit TelemetryVal(std::shared_ptr<telemetry::DblCounterFamily>);
|
explicit TelemetryVal(std::shared_ptr<telemetry::GaugeFamily>);
|
||||||
explicit TelemetryVal(std::shared_ptr<telemetry::IntGauge>);
|
explicit TelemetryVal(std::shared_ptr<telemetry::Histogram>);
|
||||||
explicit TelemetryVal(std::shared_ptr<telemetry::IntGaugeFamily>);
|
explicit TelemetryVal(std::shared_ptr<telemetry::HistogramFamily>);
|
||||||
explicit TelemetryVal(std::shared_ptr<telemetry::DblGauge>);
|
|
||||||
explicit TelemetryVal(std::shared_ptr<telemetry::DblGaugeFamily>);
|
|
||||||
explicit TelemetryVal(std::shared_ptr<telemetry::IntHistogram>);
|
|
||||||
explicit TelemetryVal(std::shared_ptr<telemetry::IntHistogramFamily>);
|
|
||||||
explicit TelemetryVal(std::shared_ptr<telemetry::DblHistogram>);
|
|
||||||
explicit TelemetryVal(std::shared_ptr<telemetry::DblHistogramFamily>);
|
|
||||||
|
|
||||||
std::optional<BrokerData> DoSerializeData() const override { return std::nullopt; }
|
std::optional<BrokerData> DoSerializeData() const override { return std::nullopt; }
|
||||||
bool DoUnserializeData(BrokerDataView data) override { return false; }
|
bool DoUnserializeData(BrokerDataView data) override { return false; }
|
||||||
|
@ -55,17 +49,11 @@ private:
|
||||||
HandleType hdl;
|
HandleType hdl;
|
||||||
};
|
};
|
||||||
|
|
||||||
using IntCounterMetricVal = TelemetryValImpl<telemetry::IntCounter>;
|
using CounterMetricVal = TelemetryValImpl<telemetry::Counter>;
|
||||||
using IntCounterMetricFamilyVal = TelemetryValImpl<telemetry::IntCounterFamily>;
|
using CounterMetricFamilyVal = TelemetryValImpl<telemetry::CounterFamily>;
|
||||||
using DblCounterMetricVal = TelemetryValImpl<telemetry::DblCounter>;
|
using GaugeMetricVal = TelemetryValImpl<telemetry::Gauge>;
|
||||||
using DblCounterMetricFamilyVal = TelemetryValImpl<telemetry::DblCounterFamily>;
|
using GaugeMetricFamilyVal = TelemetryValImpl<telemetry::GaugeFamily>;
|
||||||
using IntGaugeMetricVal = TelemetryValImpl<telemetry::IntGauge>;
|
using HistogramMetricVal = TelemetryValImpl<telemetry::Histogram>;
|
||||||
using IntGaugeMetricFamilyVal = TelemetryValImpl<telemetry::IntGaugeFamily>;
|
using HistogramMetricFamilyVal = TelemetryValImpl<telemetry::HistogramFamily>;
|
||||||
using DblGaugeMetricVal = TelemetryValImpl<telemetry::DblGauge>;
|
|
||||||
using DblGaugeMetricFamilyVal = TelemetryValImpl<telemetry::DblGaugeFamily>;
|
|
||||||
using IntHistogramMetricVal = TelemetryValImpl<telemetry::IntHistogram>;
|
|
||||||
using IntHistogramMetricFamilyVal = TelemetryValImpl<telemetry::IntHistogramFamily>;
|
|
||||||
using DblHistogramMetricVal = TelemetryValImpl<telemetry::DblHistogram>;
|
|
||||||
using DblHistogramMetricFamilyVal = TelemetryValImpl<telemetry::DblHistogramFamily>;
|
|
||||||
|
|
||||||
} // namespace zeek
|
} // namespace zeek
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
|
||||||
// See the file "COPYING" in the main distribution directory for copyright.
|
// See the file "COPYING" in the main distribution directory for copyright.
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
@ -15,7 +16,7 @@ class [[nodiscard]] Timer {
|
||||||
public:
|
public:
|
||||||
using Clock = std::chrono::steady_clock;
|
using Clock = std::chrono::steady_clock;
|
||||||
|
|
||||||
explicit Timer(std::shared_ptr<DblHistogram> h) : h_(std::move(h)) { start_ = Clock::now(); }
|
explicit Timer(std::shared_ptr<Histogram> h) : h_(std::move(h)) { start_ = Clock::now(); }
|
||||||
|
|
||||||
Timer(const Timer&) = delete;
|
Timer(const Timer&) = delete;
|
||||||
|
|
||||||
|
@ -30,14 +31,14 @@ public:
|
||||||
auto Started() const noexcept { return start_; }
|
auto Started() const noexcept { return start_; }
|
||||||
|
|
||||||
/// Calls `h.Observe` with the time passed since `start`.
|
/// Calls `h.Observe` with the time passed since `start`.
|
||||||
static void Observe(const std::shared_ptr<DblHistogram>& h, Clock::time_point start) {
|
static void Observe(const std::shared_ptr<Histogram>& h, Clock::time_point start) {
|
||||||
using DblSec = std::chrono::duration<double>;
|
using Sec = std::chrono::duration<double>;
|
||||||
if ( auto end = Clock::now(); end > start )
|
if ( auto end = Clock::now(); end > start )
|
||||||
h->Observe(std::chrono::duration_cast<DblSec>(end - start).count());
|
h->Observe(std::chrono::duration_cast<Sec>(end - start).count());
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<DblHistogram> h_;
|
std::shared_ptr<Histogram> h_;
|
||||||
Clock::time_point start_;
|
Clock::time_point start_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -3,12 +3,9 @@
|
||||||
module Telemetry;
|
module Telemetry;
|
||||||
|
|
||||||
enum MetricType %{
|
enum MetricType %{
|
||||||
DOUBLE_COUNTER,
|
COUNTER,
|
||||||
INT_COUNTER,
|
GAUGE,
|
||||||
DOUBLE_GAUGE,
|
HISTOGRAM,
|
||||||
INT_GAUGE,
|
|
||||||
DOUBLE_HISTOGRAM,
|
|
||||||
INT_HISTOGRAM,
|
|
||||||
%}
|
%}
|
||||||
|
|
||||||
%%{
|
%%{
|
||||||
|
@ -108,379 +105,192 @@ auto to_std_vec(zeek::Val* xs)
|
||||||
}
|
}
|
||||||
%%}
|
%%}
|
||||||
|
|
||||||
# -- IntCounter ----------------------------------------------------------------
|
# -- Counter ----------------------------------------------------------------
|
||||||
|
|
||||||
function Telemetry::__int_counter_family%(prefix: string,
|
function Telemetry::__counter_family%(prefix: string,
|
||||||
name: string,
|
name: string,
|
||||||
labels: string_vec,
|
labels: string_vec,
|
||||||
helptext: string &default = "Zeek Script Metric",
|
helptext: string &default = "Zeek Script Metric",
|
||||||
unit: string &default = "",
|
unit: string &default = "",
|
||||||
is_sum: bool &default = F%): opaque of int_counter_metric_family
|
is_sum: bool &default = F%): opaque of counter_metric_family
|
||||||
%{
|
%{
|
||||||
auto lbl_vec = sv_vec(labels->AsVectorVal());
|
auto lbl_vec = sv_vec(labels->AsVectorVal());
|
||||||
auto hdl = telemetry_mgr->CounterFamily(sv(prefix), sv(name), lbl_vec,
|
auto hdl = telemetry_mgr->CounterFamily(sv(prefix), sv(name), lbl_vec,
|
||||||
sv(helptext), sv(unit), is_sum);
|
sv(helptext), sv(unit), is_sum);
|
||||||
return zeek::make_intrusive<IntCounterMetricFamilyVal>(hdl);
|
return zeek::make_intrusive<CounterMetricFamilyVal>(hdl);
|
||||||
%}
|
%}
|
||||||
|
|
||||||
function Telemetry::__int_counter_metric_get_or_add%(family: opaque of int_counter_metric_family,
|
function Telemetry::__counter_metric_get_or_add%(family: opaque of counter_metric_family,
|
||||||
labels: table_string_of_string%): opaque of int_counter_metric
|
labels: table_string_of_string%): opaque of counter_metric
|
||||||
%{
|
%{
|
||||||
using ResultType = zeek::IntrusivePtr<IntCounterMetricFamilyVal>;
|
using ResultType = zeek::IntrusivePtr<CounterMetricFamilyVal>;
|
||||||
if ( auto ptr = dynamic_cast<zeek::IntCounterMetricFamilyVal*>(family) )
|
if ( auto ptr = dynamic_cast<zeek::CounterMetricFamilyVal*>(family) )
|
||||||
{
|
{
|
||||||
auto hdl = ptr->GetHandle();
|
auto hdl = ptr->GetHandle();
|
||||||
auto lbl_map = sv_tbl(labels->AsTableVal());
|
auto lbl_map = sv_tbl(labels->AsTableVal());
|
||||||
if ( labels_valid(lbl_map, hdl->LabelNames()) )
|
if ( labels_valid(lbl_map, hdl->LabelNames()) )
|
||||||
{
|
{
|
||||||
auto res = hdl->GetOrAdd(lbl_map);
|
auto res = hdl->GetOrAdd(lbl_map);
|
||||||
return zeek::make_intrusive<IntCounterMetricVal>(res);
|
return zeek::make_intrusive<CounterMetricVal>(res);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
zeek::reporter->Error("Telemetry::int_counter_metric_get_or_add: invalid label dimensions.");
|
zeek::reporter->Error("Telemetry::counter_metric_get_or_add: invalid label dimensions.");
|
||||||
return ResultType{nullptr};
|
return ResultType{nullptr};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
zeek::reporter->Error("Telemetry::int_counter_metric_get_or_add: invalid handle.");
|
zeek::reporter->Error("Telemetry::counter_metric_get_or_add: invalid handle.");
|
||||||
return ResultType{nullptr};
|
return ResultType{nullptr};
|
||||||
}
|
}
|
||||||
%}
|
%}
|
||||||
|
|
||||||
function Telemetry::__int_counter_inc%(val: opaque of int_counter_metric,
|
function Telemetry::__counter_inc%(val: opaque of counter_metric,
|
||||||
amount: int &default = 1%): bool
|
amount: double &default = 1.0%): bool
|
||||||
%{
|
%{
|
||||||
return with<IntCounterMetricVal>(val, "Telemetry::int_counter_inc: invalid handle.", [amount](auto hdl) { hdl->Inc(amount); });
|
return with<CounterMetricVal>(val, "Telemetry::counter_inc: invalid handle.", [amount](auto hdl) { hdl->Inc(amount); });
|
||||||
%}
|
%}
|
||||||
|
|
||||||
function Telemetry::__int_counter_value%(val: opaque of int_counter_metric%): int
|
function Telemetry::__counter_value%(val: opaque of counter_metric%): double
|
||||||
%{
|
%{
|
||||||
if ( auto ptr = dynamic_cast<zeek::IntCounterMetricVal*>(val) )
|
if ( auto ptr = dynamic_cast<zeek::CounterMetricVal*>(val) )
|
||||||
{
|
{
|
||||||
return zeek::val_mgr->Int(ptr->GetHandle()->Value());
|
return zeek::make_intrusive<zeek::DoubleVal>(ptr->GetHandle()->Value());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
zeek::reporter->Error("Telemetry::int_counter_value: invalid handle.");
|
zeek::reporter->Error("Telemetry::counter_value: invalid handle.");
|
||||||
return zeek::val_mgr->Int(0);
|
return zeek::make_intrusive<zeek::DoubleVal>(0);
|
||||||
}
|
}
|
||||||
%}
|
%}
|
||||||
|
|
||||||
# -- DblCounter ----------------------------------------------------------------
|
# -- Gauge ------------------------------------------------------------------
|
||||||
|
|
||||||
function Telemetry::__dbl_counter_family%(prefix: string,
|
function Telemetry::__gauge_family%(prefix: string,
|
||||||
name: string,
|
|
||||||
labels: string_vec,
|
|
||||||
helptext: string &default = "Zeek Script Metric",
|
|
||||||
unit: string &default = "",
|
|
||||||
is_sum: bool &default = F%): opaque of dbl_counter_metric_family
|
|
||||||
%{
|
|
||||||
auto lbl_vec = sv_vec(labels->AsVectorVal());
|
|
||||||
auto hdl = telemetry_mgr->CounterFamily<double>(sv(prefix), sv(name), lbl_vec,
|
|
||||||
sv(helptext), sv(unit), is_sum);
|
|
||||||
return zeek::make_intrusive<DblCounterMetricFamilyVal>(hdl);
|
|
||||||
%}
|
|
||||||
|
|
||||||
function Telemetry::__dbl_counter_metric_get_or_add%(family: opaque of dbl_counter_metric_family,
|
|
||||||
labels: table_string_of_string%): opaque of dbl_counter_metric
|
|
||||||
%{
|
|
||||||
using ResultType = zeek::IntrusivePtr<DblCounterMetricFamilyVal>;
|
|
||||||
if ( auto ptr = dynamic_cast<zeek::DblCounterMetricFamilyVal*>(family) )
|
|
||||||
{
|
|
||||||
auto hdl = ptr->GetHandle();
|
|
||||||
auto lbl_map = sv_tbl(labels->AsTableVal());
|
|
||||||
if ( labels_valid(lbl_map, hdl->LabelNames()) )
|
|
||||||
{
|
|
||||||
auto res = hdl->GetOrAdd(lbl_map);
|
|
||||||
return zeek::make_intrusive<DblCounterMetricVal>(res);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
zeek::reporter->Error("Telemetry::dbl_counter_metric_get_or_add: invalid label dimensions.");
|
|
||||||
return ResultType{nullptr};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
zeek::reporter->Error("Telemetry::dbl_counter_metric_get_or_add: invalid handle.");
|
|
||||||
return ResultType{nullptr};
|
|
||||||
}
|
|
||||||
%}
|
|
||||||
|
|
||||||
function Telemetry::__dbl_counter_inc%(val: opaque of dbl_counter_metric,
|
|
||||||
amount: double &default = 1.0%): bool
|
|
||||||
%{
|
|
||||||
return with<DblCounterMetricVal>(val, "Telemetry::dbl_counter_inc: invalid handle.", [amount](auto hdl) { hdl->Inc(amount); });
|
|
||||||
%}
|
|
||||||
|
|
||||||
function Telemetry::__dbl_counter_value%(val: opaque of dbl_counter_metric%): double
|
|
||||||
%{
|
|
||||||
if ( auto ptr = dynamic_cast<zeek::DblCounterMetricVal*>(val) )
|
|
||||||
{
|
|
||||||
return zeek::make_intrusive<DoubleVal>(ptr->GetHandle()->Value());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
zeek::reporter->Error("Telemetry::dbl_counter_value: invalid handle.");
|
|
||||||
return zeek::make_intrusive<DoubleVal>(0.0);
|
|
||||||
}
|
|
||||||
%}
|
|
||||||
|
|
||||||
# -- IntGauge ------------------------------------------------------------------
|
|
||||||
|
|
||||||
function Telemetry::__int_gauge_family%(prefix: string,
|
|
||||||
name: string,
|
name: string,
|
||||||
labels: string_vec,
|
labels: string_vec,
|
||||||
helptext: string &default = "Zeek Script Metric",
|
helptext: string &default = "Zeek Script Metric",
|
||||||
unit: string &default = "",
|
unit: string &default = "",
|
||||||
is_sum: bool &default = F%): opaque of int_gauge_metric_family
|
is_sum: bool &default = F%): opaque of gauge_metric_family
|
||||||
%{
|
%{
|
||||||
auto lbl_vec = sv_vec(labels->AsVectorVal());
|
auto lbl_vec = sv_vec(labels->AsVectorVal());
|
||||||
auto hdl = telemetry_mgr->GaugeFamily(sv(prefix), sv(name), lbl_vec,
|
auto hdl = telemetry_mgr->GaugeFamily(sv(prefix), sv(name), lbl_vec,
|
||||||
sv(helptext), sv(unit), is_sum);
|
sv(helptext), sv(unit), is_sum);
|
||||||
return zeek::make_intrusive<IntGaugeMetricFamilyVal>(hdl);
|
return zeek::make_intrusive<GaugeMetricFamilyVal>(hdl);
|
||||||
%}
|
%}
|
||||||
|
|
||||||
function Telemetry::__int_gauge_metric_get_or_add%(family: opaque of int_gauge_metric_family,
|
function Telemetry::__gauge_metric_get_or_add%(family: opaque of gauge_metric_family,
|
||||||
labels: table_string_of_string%): opaque of int_gauge_metric
|
labels: table_string_of_string%): opaque of gauge_metric
|
||||||
%{
|
%{
|
||||||
using ResultType = zeek::IntrusivePtr<IntGaugeMetricFamilyVal>;
|
using ResultType = zeek::IntrusivePtr<GaugeMetricFamilyVal>;
|
||||||
if ( auto ptr = dynamic_cast<zeek::IntGaugeMetricFamilyVal*>(family) )
|
if ( auto ptr = dynamic_cast<zeek::GaugeMetricFamilyVal*>(family) )
|
||||||
{
|
{
|
||||||
auto hdl = ptr->GetHandle();
|
auto hdl = ptr->GetHandle();
|
||||||
auto lbl_map = sv_tbl(labels->AsTableVal());
|
auto lbl_map = sv_tbl(labels->AsTableVal());
|
||||||
if ( labels_valid(lbl_map, hdl->LabelNames()) )
|
if ( labels_valid(lbl_map, hdl->LabelNames()) )
|
||||||
{
|
{
|
||||||
auto res = hdl->GetOrAdd(lbl_map);
|
auto res = hdl->GetOrAdd(lbl_map);
|
||||||
return zeek::make_intrusive<IntGaugeMetricVal>(res);
|
return zeek::make_intrusive<GaugeMetricVal>(res);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
zeek::reporter->Error("Telemetry::int_gauge_metric_get_or_add: invalid label dimensions.");
|
zeek::reporter->Error("Telemetry::gauge_metric_get_or_add: invalid label dimensions.");
|
||||||
return ResultType{nullptr};
|
return ResultType{nullptr};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
zeek::reporter->Error("Telemetry::int_gauge_metric_get_or_add: invalid handle.");
|
zeek::reporter->Error("Telemetry::gauge_metric_get_or_add: invalid handle.");
|
||||||
return ResultType{nullptr};
|
return ResultType{nullptr};
|
||||||
}
|
}
|
||||||
%}
|
%}
|
||||||
|
|
||||||
function Telemetry::__int_gauge_inc%(val: opaque of int_gauge_metric,
|
function Telemetry::__gauge_inc%(val: opaque of gauge_metric,
|
||||||
amount: int &default = 1%): bool
|
|
||||||
%{
|
|
||||||
return with<IntGaugeMetricVal>(val, "Telemetry::int_gauge_inc: invalid handle.", [amount](auto hdl) { hdl->Inc(amount); });
|
|
||||||
%}
|
|
||||||
|
|
||||||
function Telemetry::__int_gauge_dec%(val: opaque of int_gauge_metric,
|
|
||||||
amount: int &default = 1%): bool
|
|
||||||
%{
|
|
||||||
return with<IntGaugeMetricVal>(val, "Telemetry::int_gauge_dec: invalid handle.", [amount](auto hdl) { hdl->Dec(amount); });
|
|
||||||
%}
|
|
||||||
|
|
||||||
function Telemetry::__int_gauge_value%(val: opaque of int_gauge_metric%): int
|
|
||||||
%{
|
|
||||||
if ( auto ptr = dynamic_cast<zeek::IntGaugeMetricVal*>(val) )
|
|
||||||
{
|
|
||||||
return zeek::val_mgr->Int(ptr->GetHandle()->Value());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
zeek::reporter->Error("Telemetry::int_gauge_value: invalid handle.");
|
|
||||||
return zeek::val_mgr->Int(0);
|
|
||||||
}
|
|
||||||
%}
|
|
||||||
|
|
||||||
# -- DblGauge ------------------------------------------------------------------
|
|
||||||
|
|
||||||
function Telemetry::__dbl_gauge_family%(prefix: string,
|
|
||||||
name: string,
|
|
||||||
labels: string_vec,
|
|
||||||
helptext: string &default = "Zeek Script Metric",
|
|
||||||
unit: string &default = "",
|
|
||||||
is_sum: bool &default = F%): opaque of dbl_gauge_metric_family
|
|
||||||
%{
|
|
||||||
auto lbl_vec = sv_vec(labels->AsVectorVal());
|
|
||||||
auto hdl = telemetry_mgr->GaugeFamily<double>(sv(prefix), sv(name), lbl_vec,
|
|
||||||
sv(helptext), sv(unit), is_sum);
|
|
||||||
return zeek::make_intrusive<DblGaugeMetricFamilyVal>(hdl);
|
|
||||||
%}
|
|
||||||
|
|
||||||
function Telemetry::__dbl_gauge_metric_get_or_add%(family: opaque of dbl_gauge_metric_family,
|
|
||||||
labels: table_string_of_string%): opaque of dbl_gauge_metric
|
|
||||||
%{
|
|
||||||
using ResultType = zeek::IntrusivePtr<DblGaugeMetricFamilyVal>;
|
|
||||||
if ( auto ptr = dynamic_cast<zeek::DblGaugeMetricFamilyVal*>(family) )
|
|
||||||
{
|
|
||||||
auto hdl = ptr->GetHandle();
|
|
||||||
auto lbl_map = sv_tbl(labels->AsTableVal());
|
|
||||||
if ( labels_valid(lbl_map, hdl->LabelNames()) )
|
|
||||||
{
|
|
||||||
auto res = hdl->GetOrAdd(lbl_map);
|
|
||||||
return zeek::make_intrusive<DblGaugeMetricVal>(res);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
zeek::reporter->Error("Telemetry::dbl_gauge_metric_get_or_add: invalid label dimensions.");
|
|
||||||
return ResultType{nullptr};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
zeek::reporter->Error("Telemetry::dbl_gauge_metric_get_or_add: invalid handle.");
|
|
||||||
return ResultType{nullptr};
|
|
||||||
}
|
|
||||||
%}
|
|
||||||
|
|
||||||
function Telemetry::__dbl_gauge_inc%(val: opaque of dbl_gauge_metric,
|
|
||||||
amount: double &default = 1.0%): bool
|
amount: double &default = 1.0%): bool
|
||||||
%{
|
%{
|
||||||
return with<DblGaugeMetricVal>(val, "Telemetry::dbl_gauge_inc: invalid handle.", [amount](auto hdl) { hdl->Inc(amount); });
|
return with<GaugeMetricVal>(val, "Telemetry::gauge_inc: invalid handle.", [amount](auto hdl) { hdl->Inc(amount); });
|
||||||
%}
|
%}
|
||||||
|
|
||||||
function Telemetry::__dbl_gauge_dec%(val: opaque of dbl_gauge_metric,
|
function Telemetry::__gauge_dec%(val: opaque of gauge_metric,
|
||||||
amount: double &default = 1.0%): bool
|
amount: double &default = 1.0%): bool
|
||||||
%{
|
%{
|
||||||
return with<DblGaugeMetricVal>(val, "Telemetry::dbl_gauge_dec: invalid handle.", [amount](auto hdl) { hdl->Dec(amount); });
|
return with<GaugeMetricVal>(val, "Telemetry::gauge_dec: invalid handle.", [amount](auto hdl) { hdl->Dec(amount); });
|
||||||
%}
|
%}
|
||||||
|
|
||||||
function Telemetry::__dbl_gauge_value%(val: opaque of dbl_gauge_metric%): double
|
function Telemetry::__gauge_value%(val: opaque of gauge_metric%): double
|
||||||
%{
|
%{
|
||||||
if ( auto ptr = dynamic_cast<zeek::DblGaugeMetricVal*>(val) )
|
if ( auto ptr = dynamic_cast<zeek::GaugeMetricVal*>(val) )
|
||||||
{
|
{
|
||||||
return zeek::make_intrusive<DoubleVal>(ptr->GetHandle()->Value());
|
return zeek::make_intrusive<zeek::DoubleVal>(ptr->GetHandle()->Value());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
zeek::reporter->Error("Telemetry::dbl_gauge_value: invalid handle.");
|
zeek::reporter->Error("Telemetry::gauge_value: invalid handle.");
|
||||||
return zeek::make_intrusive<DoubleVal>(0.0);
|
return zeek::make_intrusive<zeek::DoubleVal>(0.0);
|
||||||
}
|
}
|
||||||
%}
|
%}
|
||||||
|
|
||||||
# -- IntHistogram --------------------------------------------------------------
|
# -- Histogram --------------------------------------------------------------
|
||||||
|
|
||||||
function Telemetry::__int_histogram_family%(prefix: string,
|
function Telemetry::__histogram_family%(prefix: string,
|
||||||
name: string,
|
|
||||||
labels: string_vec,
|
|
||||||
bounds: int_vec,
|
|
||||||
helptext: string &default = "Zeek Script Metric",
|
|
||||||
unit: string &default = ""%): opaque of int_histogram_metric_family
|
|
||||||
%{
|
|
||||||
auto lbl_vec = sv_vec(labels->AsVectorVal());
|
|
||||||
auto std_bounds = to_std_vec<int64_t>(bounds);
|
|
||||||
auto hdl = telemetry_mgr->HistogramFamily(sv(prefix), sv(name), lbl_vec,
|
|
||||||
std_bounds, sv(helptext),
|
|
||||||
sv(unit));
|
|
||||||
return zeek::make_intrusive<IntHistogramMetricFamilyVal>(hdl);
|
|
||||||
%}
|
|
||||||
|
|
||||||
function Telemetry::__int_histogram_metric_get_or_add%(family: opaque of int_histogram_metric_family,
|
|
||||||
labels: table_string_of_string%): opaque of int_histogram_metric
|
|
||||||
%{
|
|
||||||
using ResultType = zeek::IntrusivePtr<IntHistogramMetricFamilyVal>;
|
|
||||||
if ( auto ptr = dynamic_cast<zeek::IntHistogramMetricFamilyVal*>(family) )
|
|
||||||
{
|
|
||||||
auto hdl = ptr->GetHandle();
|
|
||||||
auto lbl_map = sv_tbl(labels->AsTableVal());
|
|
||||||
if ( labels_valid(lbl_map, hdl->LabelNames()) )
|
|
||||||
{
|
|
||||||
auto res = hdl->GetOrAdd(lbl_map);
|
|
||||||
return zeek::make_intrusive<IntHistogramMetricVal>(res);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
zeek::reporter->Error("Telemetry::int_histogram_metric_get_or_add: invalid label dimensions.");
|
|
||||||
return ResultType{nullptr};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
zeek::reporter->Error("Telemetry::int_histogram_metric_get_or_add: invalid handle.");
|
|
||||||
return ResultType{nullptr};
|
|
||||||
}
|
|
||||||
%}
|
|
||||||
|
|
||||||
function Telemetry::__int_histogram_observe%(val: opaque of int_histogram_metric,
|
|
||||||
measurement: int%): bool
|
|
||||||
%{
|
|
||||||
return with<IntHistogramMetricVal>(val, "Telemetry::int_histogram_inc: invalid handle.", [measurement](auto hdl) { hdl->Observe(measurement); });
|
|
||||||
%}
|
|
||||||
|
|
||||||
function Telemetry::__int_histogram_sum%(val: opaque of int_histogram_metric%): int
|
|
||||||
%{
|
|
||||||
if ( auto ptr = dynamic_cast<zeek::IntHistogramMetricVal*>(val) )
|
|
||||||
{
|
|
||||||
return zeek::val_mgr->Int(ptr->GetHandle()->Sum());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
zeek::reporter->Error("Telemetry::int_histogram_sum: invalid handle.");
|
|
||||||
return zeek::val_mgr->Int(0);
|
|
||||||
}
|
|
||||||
%}
|
|
||||||
|
|
||||||
# -- DblHistogram --------------------------------------------------------------
|
|
||||||
|
|
||||||
function Telemetry::__dbl_histogram_family%(prefix: string,
|
|
||||||
name: string,
|
name: string,
|
||||||
labels: string_vec,
|
labels: string_vec,
|
||||||
bounds: double_vec,
|
bounds: double_vec,
|
||||||
helptext: string &default = "Zeek Script Metric",
|
helptext: string &default = "Zeek Script Metric",
|
||||||
unit: string &default = ""%): opaque of dbl_histogram_metric_family
|
unit: string &default = ""%): opaque of histogram_metric_family
|
||||||
%{
|
%{
|
||||||
auto lbl_vec = sv_vec(labels->AsVectorVal());
|
auto lbl_vec = sv_vec(labels->AsVectorVal());
|
||||||
auto std_bounds = to_std_vec<double>(bounds);
|
auto std_bounds = to_std_vec<double>(bounds);
|
||||||
auto hdl = telemetry_mgr->HistogramFamily<double>(sv(prefix), sv(name),
|
auto hdl = telemetry_mgr->HistogramFamily(sv(prefix), sv(name), lbl_vec,
|
||||||
lbl_vec, std_bounds,
|
std_bounds, sv(helptext),
|
||||||
sv(helptext), sv(unit));
|
sv(unit));
|
||||||
return zeek::make_intrusive<DblHistogramMetricFamilyVal>(hdl);
|
return zeek::make_intrusive<HistogramMetricFamilyVal>(hdl);
|
||||||
%}
|
%}
|
||||||
|
|
||||||
function Telemetry::__dbl_histogram_metric_get_or_add%(family: opaque of dbl_histogram_metric_family,
|
function Telemetry::__histogram_metric_get_or_add%(family: opaque of histogram_metric_family,
|
||||||
labels: table_string_of_string%): opaque of dbl_histogram_metric
|
labels: table_string_of_string%): opaque of histogram_metric
|
||||||
%{
|
%{
|
||||||
using ResultType = zeek::IntrusivePtr<DblHistogramMetricFamilyVal>;
|
using ResultType = zeek::IntrusivePtr<HistogramMetricFamilyVal>;
|
||||||
if ( auto ptr = dynamic_cast<zeek::DblHistogramMetricFamilyVal*>(family) )
|
if ( auto ptr = dynamic_cast<zeek::HistogramMetricFamilyVal*>(family) )
|
||||||
{
|
{
|
||||||
auto hdl = ptr->GetHandle();
|
auto hdl = ptr->GetHandle();
|
||||||
auto lbl_map = sv_tbl(labels->AsTableVal());
|
auto lbl_map = sv_tbl(labels->AsTableVal());
|
||||||
if ( labels_valid(lbl_map, hdl->LabelNames()) )
|
if ( labels_valid(lbl_map, hdl->LabelNames()) )
|
||||||
{
|
{
|
||||||
auto res = hdl->GetOrAdd(lbl_map);
|
auto res = hdl->GetOrAdd(lbl_map);
|
||||||
return zeek::make_intrusive<DblHistogramMetricVal>(res);
|
return zeek::make_intrusive<HistogramMetricVal>(res);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
zeek::reporter->Error("Telemetry::dbl_histogram_metric_get_or_add: invalid label dimensions.");
|
zeek::reporter->Error("Telemetry::histogram_metric_get_or_add: invalid label dimensions.");
|
||||||
return ResultType{nullptr};
|
return ResultType{nullptr};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
zeek::reporter->Error("Telemetry::dbl_histogram_metric_get_or_add: invalid handle.");
|
zeek::reporter->Error("Telemetry::histogram_metric_get_or_add: invalid handle.");
|
||||||
return ResultType{nullptr};
|
return ResultType{nullptr};
|
||||||
}
|
}
|
||||||
%}
|
%}
|
||||||
|
|
||||||
function Telemetry::__dbl_histogram_observe%(val: opaque of dbl_histogram_metric,
|
function Telemetry::__histogram_observe%(val: opaque of histogram_metric,
|
||||||
measurement: double%): bool
|
measurement: double%): bool
|
||||||
%{
|
%{
|
||||||
return with<DblHistogramMetricVal>(val, "Telemetry::dbl_histogram_inc: invalid handle.", [measurement](auto hdl) { hdl->Observe(measurement); });
|
return with<HistogramMetricVal>(val, "Telemetry::histogram_inc: invalid handle.",
|
||||||
|
[measurement](auto hdl) { hdl->Observe(measurement); });
|
||||||
%}
|
%}
|
||||||
|
|
||||||
function Telemetry::__dbl_histogram_sum%(val: opaque of dbl_histogram_metric%): double
|
function Telemetry::__histogram_sum%(val: opaque of histogram_metric%): double
|
||||||
%{
|
%{
|
||||||
if ( auto ptr = dynamic_cast<zeek::DblHistogramMetricVal*>(val) )
|
if ( auto ptr = dynamic_cast<zeek::HistogramMetricVal*>(val) )
|
||||||
{
|
{
|
||||||
return zeek::make_intrusive<DoubleVal>(ptr->GetHandle()->Sum());
|
return zeek::make_intrusive<zeek::DoubleVal>(ptr->GetHandle()->Sum());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
zeek::reporter->Error("Telemetry::dbl_histogram_sum: invalid handle.");
|
zeek::reporter->Error("Telemetry::histogram_sum: invalid handle.");
|
||||||
return zeek::make_intrusive<DoubleVal>(0.0);
|
return make_intrusive<zeek::DoubleVal>(0.0);
|
||||||
}
|
}
|
||||||
%}
|
%}
|
||||||
|
|
||||||
|
|
|
@ -205,18 +205,12 @@ zeek::OpaqueTypePtr bloomfilter_type;
|
||||||
zeek::OpaqueTypePtr x509_opaque_type;
|
zeek::OpaqueTypePtr x509_opaque_type;
|
||||||
zeek::OpaqueTypePtr ocsp_resp_opaque_type;
|
zeek::OpaqueTypePtr ocsp_resp_opaque_type;
|
||||||
zeek::OpaqueTypePtr paraglob_type;
|
zeek::OpaqueTypePtr paraglob_type;
|
||||||
zeek::OpaqueTypePtr int_counter_metric_type;
|
zeek::OpaqueTypePtr counter_metric_type;
|
||||||
zeek::OpaqueTypePtr int_counter_metric_family_type;
|
zeek::OpaqueTypePtr counter_metric_family_type;
|
||||||
zeek::OpaqueTypePtr dbl_counter_metric_type;
|
zeek::OpaqueTypePtr gauge_metric_type;
|
||||||
zeek::OpaqueTypePtr dbl_counter_metric_family_type;
|
zeek::OpaqueTypePtr gauge_metric_family_type;
|
||||||
zeek::OpaqueTypePtr int_gauge_metric_type;
|
zeek::OpaqueTypePtr histogram_metric_type;
|
||||||
zeek::OpaqueTypePtr int_gauge_metric_family_type;
|
zeek::OpaqueTypePtr histogram_metric_family_type;
|
||||||
zeek::OpaqueTypePtr dbl_gauge_metric_type;
|
|
||||||
zeek::OpaqueTypePtr dbl_gauge_metric_family_type;
|
|
||||||
zeek::OpaqueTypePtr int_histogram_metric_type;
|
|
||||||
zeek::OpaqueTypePtr int_histogram_metric_family_type;
|
|
||||||
zeek::OpaqueTypePtr dbl_histogram_metric_type;
|
|
||||||
zeek::OpaqueTypePtr dbl_histogram_metric_family_type;
|
|
||||||
|
|
||||||
// Keep copy of command line
|
// Keep copy of command line
|
||||||
int zeek::detail::zeek_argc;
|
int zeek::detail::zeek_argc;
|
||||||
|
@ -705,18 +699,12 @@ SetupResult setup(int argc, char** argv, Options* zopts) {
|
||||||
x509_opaque_type = make_intrusive<OpaqueType>("x509");
|
x509_opaque_type = make_intrusive<OpaqueType>("x509");
|
||||||
ocsp_resp_opaque_type = make_intrusive<OpaqueType>("ocsp_resp");
|
ocsp_resp_opaque_type = make_intrusive<OpaqueType>("ocsp_resp");
|
||||||
paraglob_type = make_intrusive<OpaqueType>("paraglob");
|
paraglob_type = make_intrusive<OpaqueType>("paraglob");
|
||||||
int_counter_metric_type = make_intrusive<OpaqueType>("int_counter_metric");
|
counter_metric_type = make_intrusive<OpaqueType>("counter_metric");
|
||||||
int_counter_metric_family_type = make_intrusive<OpaqueType>("int_counter_metric_family");
|
counter_metric_family_type = make_intrusive<OpaqueType>("counter_metric_family");
|
||||||
dbl_counter_metric_type = make_intrusive<OpaqueType>("dbl_counter_metric");
|
gauge_metric_type = make_intrusive<OpaqueType>("gauge_metric");
|
||||||
dbl_counter_metric_family_type = make_intrusive<OpaqueType>("dbl_counter_metric_family");
|
gauge_metric_family_type = make_intrusive<OpaqueType>("gauge_metric_family");
|
||||||
int_gauge_metric_type = make_intrusive<OpaqueType>("int_gauge_metric");
|
histogram_metric_type = make_intrusive<OpaqueType>("histogram_metric");
|
||||||
int_gauge_metric_family_type = make_intrusive<OpaqueType>("int_gauge_metric_family");
|
histogram_metric_family_type = make_intrusive<OpaqueType>("histogram_metric_family");
|
||||||
dbl_gauge_metric_type = make_intrusive<OpaqueType>("dbl_gauge_metric");
|
|
||||||
dbl_gauge_metric_family_type = make_intrusive<OpaqueType>("dbl_gauge_metric_family");
|
|
||||||
int_histogram_metric_type = make_intrusive<OpaqueType>("int_histogram_metric");
|
|
||||||
int_histogram_metric_family_type = make_intrusive<OpaqueType>("int_histogram_metric_family");
|
|
||||||
dbl_histogram_metric_type = make_intrusive<OpaqueType>("dbl_histogram_metric");
|
|
||||||
dbl_histogram_metric_family_type = make_intrusive<OpaqueType>("dbl_histogram_metric_family");
|
|
||||||
log_delay_token_type = make_intrusive<OpaqueType>("LogDelayToken");
|
log_delay_token_type = make_intrusive<OpaqueType>("LogDelayToken");
|
||||||
|
|
||||||
// After spinning up Broker, we have background threads running now. If
|
// After spinning up Broker, we have background threads running now. If
|
||||||
|
|
|
@ -1,25 +1,23 @@
|
||||||
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
### 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 |2|
|
||||||
Telemetry::INT_COUNTER, zeek, zeek_total_sessions_total, [protocol], [tcp], 500.0
|
Telemetry::COUNTER, zeek, zeek_total_sessions_total, [protocol], [tcp], 500.0
|
||||||
count_value, 500
|
Telemetry::GAUGE, zeek, zeek_active_sessions, [protocol], [tcp], 500.0
|
||||||
Telemetry::INT_GAUGE, zeek, zeek_active_sessions, [protocol], [tcp], 500.0
|
|
||||||
count_value, 500
|
|
||||||
### bt* metrics |5|
|
### bt* metrics |5|
|
||||||
Telemetry::DOUBLE_COUNTER, btest, btest_a_test_total, [x, y], [a, b], 1.0
|
Telemetry::COUNTER, btest, btest_a_test_total, [x, y], [a, b], 1.0
|
||||||
Telemetry::DOUBLE_COUNTER, btest, btest_b_test_total, [x, y], [a, b], 10.0
|
Telemetry::COUNTER, btest, btest_b_test_total, [x, y], [a, b], 10.0
|
||||||
Telemetry::DOUBLE_COUNTER, btest, btest_c_test_total, [x, y], [a, b], 200.0
|
Telemetry::COUNTER, btest, btest_c_test_total, [x, y], [a, b], 200.0
|
||||||
Telemetry::DOUBLE_COUNTER, btest, btest_a_test_total, [x, y], [a, c], 2.0
|
Telemetry::COUNTER, btest, btest_a_test_total, [x, y], [a, c], 2.0
|
||||||
Telemetry::DOUBLE_COUNTER, btest, btest_b_test_total, [x, y], [a, c], 20.0
|
Telemetry::COUNTER, btest, btest_b_test_total, [x, y], [a, c], 20.0
|
||||||
### btest_a_metrics |2|
|
### btest_a_metrics |2|
|
||||||
Telemetry::DOUBLE_COUNTER, btest, btest_a_test_total, [x, y], [a, b], 1.0
|
Telemetry::COUNTER, btest, btest_a_test_total, [x, y], [a, b], 1.0
|
||||||
Telemetry::DOUBLE_COUNTER, btest, btest_a_test_total, [x, y], [a, c], 2.0
|
Telemetry::COUNTER, btest, btest_a_test_total, [x, y], [a, c], 2.0
|
||||||
### btest_b_metrics |2|
|
### btest_b_metrics |2|
|
||||||
Telemetry::DOUBLE_COUNTER, btest, btest_b_test_total, [x, y], [a, b], 10.0
|
Telemetry::COUNTER, btest, btest_b_test_total, [x, y], [a, b], 10.0
|
||||||
Telemetry::DOUBLE_COUNTER, btest, btest_b_test_total, [x, y], [a, c], 20.0
|
Telemetry::COUNTER, btest, btest_b_test_total, [x, y], [a, c], 20.0
|
||||||
### system_metrics |3|
|
### system_metrics |3|
|
||||||
Telemetry::DOUBLE_GAUGE, system, system_sensor_temperature_celsius, [name], [cpu0], 43.0
|
Telemetry::GAUGE, system, system_sensor_temperature_celsius, [name], [cpu0], 43.0
|
||||||
Telemetry::DOUBLE_GAUGE, system, system_sensor_temperature_celsius, [name], [cpu1], 44.1
|
Telemetry::GAUGE, system, system_sensor_temperature_celsius, [name], [cpu1], 44.1
|
||||||
Telemetry::DOUBLE_GAUGE, system, system_sensor_temperature_celsius, [name], [cpu3], 42.2
|
Telemetry::GAUGE, system, system_sensor_temperature_celsius, [name], [cpu3], 42.2
|
||||||
### btest_histogram_metrics |2|
|
### btest_histogram_metrics |2|
|
||||||
Telemetry::DOUBLE_HISTOGRAM, btest, btest_sample_histogram, [1.0, 2.0, 3.0, 4.0, 5.0, inf], [dim], [a], [2.0, 2.0, 0.0, 0.0, 0.0, 1.0], 11.5, 5.0
|
Telemetry::HISTOGRAM, btest, btest_sample_histogram, [1.0, 2.0, 3.0, 4.0, 5.0, inf], [dim], [a], [2.0, 2.0, 0.0, 0.0, 0.0, 1.0], 11.5, 5.0
|
||||||
Telemetry::DOUBLE_HISTOGRAM, btest, btest_sample_histogram, [1.0, 2.0, 3.0, 4.0, 5.0, inf], [dim], [b], [1.0, 0.0, 0.0, 0.0, 0.0, 1.0], 7.5, 2.0
|
Telemetry::HISTOGRAM, btest, btest_sample_histogram, [1.0, 2.0, 3.0, 4.0, 5.0, inf], [dim], [b], [1.0, 0.0, 0.0, 0.0, 0.0, 1.0], 7.5, 2.0
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
||||||
Telemetry::DOUBLE_HISTOGRAM, zeek, zeek_connection_duration_seconds
|
Telemetry::HISTOGRAM, zeek, zeek_connection_duration_seconds
|
||||||
[]
|
[]
|
||||||
[]
|
[]
|
||||||
[2.0, 3.0, 4.0, 5.0, 6.0, 10.0, inf]
|
[2.0, 3.0, 4.0, 5.0, 6.0, 10.0, inf]
|
||||||
[0.0, 322.0, 90.0, 5.0, 76.0, 7.0, 0.0]
|
[0.0, 322.0, 90.0, 5.0, 76.0, 7.0, 0.0]
|
||||||
500.0, 1650.264644
|
500.0, 1650.264644
|
||||||
Telemetry::DOUBLE_HISTOGRAM, zeek, zeek_realistic_connection_duration_seconds
|
Telemetry::HISTOGRAM, zeek, zeek_realistic_connection_duration_seconds
|
||||||
[proto]
|
[proto]
|
||||||
[tcp]
|
[tcp]
|
||||||
[0.1, 1.0, 10.0, 30.0, 60.0, 120.0, 300.0, 900.0, 1800.0, inf]
|
[0.1, 1.0, 10.0, 30.0, 60.0, 120.0, 300.0, 900.0, 1800.0, inf]
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
||||||
zeek, zeek_event_handler_invocations_total, [connection_state_remove], 500
|
zeek, zeek_event_handler_invocations_total, [connection_state_remove], 500.0
|
||||||
zeek, zeek_event_handler_invocations_total, [zeek_done], 1
|
zeek, zeek_event_handler_invocations_total, [zeek_done], 1.0
|
||||||
zeek, zeek_event_handler_invocations_total, [zeek_init], 1
|
zeek, zeek_event_handler_invocations_total, [zeek_init], 1.0
|
||||||
|
|
|
@ -42,7 +42,7 @@ XXXXXXXXXX.XXXXXX
|
||||||
{"10.1.1.1":[1,2],"10.2.2.2":[3,5]}
|
{"10.1.1.1":[1,2],"10.2.2.2":[3,5]}
|
||||||
{"1":{"s":"test"}}
|
{"1":{"s":"test"}}
|
||||||
{"opaque_type":"TopkVal"}
|
{"opaque_type":"TopkVal"}
|
||||||
{"_metric":{"opaque_type":"DblGaugeMetricVal"}}
|
{"_metric":{"opaque_type":"GaugeMetricVal"}}
|
||||||
{"_family":{"opaque_type":"DblGaugeMetricFamilyVal"},"_labels":["dim_1"]}
|
{"_family":{"opaque_type":"GaugeMetricFamilyVal"},"_labels":["dim_1"]}
|
||||||
{"_metric":{"opaque_type":"DblCounterMetricVal"}}
|
{"_metric":{"opaque_type":"CounterMetricVal"}}
|
||||||
{"_family":{"opaque_type":"DblCounterMetricFamilyVal"},"_labels":["dim_1"]}
|
{"_family":{"opaque_type":"CounterMetricFamilyVal"},"_labels":["dim_1"]}
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
||||||
cnt1_bar: 1
|
cnt1_bar: 1.000000
|
||||||
cnt2_bar: 42
|
cnt2_bar: 42.000000
|
||||||
cnt3_bar: 1.000000
|
|
||||||
cnt4_bar: 42.000000
|
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
||||||
gg1_bar: 1
|
gg1_bar: 1.000000
|
||||||
gg2_bar: 23
|
gg2_bar: 23.000000
|
||||||
gg3_bar: 1.000000
|
|
||||||
gg4_bar: 23.000000
|
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
||||||
hst1_bar: 12
|
hst1_bar: 6.000000
|
||||||
hst2_bar: 31337
|
hst2_bar: 64.000000
|
||||||
hst3_bar: 6.000000
|
|
||||||
hst4_bar: 64.000000
|
|
||||||
|
|
|
@ -58,9 +58,6 @@ function print_metrics(what: string, metrics: vector of Telemetry::Metric)
|
||||||
{
|
{
|
||||||
local m = metrics[i];
|
local m = metrics[i];
|
||||||
print m$opts$metric_type, m$opts$prefix, m$opts$name, m$opts$labels, m$labels, m$value;
|
print m$opts$metric_type, m$opts$prefix, m$opts$name, m$opts$labels, m$labels, m$value;
|
||||||
|
|
||||||
if (m?$count_value)
|
|
||||||
print "count_value", m$count_value;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,6 @@ event zeek_done() &priority=-100
|
||||||
for ( _, m in ms )
|
for ( _, m in ms )
|
||||||
{
|
{
|
||||||
if ( /zeek_.*|connection_.*/ in cat(m$labels))
|
if ( /zeek_.*|connection_.*/ in cat(m$labels))
|
||||||
print m$opts$prefix, m$opts$name, m$labels, m$count_value;
|
print m$opts$prefix, m$opts$name, m$labels, m$value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,25 +3,16 @@
|
||||||
# @TEST-EXEC: zeek -b %INPUT >output
|
# @TEST-EXEC: zeek -b %INPUT >output
|
||||||
# @TEST-EXEC: btest-diff output
|
# @TEST-EXEC: btest-diff output
|
||||||
|
|
||||||
global cnt1 = Telemetry::__int_counter_family("cnt1", "bar", vector("dim1", "dim2"));
|
global cnt1 = Telemetry::__counter_family("cnt1", "bar", vector("dim1", "dim2"));
|
||||||
global cnt2 = Telemetry::__int_counter_family("cnt2", "bar", vector());
|
global cnt2 = Telemetry::__counter_family("cnt2", "bar", vector());
|
||||||
global cnt3 = Telemetry::__dbl_counter_family("cnt3", "bar", vector("dim1", "dim2"));
|
|
||||||
global cnt4 = Telemetry::__dbl_counter_family("cnt4", "bar", vector());
|
|
||||||
|
|
||||||
event zeek_init()
|
event zeek_init()
|
||||||
{
|
{
|
||||||
local cnt1_bar = Telemetry::__int_counter_metric_get_or_add(cnt1, table(["dim1"] = "val1", ["dim2"] = "val2"));
|
local cnt1_bar = Telemetry::__counter_metric_get_or_add(cnt1, table(["dim1"] = "val1", ["dim2"] = "val2"));
|
||||||
Telemetry::__int_counter_inc(cnt1_bar);
|
Telemetry::__counter_inc(cnt1_bar);
|
||||||
local cnt2_bar = Telemetry::__int_counter_metric_get_or_add(cnt2, table());
|
local cnt2_bar = Telemetry::__counter_metric_get_or_add(cnt2, table());
|
||||||
Telemetry::__int_counter_inc(cnt2_bar);
|
Telemetry::__counter_inc(cnt2_bar);
|
||||||
Telemetry::__int_counter_inc(cnt2_bar, 41);
|
Telemetry::__counter_inc(cnt2_bar, 41);
|
||||||
print fmt("cnt1_bar: %d", Telemetry::__int_counter_value(cnt1_bar));
|
print fmt("cnt1_bar: %f", Telemetry::__counter_value(cnt1_bar));
|
||||||
print fmt("cnt2_bar: %d", Telemetry::__int_counter_value(cnt2_bar));
|
print fmt("cnt2_bar: %f", Telemetry::__counter_value(cnt2_bar));
|
||||||
local cnt3_bar = Telemetry::__dbl_counter_metric_get_or_add(cnt3, table(["dim1"] = "val1", ["dim2"] = "val2"));
|
|
||||||
Telemetry::__dbl_counter_inc(cnt3_bar);
|
|
||||||
local cnt4_bar = Telemetry::__dbl_counter_metric_get_or_add(cnt4, table());
|
|
||||||
Telemetry::__dbl_counter_inc(cnt4_bar);
|
|
||||||
Telemetry::__dbl_counter_inc(cnt4_bar, 41.0);
|
|
||||||
print fmt("cnt3_bar: %f", Telemetry::__dbl_counter_value(cnt3_bar));
|
|
||||||
print fmt("cnt4_bar: %f", Telemetry::__dbl_counter_value(cnt4_bar));
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,30 +3,18 @@
|
||||||
# @TEST-EXEC: zeek -b %INPUT >output
|
# @TEST-EXEC: zeek -b %INPUT >output
|
||||||
# @TEST-EXEC: btest-diff output
|
# @TEST-EXEC: btest-diff output
|
||||||
|
|
||||||
global gg1 = Telemetry::__int_gauge_family("gg1", "bar", vector("dim1", "dim2"));
|
global gg1 = Telemetry::__gauge_family("gg1", "bar", vector("dim1", "dim2"));
|
||||||
global gg2 = Telemetry::__int_gauge_family("gg2", "bar", vector());
|
global gg2 = Telemetry::__gauge_family("gg2", "bar", vector());
|
||||||
global gg3 = Telemetry::__dbl_gauge_family("gg3", "bar", vector("dim1", "dim2"));
|
|
||||||
global gg4 = Telemetry::__dbl_gauge_family("gg4", "bar", vector());
|
|
||||||
|
|
||||||
event zeek_init()
|
event zeek_init()
|
||||||
{
|
{
|
||||||
local gg1_bar = Telemetry::__int_gauge_metric_get_or_add(gg1, table(["dim1"] = "val1", ["dim2"] = "val2"));
|
local gg1_bar = Telemetry::__gauge_metric_get_or_add(gg1, table(["dim1"] = "val1", ["dim2"] = "val2"));
|
||||||
Telemetry::__int_gauge_inc(gg1_bar);
|
Telemetry::__gauge_inc(gg1_bar);
|
||||||
local gg2_bar = Telemetry::__int_gauge_metric_get_or_add(gg2, table());
|
local gg2_bar = Telemetry::__gauge_metric_get_or_add(gg2, table());
|
||||||
Telemetry::__int_gauge_inc(gg2_bar);
|
Telemetry::__gauge_inc(gg2_bar);
|
||||||
Telemetry::__int_gauge_inc(gg2_bar, 41);
|
Telemetry::__gauge_inc(gg2_bar, 41.0);
|
||||||
Telemetry::__int_gauge_dec(gg2_bar);
|
Telemetry::__gauge_dec(gg2_bar);
|
||||||
Telemetry::__int_gauge_dec(gg2_bar, 18);
|
Telemetry::__gauge_dec(gg2_bar, 18.0);
|
||||||
print fmt("gg1_bar: %d", Telemetry::__int_gauge_value(gg1_bar));
|
print fmt("gg1_bar: %f", Telemetry::__gauge_value(gg1_bar));
|
||||||
print fmt("gg2_bar: %d", Telemetry::__int_gauge_value(gg2_bar));
|
print fmt("gg2_bar: %f", Telemetry::__gauge_value(gg2_bar));
|
||||||
local gg3_bar = Telemetry::__dbl_gauge_metric_get_or_add(gg3, table(["dim1"] = "val1", ["dim2"] = "val2"));
|
|
||||||
Telemetry::__dbl_gauge_inc(gg3_bar);
|
|
||||||
local gg4_bar = Telemetry::__dbl_gauge_metric_get_or_add(gg4, table());
|
|
||||||
Telemetry::__dbl_gauge_inc(gg4_bar);
|
|
||||||
Telemetry::__dbl_gauge_inc(gg4_bar, 41.0);
|
|
||||||
Telemetry::__dbl_gauge_dec(gg4_bar);
|
|
||||||
Telemetry::__dbl_gauge_dec(gg4_bar, 18.0);
|
|
||||||
print fmt("gg3_bar: %f", Telemetry::__dbl_gauge_value(gg3_bar));
|
|
||||||
print fmt("gg4_bar: %f", Telemetry::__dbl_gauge_value(gg4_bar));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,28 +3,18 @@
|
||||||
# @TEST-EXEC: zeek -b %INPUT >output
|
# @TEST-EXEC: zeek -b %INPUT >output
|
||||||
# @TEST-EXEC: btest-diff output
|
# @TEST-EXEC: btest-diff output
|
||||||
|
|
||||||
const int_bounds = vector(+10, +20);
|
|
||||||
const dbl_bounds = vector(10.0, 20.0);
|
const dbl_bounds = vector(10.0, 20.0);
|
||||||
|
|
||||||
global hst1 = Telemetry::__int_histogram_family("hst1", "bar", vector("dim1", "dim2"), int_bounds);
|
global hst1 = Telemetry::__histogram_family("hst1", "bar", vector("dim1", "dim2"), dbl_bounds);
|
||||||
global hst2 = Telemetry::__int_histogram_family("hst2", "bar", vector(), int_bounds);
|
global hst2 = Telemetry::__histogram_family("hst2", "bar", vector(), dbl_bounds);
|
||||||
global hst3 = Telemetry::__dbl_histogram_family("hst3", "bar", vector("dim1", "dim2"), dbl_bounds);
|
|
||||||
global hst4 = Telemetry::__dbl_histogram_family("hst4", "bar", vector(), dbl_bounds);
|
|
||||||
|
|
||||||
event zeek_init()
|
event zeek_init()
|
||||||
{
|
{
|
||||||
local hst1_bar = Telemetry::__int_histogram_metric_get_or_add(hst1, table(["dim1"] = "val1", ["dim2"] = "val2"));
|
local hst1_bar = Telemetry::__histogram_metric_get_or_add(hst1, table(["dim1"] = "val1", ["dim2"] = "val2"));
|
||||||
Telemetry::__int_histogram_observe(hst1_bar, 1);
|
Telemetry::__histogram_observe(hst1_bar, 2.0);
|
||||||
Telemetry::__int_histogram_observe(hst1_bar, 11);
|
Telemetry::__histogram_observe(hst1_bar, 4.0);
|
||||||
local hst2_bar = Telemetry::__int_histogram_metric_get_or_add(hst2, table());
|
local hst2_bar = Telemetry::__histogram_metric_get_or_add(hst2, table());
|
||||||
Telemetry::__int_histogram_observe(hst2_bar, 31337);
|
Telemetry::__histogram_observe(hst2_bar, 64.0);
|
||||||
print fmt("hst1_bar: %d", Telemetry::__int_histogram_sum(hst1_bar));
|
print fmt("hst1_bar: %f", Telemetry::__histogram_sum(hst1_bar));
|
||||||
print fmt("hst2_bar: %d", Telemetry::__int_histogram_sum(hst2_bar));
|
print fmt("hst2_bar: %f", Telemetry::__histogram_sum(hst2_bar));
|
||||||
local hst3_bar = Telemetry::__dbl_histogram_metric_get_or_add(hst3, table(["dim1"] = "val1", ["dim2"] = "val2"));
|
|
||||||
Telemetry::__dbl_histogram_observe(hst3_bar, 2.0);
|
|
||||||
Telemetry::__dbl_histogram_observe(hst3_bar, 4.0);
|
|
||||||
local hst4_bar = Telemetry::__dbl_histogram_metric_get_or_add(hst4, table());
|
|
||||||
Telemetry::__dbl_histogram_observe(hst4_bar, 64.0);
|
|
||||||
print fmt("hst3_bar: %f", Telemetry::__dbl_histogram_sum(hst3_bar));
|
|
||||||
print fmt("hst4_bar: %f", Telemetry::__dbl_histogram_sum(hst4_bar));
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue