Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add a configurable number of workers to prometheus outputs #235

Merged
merged 4 commits into from
Oct 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions docs/user_guide/outputs/prometheus_output.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ outputs:
target-template:
# list of processors to apply on the message before writing
event-processors:
# an integer, sets the number of worker handling messages to be converted into Prometheus metrics
num-workers: 1
# Enables Consul service registration
service-registration:
# Consul server address, default to localhost:8500
Expand Down Expand Up @@ -458,6 +460,13 @@ When caching is enabled, the received gNMI updates are not processed and convert

Once a scrape request is received from `Prometheus`, all the cached gNMI updates are retrieved from the cache, converted to [events](../event_processors/intro.md#the-event-format), the configured processors, if any, are then applied to the whole list of events. Finally, The resulting event are converted into metrics and written back to `Prometheus` within the scrape response.

## Prometheus Output Metrics

When a Prometheus server (gNMI API) is enabled, `gnmic` prometheus output exposes 2 prometheus Gauges:

* `number_of_prometheus_metrics_total`: Number of metrics stored by the prometheus output.
* `number_of_prometheus_cached_metrics_total`: Number of metrics cached by the prometheus output.

## Examples

### **A simple Prometheus output**
Expand Down
14 changes: 14 additions & 0 deletions docs/user_guide/outputs/prometheus_write_output.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ outputs:
target-template:
# list of processors to apply on the message before writing
event-processors:
# an integer, sets the number of worker handling messages to be converted into Prometheus metrics
num-workers: 1
```

`gnmic` creates the prometheus metric name and its labels from the subscription name, the gnmic path and the value name.
Expand Down Expand Up @@ -137,3 +139,15 @@ For the previous example the labels would be:
```bash
{interface_name="1/1/1",subinterface_index=0,source="$routerIP:Port",subscription_name="port-stats"}
```

## Prometheus Write Metrics

When a Prometheus server (gNMI API) is enabled, `gnmic` prometheus write output exposes 4 prometheus counters and 2 prometheus Gauges:

* `number_of_prometheus_write_msgs_sent_success_total`: Number of msgs successfully sent by gnmic prometheus_write output.
* `number_of_prometheus_write_msgs_sent_fail_total`: Number of failed msgs sent by gnmic prometheus_write output.
* `msg_send_duration_ns`: gnmic prometheus_write output send duration in ns.

* `number_of_prometheus_write_metadata_msgs_sent_success_total`: Number of metadata msgs successfully sent by gnmic prometheus_write output.
* `number_of_prometheus_write_metadata_msgs_sent_fail_total`: Number of failed metadata msgs sent by gnmic prometheus_write output.
* `metadata_msg_send_duration_ns`: gnmic prometheus_write output metadata send duration in ns.
11 changes: 7 additions & 4 deletions outputs/prometheus_output/prometheus_output/prometheus_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@ func (p *prometheusOutput) collectFromCache(ch chan<- prometheus.Metric) {
p.logger.Printf("failed to read from cache: %v", err)
return
}
numNotifications := len(notifications)
prometheusNumberOfCachedMetrics.Set(float64(numNotifications))

p.targetsMeta.DeleteExpired()
events := make([]*formatters.EventMsg, 0, len(notifications))
events := make([]*formatters.EventMsg, 0, numNotifications)
for subName, notifs := range notifications {
// build events without processors
for _, notif := range notifs {
Expand All @@ -45,17 +48,17 @@ func (p *prometheusOutput) collectFromCache(ch chan<- prometheus.Metric) {
}
}

if p.Cfg.CacheConfig.Debug {
if p.cfg.CacheConfig.Debug {
p.logger.Printf("got %d events from cache pre processors", len(events))
}
for _, proc := range p.evps {
events = proc.Apply(events...)
}
if p.Cfg.CacheConfig.Debug {
if p.cfg.CacheConfig.Debug {
p.logger.Printf("got %d events from cache post processors", len(events))
}

ctx, cancel := context.WithTimeout(context.Background(), p.Cfg.Timeout)
ctx, cancel := context.WithTimeout(context.Background(), p.cfg.Timeout)
defer cancel()
now := time.Now()
for _, ev := range events {
Expand Down
48 changes: 48 additions & 0 deletions outputs/prometheus_output/prometheus_output/prometheus_metrics.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// © 2023 Nokia.
//
// This code is a Contribution to the gNMIc project (“Work”) made under the Google Software Grant and Corporate Contributor License Agreement (“CLA”) and governed by the Apache License 2.0.
// No other rights or licenses in or to any of Nokia’s intellectual property are granted for any other purpose.
// This code is provided on an “as is” basis without any warranties of any kind.
//
// SPDX-License-Identifier: Apache-2.0

package prometheus_output

import "github.com/prometheus/client_golang/prometheus"

const (
namespace = "gnmic"
subsystem = "prometheus_output"
)

var prometheusNumberOfMetrics = prometheus.NewGauge(
prometheus.GaugeOpts{
Namespace: namespace,
Subsystem: subsystem,
Name: "number_of_prometheus_metrics_total",
Help: "Number of metrics stored by the prometheus output",
})

var prometheusNumberOfCachedMetrics = prometheus.NewGauge(
prometheus.GaugeOpts{
Namespace: namespace,
Subsystem: subsystem,
Name: "number_of_prometheus_cached_metrics_total",
Help: "Number of metrics cached by the prometheus output",
})

func (p *prometheusOutput) initMetrics() {
if p.cfg.CacheConfig == nil {
prometheusNumberOfMetrics.Set(0)
return
}
prometheusNumberOfCachedMetrics.Set(0)
}

func (p *prometheusOutput) registerMetrics(reg *prometheus.Registry) error {
p.initMetrics()
if p.cfg.CacheConfig == nil {
return reg.Register(prometheusNumberOfMetrics)
}
return reg.Register(prometheusNumberOfCachedMetrics)
}
Loading