v0.1.6 changed target check interval per stream, version info added, makefile added

This commit is contained in:
2025-07-07 18:20:46 -04:00
parent 069818bf3d
commit 80180f74a0
14 changed files with 272 additions and 66 deletions

View File

@ -2,9 +2,6 @@
package config
type Config struct {
// Global monitor settings
Monitor MonitorConfig `toml:"monitor"`
// Stream configurations
Streams []StreamConfig `toml:"streams"`
}

View File

@ -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},
},

View File

@ -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
}

View File

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

View File

@ -4,9 +4,10 @@ package logstream
import (
"context"
"fmt"
"logwisp/src/internal/config"
"sync"
"time"
"logwisp/src/internal/config"
)
func (ls *LogStream) Shutdown() {

View File

@ -4,9 +4,11 @@ package logstream
import (
"encoding/json"
"fmt"
"github.com/valyala/fasthttp"
"strings"
"sync"
"github.com/valyala/fasthttp"
"logwisp/src/internal/version"
)
type routerServer struct {
@ -81,6 +83,7 @@ func (rs *routerServer) handleGlobalStatus(ctx *fasthttp.RequestCtx) {
status := map[string]interface{}{
"service": "LogWisp Router",
"version": version.Short(),
"port": rs.port,
"streams": streams,
"total_streams": len(streams),

View File

@ -14,6 +14,7 @@ import (
"github.com/valyala/fasthttp"
"logwisp/src/internal/config"
"logwisp/src/internal/monitor"
"logwisp/src/internal/version"
)
type HTTPStreamer struct {
@ -286,7 +287,7 @@ func (h *HTTPStreamer) handleStatus(ctx *fasthttp.RequestCtx) {
status := map[string]interface{}{
"service": "LogWisp",
"version": "3.0.0",
"version": version.Short(),
"server": map[string]interface{}{
"type": "http",
"port": h.config.Port,
@ -318,17 +319,17 @@ func (h *HTTPStreamer) handleStatus(ctx *fasthttp.RequestCtx) {
ctx.SetBody(data)
}
// GetActiveConnections returns the current number of active clients
// Returns the current number of active clients
func (h *HTTPStreamer) GetActiveConnections() int32 {
return h.activeClients.Load()
}
// GetStreamPath returns the configured stream endpoint path
// Returns the configured stream endpoint path
func (h *HTTPStreamer) GetStreamPath() string {
return h.streamPath
}
// GetStatusPath returns the configured status endpoint path
// Returns the configured status endpoint path
func (h *HTTPStreamer) GetStatusPath() string {
return h.statusPath
}

View File

@ -3,8 +3,9 @@ package stream
import (
"fmt"
"github.com/panjf2000/gnet/v2"
"sync"
"github.com/panjf2000/gnet/v2"
)
type tcpServer struct {

View File

@ -146,6 +146,7 @@ func (t *TCPStreamer) formatHeartbeat() []byte {
data["uptime_seconds"] = int(time.Since(t.startTime).Seconds())
}
// For TCP, always use JSON format
jsonData, _ := json.Marshal(data)
return append(jsonData, '\n')
}

View File

@ -0,0 +1,24 @@
// FILE: src/internal/version/version.go
package version
import "fmt"
var (
// Version is set at compile time via -ldflags
Version = "dev"
GitCommit = "unknown"
BuildTime = "unknown"
)
// returns a formatted version string
func String() string {
if Version == "dev" {
return fmt.Sprintf("dev (commit: %s, built: %s)", GitCommit, BuildTime)
}
return fmt.Sprintf("%s (commit: %s, built: %s)", Version, GitCommit, BuildTime)
}
// returns just the version tag
func Short() string {
return Version
}