Documentation ¶
Index ¶
- Constants
- Variables
- func WithConfig(conf *Config) option
- func WithCounter(m *prometheus.CounterVec) option
- func WithLogger(l Logger) option
- type Aggregation
- type AggregationResult
- type ChangeStreamEvent
- type ChangeStreamEventNamespace
- type Collector
- func (c *Collector) Collect(ch chan<- prometheus.Metric)
- func (c *Collector) Describe(ch chan<- *prometheus.Desc)
- func (c *Collector) GetServers(names []string) []*server
- func (c *Collector) RegisterAggregation(aggregation *Aggregation) error
- func (c *Collector) RegisterServer(name string, driver Driver) error
- func (c *Collector) StartCacheInvalidator() error
- type Config
- type Cursor
- type Driver
- type Logger
- type Metric
- type MongoDBDriver
- func (mdb *MongoDBDriver) Aggregate(ctx context.Context, db string, col string, pipeline bson.A) (Cursor, error)
- func (mdb *MongoDBDriver) Connect(ctx context.Context, opts ...*options.ClientOptions) error
- func (mdb *MongoDBDriver) Ping(ctx context.Context, rp *readpref.ReadPref) error
- func (mdb *MongoDBDriver) Watch(ctx context.Context, db string, col string, pipeline bson.A) (Cursor, error)
Constants ¶
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 successfully ResultSuccess = "SUCCESS" //Metric value could not been determined ResultError = "ERROR" )
Variables ¶
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
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 ChangeStreamEvent ¶
type ChangeStreamEvent struct {
NS *ChangeStreamEventNamespace
}
MongoDB event stream
type ChangeStreamEventNamespace ¶
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 (*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 ¶
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 ¶
Run metric c for each metric either in push or pull mode
func (*Collector) StartCacheInvalidator ¶
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