Documentation
¶
Index ¶
- func MetricName(measurement, fieldKey string, valueType telegraf.ValueType) string
- func SampleCount(value interface{}) (uint64, bool)
- func SampleSum(value interface{}) (float64, bool)
- func SampleValue(value interface{}) (float64, bool)
- func SanitizeLabelName(name string) (string, bool)
- func SanitizeMetricName(name string) (string, bool)
- type Collection
- type FormatConfig
- type MetricTypes
- type Serializer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MetricName ¶
MetricName returns the Prometheus metric name.
func SampleCount ¶
SampleCount converts a field value into a count suitable for a metric family of the Histogram or Summary type.
func SampleSum ¶
SampleSum converts a field value into a sum suitable for a metric family of the Histogram or Summary type.
func SampleValue ¶
SampleValue converts a field value into a value suitable for a simple sample value.
func SanitizeLabelName ¶
SanitizeLabelName checks if the name is a valid Prometheus label name. If not, it attempts to replace invalid runes with an underscore to create a valid name.
func SanitizeMetricName ¶
SanitizeMetricName checks if the name is a valid Prometheus metric name. If not, it attempts to replace invalid runes with an underscore to create a valid name.
Types ¶
type Collection ¶
type Collection struct {
// contains filtered or unexported fields
}
Collection is a cache of metrics that are being processed.
func NewCollection ¶
func NewCollection(config FormatConfig) *Collection
NewCollection creates a new Collection instance.
func (*Collection) Add ¶
func (c *Collection) Add(m telegraf.Metric, now time.Time)
Add adds a metric to the collection. It will create a new entry if the metric is not already present.
func (*Collection) Expire ¶
func (c *Collection) Expire(now time.Time, age time.Duration)
Expire removes metrics that are older than the specified age.
func (*Collection) GetEntries ¶
func (c *Collection) GetEntries() []entry
GetEntries returns a slice of all entries in the collection.
func (*Collection) GetMetrics ¶
func (c *Collection) GetMetrics(entry entry) []*metric
GetMetrics returns a slice of all metrics in the entry.
func (*Collection) GetProto ¶
func (c *Collection) GetProto() []*dto.MetricFamily
GetProto returns a slice of all metrics in the collection as protobuf messages.
type FormatConfig ¶
type FormatConfig struct {
ExportTimestamp bool `toml:"prometheus_export_timestamp"`
SortMetrics bool `toml:"prometheus_sort_metrics"`
StringAsLabel bool `toml:"prometheus_string_as_label"`
// CompactEncoding defines whether to include
// HELP metadata in Prometheus payload. Setting to true
// helps to reduce payload size.
CompactEncoding bool `toml:"prometheus_compact_encoding"`
TypeMappings MetricTypes `toml:"prometheus_metric_types"`
}
FormatConfig contains the configuration for the Prometheus serializer.
type MetricTypes ¶ added in v1.28.0
type MetricTypes struct {
Counter []string `toml:"counter"`
Gauge []string `toml:"gauge"`
// contains filtered or unexported fields
}
MetricTypes defines the mapping of metric names to their types.
func (*MetricTypes) DetermineType ¶ added in v1.28.0
DetermineType determines the type of the metric based on its name and the configured filters.
func (*MetricTypes) Init ¶ added in v1.28.0
func (mt *MetricTypes) Init() error
Init initializes the MetricTypes by compiling the filters for counter and gauge metrics.
type Serializer ¶
type Serializer struct {
FormatConfig
}
func (*Serializer) Init ¶ added in v1.28.0
func (s *Serializer) Init() error
func (*Serializer) Serialize ¶
func (s *Serializer) Serialize(metric telegraf.Metric) ([]byte, error)
func (*Serializer) SerializeBatch ¶
func (s *Serializer) SerializeBatch(metrics []telegraf.Metric) ([]byte, error)