monitor

package
v0.21.1 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

View Source
const MaxProbeTimeout = 10 * time.Second

MaxProbeTimeout is the longest agent probe timeout (currently HTTP). Hub requests that run a probe must allow this time in addition to transport overhead.

Variables

This section is empty.

Functions

This section is empty.

Types

type CertInfo added in v0.21.0

type CertInfo struct {
	// Expires is the certificate's NotAfter Unix timestamp in milliseconds.
	Expires int64  `cbor:"0,keyasint" json:"expires"`
	Issuer  string `cbor:"1,keyasint,omitempty" json:"issuer,omitempty"`
}

CertInfo holds details of the leaf TLS certificate presented by a target.

type Config

type Config struct {
	// ID is the stable network_monitors record ID generated by the hub.
	ID       string `cbor:"0,keyasint"`
	Target   string `cbor:"1,keyasint"`
	Protocol string `cbor:"2,keyasint"` // "icmp", "tcp", "http", or "dns"
	Port     uint16 `cbor:"3,keyasint,omitempty"`
	Interval uint16 `cbor:"4,keyasint"` // seconds
	// Server is the DNS server to query (host or host:port, default port 53).
	// Only used when Protocol is "dns"; empty means use the system resolver.
	Server string `cbor:"5,keyasint,omitempty"`
	// SkipTLSVerify disables certificate verification for HTTPS targets, such as
	// those with self-signed certificates. Only used when Protocol is "http".
	SkipTLSVerify bool `cbor:"6,keyasint,omitempty" db:"skipTlsVerify"`
}

Config defines a network monitor task sent from hub to agent.

type Result

type Result struct {
	AvgResponse   int64   `cbor:"0,keyasint,omitempty"`
	AvgResponse1h int64   `cbor:"1,keyasint,omitempty"`
	MinResponse   int64   `cbor:"2,keyasint,omitempty"`
	MinResponse1h int64   `cbor:"3,keyasint,omitempty"`
	MaxResponse   int64   `cbor:"4,keyasint,omitempty"`
	MaxResponse1h int64   `cbor:"5,keyasint,omitempty"`
	PacketLoss    float64 `cbor:"6,keyasint,omitempty"`
	PacketLoss1h  float64 `cbor:"7,keyasint,omitempty"`
	// LastProbeAt is the latest completed probe's Unix timestamp in milliseconds.
	LastProbeAt int64 `cbor:"8,keyasint"`
	// SampleCount includes all completed probes since this monitor started.
	// Used for alert warm-up even when the interval is longer than 20 minutes.
	SampleCount int64 `cbor:"9,keyasint,omitempty"`
	// Counts and sum cover the current response window (or latest-sample
	// fallback), not the hourly window or lifetime SampleCount.
	TotalCount   int64 `cbor:"10,keyasint"`
	SuccessCount int64 `cbor:"11,keyasint"`
	ResponseSum  int64 `cbor:"12,keyasint"`
	// Cert is set for HTTPS targets when a certificate check has new info the hub has not stored yet.
	Cert *CertInfo `cbor:"13,keyasint,omitempty"`
}

Result holds aggregated monitor results for a single target.

0: avg response in microseconds

1: 1h average response in microseconds

2: min response in microseconds

3: 1h min response in microseconds

4: max response in microseconds

5: 1h max response in microseconds

6: packet loss percentage (0-100)

7: 1h packet loss percentage (0-100)

type Stats

type Stats struct {
	ResAvg       float64 `json:"res_avg" db:"-"` // Derived for display; not stored.
	ResMin       float64 `json:"res_min" db:"res_min"`
	ResMax       float64 `json:"res_max" db:"res_max"`
	Loss         float64 `json:"loss" db:"-"` // Derived for display; not stored.
	TotalCount   int64   `json:"-" db:"total_count"`
	SuccessCount int64   `json:"-" db:"success_count"`
	ResponseSum  int64   `json:"-" db:"res_sum"`
}

Stats holds response times in microseconds and packet loss percentage (0-100).

func (Stats) FromResult

func (s Stats) FromResult(result Result) Stats

type SyncAction

type SyncAction uint8
const (
	// SyncActionReplace indicates a full sync where the provided configs should replace all existing monitors for the system.
	SyncActionReplace SyncAction = iota
	// SyncActionUpsert indicates an incremental sync where the provided config should be added or updated.
	SyncActionUpsert
	// SyncActionDelete indicates an incremental sync where the provided config should be removed.
	SyncActionDelete
)

type SyncRequest

type SyncRequest struct {
	Action  SyncAction `cbor:"0,keyasint"`
	Config  Config     `cbor:"1,keyasint,omitempty"`
	Configs []Config   `cbor:"2,keyasint,omitempty"`
	RunNow  bool       `cbor:"3,keyasint,omitempty"`
}

SyncRequest defines an incremental or full monitor sync request sent to the agent.

type SyncResponse

type SyncResponse struct {
	Result Result `cbor:"0,keyasint,omitempty"`
}

SyncResponse returns the immediate result for an upsert when requested.

Jump to

Keyboard shortcuts

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