client

package
v1.2.4 Latest Latest
Warning

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

Go to latest
Published: Jan 1, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package client provides a wrapper around the official Prometheus Go client library for querying Prometheus metrics with support for basic authentication, bearer token authentication, and PromQL queries.

Features:

  • Simple client creation with various authentication methods
  • Instant vector queries with Query()
  • Range vector queries with QueryRange()
  • Configurable timeout for all operations
  • Support for basic auth and bearer token authentication

Example:

client, err := client.NewClient("http://localhost:9090")
if err != nil {
    log.Fatal(err)
}

value, warnings, err := client.Query("up", time.Now(), 10*time.Second)
if err != nil {
    log.Fatal(err)
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewClient

func NewClient(address string) (*client, error)

NewClient creates a new Prometheus client with the specified server address.

Parameters:

Returns:

  • *client: Configured Prometheus client
  • error: Error if client creation fails

Example:

c, err := client.NewClient("http://localhost:9090")
if err != nil {
    log.Fatal(err)
}

func NewClientWithBasicAuth

func NewClientWithBasicAuth(address, username string, password string) (*client, error)

NewClientWithBasicAuth creates a new Prometheus client with HTTP basic authentication.

Parameters:

  • address: Prometheus server URL (e.g., "http://localhost:9090")
  • username: Basic auth username
  • password: Basic auth password

Returns:

  • *client: Configured Prometheus client with basic auth
  • error: Error if client creation fails

Example:

c, err := client.NewClientWithBasicAuth(
    "http://localhost:9090",
    "admin",
    "secret",
)
if err != nil {
    log.Fatal(err)
}

func NewClientWithBearerToken

func NewClientWithBearerToken(address string, token string) (*client, error)

NewClientWithBearerToken creates a new Prometheus client with bearer token authentication.

Parameters:

Returns:

  • *client: Configured Prometheus client with bearer token auth
  • error: Error if client creation fails

Example:

c, err := client.NewClientWithBearerToken(
    "http://localhost:9090",
    "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
)
if err != nil {
    log.Fatal(err)
}

Types

type Range

type Range = v1.Range

Jump to

Keyboard shortcuts

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