blob: 0f9ce63f4093be007f8ed0ed19e5228a0f1dc2ce [file] [log] [blame]
khenaidooffe076b2019-01-15 16:08:08 -05001// Copyright 2014 The Prometheus Authors
2// Licensed under the Apache License, Version 2.0 (the "License");
3// you may not use this file except in compliance with the License.
4// You may obtain a copy of the License at
5//
6// http://www.apache.org/licenses/LICENSE-2.0
7//
8// Unless required by applicable law or agreed to in writing, software
9// distributed under the License is distributed on an "AS IS" BASIS,
10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11// See the License for the specific language governing permissions and
12// limitations under the License.
13
14package prometheus
15
16// UntypedOpts is an alias for Opts. See there for doc comments.
17type UntypedOpts Opts
18
19// UntypedFunc works like GaugeFunc but the collected metric is of type
20// "Untyped". UntypedFunc is useful to mirror an external metric of unknown
21// type.
22//
23// To create UntypedFunc instances, use NewUntypedFunc.
24type UntypedFunc interface {
25 Metric
26 Collector
27}
28
29// NewUntypedFunc creates a new UntypedFunc based on the provided
30// UntypedOpts. The value reported is determined by calling the given function
31// from within the Write method. Take into account that metric collection may
32// happen concurrently. If that results in concurrent calls to Write, like in
33// the case where an UntypedFunc is directly registered with Prometheus, the
34// provided function must be concurrency-safe.
35func NewUntypedFunc(opts UntypedOpts, function func() float64) UntypedFunc {
36 return newValueFunc(NewDesc(
37 BuildFQName(opts.Namespace, opts.Subsystem, opts.Name),
38 opts.Help,
39 nil,
40 opts.ConstLabels,
41 ), UntypedValue, function)
42}