lib

package
v0.0.0-...-72eeae7 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2022 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Overview

Package lib provides utility functions to read/write/transform metrics.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TranslateHistogram

func TranslateHistogram(config *BucketConfig, mf *dto.MetricFamily)

TranslateHistogram translates the HDR Histogram into a Log10 linear histogram

Types

type BucketConfig

type BucketConfig struct {
	Bins    int
	Startns int
	// optional
	Endns   int
	Exclude string
	Include string
	Unit    string
}

BucketConfig defines the config parameters for each histogram bucket * Bins: the number of linear buckets for each log10 bucket * Startns: The lower range in nanoseconds. * Endns: Optional upper range * Exclude: Regex of histogram names to exclude * Include: Regex of histogram names to include, regardless of the exclude settings * Unit: Time unit to use for the log10 buckets

func (*BucketConfig) UnitDiv

func (b *BucketConfig) UnitDiv() float64

UnitDiv converts time units into nano secods

type Collector

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

Collector queries the database to collect custom metrics

func NewCollector

func NewCollector(ctx context.Context, config Custom) (*Collector, error)

NewCollector creates a new collector for retrieving sql activity from the internal CRDB tables

func (*Collector) GetCustomMetrics

func (c *Collector) GetCustomMetrics(ctx context.Context) error

GetCustomMetrics retrieves all the custom metrics

func (*Collector) GetStatement

func (c *Collector) GetStatement(ctx context.Context, id string) (string, error)

GetStatement retrieves the statement associated to the given in

func (*Collector) IsMainNode

func (c *Collector) IsMainNode(ctx context.Context) (bool, error)

IsMainNode returns true if the node id of the node is the max(id) in the cluster.

type Config

type Config struct {
	Bucket BucketConfig
	Port   int
	TLS    TLSConfig `yaml:"tls,omitempty"`
	URL    string
	Custom Custom `yaml:"custom,omitempty"`
}

Config has the configuration for the metrics-exporter * Bucket: Log10 Bucket Configuration * Port: Port that the export is listening to * Tls: optional Tls configuration * Url: CockroachDB Prometheus endpoint

func ReadConfig

func ReadConfig(configLocation *string) *Config

ReadConfig reads yaml configuration from a file

func (*Config) GetTLSClientContext

func (c *Config) GetTLSClientContext() (*TLSClientContext, error)

GetTLSClientContext builds the Client TLS context

func (*Config) GetTLSServerContext

func (c *Config) GetTLSServerContext() (*tls.Config, error)

GetTLSServerContext builds the Server TLS context

func (*Config) HasCustom

func (c *Config) HasCustom() bool

HasCustom returns true if there is a custom section

func (*Config) IsSecure

func (c *Config) IsSecure() bool

IsSecure returns true if there is a Tls configuration

type Custom

type Custom struct {
	URL                 string
	DisableGetStatement bool
	Limit               int
	SkipActivity        bool
	SkipEfficiency      bool
	Frequency           int
	Endpoint            string
}

Custom provides the configuration to retrieve custom metrics

type MetricsReader

type MetricsReader struct {
	Config *Config
	//SecureCtx *TlsClientContext
	Transport *http.Transport
}

MetricsReader reads the metrics from a CockroachDB endpoint (/_status/var)

func CreateMetricsReader

func CreateMetricsReader(c *Config, t *http.Transport) *MetricsReader

CreateMetricsReader instantiates a new Reader

func (*MetricsReader) ReadMetrics

func (r *MetricsReader) ReadMetrics(ctx context.Context) (map[string]*dto.MetricFamily, error)

ReadMetrics reads the metrics from the endpoint and returns a map of dto.MetricFamily

type MetricsWriter

type MetricsWriter struct {
	Config  *Config
	Exclude *regexp.Regexp
	Include *regexp.Regexp
}

MetricsWriter write metrics, after transforming them based on the configuration supplied.

func CreateMetricsWriter

func CreateMetricsWriter(config *Config) *MetricsWriter

CreateMetricsWriter instantiates a MetricsWriter

func (*MetricsWriter) WriteMetrics

func (w *MetricsWriter) WriteMetrics(
	ctx context.Context, metricFamilies map[string]*dto.MetricFamily, out io.Writer,
)

WriteMetrics writes the metrics, converting HDR Histogram into Log10 linear histograms.

type TLSClientContext

type TLSClientContext struct {
	CertPool    *x509.CertPool
	Certificate tls.Certificate
}

TLSClientContext is the context for TLS connections.

type TLSConfig

type TLSConfig struct {
	Ca          string
	Certificate string
	Host        string
	PrivateKey  string
}

TLSConfig Configuration * Ca: CA certificate file location * Certificate: X.509 certificate for the server * Host: Host name associated with X.509 certificate. * PrivateKey: Server private key

Jump to

Keyboard shortcuts

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