You've already forked bind_exporter
mirror of
https://github.com/prometheus-community/bind_exporter.git
synced 2025-07-27 12:01:46 +03:00
If -bind.stats-version is left to auto, both XML v2 and v3 versions will be handled gracefully.
29 lines
826 B
Go
29 lines
826 B
Go
package auto
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/digitalocean/bind_exporter/bind"
|
|
"github.com/digitalocean/bind_exporter/bind/v2"
|
|
"github.com/digitalocean/bind_exporter/bind/v3"
|
|
)
|
|
|
|
// Client is a client which automatically detects the statistics version of the
|
|
// BIND server and delegates the request to the correct versioned client.
|
|
type Client struct {
|
|
*bind.XMLClient
|
|
}
|
|
|
|
// NewClient returns an initialized Client.
|
|
func NewClient(url string, c *http.Client) *Client {
|
|
return &Client{XMLClient: bind.NewXMLClient(url, c)}
|
|
}
|
|
|
|
// Stats implements bind.Stats.
|
|
func (c *Client) Stats(g ...bind.StatisticGroup) (bind.Statistics, error) {
|
|
if err := c.Get(v3.StatusPath, &bind.Statistics{}); err == nil {
|
|
return (&v3.Client{XMLClient: c.XMLClient}).Stats(g...)
|
|
}
|
|
return (&v2.Client{XMLClient: c.XMLClient}).Stats(g...)
|
|
}
|