Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/netronome/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ func runServer(cmd *cobra.Command, args []string) error {
// create packet loss service if enabled
if cfg.PacketLoss.Enabled {
// We'll set the actual broadcaster after creating the server
packetLossService = speedtest.NewPacketLossService(db, notifier, nil, cfg.PacketLoss.MaxConcurrentMonitors, cfg.PacketLoss.PrivilegedMode)
packetLossService = speedtest.NewPacketLossService(db, notifier, nil, cfg.PacketLoss.MaxConcurrentMonitors, cfg.PacketLoss.PrivilegedMode, cfg.PacketLoss.MTREnableDNS)
}

// Create monitor service variable
Expand Down
1 change: 1 addition & 0 deletions config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ default_interval = 3600
default_packet_count = 10
max_concurrent_monitors = 10
privileged_mode = true
mtr_enable_dns = false

[monitor]
enabled = true
Expand Down
10 changes: 10 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ type PacketLossConfig struct {
DefaultPacketCount int `toml:"default_packet_count" env:"PACKETLOSS_DEFAULT_PACKET_COUNT"`
MaxConcurrentMonitors int `toml:"max_concurrent_monitors" env:"PACKETLOSS_MAX_CONCURRENT_MONITORS"`
PrivilegedMode bool `toml:"privileged_mode" env:"PACKETLOSS_PRIVILEGED_MODE"`
MTREnableDNS bool `toml:"mtr_enable_dns" env:"PACKETLOSS_MTR_ENABLE_DNS"`
RestoreMonitorsOnStartup bool `toml:"restore_monitors_on_startup" env:"PACKETLOSS_RESTORE_MONITORS_ON_STARTUP"`
}

Expand Down Expand Up @@ -276,6 +277,7 @@ func New() *Config {
DefaultPacketCount: 10,
MaxConcurrentMonitors: 10,
PrivilegedMode: true,
MTREnableDNS: false,
RestoreMonitorsOnStartup: false,
},
Agent: AgentConfig{
Expand Down Expand Up @@ -586,6 +588,11 @@ func (c *Config) loadPacketLossFromEnv() {
c.PacketLoss.PrivilegedMode = privileged
}
}
if v := getEnv("PACKETLOSS_MTR_ENABLE_DNS"); v != "" {
if enableDNS, err := strconv.ParseBool(v); err == nil {
c.PacketLoss.MTREnableDNS = enableDNS
}
}
if v := getEnv("PACKETLOSS_RESTORE_MONITORS_ON_STARTUP"); v != "" {
if restore, err := strconv.ParseBool(v); err == nil {
c.PacketLoss.RestoreMonitorsOnStartup = restore
Expand Down Expand Up @@ -863,6 +870,9 @@ func (c *Config) WriteToml(w io.Writer) error {
if _, err := fmt.Fprintf(w, "privileged_mode = %v # Use privileged ICMP mode for better MTR support (requires root/sudo)\n", cfg.PacketLoss.PrivilegedMode); err != nil {
return err
}
if _, err := fmt.Fprintf(w, "mtr_enable_dns = %v # Enable DNS resolution in MTR tests to show hostnames instead of IPs\n", cfg.PacketLoss.MTREnableDNS); err != nil {
return err
}

// Monitor section
if _, err := fmt.Fprintln(w, ""); err != nil {
Expand Down
22 changes: 13 additions & 9 deletions internal/speedtest/mtr_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,25 @@ func killMTRProcessGroup(pid int) error {

// buildMTRArgs builds Unix-specific MTR arguments
// On Unix, we can use the -j flag for JSON output directly
func buildMTRArgs(host string, packetCount int, privilegedMode bool) ([]string, string, error) {
func buildMTRArgs(host string, packetCount int, privilegedMode bool, enableDNS bool) ([]string, string, error) {
args := []string{
"-4", // Force IPv4
"-j", // JSON output
"-c", fmt.Sprintf("%d", packetCount), // Number of cycles
"-i", "1", // 1 second interval
"--no-dns", // Skip DNS resolution for speed
host,
"-4", // Force IPv4
"-j", // JSON output
"-c", fmt.Sprintf("%d", packetCount), // Number of cycles
"-i", "1", // 1 second interval
}


if !enableDNS {
args = append(args, "--no-dns")
}

args = append(args, host)

// Add UDP mode if not privileged
if !privilegedMode {
args = append([]string{"-u"}, args...)
}

// Return empty string to indicate Unix doesn't need parsing
return args, "", nil
}
Expand Down
12 changes: 9 additions & 3 deletions internal/speedtest/mtr_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,22 @@ func killMTRProcessGroup(pid int) error {
// buildMTRArgs builds Windows-specific MTR arguments
// Windows MTR doesn't support -j for JSON output, so we use -r for report mode
// and -w for wide format, then capture stdout and parse it
func buildMTRArgs(host string, packetCount int, privilegedMode bool) ([]string, string, error) {
func buildMTRArgs(host string, packetCount int, privilegedMode bool, enableDNS bool) ([]string, string, error) {
args := []string{
"-4", // Force IPv4
"-r", // Report mode
"-w", // Wide report, don't truncate hostnames
"-n", // No DNS lookups (numeric output only)
}

if !enableDNS {
args = append(args, "-n") // No DNS lookups (numeric output only)
}

args = append(args,
"-c", fmt.Sprintf("%d", packetCount), // Number of cycles
"-i", "1", // 1 second interval
"-t", "2", // 2 second timeout per hop to prevent hanging on unresponsive hops
}
)

// Add UDP mode if not privileged (Windows MTR defaults to ICMP in privileged mode)
if !privilegedMode {
Expand Down
8 changes: 5 additions & 3 deletions internal/speedtest/packetloss.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,11 @@ type PacketLossService struct {
}
maxConcurrent int
privilegedMode bool
enableDNS bool
}

// NewPacketLossService creates a new packet loss monitoring service
func NewPacketLossService(db database.Service, notifier *notifications.Notifier, broadcast func(types.PacketLossUpdate), maxConcurrent int, privilegedMode bool) *PacketLossService {
func NewPacketLossService(db database.Service, notifier *notifications.Notifier, broadcast func(types.PacketLossUpdate), maxConcurrent int, privilegedMode bool, enableDNS bool) *PacketLossService {
if maxConcurrent <= 0 {
maxConcurrent = 10
}
Expand All @@ -69,6 +70,7 @@ func NewPacketLossService(db database.Service, notifier *notifications.Notifier,
broadcast: broadcast,
maxConcurrent: maxConcurrent,
privilegedMode: privilegedMode,
enableDNS: enableDNS,
}
}

Expand Down Expand Up @@ -1007,7 +1009,7 @@ func (s *PacketLossService) runMTRTest(monitor *PacketLossMonitor) (*probing.Sta
defer cancel()

// Build platform-specific MTR command arguments
args, platformFlag, err := buildMTRArgs(monitor.Host, monitor.PacketCount, s.privilegedMode)
args, platformFlag, err := buildMTRArgs(monitor.Host, monitor.PacketCount, s.privilegedMode, s.enableDNS)
if err != nil {
return nil, fmt.Errorf("failed to build MTR arguments: %w", err)
}
Expand Down Expand Up @@ -1174,7 +1176,7 @@ func (s *PacketLossService) runMTRTest(monitor *PacketLossMonitor) (*probing.Sta
Msg("MTR privileged mode failed, trying UDP mode")

// Rebuild args with UDP mode for retry
retryArgs, retryPlatformFlag, buildErr := buildMTRArgs(monitor.Host, monitor.PacketCount, false)
retryArgs, retryPlatformFlag, buildErr := buildMTRArgs(monitor.Host, monitor.PacketCount, false, s.enableDNS)
if buildErr != nil {
return nil, fmt.Errorf("failed to build retry MTR arguments: %w", buildErr)
}
Expand Down
Loading