prometheus

package
v4.2.706+incompatible Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2020 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EndpointPrefix       = "/api/v1"
	ExpressionQuery      = "/query"
	ExpressionQueryRange = "/query_range"
)
View Source
const (
	// Status string literal of prometheus read/write request
	StatusSuccess = "success"
	// Status string literal of prometheus read/write request
	StatusError = "error"
)

Variables

This section is empty.

Functions

func ReadRawdata

func ReadRawdata(config *Config, queries []*Common.Query) ([]*Common.ReadRawdata, error)

func ResponseToReadRawdata

func ResponseToReadRawdata(response *Response, query *Common.Query) (*Common.ReadRawdata, error)

func WrapQueryExpression

func WrapQueryExpression(queryExpression string, aggregateFunc DBCommon.AggregateFunction, aggregateOverSeconds int64) (string, error)

Types

type Config

type Config struct {
	URL             string     `mapstructure:"url"`
	BearerTokenFile string     `mapstructure:"bearerTokenFile"`
	TLSConfig       *TLSConfig `mapstructure:"tlsConfig"`
	// contains filtered or unexported fields
}

Configuration of prometheus data source

func NewDefaultConfig

func NewDefaultConfig() *Config

Provide default configuration for prometheus

func (*Config) Validate

func (c *Config) Validate() error

Confirm the prometheus configuration is validated

type Data

type Data struct {
	ResultType ResultType    `json:"resultType"`
	Result     []interface{} `json:"result"`
}

Represents the general value of prometheus http response field "data", the format of field "result" will depends on field "resultType"

type Entity

type Entity struct {
	Labels map[string]string
	Values []UnixTimeWithSampleValue
}

Structure to store metrics data from prometheus response

type MatrixData

type MatrixData struct {
	ResultType ResultType
	Result     []struct {
		Metric map[string]string
		Values []UnixTimeWithSampleValue
	}
}

MatrixData MatrixData

type MatrixResponse

type MatrixResponse struct {
	Status string
	Data   MatrixData
}

MatrixResponse MatrixResponse

type MatrixResult

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

type Prometheus

type Prometheus struct {
	Config    *Config
	Client    *http.Client
	Transport *http.Transport
}

Prometheus client definition

func NewClient

func NewClient(config *Config) (*Prometheus, error)

Instance prometheus API client with configuration

func (*Prometheus) Close

func (p *Prometheus) Close()

Close free resource used by prometheus

func (*Prometheus) IsMetricsExist added in v0.9.166

func (p *Prometheus) IsMetricsExist(ctx context.Context, metrics []string) (bool, []string, error)

IsMetricsExist checks if metrics are existing in Prometheus, if there is an error while quering to Prometheus, returns (false, nil, error) if there are metrics not existing in Prometheus, returns (false, nonExistMetrics, nil) or if all metrics are existing, returns (true, nil, nil)

func (*Prometheus) Query

func (p *Prometheus) Query(ctx context.Context, query string, startTime, timeout *time.Time) (Response, error)

Query data over a range of time from prometheus

func (*Prometheus) QueryRange

func (p *Prometheus) QueryRange(ctx context.Context, query string, startTime, endTime *time.Time, stepTime *time.Duration) (Response, error)

QueryRange data over a range of time from prometheus

type Response

type Response struct {
	Status    string `json:"status"`
	Data      Data   `json:"data"`
	ErrorType string `json:"errorType"`
	Error     string `json:"error"`
}

Structure of prometheus http response

func (Response) GetEntities

func (r Response) GetEntities() ([]Entity, error)

func (Response) GetEntitiesMatrix

func (r Response) GetEntitiesMatrix() ([]Entity, error)

func (Response) GetEntitiesVector

func (r Response) GetEntitiesVector() ([]Entity, error)

func (Response) GetMatrixResponse

func (r Response) GetMatrixResponse() (MatrixResponse, error)

type ResultType

type ResultType string

Prometheus http resultType

var MatrixResultType ResultType = "matrix"

Prometheus http matrix resultType

var ScalarResultType ResultType = "scalar"

Prometheus http scalar resultType

var StringResultType ResultType = "string"

Prometheus http string resultType

var VectorResultType ResultType = "vector"

Prometheus http vector resultType

type ScalarResult

type ScalarResult UnixTimeWithScalarValue

type StringResult

type StringResult UnixTimeWithStringValue

type TLSConfig

type TLSConfig struct {
	InsecureSkipVerify bool `mapstructure:"insecureSkipVerify"`
}

Configuration of tls connection

type UnixTimeWithSampleValue

type UnixTimeWithSampleValue struct {
	UnixTime    time.Time
	SampleValue string
}

type UnixTimeWithScalarValue

type UnixTimeWithScalarValue struct {
	UnixTime    time.Time
	ScalarValue string
}

type UnixTimeWithStringValue

type UnixTimeWithStringValue struct {
	UnixTime    time.Time
	StringValue string
}

type Value

type Value []interface{}

type VectorData

type VectorData struct {
	ResultType ResultType
	Result     []struct {
		Metric map[string]string
		Value  UnixTimeWithSampleValue
	}
}

VectorData VectorData

type VectorResponse

type VectorResponse struct {
	Status string
	Data   VectorData
}

VectorResponse VectorResponse

type VectorResult

type VectorResult struct {
	Metric map[string]string `json:"metric"`
	Value  Value             `json:"value"`
}

Jump to

Keyboard shortcuts

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