-
Notifications
You must be signed in to change notification settings - Fork 812
Add Native-Specific Metrics to Prebid Server #930
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
Changes from 11 commits
00f48e3
6d8bf61
654fb2c
aaa9a00
5d7fa8f
bcd4b12
d484938
d5a6afe
d919002
5d76416
7661993
73e7676
569e649
44096ba
63dd6c1
5c6442c
789d60f
36e4a6a
f0d2976
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
package prometheusmetrics | ||
|
||
import ( | ||
"strconv" | ||
"time" | ||
|
||
"github.com/prebid/prebid-server/config" | ||
|
@@ -16,6 +17,7 @@ type Metrics struct { | |
connCounter prometheus.Gauge | ||
connError *prometheus.CounterVec | ||
imps *prometheus.CounterVec | ||
impTypes *prometheus.CounterVec | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it may be best to refactor What we would want to do is loop over the imps, and call We probably want to have a new ImpLabels type to help keep things clean, and make it clear that the imp type booleans only apply to This will also require the influx metrics to be refactored a bit. |
||
requests *prometheus.CounterVec | ||
reqTimer *prometheus.HistogramVec | ||
adaptRequests *prometheus.CounterVec | ||
|
@@ -44,6 +46,8 @@ func NewMetrics(cfg config.PrometheusMetrics) *Metrics { | |
bidLabelNames := []string{"demand_source", "request_type", "browser", "cookie", "adapter_bid", "adapter", "bidtype", "markup_type"} | ||
errorLabelNames := []string{"demand_source", "request_type", "browser", "cookie", "adapter_error", "adapter"} | ||
|
||
impLabelNames := []string{"banner_imps", "video_imps", "audio_imps", "native_imps"} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comparing to the latest master, I see all these label names have been converted to constants ... probably should do the same for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also can drop |
||
|
||
metrics := Metrics{} | ||
metrics.Registry = prometheus.NewRegistry() | ||
metrics.connCounter = newConnCounter(cfg) | ||
|
@@ -58,6 +62,11 @@ func NewMetrics(cfg config.PrometheusMetrics) *Metrics { | |
standardLabelNames, | ||
) | ||
metrics.Registry.MustRegister(metrics.imps) | ||
metrics.impTypes = newCounter(cfg, "imps_types_total", | ||
"Total number of impression types requested through PBS.", | ||
impLabelNames, | ||
) | ||
metrics.Registry.MustRegister(metrics.impTypes) | ||
metrics.requests = newCounter(cfg, "requests_total", | ||
"Total number of requests made to PBS.", | ||
standardLabelNames, | ||
|
@@ -190,6 +199,19 @@ func (me *Metrics) RecordRequest(labels pbsmetrics.Labels) { | |
|
||
func (me *Metrics) RecordImps(labels pbsmetrics.Labels, numImps int) { | ||
me.imps.With(resolveLabels(labels)).Add(float64(numImps)) | ||
var impLabels prometheus.Labels = resolveImpTypeLabels(labels) | ||
if labels.BannerImps > 0 { | ||
me.impTypes.With(impLabels).Add(float64(labels.BannerImps)) | ||
} | ||
if labels.VideoImps > 0 { | ||
me.impTypes.With(impLabels).Add(float64(labels.VideoImps)) | ||
} | ||
if labels.AudioImps > 0 { | ||
me.impTypes.With(impLabels).Add(float64(labels.AudioImps)) | ||
} | ||
if labels.NativeImps > 0 { | ||
me.impTypes.With(impLabels).Add(float64(labels.NativeImps)) | ||
} | ||
} | ||
|
||
func (me *Metrics) RecordRequestTime(labels pbsmetrics.Labels, length time.Duration) { | ||
|
@@ -319,6 +341,15 @@ func resolveUserSyncLabels(userLabels pbsmetrics.UserLabels) prometheus.Labels { | |
} | ||
} | ||
|
||
func resolveImpTypeLabels(labels pbsmetrics.Labels) prometheus.Labels { | ||
return prometheus.Labels{ | ||
"banner_imps": strconv.Itoa(labels.BannerImps), | ||
"video_imps": strconv.Itoa(labels.VideoImps), | ||
"audio_imps": strconv.Itoa(labels.AudioImps), | ||
"native_imps": strconv.Itoa(labels.NativeImps), | ||
} | ||
} | ||
|
||
// initializeTimeSeries precreates all possible metric label values, so there is no locking needed at run time creating new instances | ||
func initializeTimeSeries(m *Metrics) { | ||
// Connection errors | ||
|
Uh oh!
There was an error while loading. Please reload this page.