metrics

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2023 License: AGPL-3.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MetricRequestDuration     = "request_duration"
	MetricRequests            = "requests"
	MetricRequestErrors       = "request_errors"
	MetricRequestClientErrors = "request_client_errors"
)

Metric names.

View Source
const (
	ParserTraefik = "traefik"
)

Parser names. This should match the topology types.

Variables

This section is empty.

Functions

func Aggregate

func Aggregate(m []Metric) map[SetKey]MetricSet

Aggregate aggregates metrics into a service metric set.

func CounterFromMetric

func CounterFromMetric(m *dto.Metric) uint64

CounterFromMetric returns a counter metric from a prometheus metric.

Types

type Client

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

Client for the token service.

func NewClient

func NewClient(client *http.Client, baseURL, token string) (*Client, error)

NewClient creates a token service client.

func (*Client) GetPreviousData

func (c *Client) GetPreviousData(ctx context.Context) (map[string][]DataPointGroup, error)

GetPreviousData gets the agent configuration.

func (*Client) Send

func (c *Client) Send(ctx context.Context, data map[string][]DataPointGroup) error

Send sends metrics to the metrics service.

type Counter

type Counter struct {
	Name        string
	EdgeIngress string
	Ingress     string
	Service     string
	Value       uint64
}

Counter represents a counter metric.

func (Counter) EdgeIngressName

func (c Counter) EdgeIngressName() string

EdgeIngressName returns the metric edge ingress name.

func (Counter) IngressName

func (c Counter) IngressName() string

IngressName returns the metric ingress name.

func (Counter) ServiceName

func (c Counter) ServiceName() string

ServiceName returns the metric service name.

type DataPoint

type DataPoint struct {
	Timestamp int64 `avro:"timestamp"`

	ReqPerS                 float64 `avro:"req_per_s"`
	RequestErrPerS          float64 `avro:"request_error_per_s"`
	RequestErrPercent       float64 `avro:"request_error_per"`
	RequestClientErrPerS    float64 `avro:"request_client_error_per_s"`
	RequestClientErrPercent float64 `avro:"request_client_error_per"`
	AvgResponseTime         float64 `avro:"avg_response_time"`

	Seconds           int64   `avro:"seconds"`
	Requests          int64   `avro:"requests"`
	RequestErrs       int64   `avro:"request_errors"`
	RequestClientErrs int64   `avro:"request_client_errors"`
	ResponseTimeSum   float64 `avro:"response_time_sum"`
	ResponseTimeCount int64   `avro:"response_time_count"`
}

DataPoint contains fully aggregated metrics.

type DataPointGroup

type DataPointGroup struct {
	Ingress     string      `avro:"ingress"`
	EdgeIngress string      `avro:"edge_ingress"`
	Service     string      `avro:"service"`
	DataPoints  []DataPoint `avro:"data_points"`
}

DataPointGroup contains a unique group of data points (primary keys).

type DataPointGroupIterator

type DataPointGroupIterator interface {
	ForEach(tbl string, fn ForEachFunc)
}

DataPointGroupIterator is capable of iterating over data point groups.

type DataPointView

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

DataPointView provides a view for querying data points from a store.

func NewDataPointView

func NewDataPointView(s DataPointGroupIterator) *DataPointView

NewDataPointView creates a new DataPointView instance.

func (*DataPointView) FindByIngress

func (v *DataPointView) FindByIngress(table, ingress string, from, to time.Time) DataPoints

FindByIngress finds the data points for the traffic on the given ingress for the specified time range (inclusive).

func (*DataPointView) FindByIngressAndService

func (v *DataPointView) FindByIngressAndService(table, ingress, service string, from, to time.Time) (DataPoints, error)

FindByIngressAndService finds the data points for the traffic on the given service via the given ingress for the specified time range (inclusive).

func (*DataPointView) FindByService

func (v *DataPointView) FindByService(table, service string, from, to time.Time) DataPoints

FindByService finds the data points for the traffic on the given service for the specified time range (inclusive). If the traffic coming this service comes from multiple ingresses, the resulting data points will be an aggregated view of all these ingresses.

type DataPoints

type DataPoints []DataPoint

DataPoints contains a slice of data points.

func (DataPoints) Aggregate

func (p DataPoints) Aggregate() DataPoint

Aggregate aggregates the data points p.

func (DataPoints) Get

func (p DataPoints) Get(ts int64) (int, DataPoint)

Get gets the point with ts if it exists.

type ForEachFunc

type ForEachFunc func(edgeIngr, ingr, svc string, pnts DataPoints)

ForEachFunc represents a function that will be called while iterating over a table. Each time this function is called, a unique ingress and service will be given with their set of points.

type Histogram

type Histogram struct {
	Name        string
	Relative    bool
	EdgeIngress string
	Ingress     string
	Service     string
	Sum         float64
	Count       uint64
}

Histogram represents a histogram metric.

func HistogramFromMetric

func HistogramFromMetric(m *dto.Metric) *Histogram

HistogramFromMetric returns a histogram metric from a prometheus metric.

func (Histogram) EdgeIngressName

func (h Histogram) EdgeIngressName() string

EdgeIngressName returns the metric edge ingress name.

func (Histogram) IngressName

func (h Histogram) IngressName() string

IngressName returns the metric ingress name.

func (Histogram) ServiceName

func (h Histogram) ServiceName() string

ServiceName returns the metric service name.

type Manager

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

Manager orchestrates metrics scraping and sending.

func NewManager

func NewManager(client *Client, traefikURL string, store *Store, scraper *Scraper) *Manager

NewManager returns a manager.

func (*Manager) Run

func (m *Manager) Run(ctx context.Context) error

Run runs the metrics manager. This is a blocking method.

func (*Manager) SetConfig

func (m *Manager) SetConfig(sendInterval time.Duration, sendTables []string)

SetConfig updates the configuration of the metrics manager.

func (*Manager) TopologyStateChanged

func (m *Manager) TopologyStateChanged(_ context.Context, cluster *state.Cluster)

TopologyStateChanged is called every time the topology state changes.

type Metric

type Metric interface {
	EdgeIngressName() string
	IngressName() string
	ServiceName() string
}

Metric represents a metric object.

type MetricSet

type MetricSet struct {
	Requests            int64
	RequestErrors       int64
	RequestClientErrors int64
	RequestDuration     ServiceHistogram
}

MetricSet contains assembled metrics for an ingress or service.

func (MetricSet) RelativeTo

func (s MetricSet) RelativeTo(o MetricSet) MetricSet

RelativeTo returns a service metric relative to o.

func (MetricSet) ToDataPoint

func (s MetricSet) ToDataPoint(secs int64) DataPoint

ToDataPoint returns a data point calculated from s.

type Parser

type Parser interface {
	Parse(m *dto.MetricFamily, state ScrapeState) []Metric
}

Parser represents a platform-specific metrics parser.

type ScrapeState

type ScrapeState struct {
	Ingresses map[string]struct{}
}

ScrapeState contains the state used while scraping.

type Scraper

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

Scraper scrapes metrics from Prometheus.

func NewScraper

func NewScraper(c *http.Client) *Scraper

NewScraper returns a scraper instance with parser p.

func (*Scraper) Scrape

func (s *Scraper) Scrape(ctx context.Context, parser, target string, state ScrapeState) ([]Metric, error)

Scrape returns metrics scraped from all targets.

type ServiceHistogram

type ServiceHistogram struct {
	Relative bool
	Sum      float64
	Count    int64
}

ServiceHistogram contains histogram metrics.

type SetKey

type SetKey struct {
	EdgeIngress string
	Ingress     string
	Service     string
}

SetKey contains the primary key of a metric set.

type Store

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

Store is a metrics store.

func NewStore

func NewStore() *Store

NewStore returns metrics store.

func (*Store) Cleanup

func (s *Store) Cleanup()

Cleanup removes old data points no longer needed for roll up.

func (*Store) CommitMarks

func (s *Store) CommitMarks(tbl string, marks WaterMarks)

CommitMarks sets the new low water marks for a table.

func (*Store) ForEach

func (s *Store) ForEach(tbl string, fn ForEachFunc)

ForEach iterates over a table, executing fn for each row.

func (*Store) ForEachUnmarked

func (s *Store) ForEachUnmarked(tbl string, fn ForEachFunc) WaterMarks

ForEachUnmarked iterates over a table, executing fn for each row that has not been marked.

func (*Store) Insert

func (s *Store) Insert(svcs map[SetKey]DataPoint)

Insert inserts a value for an ingress and service.

func (*Store) Populate

func (s *Store) Populate(tbl string, grps []DataPointGroup) error

Populate populates the store with initial data points.

func (*Store) RollUp

func (s *Store) RollUp()

RollUp creates combines data points.

Rollup goes through each table and aggregates the points into complete points of the next granularity, if that point does not already exist in the next table.

type TraefikParser

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

TraefikParser parses Traefik metrics into a common form.

func NewTraefikParser

func NewTraefikParser() TraefikParser

NewTraefikParser returns an Traefik metrics parser.

func (TraefikParser) Parse

func (p TraefikParser) Parse(m *dto.MetricFamily, state ScrapeState) []Metric

Parse parses metrics into a common form.

type WaterMarks

type WaterMarks map[tableKey]int

WaterMarks contain low water marks for a table.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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