Documentation ¶
Overview ¶
Package metrics provides atomic measures and Prometheus exposition.
Counter, Integer, Real and Histogram are live representations of events. Value updates should be part of the respective implementation. Otherwise, use Sample for captures with a timestamp.
The Must functions deal with registration. Their use is intended for setup during application launch only. All metrics are permanent-the API offers no deletion by design.
Example (Labels) ¶
package main import ( "os" "github.com/pascaldekloe/metrics" ) func main() { // setup demo := metrics.NewRegister() Building := demo.Must2LabelInteger("hitpoints_total", "ground", "building") Arsenal := demo.Must3LabelInteger("hitpoints_total", "ground", "arsenal", "side") demo.MustHelp("hitpoints_total", "Damage Capacity") // measures Building("Genesis Pit", "Civilian Hospital").Set(800) Arsenal("Genesis Pit", "Tech Center", "Nod").Set(500) Arsenal("Genesis Pit", "Cyborg", "Nod").Set(900) Arsenal("Genesis Pit", "Cyborg", "Nod").Add(-596) Building("Genesis Pit", "Civilian Hospital").Add(-490) Arsenal("Genesis Pit", "Cyborg", "Nod").Add(110) // print metrics.SkipTimestamp = true demo.WriteTo(os.Stdout) }
Output: # Prometheus Samples # TYPE hitpoints_total gauge # HELP hitpoints_total Damage Capacity hitpoints_total{building="Civilian Hospital",ground="Genesis Pit"} 310 hitpoints_total{arsenal="Tech Center",ground="Genesis Pit",side="Nod"} 500 hitpoints_total{arsenal="Cyborg",ground="Genesis Pit",side="Nod"} 414
Index ¶
- Variables
- func Must1LabelCounter(name, labelName string) func(labelValue string) *Counter
- func Must1LabelCounterSample(name, labelName string) func(labelValue string) *Sample
- func Must1LabelHistogram(name, labelName string, buckets ...float64) func(labelValue string) *Histogram
- func Must1LabelInteger(name, labelName string) func(labelValue string) *Integer
- func Must1LabelReal(name, labelName string) func(labelValue string) *Real
- func Must1LabelRealSample(name, labelName string) func(labelValue string) *Sample
- func Must2LabelCounter(name, label1Name, label2Name string) func(label1Value, label2Value string) *Counter
- func Must2LabelCounterSample(name, label1Name, label2Name string) func(label1Value, label2Value string) *Sample
- func Must2LabelHistogram(name, label1Name, label2Name string, buckets ...float64) func(label1Value, label2Value string) *Histogram
- func Must2LabelInteger(name, label1Name, label2Name string) func(label1Value, label2Value string) *Integer
- func Must2LabelReal(name, label1Name, label2Name string) func(label1Value, label2Value string) *Real
- func Must2LabelRealSample(name, label1Name, label2Name string) func(label1Value, label2Value string) *Sample
- func Must3LabelCounter(name, label1Name, label2Name, label3Name string) func(label1Value, label2Value, label3Value string) *Counter
- func Must3LabelCounterSample(name, label1Name, label2Name, label3Name string) func(label1Value, label2Value, label3Value string) *Sample
- func Must3LabelInteger(name, label1Name, label2Name, label3Name string) func(label1Value, label2Value, label3Value string) *Integer
- func Must3LabelReal(name, label1Name, label2Name, label3Name string) func(label1Value, label2Value, label3Value string) *Real
- func Must3LabelRealSample(name, label1Name, label2Name, label3Name string) func(label1Value, label2Value, label3Value string) *Sample
- func MustHelp(name, text string)
- func ServeHTTP(resp http.ResponseWriter, req *http.Request)
- func WriteText(w io.Writer)
- func WriteTo(w io.Writer) (n int64, err error)
- type Counter
- type Histogram
- type Integer
- type Real
- type Register
- func (reg *Register) Must1LabelCounter(name, labelName string) func(labelValue string) *Counter
- func (reg *Register) Must1LabelCounterSample(name, labelName string) func(labelValue string) *Sample
- func (reg *Register) Must1LabelHistogram(name, labelName string, buckets ...float64) func(labelValue string) *Histogram
- func (reg *Register) Must1LabelInteger(name, labelName string) func(labelValue string) *Integer
- func (reg *Register) Must1LabelReal(name, labelName string) func(labelValue string) *Real
- func (reg *Register) Must1LabelRealSample(name, labelName string) func(labelValue string) *Sample
- func (reg *Register) Must2LabelCounter(name, label1Name, label2Name string) func(label1Value, label2Value string) *Counter
- func (reg *Register) Must2LabelCounterSample(name, label1Name, label2Name string) func(label1Value, label2Value string) *Sample
- func (reg *Register) Must2LabelHistogram(name, label1Name, label2Name string, buckets ...float64) func(label1Value, label2Value string) *Histogram
- func (reg *Register) Must2LabelInteger(name, label1Name, label2Name string) func(label1Value, label2Value string) *Integer
- func (reg *Register) Must2LabelReal(name, label1Name, label2Name string) func(label1Value, label2Value string) *Real
- func (reg *Register) Must2LabelRealSample(name, label1Name, label2Name string) func(label1Value, label2Value string) *Sample
- func (reg *Register) Must3LabelCounter(name, label1Name, label2Name, label3Name string) func(label1Value, label2Value, label3Value string) *Counter
- func (reg *Register) Must3LabelCounterSample(name, label1Name, label2Name, label3Name string) func(label1Value, label2Value, label3Value string) *Sample
- func (reg *Register) Must3LabelInteger(name, label1Name, label2Name, label3Name string) func(label1Value, label2Value, label3Value string) *Integer
- func (reg *Register) Must3LabelReal(name, label1Name, label2Name, label3Name string) func(label1Value, label2Value, label3Value string) *Real
- func (reg *Register) Must3LabelRealSample(name, label1Name, label2Name, label3Name string) func(label1Value, label2Value, label3Value string) *Sample
- func (reg *Register) MustCounter(name, help string) *Counter
- func (reg *Register) MustCounterSample(name, help string) *Sample
- func (reg *Register) MustHelp(name, text string)
- func (reg *Register) MustHistogram(name, help string, buckets ...float64) *Histogram
- func (reg *Register) MustInteger(name, help string) *Integer
- func (reg *Register) MustReal(name, help string) *Real
- func (reg *Register) MustRealSample(name, help string) *Sample
- func (reg *Register) ServeHTTP(resp http.ResponseWriter, req *http.Request)
- func (reg *Register) WriteText(w io.Writer)
- func (reg *Register) WriteTo(w io.Writer) (n int64, err error)
- type Sample
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var SkipTimestamp = false
SkipTimestamp controls time inclusion with sample serialisation. When false, then live running values are stamped with the current time and Samples provide their own time.
Functions ¶
func Must1LabelCounter ¶
Must1LabelCounter returns a function which registers a dedicated Counter for each unique label combination. Multiple goroutines may invoke the returned simultaneously. Remember that each Counter represents a new time series, which can dramatically increase the amount of data stored.
Must panics on any of the following: (1) name in use as another metric type, (2) name doesn't match regular expression [a-zA-Z_:][a-zA-Z0-9_:]*, (3) labelName does not match regular expression [a-zA-Z_][a-zA-Z0-9_]* or (4) labelName is already in use.
func Must1LabelCounterSample ¶
Must1LabelCounterSample returns a function which registers a dedicated Sample for each unique label combination. Multiple goroutines may invoke the returned simultaneously. Remember that each Sample represents a new time series, which can dramatically increase the amount of data stored.
Must panics on any of the following: (1) name in use as another metric type, (2) name doesn't match regular expression [a-zA-Z_:][a-zA-Z0-9_:]*, (3) labelName does not match regular expression [a-zA-Z_][a-zA-Z0-9_]* or (4) labelName is already in use.
func Must1LabelHistogram ¶
func Must1LabelHistogram(name, labelName string, buckets ...float64) func(labelValue string) *Histogram
Must1LabelHistogram returns a function which registers a dedicated Histogram for each unique label combination. Multiple goroutines may invoke the returned simultaneously. Remember that each Histogram represents a new time series, which can dramatically increase the amount of data stored.
Must panics on any of the following: (1) name in use as another metric type, (2) name doesn't match regular expression [a-zA-Z_:][a-zA-Z0-9_:]*, (3) labelName does not match regular expression [a-zA-Z_][a-zA-Z0-9_]* or (4) labelName is already in use.
Buckets are defined as upper boundary values, with positive infinity implied when absent. Any ∞ or not-a-number (NaN) value is ignored.
func Must1LabelInteger ¶
Must1LabelInteger returns a function which registers a dedicated Integer for each unique label combination. Multiple goroutines may invoke the returned simultaneously. Remember that each Integer represents a new time series, which can dramatically increase the amount of data stored.
Must panics on any of the following: (1) name in use as another metric type, (2) name doesn't match regular expression [a-zA-Z_:][a-zA-Z0-9_:]*, (3) labelName does not match regular expression [a-zA-Z_][a-zA-Z0-9_]* or (4) labelName is already in use.
func Must1LabelReal ¶
Must1LabelReal returns a function which registers a dedicated Real for each unique label combination. Multiple goroutines may invoke the returned simultaneously. Remember that each Real represents a new time series, which can dramatically increase the amount of data stored.
Must panics on any of the following: (1) name in use as another metric type, (2) name doesn't match regular expression [a-zA-Z_:][a-zA-Z0-9_:]*, (3) labelName does not match regular expression [a-zA-Z_][a-zA-Z0-9_]* or (4) labelName is already in use.
func Must1LabelRealSample ¶
Must1LabelRealSample returns a function which registers a dedicated Sample for each unique label combination. Multiple goroutines may invoke the returned simultaneously. Remember that each Sample represents a new time series, which can dramatically increase the amount of data stored.
Must panics on any of the following: (1) name in use as another metric type, (2) name doesn't match regular expression [a-zA-Z_:][a-zA-Z0-9_:]*, (3) labelName does not match regular expression [a-zA-Z_][a-zA-Z0-9_]* or (4) labelName is already in use.
func Must2LabelCounter ¶
func Must2LabelCounter(name, label1Name, label2Name string) func(label1Value, label2Value string) *Counter
Must2LabelCounter returns a function which registers a dedicated Counter for each unique label combination. Multiple goroutines may invoke the returned simultaneously. Remember that each Counter represents a new time series, which can dramatically increase the amount of data stored.
Must panics on any of the following: (1) name in use as another metric type, (2) name doesn't match regular expression [a-zA-Z_:][a-zA-Z0-9_:]*, (3) label names don't match regular expression [a-zA-Z_][a-zA-Z0-9_]* or (4) label names are already in use.
func Must2LabelCounterSample ¶
func Must2LabelCounterSample(name, label1Name, label2Name string) func(label1Value, label2Value string) *Sample
Must2LabelCounterSample returns a function which registers a dedicated Sample for each unique label combination. Multiple goroutines may invoke the returned simultaneously. Remember that each Sample represents a new time series, which can dramatically increase the amount of data stored.
Must panics on any of the following: (1) name in use as another metric type, (2) name doesn't match regular expression [a-zA-Z_:][a-zA-Z0-9_:]*, (3) label names don't match regular expression [a-zA-Z_][a-zA-Z0-9_]* or (4) label names are already in use.
func Must2LabelHistogram ¶
func Must2LabelHistogram(name, label1Name, label2Name string, buckets ...float64) func(label1Value, label2Value string) *Histogram
Must2LabelHistogram returns a function which registers a dedicated Histogram for each unique label combination. Multiple goroutines may invoke the returned simultaneously. Remember that each Histogram represents a new time series, which can dramatically increase the amount of data stored.
Must panics on any of the following: (1) name in use as another metric type, (2) name doesn't match regular expression [a-zA-Z_:][a-zA-Z0-9_:]*, (3) label names don't match regular expression [a-zA-Z_][a-zA-Z0-9_]* or (4) label names are already in use.
Buckets are defined as upper boundary values, with positive infinity implied when absent. Any ∞ or not-a-number (NaN) value is ignored.
func Must2LabelInteger ¶
func Must2LabelInteger(name, label1Name, label2Name string) func(label1Value, label2Value string) *Integer
Must2LabelInteger returns a function which registers a dedicated Integer for each unique label combination. Multiple goroutines may invoke the returned simultaneously. Remember that each Integer represents a new time series, which can dramatically increase the amount of data stored.
Must panics on any of the following: (1) name in use as another metric type, (2) name doesn't match regular expression [a-zA-Z_:][a-zA-Z0-9_:]*, (3) label names don't match regular expression [a-zA-Z_][a-zA-Z0-9_]* or (4) label names are already in use.
func Must2LabelReal ¶
func Must2LabelReal(name, label1Name, label2Name string) func(label1Value, label2Value string) *Real
Must2LabelReal returns a function which registers a dedicated Real for each unique label combination. Multiple goroutines may invoke the returned simultaneously. Remember that each Real represents a new time series, which can dramatically increase the amount of data stored.
Must panics on any of the following: (1) name in use as another metric type, (2) name doesn't match regular expression [a-zA-Z_:][a-zA-Z0-9_:]*, (3) label names don't match regular expression [a-zA-Z_][a-zA-Z0-9_]* or (4) label names are already in use.
func Must2LabelRealSample ¶
func Must2LabelRealSample(name, label1Name, label2Name string) func(label1Value, label2Value string) *Sample
Must2LabelRealSample returns a function which registers a dedicated Sample for each unique label combination. Multiple goroutines may invoke the returned simultaneously. Remember that each Sample represents a new time series, which can dramatically increase the amount of data stored.
Must panics on any of the following: (1) name in use as another metric type, (2) name doesn't match regular expression [a-zA-Z_:][a-zA-Z0-9_:]*, (3) label names don't match regular expression [a-zA-Z_][a-zA-Z0-9_]* or (4) label names are already in use.
func Must3LabelCounter ¶
func Must3LabelCounter(name, label1Name, label2Name, label3Name string) func(label1Value, label2Value, label3Value string) *Counter
Must3LabelCounter returns a function which registers a dedicated Counter for each unique label combination. Multiple goroutines may invoke the returned simultaneously. Remember that each Counter represents a new time series, which can dramatically increase the amount of data stored.
Must panics on any of the following: (1) name in use as another metric type, (2) name doesn't match regular expression [a-zA-Z_:][a-zA-Z0-9_:]*, (3) label names don't match regular expression [a-zA-Z_][a-zA-Z0-9_]* or (4) label names are already in use.
func Must3LabelCounterSample ¶
func Must3LabelCounterSample(name, label1Name, label2Name, label3Name string) func(label1Value, label2Value, label3Value string) *Sample
Must3LabelCounterSample returns a function which registers a dedicated Sample for each unique label combination. Multiple goroutines may invoke the returned simultaneously. Remember that each Sample represents a new time series, which can dramatically increase the amount of data stored.
Must panics on any of the following: (1) name in use as another metric type, (2) name doesn't match regular expression [a-zA-Z_:][a-zA-Z0-9_:]*, (3) label names don't match regular expression [a-zA-Z_][a-zA-Z0-9_]* or (4) label names are already in use.
func Must3LabelInteger ¶
func Must3LabelInteger(name, label1Name, label2Name, label3Name string) func(label1Value, label2Value, label3Value string) *Integer
Must3LabelInteger returns a function which registers a dedicated Integer for each unique label combination. Multiple goroutines may invoke the returned simultaneously. Remember that each Integer represents a new time series, which can dramatically increase the amount of data stored.
Must panics on any of the following: (1) name in use as another metric type, (2) name doesn't match regular expression [a-zA-Z_:][a-zA-Z0-9_:]*, (3) label names don't match regular expression [a-zA-Z_][a-zA-Z0-9_]* or (4) label names are already in use.
func Must3LabelReal ¶
func Must3LabelReal(name, label1Name, label2Name, label3Name string) func(label1Value, label2Value, label3Value string) *Real
Must3LabelReal returns a function which registers a dedicated Real for each unique label combination. Multiple goroutines may invoke the returned simultaneously. Remember that each Real represents a new time series, which can dramatically increase the amount of data stored.
Must panics on any of the following: (1) name in use as another metric type, (2) name doesn't match regular expression [a-zA-Z_:][a-zA-Z0-9_:]*, (3) label names don't match regular expression [a-zA-Z_][a-zA-Z0-9_]* or (4) label names are already in use.
func Must3LabelRealSample ¶
func Must3LabelRealSample(name, label1Name, label2Name, label3Name string) func(label1Value, label2Value, label3Value string) *Sample
Must3LabelRealSample returns a function which registers a dedicated Sample for each unique label combination. Multiple goroutines may invoke the returned simultaneously. Remember that each Sample represents a new time series, which can dramatically increase the amount of data stored.
Must panics on any of the following: (1) name in use as another metric type, (2) name doesn't match regular expression [a-zA-Z_:][a-zA-Z0-9_:]*, (3) label names don't match regular expression [a-zA-Z_][a-zA-Z0-9_]* or (4) label names are already in use.
func MustHelp ¶
func MustHelp(name, text string)
MustHelp sets the comment for the metric name. Any previous text is replaced. The function panics when name is not in use.
func ServeHTTP ¶
func ServeHTTP(resp http.ResponseWriter, req *http.Request)
ServeHTTP provides a sample of each metric as an http.HandlerFunc.
Types ¶
type Counter ¶
type Counter struct {
// contains filtered or unexported fields
}
Counter is a cumulative metric that represents a single monotonically increasing counter whose value can only increase or be reset to zero on restart. The default/initial value is zero. Multiple goroutines may invoke methods on a Counter simultaneously.
func MustCounter ¶
MustCounter registers a new Counter. Registration panics when name was registered before, or when name doesn't match regular expression [a-zA-Z_:][a-zA-Z0-9_:]*. Help is an optional comment text.
type Histogram ¶
type Histogram struct { // Upper value for each bucket, sorted, +Inf omitted. // This field is read-only. BucketBounds []float64 // contains filtered or unexported fields }
Histogram samples observations and counts them in configurable buckets. It also provides a sum of all observed values. Multiple goroutines may invoke methods on a Histogram simultaneously.
Example ¶
package main import ( "os" "github.com/pascaldekloe/metrics" ) func main() { // setup demo := metrics.NewRegister() Duration := demo.Must2LabelHistogram("http_latency_seconds", "method", "status", 0.001, 0.005, 0.025, 0.125) demo.MustHelp("http_latency_seconds", "Time from request initiation until response body retrieval.") // measures Duration("GET", "2xx").Add(0.076875) Duration("GET", "3xx").Add(0.000141) Duration("OPTIONS", "2xx").Add(0.000009) Duration("GET", "2xx").Add(0.002277) Duration("GET", "2xx").Add(0.001871) Duration("GET", "2xx").Add(0.002378) // print metrics.SkipTimestamp = true demo.WriteTo(os.Stdout) }
Output: # Prometheus Samples # TYPE http_latency_seconds histogram # HELP http_latency_seconds Time from request initiation until response body retrieval. http_latency_seconds_count{method="GET",status="2xx"} 4 http_latency_seconds{le="0.001",method="GET",status="2xx"} 0 http_latency_seconds{le="0.005",method="GET",status="2xx"} 3 http_latency_seconds{le="0.025",method="GET",status="2xx"} 3 http_latency_seconds{le="0.125",method="GET",status="2xx"} 4 http_latency_seconds{le="+Inf",method="GET",status="2xx"} 4 http_latency_seconds_sum{method="GET",status="2xx"} 0.083401 http_latency_seconds_count{method="GET",status="3xx"} 1 http_latency_seconds{le="0.001",method="GET",status="3xx"} 1 http_latency_seconds{le="0.005",method="GET",status="3xx"} 1 http_latency_seconds{le="0.025",method="GET",status="3xx"} 1 http_latency_seconds{le="0.125",method="GET",status="3xx"} 1 http_latency_seconds{le="+Inf",method="GET",status="3xx"} 1 http_latency_seconds_sum{method="GET",status="3xx"} 0.000141 http_latency_seconds_count{method="OPTIONS",status="2xx"} 1 http_latency_seconds{le="0.001",method="OPTIONS",status="2xx"} 1 http_latency_seconds{le="0.005",method="OPTIONS",status="2xx"} 1 http_latency_seconds{le="0.025",method="OPTIONS",status="2xx"} 1 http_latency_seconds{le="0.125",method="OPTIONS",status="2xx"} 1 http_latency_seconds{le="+Inf",method="OPTIONS",status="2xx"} 1 http_latency_seconds_sum{method="OPTIONS",status="2xx"} 9e-06
func MustHistogram ¶
MustHistogram registers a new Histogram. Registration panics when name was registered before, or when name doesn't match regular expression [a-zA-Z_:][a-zA-Z0-9_:]*. Help is an optional comment text.
Buckets are defined as upper boundary values, with positive infinity implied when absent. Any ∞ or not-a-number (NaN) value is ignored.
func (*Histogram) AddSince ¶
AddSince applies the number of seconds since start to the countings. The following one-liner measures the execution time of a function.
defer DurationHistogram.AddSince(time.Now())
func (*Histogram) Get ¶
Get appends the observation counts for each Histogram.BucketBounds to a and returns the resulting slice (as buckets). The count return has the total number of observations, a.k.a. the positive inifinity bucket.
type Integer ¶
type Integer struct {
// contains filtered or unexported fields
}
Integer gauge is a metric that represents a single numerical value that can arbitrarily go up and down. The default/initial value is zero. Multiple goroutines may invoke methods on a Integer simultaneously.
func MustInteger ¶
MustInteger registers a new gauge. Registration panics when name was registered before, or when name doesn't match regular expression [a-zA-Z_:][a-zA-Z0-9_:]*. Help is an optional comment text.
func (*Integer) Add ¶
Add summs the current value with n. Note that n can be negative (for subtraction).
type Real ¶
type Real struct {
// contains filtered or unexported fields
}
Real gauge is a metric that represents a single numerical value that can arbitrarily go up and down. The default/initial value is zero. Multiple goroutines may invoke methods on a Real simultaneously.
func MustReal ¶
MustReal registers a new gauge. Registration panics when name was registered before, or when name doesn't match regular expression [a-zA-Z_:][a-zA-Z0-9_:]*. Help is an optional comment text.
func (*Real) SetSeconds ¶ added in v1.4.0
SetSeconds defines the current value.
type Register ¶
type Register struct {
// contains filtered or unexported fields
}
Register is a metric bundle.
func NewRegister ¶
func NewRegister() *Register
NewRegister returns an empty metric bundle. The corresponding functions of each Register method operate on the (hidden) default instance.
func (*Register) Must1LabelCounter ¶
Must1LabelCounter returns a function which registers a dedicated Counter for each unique label combination. Multiple goroutines may invoke the returned simultaneously. Remember that each Counter represents a new time series, which can dramatically increase the amount of data stored.
Must panics on any of the following: (1) name in use as another metric type, (2) name doesn't match regular expression [a-zA-Z_:][a-zA-Z0-9_:]*, (3) labelName does not match regular expression [a-zA-Z_][a-zA-Z0-9_]* or (4) labelName is already in use.
func (*Register) Must1LabelCounterSample ¶
func (reg *Register) Must1LabelCounterSample(name, labelName string) func(labelValue string) *Sample
Must1LabelCounterSample returns a function which registers a dedicated Sample for each unique label combination. Multiple goroutines may invoke the returned simultaneously. Remember that each Sample represents a new time series, which can dramatically increase the amount of data stored.
Must panics on any of the following: (1) name in use as another metric type, (2) name doesn't match regular expression [a-zA-Z_:][a-zA-Z0-9_:]*, (3) labelName does not match regular expression [a-zA-Z_][a-zA-Z0-9_]* or (4) labelName is already in use.
func (*Register) Must1LabelHistogram ¶
func (reg *Register) Must1LabelHistogram(name, labelName string, buckets ...float64) func(labelValue string) *Histogram
Must1LabelHistogram returns a function which registers a dedicated Histogram for each unique label combination. Multiple goroutines may invoke the returned simultaneously. Remember that each Histogram represents a new time series, which can dramatically increase the amount of data stored.
Must panics on any of the following: (1) name in use as another metric type, (2) name doesn't match regular expression [a-zA-Z_:][a-zA-Z0-9_:]*, (3) labelName does not match regular expression [a-zA-Z_][a-zA-Z0-9_]* or (4) labelName is already in use.
Buckets are defined as upper boundary values, with positive infinity implied when absent. Any ∞ or not-a-number (NaN) value is ignored.
func (*Register) Must1LabelInteger ¶
Must1LabelInteger returns a function which registers a dedicated Integer for each unique label combination. Multiple goroutines may invoke the returned simultaneously. Remember that each Integer represents a new time series, which can dramatically increase the amount of data stored.
Must panics on any of the following: (1) name in use as another metric type, (2) name doesn't match regular expression [a-zA-Z_:][a-zA-Z0-9_:]*, (3) labelName does not match regular expression [a-zA-Z_][a-zA-Z0-9_]* or (4) labelName is already in use.
func (*Register) Must1LabelReal ¶
Must1LabelReal returns a function which registers a dedicated Real for each unique label combination. Multiple goroutines may invoke the returned simultaneously. Remember that each Real represents a new time series, which can dramatically increase the amount of data stored.
Must panics on any of the following: (1) name in use as another metric type, (2) name doesn't match regular expression [a-zA-Z_:][a-zA-Z0-9_:]*, (3) labelName does not match regular expression [a-zA-Z_][a-zA-Z0-9_]* or (4) labelName is already in use.
func (*Register) Must1LabelRealSample ¶
Must1LabelRealSample returns a function which registers a dedicated Sample for each unique label combination. Multiple goroutines may invoke the returned simultaneously. Remember that each Sample represents a new time series, which can dramatically increase the amount of data stored.
Must panics on any of the following: (1) name in use as another metric type, (2) name doesn't match regular expression [a-zA-Z_:][a-zA-Z0-9_:]*, (3) labelName does not match regular expression [a-zA-Z_][a-zA-Z0-9_]* or (4) labelName is already in use.
func (*Register) Must2LabelCounter ¶
func (reg *Register) Must2LabelCounter(name, label1Name, label2Name string) func(label1Value, label2Value string) *Counter
Must2LabelCounter returns a function which registers a dedicated Counter for each unique label combination. Multiple goroutines may invoke the returned simultaneously. Remember that each Counter represents a new time series, which can dramatically increase the amount of data stored.
Must panics on any of the following: (1) name in use as another metric type, (2) name doesn't match regular expression [a-zA-Z_:][a-zA-Z0-9_:]*, (3) label names don't match regular expression [a-zA-Z_][a-zA-Z0-9_]* or (4) label names are already in use.
func (*Register) Must2LabelCounterSample ¶
func (reg *Register) Must2LabelCounterSample(name, label1Name, label2Name string) func(label1Value, label2Value string) *Sample
Must2LabelCounterSample returns a function which registers a dedicated Sample for each unique label combination. Multiple goroutines may invoke the returned simultaneously. Remember that each Sample represents a new time series, which can dramatically increase the amount of data stored.
Must panics on any of the following: (1) name in use as another metric type, (2) name doesn't match regular expression [a-zA-Z_:][a-zA-Z0-9_:]*, (3) label names don't match regular expression [a-zA-Z_][a-zA-Z0-9_]* or (4) label names are already in use.
func (*Register) Must2LabelHistogram ¶
func (reg *Register) Must2LabelHistogram(name, label1Name, label2Name string, buckets ...float64) func(label1Value, label2Value string) *Histogram
Must2LabelHistogram returns a function which registers a dedicated Histogram for each unique label combination. Multiple goroutines may invoke the returned simultaneously. Remember that each Histogram represents a new time series, which can dramatically increase the amount of data stored.
Must panics on any of the following: (1) name in use as another metric type, (2) name doesn't match regular expression [a-zA-Z_:][a-zA-Z0-9_:]*, (3) label names don't match regular expression [a-zA-Z_][a-zA-Z0-9_]* or (4) label names are already in use.
Buckets are defined as upper boundary values, with positive infinity implied when absent. Any ∞ or not-a-number (NaN) value is ignored.
func (*Register) Must2LabelInteger ¶
func (reg *Register) Must2LabelInteger(name, label1Name, label2Name string) func(label1Value, label2Value string) *Integer
Must2LabelInteger returns a function which registers a dedicated Integer for each unique label combination. Multiple goroutines may invoke the returned simultaneously. Remember that each Integer represents a new time series, which can dramatically increase the amount of data stored.
Must panics on any of the following: (1) name in use as another metric type, (2) name doesn't match regular expression [a-zA-Z_:][a-zA-Z0-9_:]*, (3) label names don't match regular expression [a-zA-Z_][a-zA-Z0-9_]* or (4) label names are already in use.
func (*Register) Must2LabelReal ¶
func (reg *Register) Must2LabelReal(name, label1Name, label2Name string) func(label1Value, label2Value string) *Real
Must2LabelReal returns a function which registers a dedicated Real for each unique label combination. Multiple goroutines may invoke the returned simultaneously. Remember that each Real represents a new time series, which can dramatically increase the amount of data stored.
Must panics on any of the following: (1) name in use as another metric type, (2) name doesn't match regular expression [a-zA-Z_:][a-zA-Z0-9_:]*, (3) label names don't match regular expression [a-zA-Z_][a-zA-Z0-9_]* or (4) label names are already in use.
func (*Register) Must2LabelRealSample ¶
func (reg *Register) Must2LabelRealSample(name, label1Name, label2Name string) func(label1Value, label2Value string) *Sample
Must2LabelRealSample returns a function which registers a dedicated Sample for each unique label combination. Multiple goroutines may invoke the returned simultaneously. Remember that each Sample represents a new time series, which can dramatically increase the amount of data stored.
Must panics on any of the following: (1) name in use as another metric type, (2) name doesn't match regular expression [a-zA-Z_:][a-zA-Z0-9_:]*, (3) label names don't match regular expression [a-zA-Z_][a-zA-Z0-9_]* or (4) label names are already in use.
func (*Register) Must3LabelCounter ¶
func (reg *Register) Must3LabelCounter(name, label1Name, label2Name, label3Name string) func(label1Value, label2Value, label3Value string) *Counter
Must3LabelCounter returns a function which registers a dedicated Counter for each unique label combination. Multiple goroutines may invoke the returned simultaneously. Remember that each Counter represents a new time series, which can dramatically increase the amount of data stored.
Must panics on any of the following: (1) name in use as another metric type, (2) name doesn't match regular expression [a-zA-Z_:][a-zA-Z0-9_:]*, (3) label names don't match regular expression [a-zA-Z_][a-zA-Z0-9_]* or (4) label names are already in use.
func (*Register) Must3LabelCounterSample ¶
func (reg *Register) Must3LabelCounterSample(name, label1Name, label2Name, label3Name string) func(label1Value, label2Value, label3Value string) *Sample
Must3LabelCounterSample returns a function which registers a dedicated Sample for each unique label combination. Multiple goroutines may invoke the returned simultaneously. Remember that each Sample represents a new time series, which can dramatically increase the amount of data stored.
Must panics on any of the following: (1) name in use as another metric type, (2) name doesn't match regular expression [a-zA-Z_:][a-zA-Z0-9_:]*, (3) label names don't match regular expression [a-zA-Z_][a-zA-Z0-9_]* or (4) label names are already in use.
func (*Register) Must3LabelInteger ¶
func (reg *Register) Must3LabelInteger(name, label1Name, label2Name, label3Name string) func(label1Value, label2Value, label3Value string) *Integer
Must3LabelInteger returns a function which registers a dedicated Integer for each unique label combination. Multiple goroutines may invoke the returned simultaneously. Remember that each Integer represents a new time series, which can dramatically increase the amount of data stored.
Must panics on any of the following: (1) name in use as another metric type, (2) name doesn't match regular expression [a-zA-Z_:][a-zA-Z0-9_:]*, (3) label names don't match regular expression [a-zA-Z_][a-zA-Z0-9_]* or (4) label names are already in use.
func (*Register) Must3LabelReal ¶
func (reg *Register) Must3LabelReal(name, label1Name, label2Name, label3Name string) func(label1Value, label2Value, label3Value string) *Real
Must3LabelReal returns a function which registers a dedicated Real for each unique label combination. Multiple goroutines may invoke the returned simultaneously. Remember that each Real represents a new time series, which can dramatically increase the amount of data stored.
Must panics on any of the following: (1) name in use as another metric type, (2) name doesn't match regular expression [a-zA-Z_:][a-zA-Z0-9_:]*, (3) label names don't match regular expression [a-zA-Z_][a-zA-Z0-9_]* or (4) label names are already in use.
func (*Register) Must3LabelRealSample ¶
func (reg *Register) Must3LabelRealSample(name, label1Name, label2Name, label3Name string) func(label1Value, label2Value, label3Value string) *Sample
Must3LabelRealSample returns a function which registers a dedicated Sample for each unique label combination. Multiple goroutines may invoke the returned simultaneously. Remember that each Sample represents a new time series, which can dramatically increase the amount of data stored.
Must panics on any of the following: (1) name in use as another metric type, (2) name doesn't match regular expression [a-zA-Z_:][a-zA-Z0-9_:]*, (3) label names don't match regular expression [a-zA-Z_][a-zA-Z0-9_]* or (4) label names are already in use.
func (*Register) MustCounter ¶
MustCounter registers a new Counter. Registration panics when name was registered before, or when name doesn't match regular expression [a-zA-Z_:][a-zA-Z0-9_:]*. Help is an optional comment text.
func (*Register) MustCounterSample ¶
MustCounterSample registers a new Sample. Registration panics when name was registered before, or when name doesn't match regular expression [a-zA-Z_:][a-zA-Z0-9_:]*. Help is an optional comment text.
func (*Register) MustHelp ¶
MustHelp sets the comment for the metric name. Any previous text is replaced. The function panics when name is not in use.
func (*Register) MustHistogram ¶
MustHistogram registers a new Histogram. Registration panics when name was registered before, or when name doesn't match regular expression [a-zA-Z_:][a-zA-Z0-9_:]*. Help is an optional comment text.
Buckets are defined as upper boundary values, with positive infinity implied when absent. Any ∞ or not-a-number (NaN) value is ignored.
func (*Register) MustInteger ¶
MustInteger registers a new gauge. Registration panics when name was registered before, or when name doesn't match regular expression [a-zA-Z_:][a-zA-Z0-9_:]*. Help is an optional comment text.
func (*Register) MustReal ¶
MustReal registers a new gauge. Registration panics when name was registered before, or when name doesn't match regular expression [a-zA-Z_:][a-zA-Z0-9_:]*. Help is an optional comment text.
func (*Register) MustRealSample ¶
MustRealSample registers a new Sample. Registration panics when name was registered before, or when name doesn't match regular expression [a-zA-Z_:][a-zA-Z0-9_:]*. Help is an optional comment text.
func (*Register) ServeHTTP ¶
func (reg *Register) ServeHTTP(resp http.ResponseWriter, req *http.Request)
ServeHTTP provides a sample of each metric as an http.Handler.
type Sample ¶
type Sample struct {
// contains filtered or unexported fields
}
Sample is a specialised metric for measurement captures, as opposed to holding the current value at all times. The precision is enhanced with a timestamp, at the cost of performance degradation. Serialisation omits samples with a zero timestamp. The default/initial value is zero with a zero timestamp. Multiple goroutines may invoke methods on a Sample simultaneously.
Example (Lazy) ¶
package main import ( "net/http" "os" "time" "github.com/pascaldekloe/metrics" "github.com/pascaldekloe/metrics/gostat" ) var ( LogSize = metrics.MustRealSample("log_bytes", "Size reported by the filesystem.") LogIdle = metrics.MustRealSample("log_idle_seconds", "Duration since last change.") ) func main() { // mount exposition point http.HandleFunc("/metrics", func(w http.ResponseWriter, r *http.Request) { // update standard samples gostat.Capture() // update custom samples log, err := os.Stat("./mission.log") if err == nil { // ⚠️ reverse error check now := time.Now() LogSize.Set(float64(log.Size()), now) LogIdle.SetSeconds(now.Sub(log.ModTime()), now) } // serve serialized metrics.ServeHTTP(w, r) }) }
Output:
func MustCounterSample ¶
MustCounterSample registers a new Sample. Registration panics when name was registered before, or when name doesn't match regular expression [a-zA-Z_:][a-zA-Z0-9_:]*. Help is an optional comment text.
func MustRealSample ¶
MustRealSample registers a new Sample. Registration panics when name was registered before, or when name doesn't match regular expression [a-zA-Z_:][a-zA-Z0-9_:]*. Help is an optional comment text.