collector

package
v0.0.0-...-4c031ee Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 23, 2022 License: Apache-2.0 Imports: 42 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LabelMetricName                 = "__name__"
	LabelMetricNamespace            = "__namespace__"
	LabelMetricSubsystem            = "__subsystem__"
	LabelMetricHelp                 = "__help__"
	LabelMetricTime                 = "__time__"
	LabelMetricTimeFormat           = "__time_format__"
	LabelMetricValue                = "__value__"
	LabelMetricBuckets              = "__buckets__"
	LabelMetricValues               = "__values__"
	LabelMetricValuesSeparator      = "__values_separator__"
	LabelMetricValuesIndex          = "__values_index__"
	LabelMetricValuesIndexSeparator = "__values_index_separator__"
	LabelMetricValuesIndexLabelName = "__values_index_label_name__"
)
View Source
const DefaultMaxContent = 102400000
View Source
const ExporterName string = "data_exporter"

Variables

View Source
var (
	DefaultHttpConfig               = HTTPConfig{Method: "GET"}
	DatasourceDefaultTimeout        = time.Second * 30
	DatasourceDefaultConnectTimeout = time.Second * 3
)
View Source
var (
	DefaultRelabelConfig = RelabelConfig{
		Action:      Replace,
		Separator:   ";",
		Regex:       MustNewRegexp("(.*)"),
		Replacement: "$1",
	}
)
View Source
var ErrValueIsNull = fmt.Errorf("metric value is null")
View Source
var ErrorDataTooSort = errors.New("data is too short")

Functions

func AddFlags

func AddFlags(flagSet *kingpin.Application)

func RegisterCollector

func RegisterCollector(reg prometheus.Registerer)

Types

type Action

type Action string
const (
	// Replace performs a regex replacement.
	Replace Action = "replace"
	// TemplateExecute performs a template execute replacement.
	TemplateExecute Action = "templexec"
	// Keep drops targets for which the input does not match the regex.
	Keep Action = "keep"
	// Drop drops targets for which the input does match the regex.
	Drop Action = "drop"
	// HashMod sets a label to the modulus of a hash of labels.
	HashMod Action = "hashmod"
	// LabelMap copies labels to other labelnames based on a regex.
	LabelMap Action = "labelmap"
	// LabelDrop drops any label matching the regex.
	LabelDrop Action = "labeldrop"
	// LabelKeep drops any label not matching the regex.
	LabelKeep Action = "labelkeep"
)

type Builder

type Builder struct {
	// contains filtered or unexported fields
}

Builder allows modifying Labels.

func NewBuilder

func NewBuilder(base Labels) *Builder

NewBuilder returns a new LabelsBuilder.

func (*Builder) Del

func (b *Builder) Del(ns ...string) *Builder

Del deletes the label of the given name.

func (*Builder) Labels

func (b *Builder) Labels() Labels

Labels returns the labels from the builder. If no modifications were made, the original labels are returned.

func (*Builder) Reset

func (b *Builder) Reset(base Labels)

Reset clears all current state for the builder.

func (*Builder) Set

func (b *Builder) Set(n, v string) *Builder

Set the name/value pair as a label.

type CollectConfig

type CollectConfig struct {
	Name           string         `yaml:"name,omitempty"`
	RelabelConfigs RelabelConfigs `yaml:"relabel_configs,omitempty"`
	DataFormat     DataFormat     `yaml:"data_format"`
	Datasource     []*Datasource  `yaml:"datasource"`
	Metrics        MetricConfigs  `yaml:"metrics"`
	// contains filtered or unexported fields
}

func (*CollectConfig) GetMetric

func (c *CollectConfig) GetMetric(logger log.Logger, data []byte, rcs RelabelConfigs, metrics chan<- MetricGenerator)

func (*CollectConfig) GetMetricByDs

func (c *CollectConfig) GetMetricByDs(ctx context.Context, logger log.Logger, ds *Datasource, metrics chan<- MetricGenerator)

func (*CollectConfig) SetLogger

func (c *CollectConfig) SetLogger(logger log.Logger)

func (*CollectConfig) StartStreamCollect

func (c *CollectConfig) StartStreamCollect(ctx context.Context) error

func (*CollectConfig) StopStreamCollect

func (c *CollectConfig) StopStreamCollect()

func (*CollectConfig) UnmarshalYAML

func (c *CollectConfig) UnmarshalYAML(value *yaml.Node) error

type CollectContext

type CollectContext struct {
	*CollectConfig

	context.Context
	DatasourceName string
	DatasourceUrl  string
	// contains filtered or unexported fields
}

func (*CollectContext) Collect

func (c *CollectContext) Collect(proMetrics chan<- prometheus.Metric)

func (*CollectContext) Describe

func (c *CollectContext) Describe(_ chan<- *prometheus.Desc)

type Collects

type Collects []CollectConfig

func (Collects) Get

func (c Collects) Get(name string) *CollectConfig

func (*Collects) SetLogger

func (c *Collects) SetLogger(logger log.Logger)

func (*Collects) StartStreamCollect

func (c *Collects) StartStreamCollect(ctx context.Context) error

func (*Collects) StopStreamCollect

func (c *Collects) StopStreamCollect()

type ConnReader

type ConnReader struct {
	net.Conn
	// contains filtered or unexported fields
}

func NewConnReader

func NewConnReader(conn net.Conn, transferTime time.Duration) *ConnReader

func (*ConnReader) Read

func (c *ConnReader) Read(p []byte) (n int, err error)

type ContextKey

type ContextKey string
var LoggerContextName ContextKey = "_logger_"

type DataFormat

type DataFormat string
const (
	Regex DataFormat = "regex"
	Json  DataFormat = "json"
	Xml   DataFormat = "xml"
	Yaml  DataFormat = "yaml"
)

func (DataFormat) ToLower

func (d DataFormat) ToLower() DataFormat

type Datapoint

type Datapoint map[string]string

func (*Datapoint) UnmarshalJSON

func (d *Datapoint) UnmarshalJSON(raw []byte) error

type Datasource

type Datasource struct {
	Name                 string             `yaml:"name,omitempty"`
	Url                  string             `yaml:"url"`
	AllowReplace         bool               `yaml:"allow_replace,omitempty"`
	Type                 DatasourceType     `yaml:"type"`
	Timeout              time.Duration      `yaml:"timeout"`
	RelabelConfigs       RelabelConfigs     `yaml:"relabel_configs,omitempty"`
	MaxContentLength     *int64             `yaml:"max_content_length"`
	MinContentLength     *int               `yaml:"min_content_length,omitempty"`
	LineMaxContentLength *int               `yaml:"line_max_content_length"`
	LineSeparator        buffer.SliceString `yaml:"line_separator"`

	EndOf    string             `yaml:"end_of,omitempty"`
	ReadMode DatasourceReadMode `yaml:"read_mode"`
	Config   Streamer           `yaml:"-"`
	Whence   int                `yaml:"whence"`

	// Deprecated
	HTTPConfig *HTTPConfig `yaml:"http,omitempty"`
	// Deprecated
	TCPConfig *NetConfig `yaml:"tcp,omitempty"`
	// Deprecated
	UDPConfig *NetConfig `yaml:"udp,omitempty"`
	// contains filtered or unexported fields
}

func (*Datasource) Close

func (d *Datasource) Close()

func (*Datasource) GetLineStream

func (d *Datasource) GetLineStream(ctx context.Context, logger log.Logger) (buffer.ReadLineCloser, error)

func (*Datasource) GetStream

func (d *Datasource) GetStream(ctx context.Context) (io.ReadCloser, error)

func (*Datasource) MarshalYAML

func (d *Datasource) MarshalYAML() (interface{}, error)

func (*Datasource) ReadAll

func (d *Datasource) ReadAll(ctx context.Context) ([]byte, error)

func (*Datasource) UnmarshalYAML

func (d *Datasource) UnmarshalYAML(value *yaml.Node) error

type DatasourceReadMode

type DatasourceReadMode string
const (
	Line       DatasourceReadMode = "line"
	Stream     DatasourceReadMode = "stream"
	StreamLine DatasourceReadMode = "stream-line"
	FullText   DatasourceReadMode = "full-text"
	Full       DatasourceReadMode = "full"
)

func (DatasourceReadMode) ToLower

type DatasourceType

type DatasourceType string
const (
	Http  DatasourceType = "http"
	Https DatasourceType = "https"
	File  DatasourceType = "file"
	Tcp   DatasourceType = "tcp"
	Udp   DatasourceType = "udp"
)

func (DatasourceType) ToLower

func (d DatasourceType) ToLower() DatasourceType

func (DatasourceType) ToLowerString

func (d DatasourceType) ToLowerString() string

type GArray

type GArray []gjson.Result

func (GArray) String

func (G GArray) String() string

type GMap

type GMap map[string]gjson.Result

func (GMap) String

func (G GMap) String() string

type HTTPConfig

type HTTPConfig struct {
	HTTPClientConfig promconfig.HTTPClientConfig `yaml:"http_client_config,inline"`
	Body             string                      `yaml:"body,omitempty"`
	Headers          map[string]string           `yaml:"headers,omitempty"`
	Method           string                      `yaml:"method,omitempty"`
	ValidStatusCodes []int                       `yaml:"valid_status_codes,omitempty"`
	MaxConnectTime   time.Duration               `yaml:"max_connect_time"`
}

func (HTTPConfig) GetStream

func (h HTTPConfig) GetStream(ctx context.Context, name, targetURL string) (io.ReadCloser, error)

func (*HTTPConfig) UnmarshalYAML

func (h *HTTPConfig) UnmarshalYAML(value *yaml.Node) error

type Label

type Label struct {
	Name, Value string
}

type Labels

type Labels []Label

func FromMap

func FromMap(m map[string]string) Labels

FromMap returns new sorted Labels from the given map.

func New

func New(ls ...Label) Labels

New returns a sorted Labels from the given labels. The caller has to guarantee that all label names are unique.

func (*Labels) Append

func (ls *Labels) Append(name, val string)

func (Labels) Bytes

func (ls Labels) Bytes(buf []byte) []byte

Bytes returns ls as a byte slice. It uses an byte invalid character as a separator and so should not be used for printing.

func (Labels) Copy

func (ls Labels) Copy() Labels

Copy returns a copy of the labels.

func (Labels) Get

func (ls Labels) Get(name string) string

Get returns the value for the label with the given name. Returns an empty string if the label doesn't exist.

func (Labels) Has

func (ls Labels) Has(name string) bool

Has returns true if the label with the given name is present.

func (Labels) HasDuplicateLabelNames

func (ls Labels) HasDuplicateLabelNames() (string, bool)

HasDuplicateLabelNames returns whether ls has duplicate label names. It assumes that the labelset is sorted.

func (Labels) Hash

func (ls Labels) Hash() uint64

Hash returns a hash value for the label set.

func (Labels) HashForLabels

func (ls Labels) HashForLabels(b []byte, names ...string) (uint64, []byte)

HashForLabels returns a hash value for the labels matching the provided names. 'names' have to be sorted in ascending order.

func (Labels) HashWithoutLabels

func (ls Labels) HashWithoutLabels(b []byte, names ...string) (uint64, []byte)

HashWithoutLabels returns a hash value for all labels except those matching the provided names. 'names' have to be sorted in ascending order.

func (Labels) Keys

func (ls Labels) Keys() []string

func (Labels) Len

func (ls Labels) Len() int

func (Labels) Less

func (ls Labels) Less(i, j int) bool

func (Labels) Map

func (ls Labels) Map() map[string]string

Map returns a string map of the labels.

func (Labels) MarshalJSON

func (ls Labels) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (Labels) MarshalYAML

func (ls Labels) MarshalYAML() (interface{}, error)

MarshalYAML implements yaml.Marshaler.

func (Labels) MatchLabels

func (ls Labels) MatchLabels(on bool, names ...string) Labels

MatchLabels returns a subset of Labels that matches/does not match with the provided label names based on the 'on' boolean. If on is set to true, it returns the subset of labels that match with the provided label names and its inverse when 'on' is set to false.

func (Labels) String

func (ls Labels) String() string

func (Labels) Swap

func (ls Labels) Swap(i, j int)

func (*Labels) UnmarshalJSON

func (ls *Labels) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaler.

func (*Labels) UnmarshalYAML

func (ls *Labels) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML implements yaml.Unmarshaler.

func (Labels) WithLabels

func (ls Labels) WithLabels(names ...string) Labels

WithLabels returns a new labels.Labels from ls that only contains labels matching names. 'names' have to be sorted in ascending order.

func (Labels) WithoutEmpty

func (ls Labels) WithoutEmpty() Labels

WithoutEmpty returns the labelset without empty labels. May return the same labelset.

func (Labels) WithoutLabels

func (ls Labels) WithoutLabels(names ...string) Labels

WithoutLabels returns a new labels.Labels from ls that contains labels not matching names. 'names' have to be sorted in ascending order.

type MetricConfig

type MetricConfig struct {
	Name           string         `yaml:"name,omitempty"`
	RelabelConfigs RelabelConfigs `yaml:"relabel_configs,omitempty" json:"relabel_configs"`
	Match          MetricMatch    `yaml:"match"`
	MetricType     MetricType     `yaml:"metric_type" json:"metric_type"`
	// contains filtered or unexported fields
}

func (*MetricConfig) BuildRegexp

func (mc *MetricConfig) BuildRegexp(pointPrefix string) (err error)

func (*MetricConfig) BuildTemplate

func (mc *MetricConfig) BuildTemplate(pointPrefix string) (err error)

func (*MetricConfig) GetDatapointsByJson

func (mc *MetricConfig) GetDatapointsByJson(logger log.Logger, data []byte) []Datapoint

func (*MetricConfig) GetDatapointsByRegex

func (mc *MetricConfig) GetDatapointsByRegex(logger log.Logger, data []byte) []Datapoint

func (*MetricConfig) GetDatapointsByXml

func (mc *MetricConfig) GetDatapointsByXml(logger log.Logger, data []byte) []Datapoint

func (*MetricConfig) GetDatapointsByYaml

func (mc *MetricConfig) GetDatapointsByYaml(logger log.Logger, data []byte) []Datapoint

func (*MetricConfig) Relabels

func (mc *MetricConfig) Relabels(logger log.Logger, rcs RelabelConfigs, lvs Labels) (newLvs Labels, err error)

func (*MetricConfig) SetLogger

func (mc *MetricConfig) SetLogger(logger log.Logger)

func (*MetricConfig) UnmarshalJSON

func (mc *MetricConfig) UnmarshalJSON(raw []byte) error

func (*MetricConfig) UnmarshalYAML

func (mc *MetricConfig) UnmarshalYAML(value *yaml.Node) error

type MetricConfigs

type MetricConfigs []*MetricConfig

type MetricGenerator

type MetricGenerator struct {
	MetricType MetricType
	Labels     Labels
	Datasource *Datasource
	Datapoint  *MetricConfig

	Name string
	// contains filtered or unexported fields
}

func NewMetricGenerator

func NewMetricGenerator(logger log.Logger, name string, metricType MetricType) *MetricGenerator

func (*MetricGenerator) GetMetrics

func (m *MetricGenerator) GetMetrics() ([]prometheus.Metric, []error)

type MetricGenerators

type MetricGenerators struct {
	// contains filtered or unexported fields
}

func NewMetricGenerators

func NewMetricGenerators(size int, logger log.Logger) *MetricGenerators

func (*MetricGenerators) Ch

func (mgs *MetricGenerators) Ch() chan MetricGenerator

func (*MetricGenerators) Collect

func (mgs *MetricGenerators) Collect(proMetrics chan<- prometheus.Metric)

func (*MetricGenerators) Describe

func (*MetricGenerators) Describe(_ chan<- *prometheus.Desc)

type MetricGroup

type MetricGroup struct {
	// contains filtered or unexported fields
}

func (*MetricGroup) Collect

func (mg *MetricGroup) Collect(metrics chan<- prometheus.Metric)

type MetricMatch

type MetricMatch struct {
	Datapoint string            `yaml:"datapoint"`
	Labels    map[string]string `yaml:"labels"`
	// contains filtered or unexported fields
}

type MetricType

type MetricType string
const (
	Gauge     MetricType = "gauge"
	Counter   MetricType = "counter"
	Histogram MetricType = "histogram"
)

func (MetricType) ToLower

func (d MetricType) ToLower() MetricType

type NetConfig

type NetConfig struct {
	Send            SendConfigs       `yaml:"send,omitempty"`
	MaxTransferTime *time.Duration    `yaml:"max_transfer_time"`
	MaxConnectTime  time.Duration     `yaml:"max_connect_time"`
	TLSConfig       *config.TLSConfig `yaml:"tls_config,omitempty" json:"tls_config,omitempty"`
	EndOf           string            `yaml:"end_of"`
	// contains filtered or unexported fields
}

func NewNetConfig

func NewNetConfig(protocol string) *NetConfig

func (NetConfig) GetStream

func (t NetConfig) GetStream(ctx context.Context, _, targetURL string) (io.ReadCloser, error)

func (*NetConfig) UnmarshalYAML

func (t *NetConfig) UnmarshalYAML(value *yaml.Node) error

type Regexp

type Regexp struct {
	*regexp.Regexp
	// contains filtered or unexported fields
}

func MustNewRegexp

func MustNewRegexp(s string) Regexp

func NewRegexp

func NewRegexp(s string) (Regexp, error)

func (Regexp) MarshalYAML

func (re Regexp) MarshalYAML() (interface{}, error)

func (*Regexp) UnmarshalJSON

func (re *Regexp) UnmarshalJSON(raw []byte) error

func (*Regexp) UnmarshalYAML

func (re *Regexp) UnmarshalYAML(value *yaml.Node) error

type RelabelConfig

type RelabelConfig struct {
	// A list of labels from which values are taken and concatenated
	// with the configured separator in order.
	SourceLabels model.LabelNames `yaml:"source_labels,flow,omitempty" json:"source_labels"`
	// Separator is the string between concatenated values from the source labels.
	Separator string `yaml:"separator,omitempty"`
	// Regex against which the concatenation is matched.
	Regex Regexp `yaml:"regex,omitempty"`
	// Template perform the replacement according to the template
	Template Template `yaml:"template,omitempty"`
	// Modulus to take of the hash of concatenated values from the source labels.
	Modulus uint64 `yaml:"modulus,omitempty"`
	// TargetLabel is the label to which the resulting string is written in a replacement.
	// Regexp interpolation is allowed for the replace action.
	TargetLabel string `yaml:"target_label,omitempty" json:"target_label"`
	// Replacement is the regex replacement pattern to be used.
	Replacement string `yaml:"replacement,omitempty"`
	// Action is the action to be performed for the relabeling.
	Action Action `yaml:"action,omitempty"`
}

func (*RelabelConfig) UnmarshalJSON

func (c *RelabelConfig) UnmarshalJSON(raw []byte) error

func (*RelabelConfig) UnmarshalYAML

func (c *RelabelConfig) UnmarshalYAML(value *yaml.Node) error

type RelabelConfigs

type RelabelConfigs []*RelabelConfig

func (RelabelConfigs) Process

func (rcs RelabelConfigs) Process(labels Labels) (Labels, error)

Process returns a relabeled copy of the given label set. The relabel configurations are applied in order of input. If a label set is dropped, nil is returned. May return the input labelSet modified.

func (RelabelConfigs) String

func (rcs RelabelConfigs) String() string

type SendConfig

type SendConfig struct {
	Msg   string        `yaml:"msg,omitempty"`
	Delay time.Duration `yaml:"delay,omitempty"`
}

func (*SendConfig) UnmarshalYAML

func (s *SendConfig) UnmarshalYAML(value *yaml.Node) error

type SendConfigs

type SendConfigs []SendConfig

func (*SendConfigs) UnmarshalYAML

func (s *SendConfigs) UnmarshalYAML(value *yaml.Node) error

type Streamer

type Streamer interface {
	GetStream(ctx context.Context, name, targetURL string) (io.ReadCloser, error)
}

type Template

type Template struct {
	*template.Template
	// contains filtered or unexported fields
}

func MustNewTemplate

func MustNewTemplate(name string, text string) Template

func NewTemplate

func NewTemplate(name string, text string) (*Template, error)

func (*Template) Execute

func (t *Template) Execute(data interface{}) ([]byte, error)

func (*Template) ExecuteTemplate

func (t *Template) ExecuteTemplate(name string, data interface{}) ([]byte, error)

func (*Template) Funcs

func (t *Template) Funcs(funcMap template.FuncMap) *Template

func (Template) MarshalYAML

func (t Template) MarshalYAML() (interface{}, error)

func (*Template) UnmarshalJSON

func (t *Template) UnmarshalJSON(raw []byte) error

func (*Template) UnmarshalYAML

func (t *Template) UnmarshalYAML(value *yaml.Node) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL