v0.1.6 changed target check interval per stream, version info added, makefile added
This commit is contained in:
@ -2,9 +2,6 @@
|
||||
package config
|
||||
|
||||
type Config struct {
|
||||
// Global monitor settings
|
||||
Monitor MonitorConfig `toml:"monitor"`
|
||||
|
||||
// Stream configurations
|
||||
Streams []StreamConfig `toml:"streams"`
|
||||
}
|
||||
|
||||
@ -3,21 +3,20 @@ package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
lconfig "github.com/lixenwraith/config"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
lconfig "github.com/lixenwraith/config"
|
||||
)
|
||||
|
||||
func defaults() *Config {
|
||||
return &Config{
|
||||
Monitor: MonitorConfig{
|
||||
CheckIntervalMs: 100,
|
||||
},
|
||||
Streams: []StreamConfig{
|
||||
{
|
||||
Name: "default",
|
||||
Monitor: &StreamMonitorConfig{
|
||||
CheckIntervalMs: 100,
|
||||
Targets: []MonitorTarget{
|
||||
{Path: "./", Pattern: "*.log", IsFile: false},
|
||||
},
|
||||
|
||||
@ -17,7 +17,7 @@ type StreamConfig struct {
|
||||
}
|
||||
|
||||
type StreamMonitorConfig struct {
|
||||
CheckIntervalMs *int `toml:"check_interval_ms"`
|
||||
CheckIntervalMs int `toml:"check_interval_ms"`
|
||||
Targets []MonitorTarget `toml:"targets"`
|
||||
}
|
||||
|
||||
@ -35,8 +35,8 @@ func (s *StreamConfig) GetTargets(defaultTargets []MonitorTarget) []MonitorTarge
|
||||
}
|
||||
|
||||
func (s *StreamConfig) GetCheckInterval(defaultInterval int) int {
|
||||
if s.Monitor != nil && s.Monitor.CheckIntervalMs != nil {
|
||||
return *s.Monitor.CheckIntervalMs
|
||||
if s.Monitor != nil && s.Monitor.CheckIntervalMs > 0 {
|
||||
return s.Monitor.CheckIntervalMs
|
||||
}
|
||||
return defaultInterval
|
||||
}
|
||||
@ -7,10 +7,6 @@ import (
|
||||
)
|
||||
|
||||
func (c *Config) validate() error {
|
||||
if c.Monitor.CheckIntervalMs < 10 {
|
||||
return fmt.Errorf("check interval too small: %d ms", c.Monitor.CheckIntervalMs)
|
||||
}
|
||||
|
||||
if len(c.Streams) == 0 {
|
||||
return fmt.Errorf("no streams configured")
|
||||
}
|
||||
@ -29,11 +25,17 @@ func (c *Config) validate() error {
|
||||
}
|
||||
streamNames[stream.Name] = true
|
||||
|
||||
// Stream must have targets
|
||||
// Stream must have monitor config with targets
|
||||
if stream.Monitor == nil || len(stream.Monitor.Targets) == 0 {
|
||||
return fmt.Errorf("stream '%s': no monitor targets specified", stream.Name)
|
||||
}
|
||||
|
||||
// Validate check interval
|
||||
if stream.Monitor.CheckIntervalMs < 10 {
|
||||
return fmt.Errorf("stream '%s': check interval too small: %d ms (min: 10ms)",
|
||||
stream.Name, stream.Monitor.CheckIntervalMs)
|
||||
}
|
||||
|
||||
for j, target := range stream.Monitor.Targets {
|
||||
if target.Path == "" {
|
||||
return fmt.Errorf("stream '%s' target %d: empty path", stream.Name, j)
|
||||
|
||||
Reference in New Issue
Block a user