metrics

package
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 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}

	// PG
	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}

	// 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"
)

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