config

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2016 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package config handles configuration parser and container.

Example

Configuration is in JSON file, for example:

{
  "interval": 10,
  "period": [288, 300],
  "storage": {
    "path": "storage/"
  },
  "detector": {
    "port": 2015,
    "factor": 0.05,
    "blacklist": ["statsd.*"],
    "intervalHitLimit": 100,
    "defaultTrustLines": {"timer.count_ps.*": 30},
    "fillBlankZeros": ["counter.*.exc"]
  },
  "webapp": {
    "port": 2016,
    "auth": ["user", "pass"],
    "static": "static/dist"
  },
  "alerter": {
    "command": "",
    "workers": 4,
    "interval": 1200,
    "oneDayLimit": 5
  }
}

To use config file with banshee:

banshee -c path/to/config.json

Documents

The documents for each configuration item with default values:

interval                   // All metrics incoming interval (in seconds), default: 10
period                     // All metrics period (in seconds), in form of [NumGrid, GirdLen], default: [288, 300]
storage.path               // Storage directory path.
detector.port              // Detector tcp port to listen.
detector.factor            // Detection weighted moving factor, should be a number between 0 and 1, default: 0.05
detector.blacklist         // Incoming metrics blacklist, each one should be a wildcard pattern, default: []
detector.intervalHitLimit  // Limitation for number of filtered metrics for each rule in one interval. default: 100
detector.defaultTrustLines // Default trustlines for rules, a wildcard pattern to trustline number map. default: {}
detector.filterBlankZeros  // Detector will fill metric blanks with zeros if it matches any of these wildcard patterns. default: []
webapp.port                // Webapp http port to listen.
webapp.auth                // Webapp admin pages basic auth, in form of [user, pass], use empty string ["", ""] to disable auth. default: ["admin", "admin"]
webapp.static              // Webapp static files (htmls/css/js) path, default: "static/dist"
alerter.command            // Alerter command or script to execute on anomalies found. default: ""
alerter.workers            // Number of workers to consume command execution jobs. default: 4
alerter.interval           // Minimal interval (in seconds) between two alerting message for one metric. default: 1200
alerter.oneDayLimit        // Limitation for number of alerting times for one metric in a day. default: 5

Index

Constants

View Source
const (
	// Time
	Second uint32 = 1
	Minute        = 60 * Second
	Hour          = 60 * Minute
	Day           = 24 * Hour
)

Measures

View Source
const (
	// Default time interval for all metrics in seconds.
	DefaultInterval uint32 = 10 * Second
	// Default hit limit to a rule in an interval
	DefaultIntervalHitLimit int = 100
	// Default grid length in seconds.
	DefaultGridLen uint32 = 5 * Minute
	// Default number of grids in one period.
	DefaultNumGrid uint32 = 1 * Day / DefaultGridLen
	// Default weight factor for moving average and standard deviation.
	DefaultWeightFactor float64 = 0.05
	// Default value of alerting interval.
	DefaultAlerterInterval uint32 = 20 * Minute
	// Default value of alert times limit in one day for the same metric
	DefaultAlerterOneDayLimit uint32 = 5
)

Defaults

View Source
const (
	// Max value for the number of DefaultTrustLines.
	MaxDefaltTrustLinesLen = 8
	// Max value for the number of FillBlankZeros.
	MaxFillBlankZerosLen = 8
)

Limitations

Variables

View Source
var (
	// Error
	ErrInterval                     = errors.New("interval should be an integer between 1s~10min")
	ErrPeriodNumGrid                = errors.New("period[0] should be an integer not less than 1")
	ErrPeriodGridLen                = errors.New("period[1] should be an integer not less than 5min")
	ErrDetectorPort                 = errors.New("invalid detector.port")
	ErrDetectorFactor               = errors.New("detector.factor should be an float between 0 and 1")
	ErrDetectorDefaultTrustLinesLen = errors.New("detector.defaultTrustLines should have up to 8 items")
	ErrDetectorDefaultTrustLineZero = errors.New("detector.defaultTrustLines should not contain zeros")
	ErrDetectorFillBlankZerosLen    = errors.New("detector.fillBlankZeros should have up to 8 items")
	ErrWebappPort                   = errors.New("invalid webapp.port")
	ErrAlerterInterval              = errors.New("alerter.interval should be greater than 0")
	ErrAlerterOneDayLimit           = errors.New("alerter.oneDayLimit should be greater than 0")
	// Warn
	ErrAlerterCommandEmpty = errors.New("alerter.command is empty")
)

Errors

Functions

This section is empty.

Types

type Config

type Config struct {
	Interval uint32         `json:"interval"`
	Period   [2]uint32      `json:"period"`
	Storage  configStorage  `json:"storage"`
	Detector configDetector `json:"detector"`
	Webapp   configWebapp   `json:"webapp"`
	Alerter  configAlerter  `json:"alerter"`
}

Config is the configuration container.

func New

func New() *Config

New creates a Config with default values.

func (*Config) Copy

func (config *Config) Copy() *Config

Copy config.

func (*Config) LeastC

func (config *Config) LeastC() uint32

LeastC returns the least count to start detection, if the count of a metric is less than this value, it will be trusted without an calculation on its score.

func (*Config) UpdateWithJSONFile

func (config *Config) UpdateWithJSONFile(fileName string) error

UpdateWithJSONFile update the config from a json file.

func (*Config) Validate

func (config *Config) Validate() error

Validate config

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳