metrics

package
v1.1.11-rc1 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CutOverOutcomeSuccess = "success"
	CutOverOutcomeRetry   = "retry"
	CutOverOutcomeAbort   = "abort"

	CutOverPhaseMagicLock         = "magic_lock"
	CutOverPhaseOriginalTableLock = "original_table_lock"
	CutOverPhaseMagicRename       = "magic_rename"
	CutOverPhaseUnlock            = "unlock"
)

Variables

View Source
var Noop = &Client{}

Noop is a StatsD client that discards all metrics. NewClient("", ...) returns this exact pointer so callers can use `client == metrics.Noop`.

Functions

func EmitBinlogBacklogGauges added in v1.1.11

func EmitBinlogBacklogGauges(emit Emitter, backlogSize, backlogCapacity int)

EmitBinlogBacklogGauges emits apply-events queue depth gauges (namespace is applied by the client): gh_ost.binlog.backlog_size, gh_ost.binlog.backlog_capacity, gh_ost.binlog.backlog_utilization.

func EmitGoRuntimeGauges

func EmitGoRuntimeGauges(emit Emitter, m *runtime.MemStats, numGoroutine int)

EmitGoRuntimeGauges emits gh_ost.go_runtime.* gauges (namespace is applied by the client). m and numGoroutine are typically from runtime.ReadMemStats and runtime.NumGoroutine.

func EmitLagGauges added in v1.1.11

func EmitLagGauges(emit Emitter, replicationLagSeconds, heartbeatLagSeconds float64, throttled bool)

EmitLagGauges emits replication and heartbeat lag gauges (namespace is applied by the client): gh_ost.lag.replication_seconds, gh_ost.lag.heartbeat_seconds, each tagged throttled:true|false.

These are point-in-time readings each status tick (not a distribution), so gauges are used rather than histograms; DogStatsD histogram aggregation exposes count/max series that do not match the log line lag values in Prometheus/Grafana.

func EmitProgressGauges added in v1.1.11

func EmitProgressGauges(emit Emitter, rowsCopied, rowsEstimate, dmlEventsApplied int64)

EmitProgressGauges emits row-copy and DML progress gauges (namespace is applied by the client): gh_ost.row_copy.rows_copied, gh_ost.row_copy.rows_estimate, gh_ost.dml.events_applied.

func EmitThrottleActiveGauge added in v1.1.11

func EmitThrottleActiveGauge(emit Emitter, active bool)

EmitThrottleActiveGauge emits whether throttling is currently active.

func EmitThrottleInterval added in v1.1.11

func EmitThrottleInterval(emit Emitter, duration time.Duration, reason string)

EmitThrottleInterval emits one event and one duration sample for a completed throttled interval.

func RecordCutOverAttempt added in v1.1.11

func RecordCutOverAttempt(emit Emitter, outcome string)

RecordCutOverAttempt emits gh_ost.cut_over.attempts_total.

func RecordCutOverPhase added in v1.1.11

func RecordCutOverPhase(emit Emitter, phase string, duration time.Duration, err error)

RecordCutOverPhase emits gh_ost.cut_over.phase_duration_milliseconds.

func RecordCutOverTotal added in v1.1.11

func RecordCutOverTotal(emit Emitter, duration time.Duration, err error)

RecordCutOverTotal emits gh_ost.cut_over.total_duration_milliseconds for terminal cut-over outcomes.

func RecordQueryDuration added in v1.1.11

func RecordQueryDuration(emit Emitter, side string, kind string, duration time.Duration, err error)

RecordQueryDuration emits gh_ost.query.duration_milliseconds with side/kind/outcome tags.

func RecordSleep added in v1.1.11

func RecordSleep(emit Emitter, stage string, d time.Duration)

RecordSleep emits per-stage sleep/wait metrics (namespace is applied by the client): gh_ost.sleep.duration_milliseconds and gh_ost.sleep.total_milliseconds, both tagged by stage.

func StartGoRuntimeReporter

func StartGoRuntimeReporter(ctx context.Context, client *Client, interval time.Duration)

StartGoRuntimeReporter periodically samples runtime memory and goroutines and emits gauges until ctx is cancelled. It is a no-op when interval <= 0, client is nil, or StatsD is disabled (noop client).

Types

type Client

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

Client wraps a StatsD client with namespace and global tags (from --statsd-tags).

func NewClient

func NewClient(addr string, tags []string, namespace string) (*Client, error)

NewClient connects to addr for StatsD. If addr is empty, returns Noop and nil error. namespace is typically "gh_ost." (metrics are named namespace + short name, e.g. gh_ost.startup). tags are global tags applied to every metric (repeatable --statsd-tags).

func (*Client) Close

func (c *Client) Close() error

Close flushes buffered metrics; safe for Noop.

func (*Client) Count

func (c *Client) Count(name string, value int64, tags ...string)

func (*Client) Gauge

func (c *Client) Gauge(name string, value float64, tags ...string)

func (*Client) Histogram added in v1.1.11

func (c *Client) Histogram(name string, value float64, tags ...string)

type Emitter added in v1.1.11

type Emitter interface {
	Gauge(name string, value float64, tags ...string)
	Count(name string, value int64, tags ...string)
	Histogram(name string, value float64, tags ...string)
}

Emitter is the unified metrics abstraction implemented by *Client. Helpers in the metrics package take an Emitter so tests can supply spies without UDP.

Jump to

Keyboard shortcuts

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