...

Package prometheus

import "github.com/prometheus/client_golang/api/prometheus"
Overview
Index

Overview ▾

Package prometheus provides bindings to the Prometheus HTTP API: http://prometheus.io/docs/querying/api/

type CancelableTransport

type CancelableTransport interface {
    http.RoundTripper
    CancelRequest(req *http.Request)
}

CancelableTransport is like net.Transport but provides per-request cancelation functionality.

var DefaultTransport CancelableTransport = &http.Transport{
    Proxy: http.ProxyFromEnvironment,
    Dial: (&net.Dialer{
        Timeout:   30 * time.Second,
        KeepAlive: 30 * time.Second,
    }).Dial,
    TLSHandshakeTimeout: 10 * time.Second,
}

DefaultTransport is used if no Transport is set in Config.

type Client

type Client interface {
    // contains filtered or unexported methods
}

Client is the interface for an API client.

func New

func New(cfg Config) (Client, error)

New returns a new Client.

It is safe to use the returned Client from multiple goroutines.

type Config

type Config struct {
    // The address of the Prometheus to connect to.
    Address string

    // Transport is used by the Client to drive HTTP requests. If not
    // provided, DefaultTransport will be used.
    Transport CancelableTransport
}

Config defines configuration parameters for a new client.

type Error

type Error struct {
    Type ErrorType
    Msg  string
}

Error is an error returned by the API.

func (*Error) Error

func (e *Error) Error() string

type ErrorType

type ErrorType string

ErrorType models the different API error types.

const (
    ErrBadData     ErrorType = "bad_data"
    ErrTimeout               = "timeout"
    ErrCanceled              = "canceled"
    ErrExec                  = "execution"
    ErrBadResponse           = "bad_response"
)

Possible values for ErrorType.

type QueryAPI

type QueryAPI interface {
    // Query performs a query for the given time.
    Query(ctx context.Context, query string, ts time.Time) (model.Value, error)
    // Query performs a query for the given range.
    QueryRange(ctx context.Context, query string, r Range) (model.Value, error)
}

QueryAPI provides bindings the Prometheus's query API.

func NewQueryAPI

func NewQueryAPI(c Client) QueryAPI

NewQueryAPI returns a new QueryAPI for the client.

It is safe to use the returned QueryAPI from multiple goroutines.

type Range

type Range struct {
    // The boundaries of the time range.
    Start, End time.Time
    // The maximum time between two slices within the boundaries.
    Step time.Duration
}

Range represents a sliced time range.