metricator/pkg/schema/metric.go

42 lines
995 B
Go
Raw Normal View History

package schema
// Metric is a generic metric structure. Used in HTTP responses and data storage.
type Metric struct {
// BaseName is a metric's base name, used for constructing name.
BaseName string
2020-12-23 19:31:09 +05:00
// Name is a metric name.
Name string
2020-12-23 19:31:09 +05:00
// Description is a metric description from HELP line.
Description string
2020-12-23 19:31:09 +05:00
// Type is a metric type from TYPE line.
2020-12-23 13:45:33 +05:00
Type string
2020-12-23 19:31:09 +05:00
// Value is a metric value.
Value string
2020-12-23 19:31:09 +05:00
// Params is an additional params which are placed inside "{}".
Params []string
}
// NewMetric creates new structure for storing single metric data.
2020-12-23 13:45:33 +05:00
func NewMetric(name, mType, description string, params []string) Metric {
m := Metric{
BaseName: name,
Name: name,
Description: description,
2020-12-23 13:45:33 +05:00
Type: mType,
Params: params,
2020-12-23 19:31:09 +05:00
Value: "",
}
return m
}
// GetValue returns metric's value.
func (m *Metric) GetValue() string {
return m.Value
}
// SetValue sets value for metric.
func (m *Metric) SetValue(value string) {
m.Value = value
}