prometheus

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2025 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildCPULimitsQuery

func BuildCPULimitsQuery(labelFilter string) string

BuildCPULimitsQuery builds a PromQL query for CPU limits

func BuildCPURequestsQuery

func BuildCPURequestsQuery(labelFilter string) string

BuildCPURequestsQuery PromQL query for CPU requests

func BuildCPUUsageQuery

func BuildCPUUsageQuery(labelFilter string) string

BuildCPUUsageQuery builds a PromQL query for CPU usage rate

func BuildLabelFilter

func BuildLabelFilter(componentID, projectID, environmentID string) string

BuildLabelFilter builds a Prometheus label filter string for component identification

func BuildMemoryLimitsQuery

func BuildMemoryLimitsQuery(labelFilter string) string

BuildMemoryLimitsQuery builds a PromQL query for memory limits

func BuildMemoryRequestsQuery

func BuildMemoryRequestsQuery(labelFilter string) string

BuildMemoryRequestsQuery builds a PromQL query for memory requests

func BuildMemoryUsageQuery

func BuildMemoryUsageQuery(labelFilter string) string

BuildMemoryUsageQuery builds a PromQL query for memory usage

Types

type Client

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

func NewClient

func NewClient(cfg *config.PrometheusConfig, logger *slog.Logger) (*Client, error)

func (*Client) HealthCheck

func (c *Client) HealthCheck(ctx context.Context) error

HealthCheck performs a health check on Prometheus using the official API

func (*Client) QueryRangeTimeSeries

func (c *Client) QueryRangeTimeSeries(ctx context.Context, query string, start, end time.Time, step time.Duration) (*TimeSeriesResponse, error)

QueryRangeTimeSeries executes a PromQL range query and returns full time series data This method returns all data points in the time range, suitable for charting and visualization

type DataPoint

type DataPoint struct {
	Timestamp float64 `json:"timestamp"` // Unix timestamp in seconds
	Value     string  `json:"value"`     // Metric value as string for precision
}

DataPoint represents a single timestamp-value pair in a time series

type MetricsRequest

type MetricsRequest struct {
	ComponentID   string    `json:"componentId"`
	EnvironmentID string    `json:"environmentId"`
	ProjectID     string    `json:"projectId"`
	StartTime     time.Time `json:"startTime"`
	EndTime       time.Time `json:"endTime"`
}

MetricsRequest represents a metrics query request

type MetricsService

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

MetricsService provides metrics query functionality

func NewMetricsService

func NewMetricsService(client *Client, logger *slog.Logger) *MetricsService

NewMetricsService creates a new metrics service

func (*MetricsService) QueryRangeTimeSeries

func (s *MetricsService) QueryRangeTimeSeries(ctx context.Context, query string, start, end time.Time, step time.Duration) (*TimeSeriesResponse, error)

QueryRangeTimeSeries executes a Prometheus range query and returns time series data

type ResourceMetricsTimeSeries

type ResourceMetricsTimeSeries struct {
	CPUUsage       []TimeValuePoint `json:"cpuUsage"`
	CPURequests    []TimeValuePoint `json:"cpuRequests"`
	CPULimits      []TimeValuePoint `json:"cpuLimits"`
	Memory         []TimeValuePoint `json:"memory"`
	MemoryRequests []TimeValuePoint `json:"memoryRequests"`
	MemoryLimits   []TimeValuePoint `json:"memoryLimits"`
}

ResourceMetricsTimeSeries represents resource usage metrics with time series data

type TimeSeries

type TimeSeries struct {
	Metric map[string]string `json:"metric"`
	Values []DataPoint       `json:"values"`
}

TimeSeries represents a single time series with metric labels and data points

type TimeSeriesData

type TimeSeriesData struct {
	ResultType string       `json:"resultType"`
	Result     []TimeSeries `json:"result"`
}

TimeSeriesData contains the result type and time series results

type TimeSeriesResponse

type TimeSeriesResponse struct {
	Status    string         `json:"status"`
	Data      TimeSeriesData `json:"data"`
	Error     string         `json:"error,omitempty"`
	ErrorType string         `json:"errorType,omitempty"`
}

TimeSeriesResponse represents a Prometheus range query response with time series data

type TimeValuePoint

type TimeValuePoint struct {
	Time  string  `json:"time"`  // ISO 8601 formatted timestamp
	Value float64 `json:"value"` // Numeric value
}

TimeValuePoint represents a simplified data point with ISO 8601 time format

func ConvertTimeSeriesToTimeValuePoints

func ConvertTimeSeriesToTimeValuePoints(ts TimeSeries) []TimeValuePoint

ConvertTimeSeriesToTimeValuePoints converts a TimeSeries to an array of TimeValuePoint with ISO 8601 formatted timestamps and float64 values

Jump to

Keyboard shortcuts

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