metrics

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2025 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const PGWaitEventPrefix = "pg_wait_event_"

Variables

View Source
var (
	// CPU
	NodeCPUCount = MetricDef{Key: "node_cpu_count", Type: Int}
	NodeCPUUsage = MetricDef{Key: "node_cpu_usage", Type: Float}

	// Memory
	NodeMemoryTotal               = MetricDef{Key: "node_memory_total", Type: Bytes}
	NodeMemoryUsed                = MetricDef{Key: "node_memory_used", Type: Bytes}
	NodeMemoryUsedPercentage      = MetricDef{Key: "node_memory_used_percentage", Type: Percentage}
	NodeMemoryFreeable            = MetricDef{Key: "node_memory_freeable", Type: Bytes}
	NodeMemoryAvailablePercentage = MetricDef{Key: "node_memory_available_percentage", Type: Percentage}

	// Load
	NodeLoadAverage = MetricDef{Key: "node_load_average", Type: Float}
	// Load - NOTE: These are per second
	NodeDiskIOPSReadPerSecond  = MetricDef{Key: "node_disk_iops_read", Type: Float}
	NodeDiskIOPSWritePerSecond = MetricDef{Key: "node_disk_iops_write", Type: Float}
	NodeDiskIOPSTotalPerSecond = MetricDef{Key: "node_disk_iops_total", Type: Float}
	// Load - NOTE: These are total count, as used in adapter pgprem
	NodeDiskIOReadCount  = MetricDef{Key: "node_disk_io_ops_read", Type: Int}
	NodeDiskIOWriteCount = MetricDef{Key: "node_disk_io_ops_write", Type: Int}
	NodeDiskIOTotalCount = MetricDef{Key: "node_disk_io_ops_total", Type: Int}

	// Disk
	NodeDiskSize           = MetricDef{Key: "node_disk_size", Type: Bytes}
	NodeDiskUsedPercentage = MetricDef{Key: "node_disk_used_percentage", Type: Percentage}

	// Network
	NodeNetworkReceiveCount     = MetricDef{Key: "node_net_receive_count", Type: Int}
	NodeNetworkSendCount        = MetricDef{Key: "node_net_send_count", Type: Int}
	NodeNetworkReceivePerSecond = MetricDef{Key: "node_net_receive_per_second", Type: Float}
	NodeNetworkSendPerSecond    = MetricDef{Key: "node_net_send_per_second", Type: Float}

	// OS Info
	NodeOSInfo        = MetricDef{Key: "node_os_info", Type: String}
	NodeStorageType   = MetricDef{Key: "node_storage_type", Type: String}
	NodeOSPlatform    = MetricDef{Key: "system_info_platform", Type: String}
	NodeOSPlatformVer = MetricDef{Key: "system_info_platform_version", Type: String}

	PGVersion                  = MetricDef{Key: "pg_version", Type: String}
	PGMaxConnections           = MetricDef{Key: "pg_max_connections", Type: Int}
	PGStatStatementsDelta      = MetricDef{Key: "pg_stat_statements_delta", Type: PgssDelta}
	PGStatStatementsDeltaCount = MetricDef{Key: "pg_stat_statements_delta_count", Type: Int}
	PGActiveConnections        = MetricDef{Key: "pg_active_connections", Type: Int}
	PGInstanceSize             = MetricDef{Key: "pg_instance_size", Type: Bytes}
	PGAutoVacuumCount          = MetricDef{Key: "pg_autovacuum_count", Type: Int}
	PGCacheHitRatio            = MetricDef{Key: "pg_cache_hit_ratio", Type: Percentage}

	PGTuplesReturned = MetricDef{Key: "pg_tuples_returned", Type: Int}
	PGTuplesFetched  = MetricDef{Key: "pg_tuples_fetched", Type: Int}
	PGTuplesInserted = MetricDef{Key: "pg_tuples_inserted", Type: Int}
	PGTuplesUpdated  = MetricDef{Key: "pg_tuples_updated", Type: Int}
	PGTuplesDeleted  = MetricDef{Key: "pg_tuples_deleted", Type: Int}

	PGTempFiles = MetricDef{Key: "pg_tuples_updated", Type: Int}
	PGTempBytes = MetricDef{Key: "pg_tuples_updated", Type: Int}

	PGIdleInTransactionTime = MetricDef{Key: "pg_idle_in_transaction_time", Type: Float}

	PGAutoVacuumCountM = MetricDef{Key: "pg_autovacuum_count_per_table", Type: IntMap}
	PGAutoAnalyzeCount = MetricDef{Key: "pg_auto_analyze_count", Type: IntMap}
	PGNLiveTuples      = MetricDef{Key: "pg_live_tuples", Type: IntMap}
	PGNDeadTuples      = MetricDef{Key: "pg_dead_tuples", Type: IntMap}
	PGNModSinceAnalyze = MetricDef{Key: "pg_n_mod_since_analyze", Type: IntMap}
	PGNInsSinceVacuum  = MetricDef{Key: "pg_n_ins_since_vacuum", Type: IntMap}
	PGLastAutoVacuum   = MetricDef{Key: "pg_last_autovacuum", Type: TimeMap}
	PGLastAutoAnalyze  = MetricDef{Key: "pg_last_autoanalyze", Type: TimeMap}

	PGDeadlocks = MetricDef{Key: "pg_deadlocks", Type: Int}

	PGSeqScan     = MetricDef{Key: "pg_seq_scan", Type: IntMap}
	PGSeqTupRead  = MetricDef{Key: "pg_sec_tup_read", Type: IntMap}
	PGIdxScan     = MetricDef{Key: "pg_idx_scan", Type: IntMap}
	PGIdxTupFetch = MetricDef{Key: "pg_idx_tup_fetch", Type: IntMap}

	PGBGWBuffersClean    = MetricDef{Key: "pg_bg_buffers_clean", Type: Int}
	PGMBGWaxWrittenClean = MetricDef{Key: "pg_bg_max_written_clean", Type: Int}
	PGBGWBuffersAlloc    = MetricDef{Key: "pg_bg_buffers_alloc", Type: Int}

	PGCPNumTimed       = MetricDef{Key: "pg_cp_num_timed", Type: Int}
	PGCPNumRequested   = MetricDef{Key: "pg_cp_num_requested", Type: Int}
	PGCPWriteTime      = MetricDef{Key: "pg_cp_write_time", Type: Float}
	PGCPSyncTime       = MetricDef{Key: "pg_cp_sync_time", Type: Float}
	PGCPBuffersWritten = MetricDef{Key: "pg_cp_buffers_written", Type: Int}
	PGWALRecords       = MetricDef{Key: "pg_wal_records", Type: Int}
	PGWALFpi           = MetricDef{Key: "pg_wal_fpi", Type: Int}
	PGWALBytes         = MetricDef{Key: "pg_wal_bytes", Type: Int}
	PGWALBuffersFull   = MetricDef{Key: "pg_wal_buffers_full", Type: Int}

	// Performance
	PerfAverageQueryRuntime   = MetricDef{Key: "perf_average_query_runtime", Type: Float}
	PerfTransactionsPerSecond = MetricDef{Key: "perf_transactions_per_second", Type: Float}

	// Misc
	ServerUptimeMinutes = MetricDef{Key: "server_uptime", Type: Float}
)

Functions

func TryUint64ToInt64

func TryUint64ToInt64(value uint64) (int64, error)

Types

type FlatValue

type FlatValue struct {
	Key   string      `json:"key"`
	Value interface{} `json:"value"`
	Type  MetricType  `json:"type"`
}

FlatValue is a struct that represents a flat metric value.

func NewMetric

func NewMetric(key string, value interface{}, typeStr MetricType) (FlatValue, error)

NewMetric creates a new Metric object based on the provided key, value, and type.

type FormattedMetrics

type FormattedMetrics struct {
	Metrics   map[string]MetricData `json:"metrics"`
	Timestamp string                `json:"timestamp"`
}

FormattedMetrics matches the expected payload of DBtune backend

func FormatMetrics

func FormatMetrics(metrics []FlatValue) FormattedMetrics

TODO: write util tests for this FormatMetrics converts the MetricsState object into a FormattedMetrics object to be used as a metrics payload

type FormattedSystemInfo

type FormattedSystemInfo struct {
	SystemInfo map[string]MetricData `json:"system_info"`
	Timestamp  string                `json:"timestamp"`
}

func FormatSystemInfo

func FormatSystemInfo(metrics []FlatValue) FormattedSystemInfo

type MetricData

type MetricData struct {
	Type  string      `json:"type"`
	Value interface{} `json:"value"`
}

type MetricDef

type MetricDef struct {
	Key  string
	Type MetricType
}

func (MetricDef) AsFlatValue

func (m MetricDef) AsFlatValue(value any) (FlatValue, error)

type MetricType

type MetricType string
const (
	Int        MetricType = "int"
	Float      MetricType = "float"
	String     MetricType = "string"
	Bytes      MetricType = "bytes"
	Boolean    MetricType = "boolean"
	Time       MetricType = "time"
	Percentage MetricType = "percentage"
	PgssDelta  MetricType = "pgss_delta"
	IntMap     MetricType = "int_map"
	FloatMap   MetricType = "float_map"
	TimeMap    MetricType = "time_map"
)

type PGWaitEvent

type PGWaitEvent struct {
	Name string
}

One created for each type of wait event, each is Int

func (PGWaitEvent) AsFlatValue

func (e PGWaitEvent) AsFlatValue(value int) (FlatValue, error)

Jump to

Keyboard shortcuts

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