Documentation
¶
Overview ¶
Package metrics is responsible for reading and writing metric definitions.
At the moment, metric definitions support two storages:
- PostgreSQL database
- YAML file
Content ¶
- `postgres*.go` files cover the functionality for the PostgreSQL database.
- `yaml*.go` files cover the functionality for the YAML file.
- `metrics.yaml` holds all default metrics and presets.
- `default.go` provides access to default metrics.
Index ¶
- Constants
- Variables
- func GetDefaultBuiltInMetrics() []string
- func RowToMeasurement(row pgx.CollectableRow) (map[string]any, error)
- type CmdOpts
- type ExtensionInfo
- type ExtensionOverrides
- type Measurement
- type MeasurementEnvelope
- type Measurements
- type Metric
- type MetricAttrs
- type MetricDefs
- type Metrics
- type Preset
- type PresetDefs
- type Reader
- type ReaderWriter
- func NewDefaultMetricReader(context.Context) (ReaderWriter, error)
- func NewPostgresMetricReaderWriter(ctx context.Context, connstr string) (ReaderWriter, error)
- func NewPostgresMetricReaderWriterConn(ctx context.Context, conn db.PgxPoolIface) (ReaderWriter, error)
- func NewYAMLMetricReaderWriter(ctx context.Context, path string) (ReaderWriter, error)
- type SQLs
- type Writer
Constants ¶
const ( EpochColumnName string = "epoch_ns" // this column (epoch in nanoseconds) is expected in every metric query TagPrefix string = "tag_" )
const MigrationsCount = 2
MigrationsCount is the total number of migrations in pgwatch.migration table
Variables ¶
var ( ErrNeedsMigration = errors.New("config database schema is outdated, please run migrations using `pgwatch config upgrade` command") ErrMetricNotFound = errors.New("metric not found") ErrPresetNotFound = errors.New("preset not found") ErrInvalidMetric = errors.New("invalid metric") ErrInvalidPreset = errors.New("invalid preset") ErrMetricExists = errors.New("metric already exists") ErrPresetExists = errors.New("preset already exists") )
Functions ¶
func GetDefaultBuiltInMetrics ¶
func GetDefaultBuiltInMetrics() []string
func RowToMeasurement ¶
func RowToMeasurement(row pgx.CollectableRow) (map[string]any, error)
RowToMap returns a map scanned from row.
Types ¶
type CmdOpts ¶
type CmdOpts struct {
Metrics string `` /* 137-byte string literal not displayed */
DirectOSStats bool `` /* 191-byte string literal not displayed */
InstanceLevelCacheMaxSeconds int64 `` /* 264-byte string literal not displayed */
EmergencyPauseTriggerfile string `` /* 227-byte string literal not displayed */
}
CmdOpts specifies metric command-line options
type ExtensionInfo ¶
type ExtensionOverrides ¶
type ExtensionOverrides struct {
TargetMetric string `yaml:"target_metric"`
ExpectedExtensionVersions []ExtensionInfo `yaml:"expected_extension_versions"`
}
type Measurement ¶
func NewMeasurement ¶
func NewMeasurement(epoch int64) Measurement
func (Measurement) GetEpoch ¶
func (m Measurement) GetEpoch() int64
type MeasurementEnvelope ¶
type MeasurementEnvelope struct {
DBName string
MetricName string
CustomTags map[string]string
Data Measurements
}
type Measurements ¶
func (Measurements) DeepCopy ¶
func (m Measurements) DeepCopy() Measurements
func (Measurements) GetEpoch ¶
func (m Measurements) GetEpoch() int64
func (Measurements) IsEpochSet ¶
func (m Measurements) IsEpochSet() bool
func (Measurements) Touch ¶
func (m Measurements) Touch()
Touch updates the last modified time of the metric definitions
type Metric ¶
type Metric struct {
SQLs SQLs
InitSQL string `yaml:"init_sql,omitempty"`
NodeStatus string `yaml:"node_status,omitempty"`
Gauges []string `yaml:",omitempty"`
IsInstanceLevel bool `yaml:"is_instance_level,omitempty"`
StorageName string `yaml:"storage_name,omitempty"`
Description string `yaml:"description,omitempty"`
}
func (Metric) PrimaryOnly ¶
func (Metric) StandbyOnly ¶
type MetricAttrs ¶
type MetricAttrs struct {
ExtensionVersionOverrides []ExtensionOverrides `yaml:"extension_version_based_overrides,omitempty"`
IsPrivate bool `yaml:"is_private,omitempty"` // used only for extension overrides currently and ignored otherwise
DisabledDays string `yaml:"disabled_days,omitempty"` // Cron style, 0 = Sunday. Ranges allowed: 0,2-4
DisableTimes []string `yaml:"disabled_times,omitempty"` // "11:00-13:00"
StatementTimeoutSeconds int64 `yaml:"statement_timeout_seconds,omitempty"` // overrides per monitored DB settings
}
type MetricDefs ¶
type Metrics ¶
type Metrics struct {
MetricDefs MetricDefs `yaml:"metrics,omitempty"`
PresetDefs PresetDefs `yaml:"presets,omitempty"`
}
func GetDefaultMetrics ¶
func GetDefaultMetrics() (metrics *Metrics)
func (*Metrics) FilterByNames ¶
FilterByNames returns a new Metrics struct containing only the specified metrics and/or presets. When a preset is requested, it includes both the preset definition and all its metrics. If names is empty, returns a full copy of all metrics and presets. Returns an error if any name is not found.
type PresetDefs ¶
type ReaderWriter ¶
func NewDefaultMetricReader ¶
func NewDefaultMetricReader(context.Context) (ReaderWriter, error)
NewDefaultMetricReader creates a new default metric reader with an empty path.
func NewPostgresMetricReaderWriter ¶
func NewPostgresMetricReaderWriter(ctx context.Context, connstr string) (ReaderWriter, error)
func NewPostgresMetricReaderWriterConn ¶
func NewPostgresMetricReaderWriterConn(ctx context.Context, conn db.PgxPoolIface) (ReaderWriter, error)
func NewYAMLMetricReaderWriter ¶
func NewYAMLMetricReaderWriter(ctx context.Context, path string) (ReaderWriter, error)
type Writer ¶
type Writer interface {
WriteMetrics(metricDefs *Metrics) error
DeleteMetric(metricName string) error
DeletePreset(presetName string) error
UpdateMetric(metricName string, metric Metric) error
UpdatePreset(presetName string, preset Preset) error
CreateMetric(metricName string, metric Metric) error
CreatePreset(presetName string, preset Preset) error
}