Documentation ¶
Index ¶
- Constants
- type Duration
- type Entry
- type Monitor
- func (monitor *Monitor) CheckSites(ctx context.Context)
- func (monitor *Monitor) Collect(ch chan<- prometheus.Metric)
- func (monitor *Monitor) Describe(ch chan<- *prometheus.Desc)
- func (monitor *Monitor) GetEntry(url string) (entry Entry, ok bool)
- func (monitor *Monitor) Health(w http.ResponseWriter, _ *http.Request)
- func (monitor *Monitor) Run(ctx context.Context, interval time.Duration) (err error)
- type SiteSpec
- type SiteState
Constants ¶
const DefaultMaxConcurrentChecks = 5
DefaultMaxConcurrentChecks specifies the default maximum number of parallel checks
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Duration ¶
Duration datatype. Equivalent to time.Duration, but allows us to marshal/unmarshal Entry data structure to/from json
func (Duration) MarshalJSON ¶
MarshalJSON marshals Duration to bytes
func (*Duration) UnmarshalJSON ¶
UnmarshalJSON unmarshals bytes to a Duration
type Entry ¶
type Entry struct { // Spec contains the site's specification. See SiteSpec Spec SiteSpec `json:"spec"` // State contains the site's state. See SiteState State *SiteState `json:"state,omitempty"` }
The Entry structure holds all information on one host to be checked
type Monitor ¶
type Monitor struct { // The Register channel is used to add a host to the monitor Register chan SiteSpec // The Unregister channel is used to remove a host from the monitor Unregister chan SiteSpec // HTTPClient is the http.Client that will be used to check sites. // Under normal circumstances, this can be left blank and Monitor will create the required client. HTTPClient *http.Client // MaxConcurrentChecks limits the number of sites that are checked in parallel. Default: DefaultMaxConcurrentChecks MaxConcurrentChecks int64 // contains filtered or unexported fields }
A Monitor checks a list of website, either on a continuous basis through the Run() function, or on demand via the CheckSites method. See the Entry structure for attributes of a site that are checked.
func (*Monitor) CheckSites ¶
CheckSites checks each site. The site's status isn't reported here, but is kept internally to be scraped by Prometheus using the Collect function.
func (*Monitor) Collect ¶
func (monitor *Monitor) Collect(ch chan<- prometheus.Metric)
Collect implements the prometheus collector Collect interface
func (*Monitor) Describe ¶
func (monitor *Monitor) Describe(ch chan<- *prometheus.Desc)
Describe implements the prometheus collector Describe interface
func (*Monitor) GetEntry ¶
GetEntry returns the monitor's entry for the specified site URL. Should only be used for testing purposes
func (*Monitor) Health ¶
func (monitor *Monitor) Health(w http.ResponseWriter, _ *http.Request)
Health reports back all configured sites and their state
type SiteSpec ¶ added in v0.3.4
type SiteSpec struct { // URL of the site URL string `json:"url"` // Name of the site Name string `json:"name,omitempty"` }
A SiteSpec to monitor
type SiteState ¶ added in v0.3.4
type SiteState struct { // Up indicates if the site is up or down Up bool `json:"up"` // LastError is the last error received when checking the site LastError string `json:"last_error,omitempty"` // HTTPCode is the last HTTP Code received when checking the site HTTPCode int `json:"http_code,omitempty"` // CertificateAge contains the number of days that the site's TLS certificate is still valid // IsTLS indicates the site is using encryption (i.e. TLS) IsTLS bool `json:"is_tls"` // For HTTP sites, this will be zero. CertificateAge float64 `json:"certificate_age,omitempty"` // Latency contains the time it took to check the site Latency Duration `json:"latency,omitempty"` // LastCheck is the timestamp the site was last checked. Before there first check, this is zero LastCheck time.Time `json:"last_check,omitempty"` }
The SiteState structure holds the attributes that will be checked