example

package
v1.6.1 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2025 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package example provides example monitor implementations that demonstrate the monitor registration and factory patterns used by Node Doctor.

This package serves as both documentation and a testing utility. The no-op monitor is particularly useful for testing the registry system and as a template for implementing new monitor types.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewNoOpMonitor

func NewNoOpMonitor(ctx context.Context, config types.MonitorConfig) (types.Monitor, error)

NewNoOpMonitor creates a new no-op monitor instance. This factory function demonstrates the standard pattern for monitor creation:

  1. Parse monitor-specific configuration from config.Config
  2. Validate required parameters
  3. Apply defaults for optional parameters
  4. Create and return the monitor instance

The factory is thread-safe and stateless, allowing concurrent creation of multiple monitor instances.

func ValidateNoOpConfig

func ValidateNoOpConfig(config types.MonitorConfig) error

ValidateNoOpConfig validates the no-op monitor configuration. This function demonstrates configuration validation patterns and provides early error detection before monitor creation.

While the no-op monitor is very permissive, real monitors should validate required parameters, file paths, network addresses, etc.

Types

type NoOpConfig

type NoOpConfig struct {
	// Interval controls how often the monitor sends status updates.
	// Defaults to 30 seconds if not specified.
	Interval string `json:"interval,omitempty"`

	// TestMessage is included in status reports for testing purposes.
	// Defaults to "NoOp monitor is healthy".
	TestMessage string `json:"testMessage,omitempty"`

	// IncludeEvents controls whether the monitor includes test events
	// in its status reports. Defaults to false.
	IncludeEvents bool `json:"includeEvents,omitempty"`
}

NoOpConfig contains configuration options specific to the no-op monitor. This demonstrates how monitors can define their own configuration schemas within the generic MonitorConfig.Config map.

type NoOpMonitor

type NoOpMonitor struct {
	// contains filtered or unexported fields
}

NoOpMonitor is a monitor implementation that does nothing but report healthy status. It serves as an example of the monitor interface implementation and can be used for testing registry functionality without side effects.

The NoOpMonitor periodically sends status updates but never reports problems. It can be configured with custom intervals and test data for validation purposes.

func (*NoOpMonitor) GetName

func (n *NoOpMonitor) GetName() string

GetName returns the monitor name for debugging purposes. This is not part of the Monitor interface but can be useful for testing.

func (*NoOpMonitor) IsRunning

func (n *NoOpMonitor) IsRunning() bool

IsRunning returns whether the monitor is currently running. This is not part of the Monitor interface but can be useful for testing.

func (*NoOpMonitor) Start

func (n *NoOpMonitor) Start() (<-chan *types.Status, error)

Start begins the monitoring process and returns a channel for status updates. This implements the types.Monitor interface and demonstrates the standard monitoring loop pattern.

The monitor runs asynchronously and sends periodic status updates through the returned channel until Stop() is called.

func (*NoOpMonitor) Stop

func (n *NoOpMonitor) Stop()

Stop gracefully stops the monitor. This implements the types.Monitor interface and demonstrates proper cleanup.

Stop blocks until the monitoring goroutine has fully stopped and cleaned up.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL