discovery

package
v0.0.0-...-c7d5118 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2026 License: Apache-2.0 Imports: 66 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(commandRunner *gloutonexec.Runner, 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, error)

CheckNow is type of check function.

type Discoverer

type Discoverer interface {
	Discovery(ctx context.Context) ([]Service, time.Time, error)
}

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,
	commandRunner *gloutonexec.Runner,
	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,
	logProcessingCfg config.OpenTelemetry,
) (*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(_ context.Context, zipFile types.ArchiveWriter) error

DiagnosticArchive add to a zipfile useful diagnostic information.

func (*Discovery) GetCheckNow

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

GetCheckNow returns the GetCheckNow function associated to a NameInstance.

func (*Discovery) GetLatestDiscovery

func (d *Discovery) GetLatestDiscovery() ([]Service, time.Time)

GetLatestDiscovery return list of services detected on the system with date of latest update.

func (*Discovery) RemoveIfNonRunning

func (d *Discovery) RemoveIfNonRunning(services []Service)

RemoveIfNonRunning remove a service if the service is not running.

This is useful to remove persisted service that no longer run. The service will immediately be remove from next call to GetLatestDiscovery and a next discovery will be run asynchroniously if from entry were deleted.

func (*Discovery) Run

func (d *Discovery) Run(ctx context.Context) error

Run execute the discovery thread that will update the discovery when needed.

func (*Discovery) Subscribe

func (d *Discovery) Subscribe(ctx context.Context) <-chan []Service

Subscribe return a channel that will receive all update of services after a discovery run.

On subscribe a list of current discovered service will be sent, unless no discovery have yet run.

The channel will be closed when ctx expire. You must drain the full channel or discovery could be blocked.

func (*Discovery) TriggerUpdate

func (d *Discovery) TriggerUpdate()

TriggerUpdate ask for a new discovery to be run. This function as asynchronous and the discovery might not have finished when TriggerUpdate return.

Use Subscribe to get notified after every change in discovery.

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) ([]Service, time.Time, error)

Discovery detect service running on the system and return a list of Service object. It also return a date for wanted next update.

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) (types.Registration, error)
	RegisterInput(opt registry.RegistrationOption, input telegraf.Input) (types.Registration, error)
}

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) (services []Service, wantedNextUpdate time.Time, err error)

Discovery implements Discoverer.

func (*MockDiscoverer) GetLatestDiscovery

func (md *MockDiscoverer) GetLatestDiscovery() ([]Service, time.Time)

GetLatestDiscovery implements Discoverer.

func (*MockDiscoverer) RemoveIfNonRunning

func (md *MockDiscoverer) RemoveIfNonRunning([]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 {
	GetLatestDiscovery() ([]Service, time.Time)
	RemoveIfNonRunning(services []Service)
}

PersistentDiscoverer also allow to remove a non-running service and get latest discovery done.

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
	// May be nil if no log processing should be applied.
	LogProcessing []ServiceLogReceiver

	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 ServiceLogReceiver

type ServiceLogReceiver struct {
	FilePath string // ignored if in a container
	Format   string
	Filter   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"
	MariaDBService       ServiceName = "mariadb"
	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"
	ValkeyService        ServiceName = "valkey"
	VarnishService       ServiceName = "varnish"
	UPSDService          ServiceName = "upsd"
	ZookeeperService     ServiceName = "zookeeper"

	CustomService ServiceName = "__custom__"
)

List of known service names.

type State

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

State allow to persite object.

type SudoFileReader

type SudoFileReader struct {
	HostRootPath string
	Runner       *gloutonexec.Runner
}

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

func (SudoFileReader) ReadFile

func (s SudoFileReader) ReadFile(ctx context.Context, 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