exporter

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2020 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AppConfig

type AppConfig struct {
	Name        string           `yaml:"name"`
	SourceFiles []string         `yaml:"source_files"`
	Relables    []*RelabelConfig `yaml:"relabels"`
}

AppConfig config an APP observer APP observer has a name, which will be labeled in metrics as app={name} APP observer can read from multple files APP observer can overide namespace's default relabel configs

type AppObserver

type AppObserver struct {
	Name string
	// contains filtered or unexported fields
}

AppObserver reads incoming nginx logs and gather values

func NewAppObserver

func NewAppObserver(ns *Namespace, appCfg AppConfig) *AppObserver

NewAppObserver create a new AppObserver

type ExcactReplaceConfig

type ExcactReplaceConfig struct {
	Match       string `yaml:"match"`
	Replacement string `yaml:"replacement"`
}

ExcactReplaceConfig tells how to extract label value from source value

type Follower

type Follower interface {
	Lines() chan string
	OnError(func(error))
}

Follower describes an object that continuously emits a stream of lines

func NewFileFollower

func NewFileFollower(filename string) (Follower, error)

NewFileFollower creates a new Follower instance for a given file (given by name)

type Metrics

type Metrics interface {
	Observe(entry *gonx.Entry, labelValues []string)
	GetLabels() []string
}

Metrics is an interface to observe value

type Namespace

type Namespace struct {
	Name    string
	Parser  *gonx.Parser
	Metrics Metrics

	Labels   []string
	Relabels map[string]*Relabeling

	Observers []*AppObserver

	LabelIndexer map[string]int
}

Namespace collect a group of metrics of different APP

func NewNamespace

func NewNamespace(nsCfg NamespaceConfig) *Namespace

NewNamespace create a Namespace object from nsCfg

func NewNamespaceWithMetrics

func NewNamespaceWithMetrics(nsCfg NamespaceConfig, metrics Metrics) *Namespace

NewNamespaceWithMetrics create a Namespace object from config and metrics

It uses labels in metrics and ignore labels in nsCfg

func (*Namespace) StartObserve

func (ns *Namespace) StartObserve(stopChan <-chan bool)

StartObserve start goroutines to observe metrics of different APP Observers

type NamespaceConfig

type NamespaceConfig struct {
	Name             string           `yaml:"name"`
	Labels           []string         `yaml:"labels"`
	Format           string           `yaml:"format"`
	DefaultRelabels  []*RelabelConfig `yaml:"default_relabels"`
	HistogramBuckets []float64        `yaml:"histogram_buckets"`

	Apps []AppConfig
}

NamespaceConfig config a group of metric scraper metrics in a namespace share:

  • group of metric names
  • labels
  • nginx log format
  • historgram buckets

a namespace has default relabel configs, they can be changed by child APP observers

type RegexReplace

type RegexReplace struct {
	CompiledRegexp *regexp.Regexp
	Replacement    string
}

RegexReplace match and convert value

func NewRegexReplace

func NewRegexReplace(cfg *RegexReplaceConfig) *RegexReplace

NewRegexReplace create RegexReplace object

func (*RegexReplace) Convert

func (rr *RegexReplace) Convert(before string) (matched bool, after string)

Convert convert source value if matched

type RegexReplaceConfig

type RegexReplaceConfig struct {
	RegexpString string `yaml:"regexp"`      // pattern to match source value
	Replacement  string `yaml:"replacement"` // replace pattern, like "abc_$1"
}

RegexReplaceConfig tells how to extract label value from source value

type RelabelConfig

type RelabelConfig struct {
	Name          string                 `yaml:"name"`   // label name
	Source        string                 `yaml:"source"` // keyword in nginx log format
	Split         int                    `yaml:"split"`  // sometimes we need onyl part of source value, we can split source value and take specific part
	Preprocesses  []*RegexReplaceConfig  `yaml:"preprocesses"`
	RegexMatches  []*RegexReplaceConfig  `yaml:"regex_matches"`
	ExcactMatches []*ExcactReplaceConfig `yaml:"exact_matches"`
}

RelabelConfig tells the application how to extract a metric label value

type Relabeling

type Relabeling struct {
	Name         string
	Source       string
	Split        int
	Preprocesses []*RegexReplace
	RegexMatches []*RegexReplace
	ExactMatches map[string]string
}

Relabeling extract label value from source value

func NewRelabeling

func NewRelabeling(cfg *RelabelConfig) *Relabeling

NewRelabeling create Relabeling object from config

func (*Relabeling) Extract

func (r *Relabeling) Extract(entry *gonx.Entry) string

Extract extract label value from nginx log entry

Jump to

Keyboard shortcuts

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