config

package
v0.3.6 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Defaults = Config{
	ConfigFile:  "config.yaml",
	BufferSize:  1000,
	WorkerCount: 0,
	Preset:      "simple",
	Debug:       Debug{},
	Log: Log{
		Format: "console",
		Level:  slog.LevelInfo,
	},
	Web: Web{
		ListenAddress: ":4040",
	},
	Syslog: Syslog{
		ListenAddress: "udp://[::]:8514",
	},
}
View Source
var ErrEmptyConfigFile = errors.New("configuration file is empty")
View Source
var ErrRequired = errors.New("required")
View Source
var ErrVersion = errors.New("flag: version requested")

Functions

func Validate

func Validate(conf Config) error

Validate validates the config.

Types

type Config

type Config struct {
	Presets      Presets `json:"presets"     yaml:"presets"`
	Nginx        Nginx   `json:"nginx"       yaml:"nginx"`
	Web          Web     `json:"web"         yaml:"web"`
	ConfigFile   string  `json:"config"      yaml:"config"`
	Syslog       Syslog  `json:"syslog"      yaml:"syslog"`
	Preset       string  `json:"preset"      yaml:"preset"`
	Log          Log     `json:"log"         yaml:"log"`
	WorkerCount  int     `json:"workerCount" yaml:"workerCount"`
	BufferSize   uint    `json:"bufferSize"  yaml:"bufferSize"`
	Debug        Debug   `json:"debug"       yaml:"debug"`
	VerifyConfig bool    `json:"-"`
}

func New

func New(args []string, writer io.Writer) (Config, error)

New loads the configuration from configuration files, command line arguments and environment variables in that order.

func (*Config) ReadFromConfigFile

func (c *Config) ReadFromConfigFile(configFilePath string) error

ReadFromConfigFile reads the configuration from a configuration file and command line arguments.

func (*Config) ReadFromFlagAndEnvironment

func (c *Config) ReadFromFlagAndEnvironment(args []string, writer io.Writer) error

ReadFromFlagAndEnvironment reads the configuration from command line arguments and environment variables.

func (Config) String

func (c Config) String() string

type Debug

type Debug struct {
	Enable bool `json:"enable" yaml:"enable"`
}

type Label

type Label struct {
	Name         string        `json:"name"                   yaml:"name"`
	Replacements []Replacement `json:"replacements,omitempty" yaml:"replacements,omitempty"`
	LineIndex    uint          `json:"lineIndex"              yaml:"lineIndex"`
	UserAgent    bool          `json:"userAgent"              yaml:"userAgent"`
}

type Log

type Log struct {
	Format string     `json:"format" yaml:"format"`
	Level  slog.Level `json:"level"  yaml:"level"`
}

type Math

type Math struct {
	Enabled bool    `json:"enabled" yaml:"enabled"`
	Mul     float64 `json:"mul"     yaml:"mul"`
	Div     float64 `json:"div"     yaml:"div"`
}

type Metric

type Metric struct {
	ConstLabels  map[string]string  `json:"constLabels"            yaml:"constLabels"`
	ValueIndex   *uint              `json:"valueIndex,omitempty"   yaml:"valueIndex,omitempty"`
	Name         string             `json:"name"                   yaml:"name"`
	Type         string             `json:"type"                   yaml:"type"`
	Help         string             `json:"help"                   yaml:"help"`
	Buckets      types.Float64Slice `json:"buckets,omitempty"      yaml:"buckets,omitempty"`
	Labels       []Label            `json:"labels"                 yaml:"labels"`
	Replacements []Replacement      `json:"replacements,omitempty" yaml:"replacements,omitempty"`
	Upstream     Upstream           `json:"upstream"               yaml:"upstream"`
	Math         Math               `json:"math"                   yaml:"math"`
}

type Nginx added in v0.1.8

type Nginx struct {
	ScrapeURL types.URL `json:"scrapeUri" yaml:"scrapeUri"`
}

type Preset

type Preset struct {
	Metrics []Metric `json:"metrics" yaml:"metrics"`
}

type Presets

type Presets map[string]Preset

type Replacement

type Replacement struct {
	String         *string           `json:"string,omitempty" yaml:"string,omitempty"`
	Regexp         *regexp.Regexp    `json:"regexp,omitempty" yaml:"regexp,omitempty"`
	StringReplacer *strings.Replacer `json:"-"                yaml:"-"`
	Replacement    string            `json:"replacement"      yaml:"replacement"`
}

func (*Replacement) UnmarshalYAML added in v0.3.0

func (r *Replacement) UnmarshalYAML(data *yaml.Node) error

type Syslog

type Syslog struct {
	ListenAddress string `json:"listenAddress" yaml:"listenAddress"`
}

type Upstream

type Upstream struct {
	Excludes      []string `json:"excludes"      yaml:"excludes"`
	AddrLineIndex uint     `json:"addrLineIndex" yaml:"addrLineIndex"`
	Enabled       bool     `json:"enabled"       yaml:"enabled"`
	Label         bool     `json:"label"         yaml:"label"`
}

type Web

type Web struct {
	ListenAddress string `json:"listenAddress" yaml:"listenAddress"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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