discovery

package
v0.0.0-...-48273b5 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2024 License: Apache-2.0 Imports: 63 Imported by: 0

Documentation

Overview

Package discovery contains function related to the service discovery.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddDefaultInputs

func AddDefaultInputs(metricRegistry GathererRegistry, inputsConfig inputs.CollectorConfig, vethProvider *veth.Provider) error

AddDefaultInputs adds system inputs to a collector.

Types

type Application

type Application struct {
	Name string
	Type ApplicationType
}

type ApplicationType

type ApplicationType int
const (
	ApplicationUnset         ApplicationType = 0
	ApplicationDockerCompose ApplicationType = 1
)

type CheckDetails

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

CheckDetails is used to save a check and his id.

type CheckNow

type CheckNow func(ctx context.Context) types.StatusDescription

CheckNow is type of check function.

type Collector

type Collector interface {
	AddInput(input telegraf.Input, shortName string) (int, error)
	RemoveInput(id int)
}

Collector will gather metrics for added inputs.

type Discoverer

type Discoverer interface {
	Discovery(ctx context.Context, maxAge time.Duration) (services []Service, err error)
	LastUpdate() time.Time
}

Discoverer allow to discover services. See DynamicDiscovery and Discovery.

type Discovery

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

Discovery implements the full discovery mechanism. It will take information from both the dynamic discovery (service currently running) and previously detected services. It will configure metrics input and add them to a Collector.

func New

func New(
	dynamicDiscovery Discoverer,
	metricRegistry GathererRegistry,
	state State,
	containerInfo containerInfoProvider,
	servicesOverride []config.Service,
	isServiceIgnored func(Service) bool,
	isCheckIgnored func(Service) bool,
	isInputIgnored func(Service) bool,
	isContainerIgnored func(c facts.Container) bool,
	processFact processFact,
	absentServiceDeactivationDelay time.Duration,
) (*Discovery, prometheus.MultiError)

New returns a new Discovery and some warnings.

func (*Discovery) Close

func (d *Discovery) Close()

Close stop & cleanup inputs & check created by the discovery.

func (*Discovery) DiagnosticArchive

func (d *Discovery) DiagnosticArchive(ctx context.Context, zipFile types.ArchiveWriter) error

DiagnosticArchive add to a zipfile useful diagnostic information.

func (*Discovery) Discovery

func (d *Discovery) Discovery(ctx context.Context, maxAge time.Duration) (services []Service, err error)

Discovery detect service on the system and return a list of Service object.

It may trigger an update of metric inputs present in the Collector.

func (*Discovery) GetCheckNow

func (d *Discovery) GetCheckNow(nameInstance NameInstance) (CheckNow, error)

GetCheckNow returns the GetCheckNow function associated to a NameInstance.

func (*Discovery) LastUpdate

func (d *Discovery) LastUpdate() time.Time

LastUpdate return when the last update occurred.

func (*Discovery) RemoveIfNonRunning

func (d *Discovery) RemoveIfNonRunning(ctx context.Context, services []Service)

RemoveIfNonRunning remove a service if the service is not running

This is useful to remove persisted service that no longer run.

type DynamicDiscovery

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

DynamicDiscovery implement the dynamic discovery. It will only return service dynamically discovery from processes list, containers running, ... It don't include manually configured service or previously detected services.

func NewDynamic

func NewDynamic(opts Option) *DynamicDiscovery

NewDynamic create a new dynamic service discovery which use information from processes and netstat to discovery services.

func (*DynamicDiscovery) Discovery

func (dd *DynamicDiscovery) Discovery(ctx context.Context, maxAge time.Duration) (services []Service, err error)

Discovery detect service running on the system and return a list of Service object.

func (*DynamicDiscovery) LastUpdate

func (dd *DynamicDiscovery) LastUpdate() time.Time

LastUpdate return when the last update occurred.

func (*DynamicDiscovery) ProcessServiceInfo

func (dd *DynamicDiscovery) ProcessServiceInfo(cmdLine []string, pid int, createTime time.Time) (serviceName ServiceName, containerName string)

ProcessServiceInfo return the service & container a process belong based on its command line + pid & start time.

type GathererRegistry

type GathererRegistry interface {
	RegisterGatherer(opt registry.RegistrationOption, gatherer prometheus.Gatherer) (int, error)
	RegisterInput(opt registry.RegistrationOption, input telegraf.Input) (int, error)
	Unregister(id int) bool
}

GathererRegistry allow to register/unregister prometheus Gatherer.

type IgnoredService

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

IgnoredService saves the ignored services (checks/metrics/everything) imported from the configuration file.

func NewIgnoredService

func NewIgnoredService(ignoredNamesInstances []config.NameInstance) IgnoredService

NewIgnoredService initializes IgnoredService struct.

func (IgnoredService) IsServiceIgnored

func (ic IgnoredService) IsServiceIgnored(srv Service) bool

IsServiceIgnored returns whether the given service should be ignored or not.

func (IgnoredService) IsServiceIgnoredNameAndContainer

func (ic IgnoredService) IsServiceIgnoredNameAndContainer(name, containerName string) bool

IsServiceIgnoredNameAndContainer does the same as IsServiceIgnored, but without the whole Service type.

type MockDiscoverer

type MockDiscoverer struct {
	UpdatedAt time.Time
	// contains filtered or unexported fields
}

MockDiscoverer is useful for tests.

func (*MockDiscoverer) Discovery

func (md *MockDiscoverer) Discovery(_ context.Context, maxAge time.Duration) (services []Service, err error)

Discovery implements Discoverer.

func (*MockDiscoverer) LastUpdate

func (md *MockDiscoverer) LastUpdate() time.Time

LastUpdate implements Discoverer.

func (*MockDiscoverer) RemoveIfNonRunning

func (md *MockDiscoverer) RemoveIfNonRunning(context.Context, []Service)

RemoveIfNonRunning implements PersistentDiscoverer.

func (*MockDiscoverer) SetResult

func (md *MockDiscoverer) SetResult(services []Service, err error)

SetResult fill result of Discovery.

type NameInstance

type NameInstance struct {
	Name     string
	Instance string
}

NameInstance contains the service and instance names.

The instance could be either a container name OR simply a arbitrary value.

type Option

type Option struct {
	PS                 processFact
	Netstat            netstatProvider
	ContainerInfo      containerInfoProvider
	IsContainerIgnored func(facts.Container) bool
	IsServiceIgnored   func(Service) bool
	FileReader         fileReader
	DefaultStack       string
}

type PersistentDiscoverer

type PersistentDiscoverer interface {
	Discoverer
	RemoveIfNonRunning(ctx context.Context, services []Service)
}

PersistentDiscoverer also allow to remove a non-running service.

type Registry

type Registry interface {
	AddTask(task task.Runner, shortName string) (int, error)
	RemoveTask(taskID int)
}

Registry will contains checks.

type Service

type Service struct {
	Config          config.Service
	Name            string
	Instance        string
	Tags            []string
	Applications    []Application
	ServiceType     ServiceName
	ContainerID     string
	ContainerName   string // If ContainerName is set, Instance must be the same value.
	IPAddress       string // IPAddress is the IPv4 address to reach service for metrics gathering. If empty, it means IP was not found
	ListenAddresses []facts.ListenAddress
	ExePath         string
	IgnoredPorts    map[int]bool
	Active          bool
	CheckIgnored    bool
	MetricsIgnored  bool
	// The interval of the check, used only for custom checks.
	Interval time.Duration

	HasNetstatInfo  bool
	LastNetstatInfo time.Time

	LastTimeSeen time.Time
	// contains filtered or unexported fields
}

Service is the information found about a given service.

func (Service) AddressForPort

func (s Service) AddressForPort(port int, network string, force bool) string

AddressForPort return the IP address for given port & network (tcp, udp).

func (Service) AddressPort

func (s Service) AddressPort() (string, int)

AddressPort return the IP address &port for the "main" service (e.g. for RabbitMQ the AMQP port, not the management port).

func (Service) AnnotationsOfStatus

func (s Service) AnnotationsOfStatus() types.MetricAnnotations

AnnotationsOfStatus returns the annotations for the status metrics of this service.

func (Service) LabelsOfStatus

func (s Service) LabelsOfStatus() map[string]string

LabelsOfStatus returns the labels for the status metrics of this service.

func (Service) String

func (s Service) String() string

type ServiceName

type ServiceName string

ServiceName is the name of a supported service.

const (
	ApacheService        ServiceName = "apache"
	AsteriskService      ServiceName = "asterisk"
	BindService          ServiceName = "bind"
	BitBucketService     ServiceName = "bitbucket"
	CassandraService     ServiceName = "cassandra"
	ConfluenceService    ServiceName = "confluence"
	DovecotService       ServiceName = "dovecot"
	EjabberService       ServiceName = "ejabberd"
	ElasticSearchService ServiceName = "elasticsearch"
	EximService          ServiceName = "exim"
	Fail2banService      ServiceName = "fail2ban"
	FreeradiusService    ServiceName = "freeradius"
	HAProxyService       ServiceName = "haproxy"
	InfluxDBService      ServiceName = "influxdb"
	JenkinsService       ServiceName = "jenkins"
	JIRAService          ServiceName = "jira"
	KafkaService         ServiceName = "kafka"
	LibvirtService       ServiceName = "libvirt"
	MemcachedService     ServiceName = "memcached"
	MongoDBService       ServiceName = "mongodb"
	MosquittoService     ServiceName = "mosquitto" //nolint:misspell
	MySQLService         ServiceName = "mysql"
	NatsService          ServiceName = "nats"
	NfsService           ServiceName = "nfs"
	NginxService         ServiceName = "nginx"
	NTPService           ServiceName = "ntp"
	OpenLDAPService      ServiceName = "openldap"
	OpenVPNService       ServiceName = "openvpn"
	PHPFPMService        ServiceName = "phpfpm"
	PostfixService       ServiceName = "postfix"
	PostgreSQLService    ServiceName = "postgresql"
	RabbitMQService      ServiceName = "rabbitmq"
	RedisService         ServiceName = "redis"
	SaltMasterService    ServiceName = "salt_master"
	SquidService         ServiceName = "squid"
	UWSGIService         ServiceName = "uwsgi"
	VarnishService       ServiceName = "varnish"
	UPSDService          ServiceName = "upsd"
	ZookeeperService     ServiceName = "zookeeper"

	CustomService ServiceName = "__custom__"
)

List of known service names.

type ServiceOverride

type ServiceOverride struct {
	IgnoredPorts   []int
	Interval       time.Duration
	ExtraAttribute map[string]string
}

type State

type State interface {
	Get(key string, result interface{}) error
	Set(key string, object interface{}) error
}

State allow to persite object.

type SudoFileReader

type SudoFileReader struct {
	HostRootPath string
}

SudoFileReader read file using sudo cat (or direct read if running as root).

func (SudoFileReader) ReadFile

func (s SudoFileReader) ReadFile(path string) ([]byte, error)

ReadFile does the same as os.ReadFile but use sudo cat.

Directories

Path Synopsis
Package promexporter implement an discovery of Prometheus exporter based on Docker labels / Kubernetes annotations
Package promexporter implement an discovery of Prometheus exporter based on Docker labels / Kubernetes annotations

Jump to

Keyboard shortcuts

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