Documentation
¶
Overview ¶
Package monitor provides the orchestration API for agentwatch. It constructs and runs monitors, exposes snapshots, and delivers events.
Index ¶
- type Event
- type EventSink
- type EventSinkFunc
- type EventType
- type Health
- type HealthStatus
- type Monitor
- type MultiSink
- type Option
- func WithClock(c clock.Clock) Option
- func WithCompletionRetention(d time.Duration) Option
- func WithHealthThreshold(n int) Option
- func WithLogger(l *slog.Logger) Option
- func WithPollInterval(d time.Duration) Option
- func WithSink(sink EventSink) Option
- func WithSources(sources ...source.Source) Option
- func WithStaleThreshold(d time.Duration) Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Event ¶
type Event struct {
Seq uint64 `json:"seq"`
At time.Time `json:"at"`
Type EventType `json:"type"`
Sessions []session.SessionState `json:"sessions,omitempty"`
Updates []session.SessionState `json:"updates,omitempty"`
Removed []string `json:"removed,omitempty"`
Lifecycle *session.LifecycleEvent `json:"lifecycle,omitempty"`
Health *Health `json:"health,omitempty"`
}
Event is the single envelope delivered to EventSink implementations. Seq is monotonically increasing per monitor instance. Events are delivered after state commit and outside store locks.
type EventSink ¶
EventSink receives events from a Monitor. HandleEvent must return quickly; long-running sinks should wrap themselves in an async queue.
type EventSinkFunc ¶
EventSinkFunc is a function adapter for EventSink.
func (EventSinkFunc) HandleEvent ¶
func (f EventSinkFunc) HandleEvent(ctx context.Context, ev Event) error
HandleEvent implements EventSink.
type EventType ¶
type EventType string
EventType names the kind of monitor event.
const ( // EventSnapshot carries the full current state of all sessions. EventSnapshot EventType = "snapshot" // EventDelta carries only sessions that changed since the last event. EventDelta EventType = "delta" // EventLifecycle carries a single session lifecycle transition. EventLifecycle EventType = "lifecycle" // EventHealth carries an updated health record for a source. EventHealth EventType = "health" )
type Health ¶
type Health struct {
Source string `json:"source"`
Status HealthStatus `json:"status"`
DiscoverFailures int `json:"discoverFailures"`
ParseFailures int `json:"parseFailures"`
LastError string `json:"lastError,omitempty"`
UpdatedAt time.Time `json:"updatedAt"`
}
Health reports the operational state of a single source.
type HealthStatus ¶
type HealthStatus string
HealthStatus indicates the operational state of a source.
const ( // HealthHealthy means the source is operating normally. HealthHealthy HealthStatus = "healthy" // HealthDegraded means the source is experiencing intermittent failures. HealthDegraded HealthStatus = "degraded" // HealthFailed means the source has stopped providing data. HealthFailed HealthStatus = "failed" )
type Monitor ¶
type Monitor struct {
// contains filtered or unexported fields
}
Monitor orchestrates source polling, state management, and event delivery.
func New ¶
New creates a Monitor with the given options. It returns an error if the configuration is invalid.
func (*Monitor) Get ¶
func (m *Monitor) Get(id string) (session.SessionState, bool)
Get returns a deep copy of the session with the given ID and true, or a zero SessionState and false if no session with that ID exists.
func (*Monitor) Health ¶
Health returns the current health state for all sources. The returned map is safe to read and mutate without affecting the monitor.
func (*Monitor) PollOnce ¶
PollOnce discovers and parses all sources, updates the internal store, and delivers events to sinks. Individual source errors are logged but do not stop the poll. Returns ctx.Err() if the context is canceled.
func (*Monitor) Run ¶
Run starts the monitor loop. It polls sources at the configured interval and reaps terminal sessions whose retention window has expired. Run blocks until ctx is canceled and returns ctx.Err().
func (*Monitor) Snapshot ¶
func (m *Monitor) Snapshot() []session.SessionState
Snapshot returns a deep copy of all currently tracked sessions. The returned slice is safe to read and mutate without affecting the monitor.
type MultiSink ¶
type MultiSink struct {
// contains filtered or unexported fields
}
MultiSink delivers events to multiple sinks sequentially. It returns a joined error from all failing sinks.
func NewMultiSink ¶
NewMultiSink returns a MultiSink that delivers to the given sinks in order.
type Option ¶
type Option func(*config)
Option configures a Monitor.
func WithCompletionRetention ¶
WithCompletionRetention sets how long terminal sessions remain in the store before being removed.
func WithHealthThreshold ¶
WithHealthThreshold sets the number of consecutive failures before a source transitions from healthy to degraded. At 2*threshold it transitions to failed. A successful poll resets the failure count and returns the source to healthy.
func WithPollInterval ¶
WithPollInterval sets how often Run calls PollOnce.
func WithSources ¶
WithSources sets the sources the monitor will poll.
func WithStaleThreshold ¶
WithStaleThreshold sets how long an active session can go without new data before being transitioned to terminal with a "stale" event. A zero value disables stale detection.