Skip to content

Commit

Permalink
Implement RetryKeepSecs configuration parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
Felixoid committed Aug 2, 2020
1 parent 72ce29d commit ce87f54
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ Most of the time you need to use default (recommended) configuration of grafsy,
- `supervisor` - supervisor manager which is used to run Grafsy. e.g. systemd or supervisord. Default is none
- `clientSendInterval` - the interval, after which client will send data to graphite. In seconds
- `metricsPerSecond` - maximum amount of metrics which can be processed per second
In case of problems with connection/amount of metrics, this configuration will save up to `MetricsPerSecond*ClientSendInterval*10` metrics in retryDir
In case of problems with connection/amount of metrics, this configuration will save up to `MetricsPerSecond*RetryKeepSecs` metrics in retryDir
Also these 2 params are exactly allocating memory
- `retryKeepSecs` - how many seconds should be kept in retry files, at least
- `allowedMetrics` - regexp of allowed metric. Every metric which is not passing check against regexp will be removed
- `log` - main log file, `-` is treated as STDOUT
- `hostname` - alias to use instead of os.Hostname() result
Expand Down
10 changes: 9 additions & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ type Config struct {
// Data, which was not sent will be buffered in this directory.
RetryDir string

// Time in seconds to keep metrics in retry file, at least
RetryKeepSecs int

// Prefix for metric to sum.
// Do not forget to include it in allowedMetrics if you change it.
SumPrefix string
Expand Down Expand Up @@ -145,6 +148,11 @@ func (conf *Config) LoadConfig(configFile string) error {
"MetricsPerSecond, ConnectTimeout must be greater than 0")
}

if conf.RetryKeepSecs <= 0 {
// Backward compatibility with old behavior
conf.RetryKeepSecs = conf.ClientSendInterval * 10
}

if conf.MonitoringPath == "" {
// This will be replaced later by monitoring routine
conf.MonitoringPath = "HOSTNAME"
Expand Down Expand Up @@ -262,7 +270,7 @@ func (conf *Config) GenerateLocalConfig() (*LocalConfig, error) {
/*
Retry file will take only 10 full buffers
*/
fileMetricSize: conf.MetricsPerSecond * conf.ClientSendInterval * 10,
fileMetricSize: conf.MetricsPerSecond * conf.RetryKeepSecs,
lg: lg,
allowedMetrics: regexp.MustCompile(conf.AllowedMetrics),
aggrRegexp: regexp.MustCompile(fmt.Sprintf("^(%s|%s|%s|%s)..*", conf.AvgPrefix, conf.SumPrefix, conf.MinPrefix, conf.MaxPrefix)),
Expand Down
3 changes: 3 additions & 0 deletions grafsy.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ useACL = false

retryDir = "/tmp/grafsy/retry"

# By default this one is equal to clientSendInterval*10
retryKeepSecs = 200

sumPrefix = "SUM."
avgPrefix = "AVG."
minPrefix = "MIN."
Expand Down

0 comments on commit ce87f54

Please sign in to comment.