diff --git a/push.go b/push.go index 4f69bc0..c2f93ab 100644 --- a/push.go +++ b/push.go @@ -52,7 +52,7 @@ func InitPushWithOptions(ctx context.Context, pushURL string, interval time.Dura writeMetrics := func(w io.Writer) { WritePrometheus(w, pushProcessMetrics) } - return initPushWithOptions(ctx, pushURL, interval, writeMetrics, opts) + return InitPushExtWithOptions(ctx, pushURL, interval, writeMetrics, opts) } // InitPushProcessMetrics sets up periodic push for 'process_*' metrics to the given pushURL with the given interval. @@ -115,7 +115,7 @@ func (s *Set) InitPushWithOptions(ctx context.Context, pushURL string, interval writeMetrics := func(w io.Writer) { s.WritePrometheus(w) } - return initPushWithOptions(ctx, pushURL, interval, writeMetrics, opts) + return InitPushExtWithOptions(ctx, pushURL, interval, writeMetrics, opts) } // InitPush sets up periodic push for metrics from s to the given pushURL with the given interval. @@ -158,10 +158,27 @@ func InitPushExt(pushURL string, interval time.Duration, extraLabels string, wri opts := &PushOptions{ ExtraLabels: extraLabels, } - return initPushWithOptions(context.Background(), pushURL, interval, writeMetrics, opts) + return InitPushExtWithOptions(context.Background(), pushURL, interval, writeMetrics, opts) } -func initPushWithOptions(ctx context.Context, pushURL string, interval time.Duration, writeMetrics func(w io.Writer), opts *PushOptions) error { +// InitPushExtWithOptions sets up periodic push for metrics obtained by calling writeMetrics with the given interval. +// +// The writeMetrics callback must write metrics to w in Prometheus text exposition format without timestamps and trailing comments. +// See https://github.com/prometheus/docs/blob/main/content/docs/instrumenting/exposition_formats.md#text-based-format +// +// The periodic push is stopped when the ctx is canceled. +// +// opts may contain additional configuration options if non-nil. +// +// It is recommended pushing metrics to /api/v1/import/prometheus endpoint according to +// https://docs.victoriametrics.com/#how-to-import-data-in-prometheus-exposition-format +// +// It is OK calling InitPushExtWithOptions multiple times with different pushURL - +// in this case metrics are pushed to all the provided pushURL urls. +// +// It is OK calling InitPushExtWithOptions multiple times with different writeMetrics - +// in this case all the metrics generated by writeMetrics callbacks are written to pushURL. +func InitPushExtWithOptions(ctx context.Context, pushURL string, interval time.Duration, writeMetrics func(w io.Writer), opts *PushOptions) error { // validate pushURL pu, err := url.Parse(pushURL) if err != nil {