config

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2019 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package config handles reading and generating configuration files

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddDatasource

func AddDatasource(configDir string, filename string, datasource Datasource) error

AddDatasource writes a new datasource to a given file in a given directory

func AddSender

func AddSender(configDir string, filename string, s sender.Sender) error

AddSender writes a new sender to a given file in a given directory

func InitConfig

func InitConfig(configDir string) error

InitConfig initializes a new, default configuration. It creates three files: _collectors.hcl, _datasources.hcl and _senders.hcl in a given directory

func IsCronValid

func IsCronValid(spec string) bool

IsCronValid validates the cron expression

func ParseSender

func ParseSender(args []string) (*sender.Sender, error)

ParseSender parses CLI arguments into Sender

func ReadConfig

func ReadConfig(dir string) (*Config, *ConfigError)

ReadConfig finds, parses and merges all .hcl and .json files in a given directory, then it decodes the data into Config struct or returns ConfigError

func SetCollectorCron

func SetCollectorCron(configDir string, filename string, typ string, cron string) error

SetCollectorCron sets a new cron expression of a collector of a given type, which is defined in a given file in a given directory

func SetCollectorEnabled

func SetCollectorEnabled(configDir string, filename string, typ string, enabled bool) error

SetCollectorEnabled enables/disables a collector of a given type, which is defined in a given file in a given directory

Types

type Config

type Config struct {
	Datasources []Datasource  `hcl:"datasource,block"`
	System      *System       `hcl:"system,block"`
	Postgres    *Postgres     `hcl:"postgres,block"`
	Sout        *sender.Sout  `hcl:"console,block"`
	Http        []sender.Http `hcl:"http,block"`
}

Config represents the top-level configuration

func (*Config) SendersToInterface

func (c *Config) SendersToInterface() []sender.Sender

SendersToInterface returns a slice of interfaces, casting all senders to interface

type ConfigError

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

ConfigError represents all parsing errors, which occurred while reading the configuration file

func (ConfigError) Print

func (ce ConfigError) Print() error

Print pretty-prints all the parsing errors

type Datasource

type Datasource struct {
	Host        string            `hcl:"host"`
	Port        int               `hcl:"port"`
	Username    string            `hcl:"username"`
	Password    string            `hcl:"password"`
	DbName      string            `hcl:"dbname"`
	SslMode     *string           `hcl:"sslmode"`
	SslKey      *string           `hcl:"sslkey"`
	SslCert     *string           `hcl:"sslcert"`
	SslRootCert *string           `hcl:"sslrootcert"`
	Tags        map[string]string `hcl:"tags"`
}

Datasource represents a single PostgreSQL database connection info

func ParseDSN

func ParseDSN(dsn string, tags []string) (*Datasource, error)

ParseDSN parses DSN string into Datasource

type Postgres

type Postgres struct {
	PgStatStatements  *collector.PgStatStatements  `hcl:"pg_stat_statements,block"`
	PgStatUserTables  *collector.PgStatUserTables  `hcl:"pg_stat_user_tables,block"`
	PgStatUserIndexes *collector.PgStatUserIndexes `hcl:"pg_stat_user_indexes,block"`
	PgStatActivity    *collector.PgStatActivity    `hcl:"pg_stat_activity,block"`
	PgLocks           *collector.PgLocks           `hcl:"pg_locks,block"`
	PgStatArchiver    *collector.PgStatArchiver    `hcl:"pg_stat_archiver,block"`
}

Postgres represents configuration of PostgreSQL collectors

func (*Postgres) ToInterface

func (p *Postgres) ToInterface() []collector.Collector

ToInterface returns a slice of interfaces, casting all Postgres collectors to interface

type System

type System struct {
	Cpu     *collector.Cpu     `hcl:"cpu,block"`
	VirtMem *collector.VirtMem `hcl:"virtual_memory,block"`
	SwapMem *collector.SwapMem `hcl:"swap_memory,block"`
	Disk    *collector.Disk    `hcl:"disk,block"`
	Net     *collector.Net     `hcl:"network,block"`
	Load    *collector.Load    `hcl:"load,block"`
}

System represents configuration of system collectors

func (*System) ToInterface

func (s *System) ToInterface() []collector.Collector

ToInterface returns a slice of interfaces, casting all System collectors to interface

Jump to

Keyboard shortcuts

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