config

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 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": 86400,
  "expiration": 604800,
  "storage": {
    "path": "storage/"
  },
  "detector": {
    "port": 2015,
    "trendingFactor": 0.1,
    "filterOffset": 0.01,
    "leastCount": 30,
    "blacklist": ["statsd.*"],
    "intervalHitLimit": 100,
	"defaultThresholdMaxs": {},
	"defaultThresholdMins": {"timer.mean_90": 300},
    "fillBlankZeros": ["counter.*.exc"]
  },
  "webapp": {
    "port": 2016,
    "auth": ["user", "pass"],
    "static": "static/dist"
  },
  "alerter": {
    "command": "",
    "workers": 4,
    "interval": 1200,
    "oneDayLimit": 5
  },
  "cleaner": {
    "interval": 10800,
    "threshold": 259200
  }
}

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), default: 86400 (1 day)
expiration                     // All metrics expiration (in seconds), default: 604800 (7 days)
storage.path                   // Storage directory path.
detector.port                  // Detector tcp port to listen.
detector.trendingFactor        // Detection weighted moving factor, should be a number between 0 and 1, default: 0.1
detector.filterOffset          // Offset to filter history data, as a percentage to period, default: 0.01
detector.leastCount            // Least count to start detection. default: 30
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.defaultThresholdMaxs  // Default thresholdMax for all rules, a wildcard pattern to number map. default: {}
detector.defaultThresholdMins  // Default thresholdMin for all rules, a wildcard pattern to 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
cleaner.interval               // Time interval to check outdated data to clean. default: 10800 (4 hours)
cleaner.threshold              // One metric will be cleaned if the age it incoming exceeds this threshold (in seconds). default: 259200 (3 days)

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 period for all metrics in seconds.
	DefaultPeriod uint32 = 1 * Day
	// Default metric expiration.
	DefaultExpiration uint32 = 7 * Day
	// Default weight factor for moving average.
	DefaultTrendingFactor float64 = 0.1
	// Default filter offset to query history metrics.
	DefaultFilterOffset float64 = 0.01
	// Default cleaner interval.
	DefaultCleanerInterval uint32 = 3 * Hour
	// Default cleaner threshold.
	DefaultCleanerThreshold uint32 = 3 * Day
	// 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
	// Default value of least count.
	DefaultLeastCount uint32 = 5 * Minute / DefaultInterval
)

Defaults

View Source
const (
	// Max value for the number of DefaultThresholdMaxs.
	MaxNumDefaultThresholdMaxs = 8
	// Max value for the number of DefaultThresholdMins.
	MaxNumDefaultThresholdMins = 8
	// Max value for the number of FillBlankZeros.
	MaxFillBlankZerosLen = 8
	// Min value for the expiration to period.
	MinExpirationNumToPeriod uint32 = 5
	// Min value for the cleaner threshold to period.
	MinCleanerThresholdNumToPeriod uint32 = 2
)

Limitations

Variables

View Source
var (
	// Error
	ErrInterval                        = errors.New("interval should be an integer between 1s~10min")
	ErrPeriod                          = errors.New("period should be an integer greater than interval")
	ErrExpiration                      = errors.New("expiration should be an integer greater than 5 * period")
	ErrDetectorPort                    = errors.New("invalid detector.port")
	ErrDetectorTrendingFactor          = errors.New("detector.trendingFactor should be a float between 0 and 1")
	ErrDetectorFilterOffset            = errors.New("detector.filterOffset should be a float between 0 and 1")
	ErrDetectorDefaultThresholdMaxsLen = errors.New("detector.defaultThresholdMaxs should have up to 8 items")
	ErrDetectorDefaultThresholdMinsLen = errors.New("detector.defaultThresholdMins should have up to 8 items")
	ErrDetectorDefaultThresholdMaxZero = errors.New("detector.defaultThresholdMaxs should not contain zeros")
	ErrDetectorDefaultThresholdMinZero = errors.New("detector.defaultThresholdMins 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")
	ErrCleanerThreshold                = errors.New("cleaner.threshold should be an integer greater than 2 * period")
	// 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     uint32         `json:"period"`
	Expiration uint32         `json:"expiration"`
	Storage    configStorage  `json:"storage"`
	Detector   configDetector `json:"detector"`
	Webapp     configWebapp   `json:"webapp"`
	Alerter    configAlerter  `json:"alerter"`
	Cleaner    configCleaner  `json:"cleaner"`
}

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) 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