pollers

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2022 License: GPL-2.0 Imports: 23 Imported by: 0

Documentation

Overview

package status defines a status collector metric which aggregates status responses from underlying services.

Index

Constants

View Source
const (
	PollerTypeBasic             = "basic"
	PollerTypeChallengeResponse = "challenge-response"
	PollerTypeHTTP              = "http"
)
View Source
const MetricLabelFailed = "failed"
View Source
const MetricLabelSuccess = "successful"
View Source
const Namespace = "poller"
View Source
const PollStatusFailed = Status(float64(0))
View Source
const PollStatusSuccess = Status(float64(1))

Variables

View Source
var ErrTooManyRedirects = errors.New("Too many redirects")
View Source
var PollStatusUnknown = Status(math.NaN()) //nolint:gochecknoglobals

Functions

func NewHTTPClient

func NewHTTPClient(conn *PollConnection, enableRedirects bool, maxRedirects int64) (*http.Client, *atomic.Int64)

NewHTTPClient returns an HTTP client which talks over the already established connection.

Types

type BasePoller added in v0.9.1

type BasePoller interface {
	Poller
	// contains filtered or unexported methods
}

BasePoller implements the doPoll method which returns the net.Conn so a higher level Poller can use it. Poller's which functionally cannot release the connection cannot be BasePollers.

func NewBasicService

func NewBasicService(host *Host, opts config.BasicServiceConfig, constantLabels prometheus.Labels) BasePoller

type BasicService

type BasicService struct {
	PortOpen      prometheus.Gauge       // Port open metric
	PortOpenCount *prometheus.CounterVec // Cumulative number of port open checks
	// contains filtered or unexported fields
}

func (*BasicService) Collect

func (s *BasicService) Collect(ch chan<- prometheus.Metric)

func (*BasicService) Describe

func (s *BasicService) Describe(ch chan<- *prometheus.Desc)

func (*BasicService) Host

func (s *BasicService) Host() *Host

func (*BasicService) Labels added in v0.10.0

func (s *BasicService) Labels() prometheus.Labels

func (*BasicService) LogFields added in v0.10.0

func (s *BasicService) LogFields() []zap.Field

LogFields returns a description of this poller as zap logging fields.

func (*BasicService) Name

func (s *BasicService) Name() string

func (*BasicService) Poll

func (s *BasicService) Poll()

Poll implements the actual polling functionality of the service. It is distinct to the prometheus scrapers because we only ever want to run polls on *our* schedule.

func (*BasicService) Port

func (s *BasicService) Port() uint64

func (*BasicService) Proto

func (s *BasicService) Proto() string

func (*BasicService) Status

func (s *BasicService) Status() Status

type ChallengeResponseMetricSet added in v0.9.1

type ChallengeResponseMetricSet struct {
	ServiceRequestSuccessful       prometheus.Gauge // Indicates if the service could be successfully sent data
	ServiceRequestSize             prometheus.Gauge // Number of bytes sent to the service
	ServiceChallengeStartTimeStamp prometheus.Gauge // Timestamp when the most recent service challenge started
	ServiceChallengeTime           prometheus.Gauge // Time it took to send the challenge

	ServiceResponseTimeToFirstByte prometheus.Gauge // Time it took the service to send anything

	ServiceRespondedSuccessfully prometheus.Gauge // Indicates if the service responded with expected data
	ServiceResponseSize          prometheus.Gauge // Number of bytes read before response match
	ServiceResponseDuration      prometheus.Gauge // Time in microseconds to read the response bytes

	ServiceRequestCount                 *prometheus.CounterVec // Cumulative count of service requests
	ServiceRespondedCount               *prometheus.CounterVec // Cumulative count of service responses
	ServiceResponseTimeToFirstByteCount prometheus.Counter     // Cumulative count of service responses
}

ChallengeResponseMetricSet implements the actual challenge-response metrics.

func NewChallengeResponseMetricSet added in v0.9.1

func NewChallengeResponseMetricSet(constantLabels prometheus.Labels) ChallengeResponseMetricSet

NewChallengeResponseMetricSet initializes a new set of metrics with the given constant labels.

func (*ChallengeResponseMetricSet) Collect added in v0.9.1

func (crms *ChallengeResponseMetricSet) Collect(ch chan<- prometheus.Metric)

func (*ChallengeResponseMetricSet) Describe added in v0.9.1

func (crms *ChallengeResponseMetricSet) Describe(ch chan<- *prometheus.Desc)

type ChallengeResponseService

type ChallengeResponseService struct {
	ChallengeResponseMetricSet

	BasePoller
	// contains filtered or unexported fields
}

ChallengeResponseService implements a bare challenge-response service.

func NewChallengeResponseService

func NewChallengeResponseService(host *Host, opts config.ChallengeResponseConfig) *ChallengeResponseService

func (*ChallengeResponseService) Challenge

func (crs *ChallengeResponseService) Challenge(conn io.Writer) (float64, Status)

Challenge sends the challenge to the service connection, and returns in Prometheus form the number of bytes and result.

func (*ChallengeResponseService) Collect

func (crs *ChallengeResponseService) Collect(ch chan<- prometheus.Metric)

func (*ChallengeResponseService) Describe

func (crs *ChallengeResponseService) Describe(ch chan<- *prometheus.Desc)

Describe returns the Prometheus metrics description.

func (*ChallengeResponseService) Poll

func (crs *ChallengeResponseService) Poll()

func (*ChallengeResponseService) PollerType added in v0.10.0

func (crs *ChallengeResponseService) PollerType() string

func (*ChallengeResponseService) Status

func (crs *ChallengeResponseService) Status() Status

Status is used by the web-UI for quick inspections.

type HTTPService

type HTTPService struct {
	ChallengeResponseMetricSet

	Poller // but it is a Poller
	// contains filtered or unexported fields
}

HTTPService is a degenerate ChallengeResponse service which does specific status code checking and always reads all the bytes it's sent. However a challenge response poller is quite different to using the HTTP client library so an HTTPService only inherits challenge-response configuration, and a basic poller for connections - it does not actually a challenge-response service.

func NewHTTPService

func NewHTTPService(host *Host, opts config.HTTPServiceConfig) *HTTPService

func (*HTTPService) Collect

func (hs *HTTPService) Collect(ch chan<- prometheus.Metric)

func (*HTTPService) Describe

func (hs *HTTPService) Describe(ch chan<- *prometheus.Desc)

func (*HTTPService) Poll

func (hs *HTTPService) Poll()

func (*HTTPService) Status

func (hs *HTTPService) Status() Status

Return true if the last polled status was one of the allowed statuses.

type Host

type Host struct {
	IP string // Resolved IP address (from last poll)

	Pollers []Poller // List of services to poll

	// Instantaneous metrics (easy to alert against)
	NumPolls      prometheus.Counter // Number of times polls have been attempted
	LastPollTime  prometheus.Gauge   // Time of last poll
	Resolvable    prometheus.Gauge   // Is the hostname resolvable (IP is always true)
	PathReachable prometheus.Gauge   // Is the host IP routable?
	PingLatency   prometheus.Gauge   // Latency to contact host - NaN if unavailable

	// Tally metrics (more accurate but harder)
	ResolvableCount *prometheus.CounterVec // success/failure count
	ReachableCount  *prometheus.CounterVec // success/failure count
	PingResultCount *prometheus.CounterVec // cumulative count of pings
	LatencyCount    prometheus.Counter     // cumulative latency from successful polls

	*config.HostConfig
	// contains filtered or unexported fields
}

Hosts are the top of a service hierarchy and contain a number of pollers. If the host fails to be resolvable or routable, then all pollers beneath it stop returning data (specifically they return NaN).

func NewHost

func NewHost(opts *config.HostConfig) *Host

func (*Host) Collect

func (s *Host) Collect(ch chan<- prometheus.Metric)

func (*Host) Describe

func (s *Host) Describe(ch chan<- *prometheus.Desc)

func (*Host) LastPoll

func (s *Host) LastPoll() time.Time

func (*Host) Latency

func (s *Host) Latency() time.Duration

func (*Host) NextPoll

func (s *Host) NextPoll() time.Duration

Return the expected time till the next poll is attempted.

func (*Host) Poll

func (s *Host) Poll(limiter *Limiter, hostQueue chan<- *Host)

Polls this host, and queues up the next poll.

func (*Host) SincePoll

func (s *Host) SincePoll() time.Duration

func (*Host) Status

func (s *Host) Status() Status

type Limiter

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

Basic generic resource limiter.

func NewLimiter

func NewLimiter(size int) *Limiter

func (*Limiter) Lock

func (lim *Limiter) Lock()

func (*Limiter) Unlock

func (lim *Limiter) Unlock()

type PollConnection added in v0.9.1

type PollConnection struct {
	net.Conn
	// contains filtered or unexported fields
}

PollConnection wraps net.Conn and carries additional information about the service poll.

func (*PollConnection) Context added in v0.9.1

func (p *PollConnection) Context() context.Context

func (*PollConnection) Deadline added in v0.9.1

func (p *PollConnection) Deadline() time.Time

Deadline is the timeout set when the connection was originally opened.

func (*PollConnection) Dialer added in v0.9.1

func (p *PollConnection) Dialer() proxy.ContextDialer

type Poller

type Poller interface {
	// Poll causes the service to update it's internal state.
	// Every Poll implementation should call any nested Poll implementations
	// *first* before running it's own functionality.
	Poll()

	Name() string   // Returns the name of the poller
	Proto() string  // Returns the protocol of the poller
	Port() uint64   // Returns the port of the poller
	Status() Status // Returns the overall status of the service
	Host() *Host    // Returns the attached host of the service

	Labels() prometheus.Labels
	Describe(ch chan<- *prometheus.Desc)
	Collect(ch chan<- prometheus.Metric)

	LogFields() []zap.Field // Return a description of this poller in zap fields
	// contains filtered or unexported methods
}

type ServiceStatusMetricCollector added in v0.10.0

type ServiceStatusMetricCollector struct {
	ServiceStatus *prometheus.GaugeVec
	// contains filtered or unexported fields
}

func NewServiceStatusMetrics added in v0.10.0

func NewServiceStatusMetrics() *ServiceStatusMetricCollector

NewServiceStatusMetrics creates a new service status metric collector.

func (*ServiceStatusMetricCollector) AddPoller added in v0.10.0

func (ssm *ServiceStatusMetricCollector) AddPoller(pollers ...Poller)

AddPoller ads a poller to the collector.

func (*ServiceStatusMetricCollector) Collect added in v0.10.0

func (ssm *ServiceStatusMetricCollector) Collect(ch chan<- prometheus.Metric)

Collect implements the prometheus metric descriptors interface.

func (*ServiceStatusMetricCollector) Describe added in v0.10.0

func (ssm *ServiceStatusMetricCollector) Describe(ch chan<- *prometheus.Desc)

Describe implements the prometheus metric descriptors interface.

type Status

type Status float64

func TryReadMatch added in v0.9.1

func TryReadMatch(conn io.Reader, config *config.ChallengeResponseConfig) (Status, float64, time.Duration)

type TLSService added in v0.9.1

type TLSService struct {
	CertificateNotAfter   *prometheus.GaugeVec   // Epoch time the SSL certificate expires
	CertificateNotBefore  *prometheus.GaugeVec   // Epoch time the SSL certificate is not valid before
	CertificateValid      *prometheus.GaugeVec   // Whether the certificate validates to this host
	CertificateValidCount *prometheus.CounterVec // Cumulative count of SSL validations

	CertificateMatchesPin prometheus.Gauge // Whether the certificate matches the pinned certificate list

	BasePoller
	// contains filtered or unexported fields
}

A TLS protected service. This can be any type of service, and simply adds certificate metrics to the base service. As a result it is not directly instantiated.

func (*TLSService) Collect added in v0.9.1

func (s *TLSService) Collect(ch chan<- prometheus.Metric)

func (*TLSService) Describe added in v0.9.1

func (s *TLSService) Describe(ch chan<- *prometheus.Desc)

func (*TLSService) Poll added in v0.9.1

func (s *TLSService) Poll()

Poll but for the SSL service.

func (*TLSService) Status added in v0.12.0

func (s *TLSService) Status() Status

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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