metrics

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2026 License: Apache-2.0 Imports: 18 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package metrics stores task resource samples from the agents in VictoriaMetrics and reads them back for the dashboard (§9.1).

Index

Constants

This section is empty.

Variables

View Source
var ErrDisabled = errors.New("metrics storage is not configured")

ErrDisabled means no VictoriaMetrics is configured.

View Source
var Ranges = map[string]time.Duration{"15m": 15 * time.Minute, "1h": time.Hour, "6h": 6 * time.Hour, "24h": 24 * time.Hour, "7d": 7 * 24 * time.Hour}

Ranges the dashboard offers, with their query step.

Functions

func Relabel

func Relabel(r io.Reader, names map[string]ServiceName) ([]byte, error)

Relabel keeps Traefik's service, router and entrypoint series and adds SynCloud labels to service series. The uptime monitor's probes are left out: they are not the service's traffic.

Types

type Labeled

type Labeled struct {
	Labels map[string]string `json:"labels"`
	Points [][2]float64      `json:"points"` // [unix ms, value]
}

Labeled is a series of an ad-hoc query with all its labels.

type NetworkResult

type NetworkResult struct {
	Result
	TopServices []Talker `json:"topServices"`
	TopTasks    []Talker `json:"topTasks"`
}

NetworkResult is the Network › Traffic data (§8.4): per-node throughput on all interfaces and over the mesh, and the busiest services and tasks.

type Result

type Result struct {
	Start  time.Time           `json:"start"`
	End    time.Time           `json:"end"`
	Step   int                 `json:"stepSeconds"`
	Charts map[string][]Series `json:"charts"` // cpu, memory, netRx, netTx, diskRead, diskWrite
}

Result holds the charts of one query.

type RouteTraffic

type RouteTraffic struct {
	ServiceID   string  `json:"serviceId"`
	Project     string  `json:"project"`
	Environment string  `json:"environment"`
	Service     string  `json:"service"`
	RPS         float64 `json:"rps"`
	Errors4xx   float64 `json:"errors4xx"` // per second
	Errors5xx   float64 `json:"errors5xx"` // per second
	P50Ms       float64 `json:"p50Ms"`
	P95Ms       float64 `json:"p95Ms"`
	BytesIn     float64 `json:"bytesIn"`  // per second
	BytesOut    float64 `json:"bytesOut"` // per second
}

RouteTraffic is one service's traffic over the summary window.

type Sample

type Sample struct {
	Labels map[string]string
	Value  float64
}

Sample is one series of an instant query.

type Scope

type Scope struct {
	ServiceID   string // one service, a series per task
	Project     string // or a whole environment, a series per service
	Environment string
}

Scope selects the tasks to chart and how to group them.

type Series

type Series struct {
	Key    string       `json:"key"`    // task ID or service name
	Node   string       `json:"node"`   // per-task series only
	Points [][2]float64 `json:"points"` // [unix ms, value]
}

Series is one line on a chart.

type ServiceName added in v0.1.4

type ServiceName struct{ ID, Project, Environment, Name string }

ServiceName is the service a Traefik service's metrics are labelled with.

type ServiceNames

type ServiceNames func(ctx context.Context) map[string]ServiceName

ServiceNames maps service IDs ("svc_ab12") and custom domains' route names ("dom-xy34") to their service, for labelling Traefik's metrics.

type Store

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

func New

func New(baseURL string, log *slog.Logger) *Store

New returns a store writing to VictoriaMetrics at baseURL ("" disables it).

func (*Store) Add

func (s *Store) Add(node string, ms []*agentv1.TaskMetrics)

Add queues samples from a node's heartbeat; it never blocks.

func (*Store) AddNode

func (s *Store) AddNode(node string, hb *agentv1.Heartbeat)

AddNode queues a node's own counters from its heartbeat: network traffic on all interfaces and over the mesh (§8.4).

func (*Store) Database

func (s *Store) Database(ctx context.Context, databaseID string, d time.Duration, now time.Time) (Result, error)

Database charts a managed database over the last d (Phase 12): operations, memory against maxmemory, clients, keys, hit rate, evictions and expirations, replication lag, CPU and network, a series per member where it helps.

func (*Store) Explore

func (s *Store) Explore(ctx context.Context, q string, start, end time.Time, step int) ([]Labeled, bool, error)

Explore runs a PromQL range query (Metrics explorer, §9.1). step <= 0 picks one that gives about 240 points.

func (*Store) Import

func (s *Store) Import(ctx context.Context, text string) error

Import writes Prometheus text-format samples (current time).

func (*Store) Instant

func (s *Store) Instant(ctx context.Context, q string) ([]Sample, error)

Instant runs a MetricsQL instant query; NaN and infinite values are left out.

func (*Store) MetricNames

func (s *Store) MetricNames(ctx context.Context) ([]string, error)

MetricNames lists the stored metric names (for the explorer's suggestions).

func (*Store) Network

func (s *Store) Network(ctx context.Context, d time.Duration, now time.Time) (NetworkResult, error)

Network charts node and mesh throughput over d and ranks the busiest services and tasks over the last 5 minutes.

func (*Store) Node

func (s *Store) Node(ctx context.Context, node string, d time.Duration, now time.Time) (Result, error)

Node charts one node over the last d for its page: CPU, memory and disk (used and total, bytes), load, network and mesh throughput, running tasks, and the CPU and memory of its tasks by service.

func (*Store) Overview

func (s *Store) Overview(ctx context.Context, d time.Duration, now time.Time) (Result, error)

Overview charts the whole cluster over the last d for the dashboard's Overview (§10.2): per-node CPU, memory, disk, load and task counts, node network throughput, requests and latency over every route, and the controller process. Every chart is a fixed window, so old points fall off.

func (*Store) Query

func (s *Store) Query(ctx context.Context, sc Scope, d time.Duration, now time.Time) (Result, error)

Query returns CPU (percent of one core), memory (bytes) and network and disk throughput (bytes/s) over the last d.

func (*Store) RecordController

func (s *Store) RecordController(ctx context.Context, heapBytes uint64, goroutines int) error

RecordController writes the controller process's own gauges.

func (*Store) Run

func (s *Store) Run(ctx context.Context)

Run writes queued samples in batches until ctx ends.

func (*Store) Scaling

func (s *Store) Scaling(ctx context.Context, serviceID string, d time.Duration, now time.Time) (Result, error)

Scaling charts an autoscaled service: desired and running tasks, and the policy's metric against its target (§5.5).

func (*Store) ScrapeTraefik

func (s *Store) ScrapeTraefik(ctx context.Context, metricsURL, edge string, names ServiceNames, interval time.Duration)

ScrapeTraefik copies Traefik's request metrics (§5.7, §9.1) into VictoriaMetrics every interval until ctx ends. Each series gets the SynCloud labels service_id, project, environment and app, and edge (the node Traefik runs on).

func (*Store) ScrapeTraefikOnce

func (s *Store) ScrapeTraefikOnce(ctx context.Context, metricsURL, edge string, names ServiceNames) error

ScrapeTraefikOnce imports one scrape (edge nodes are scraped by their manager).

func (*Store) Traffic

func (s *Store) Traffic(ctx context.Context, sc TrafficScope, d time.Duration, now time.Time) (Result, error)

Traffic charts requests per second by status class, latency percentiles (ms), bandwidth (bytes/s) and, beyond one service, requests per service, from Traefik's metrics (§5.7).

func (*Store) TrafficSummary

func (s *Store) TrafficSummary(ctx context.Context, sc TrafficScope, window time.Duration) ([]RouteTraffic, error)

TrafficSummary returns every route's traffic over the last window, busiest first.

type Talker

type Talker struct {
	Key   string  `json:"key"` // task ID or project/env/service
	Node  string  `json:"node,omitempty"`
	Owner string  `json:"owner,omitempty"` // a task's service
	RxBps float64 `json:"rxBps"`
	TxBps float64 `json:"txBps"`
}

Talker is a task's or service's recent throughput.

type TrafficScope

type TrafficScope struct {
	ServiceID   string
	Project     string
	Environment string
}

TrafficScope selects the routes to chart: one service, a project environment, or every service (all fields empty). The platform's own routes (the dashboard and its API, the registry) are never included: the dashboard's polling is not traffic.

Jump to

Keyboard shortcuts

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