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 ¶
NewClient creates a new Prometheus client with the specified server address.
Parameters:
- address: Prometheus server URL (e.g., "http://localhost:9090")
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 ¶
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 ¶
NewClientWithBearerToken creates a new Prometheus client with bearer token authentication.
Parameters:
- address: Prometheus server URL (e.g., "http://localhost:9090")
- token: Bearer token for authentication
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 ¶
Click to show internal directories.
Click to hide internal directories.