collector

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2022 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	//Gauge metric type (Can increase and decrease)
	TypeGauge = "gauge"
	//Pull mode (with interval)
	ModePull = "pull"
	//Push mode (Uses changestream which is only supported with MongoDB >= 3.6)
	ModePush = "push"
	//Metric generated succesfully
	ResultSuccess = "SUCCESS"
	//Metric value could not been determined
	ResultError = "ERROR"
)

Variables

View Source
var (
	//Only Gauge is a supported metric types
	ErrInvalidType = errors.New("unknown metric type provided. Only gauge is supported")
	//The value was not found in the aggregation result set
	ErrValueNotFound = errors.New("value not found in result set")
	//No cached metric available
	ErrNotCached = errors.New("metric not available from cache")
)

Functions

func WithConfig

func WithConfig(conf *Config) option

Pass a collector configuration (Defaults for metrics)

func WithCounter

func WithCounter(m *prometheus.CounterVec) option

Pass a counter metrics about query stats

func WithLogger

func WithLogger(l Logger) option

Pass a logger to the collector

Types

type Aggregation

type Aggregation struct {
	Servers    []string
	Cache      time.Duration
	Mode       string
	Database   string
	Collection string
	Pipeline   string
	Metrics    []*Metric
	// contains filtered or unexported fields
}

Aggregation defines what aggregation pipeline is executed on what servers

type AggregationResult

type AggregationResult map[string]interface{}

MongoDB aggregation result

type ChangeStreamEvent

type ChangeStreamEvent struct {
	NS *ChangeStreamEventNamespace
}

MongoDB event stream

type ChangeStreamEventNamespace

type ChangeStreamEventNamespace struct {
	DB   string
	Coll string
}

MongoDB event stream

type Collector

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

A collector is a metric collector group for one single MongoDB server. Each collector needs a MongoDB client and a list of metrics which should be generated. You may initialize multiple collectors for multiple MongoDB servers.

func New

func New(opts ...option) *Collector

Create a new collector

func (*Collector) Collect

func (c *Collector) Collect(ch chan<- prometheus.Metric)

Collect all metrics from queries

func (*Collector) Describe

func (c *Collector) Describe(ch chan<- *prometheus.Desc)

Describe is implemented with DescribeByCollect

func (*Collector) GetServers

func (c *Collector) GetServers(names []string) []*server

Return registered drivers You may provide a list of names to only return matching drivers by name

func (*Collector) RegisterAggregation

func (c *Collector) RegisterAggregation(aggregation *Aggregation) error

Run metric c for each metric either in push or pull mode

func (*Collector) RegisterServer

func (c *Collector) RegisterServer(name string, driver Driver) error

Run metric c for each metric either in push or pull mode

func (*Collector) StartCacheInvalidator

func (c *Collector) StartCacheInvalidator() error

Start MongoDB watchers for metrics where push is enabled. As soon as a new event is registered the cache gets invalidated and the aggregation will be re evaluated during the next scrape. This is a non blocking operation.

type Config

type Config struct {
	QueryTimeout      time.Duration
	DefaultCache      time.Duration
	DefaultMode       string
	DefaultDatabase   string
	DefaultCollection string
}

Collector configuration with default metric configurations

type Cursor

type Cursor interface {
	Next(ctx context.Context) bool
	Close(ctx context.Context) error
	Decode(val interface{}) error
}

Represents a cursor to fetch records from

type Driver

type Driver interface {
	Connect(ctx context.Context, opts ...*options.ClientOptions) error
	Ping(ctx context.Context, rp *readpref.ReadPref) error
	Aggregate(ctx context.Context, db string, col string, pipeline bson.A) (Cursor, error)
	Watch(ctx context.Context, db string, col string, pipeline bson.A) (Cursor, error)
}

MongoDB driver abstraction

type Logger

type Logger interface {
	Debugf(msg string, keysAndValues ...interface{})
	Infof(msg string, keysAndValues ...interface{})
	Errorf(msg string, keysAndValues ...interface{})
	Warnf(msg string, keysAndValues ...interface{})
	Fatalf(msg string, keysAndValues ...interface{})
	Panicf(msg string, keysAndValues ...interface{})
}

Logger interface which is used in the collector You may use a custom loggger implementing this interface and pass to the collector with Collector.WithLogger(logger)

type Metric

type Metric struct {
	Name          string
	Type          string
	Help          string
	Value         string
	OverrideEmpty bool
	EmptyValue    int64
	ConstLabels   prometheus.Labels
	Labels        []string
	// contains filtered or unexported fields
}

A metric defines how a certain value is exported from a MongoDB aggregation

type MongoDBDriver

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

MongoDB driver

func (*MongoDBDriver) Aggregate

func (mdb *MongoDBDriver) Aggregate(ctx context.Context, db string, col string, pipeline bson.A) (Cursor, error)

Aggregation rquery

func (*MongoDBDriver) Connect

func (mdb *MongoDBDriver) Connect(ctx context.Context, opts ...*options.ClientOptions) error

Connect to the server

func (*MongoDBDriver) Ping

func (mdb *MongoDBDriver) Ping(ctx context.Context, rp *readpref.ReadPref) error

Enforce connection to the server

func (*MongoDBDriver) Watch

func (mdb *MongoDBDriver) Watch(ctx context.Context, db string, col string, pipeline bson.A) (Cursor, error)

Start an eventstream

Jump to

Keyboard shortcuts

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