metrics

command
v2.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 21, 2026 License: MIT Imports: 3 Imported by: 0

README

Metrics Example

This example demonstrates how to monitor the rules engine's performance using the MetricsCollector interface.

How it works

The engine allows you to inject a metrics collector that satisfies the MetricsCollector interface defined in src/types.go.

In this example, we implement a FakePrometheusCollector that simulates how you would integrate with a real monitoring system like Prometheus or OpenTelemetry.

Metrics Tracked:
  • Rule Evaluations: Records the duration and result of every single rule.
  • Engine Runs: Records the total execution time and rule count.
  • Event Executions: Records the duration and result of event handlers.

Running the example

go run docs/examples/metrics/main.go

Integrating with real Prometheus

To use real Prometheus, your implementation would look like this:

type PrometheusCollector struct {
    ruleDuration *prometheus.HistogramVec
    runDuration  *prometheus.Histogram
}

func (c *PrometheusCollector) ObserveRuleEvaluation(name string, result bool, d time.Duration) {
    c.ruleDuration.WithLabelValues(name, strconv.FormatBool(result)).Observe(d.Seconds())
}

// ... and so on

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL