@@ -164,12 +164,24 @@ node's metrics port::
164164 ...
165165
166166To simplify telemetry collection from all nodes in a cluster, Zeek supports
167- `Prometheus HTTP Service Discovery `_ on the manager node. In this approach, the
167+ `Prometheus HTTP Service Discovery `_ on the manager node. Using this approach, the
168168endpoint ``http://<manager>:<manager-metrics-port>/services.json `` returns a
169169JSON data structure that itemizes all metrics endpoints in the
170170cluster. Prometheus scrapers supporting service discovery then proceed to
171- collect telemetry from the listed endpoints in turn. See the `Prometheus Getting
172- Started Guide `_ for additional information.
171+ collect telemetry from the listed endpoints in turn.
172+
173+ The following is an example service discovery scrape config entry within
174+ Prometheus server's ``prometheus.yml `` configuration file::
175+
176+ ...
177+ scrape_configs:
178+ - job_name: zeek-discovery
179+ scrape_interval: 5s
180+ http_sd_configs:
181+ - url: http://localhost:9991/services.json
182+ refresh_interval: 10s
183+
184+ See the `Prometheus Getting Started Guide `_ for additional information.
173185
174186.. note ::
175187
@@ -184,8 +196,8 @@ Started Guide`_ for additional information.
184196
185197If these setups aren't right for your environment, there's the possibility to
186198redefine the options in ``local.zeek `` to something more suitable. For example,
187- the following snippet opens an individual Prometheus port for each Zeek process
188- (relative to the port used in ``cluster-layout.zeek ``) ::
199+ the following snippet selects the metrics port of each Zeek process relative
200+ to the cluster port used in ``cluster-layout.zeek ``::
189201
190202 @load base/frameworks/cluster
191203
@@ -194,15 +206,6 @@ the following snippet opens an individual Prometheus port for each Zeek process
194206
195207 redef Telemetry::metrics_port = my_metrics_port;
196208
197- As a different example, to only change the port from 9911 to 1234 on the manager
198- process, but keep the export and import of metrics enabled, use the following snippet::
199-
200- @load base/frameworks/cluster
201-
202- @ifdef ( Cluster::local_node_type() == Cluster::MANAGER )
203- redef Telemetry::metrics_port = 1234/tcp;
204- @endif
205-
206209
207210Examples of Metrics Application
208211===============================
@@ -276,7 +279,7 @@ directly.
276279 :tab-width: 4
277280
278281
279- For metrics without labels, the metric instances can also be * cached * as global
282+ For metrics without labels, the metric instances can also be cached as global
280283variables directly. The following example counts the number of http requests.
281284
282285.. literalinclude :: telemetry/global-http-counter.zeek
@@ -290,23 +293,39 @@ Sync
290293^^^^
291294
292295In case the scripting overhead of the previous approach is still too high,
293- individual writes (or events) can be tracked in a table and then
294- synchronized / mirrored during execution of the :zeek:see: ` Telemetry::sync `
295- hook.
296+ individual writes (or events) can be tracked in a table or global variable
297+ and then synchronized / mirrored to concrete counter and gauge instances
298+ during execution of the :zeek:see: ` Telemetry::sync ` hook.
296299
297300.. literalinclude :: telemetry/log-writes-sync.zeek
298301 :caption: log-writes-sync.zeek
299302 :language: zeek
300303 :linenos:
301304 :tab-width: 4
302305
303- For the use-case of tracking log writes, this is unlikely to be required, but
304- for updating metrics within high frequency events that otherwise have very
305- low processing overhead it's a valuable approach. Note, metrics will be stale
306- up to the next :zeek:see: `Telemetry::sync_interval ` using this method.
306+ For tracking log writes, this is unlikely to be required (and Zeek exposes
307+ various logging natively through the framework already), but for updating
308+ metrics within high frequency events that otherwise have low script processing
309+ overhead, it's a valuable approach.
310+
311+
312+ .. versionchanged :: 7.1
313+
314+ The :zeek:see: `Telemetry::sync ` hook is invoked on-demand only. Either when
315+ one of the :zeek:see: `Telemetry::collect_metrics `
316+ or :zeek:see: `Telemetry::collect_histogram_metrics ` functions is invoked, or
317+ when querying Prometheus endpoint. It's an error to call either of the
318+ collection BiFs within the :zeek:see: `Telemetry::sync ` hook and results
319+ in a reporter warning.
320+
321+
322+ .. note ::
307323
324+ In versions before Zeek 7.1, :zeek:see: `Telemetry::sync ` was invoked on a
325+ fixed schedule, potentially resulting in stale metrics at collection time,
326+ as well as generating small runtime overhead when metrics are not collected.
308327
309- Table sizes
328+ Table Sizes
310329-----------
311330
312331It can be useful to expose the size of tables as metrics, as they often
0 commit comments