Documentation ¶
Overview ¶
Package graphite provides client to graphite-web-api (http://graphite-api.readthedocs.io/en/latest/api.html).
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var WrongUrlError = errors.New("Wrong url")
Functions ¶
This section is empty.
Types ¶
type Client ¶
Client is client to `graphite web api` (http://graphite-api.readthedocs.io/en/latest/api.html). You can either instantiate it manually by providing `url` and `client` or use a `NewFromString` shortcut.
func NewFromString ¶
NewFromString is a convenient function for constructing `graphite.Client` from url string. For example 'https://my-graphite.tld'. NewFromString could return either `graphite.Client` instance or `WrongUrlError` error.
Example ¶
client, _ := NewFromString("http://my-graphite.tld") fmt.Printf(client.Url.Host)
Output: my-graphite.tld
func (*Client) ExpandMetrics ¶
func (c *Client) ExpandMetrics(r ExpandMetricRequest) (ExpandResult, error)
FindMetrics perform request to /metrics/expand API: http://graphite-api.readthedocs.io/en/latest/api.html#metrics-expand It returns slice of Metric if all is OK or RequestError if things goes wrong.
Example ¶
ts := createExpandMetricsTestServer() defer ts.Close() client, _ := NewFromString(ts.URL) res, _ := client.ExpandMetrics( ExpandMetricRequest{ Query: "cluster.*", }, ) fmt.Printf("%+v", res)
Output: {Results:[cluster.one cluster.two]}
func (*Client) FindMetrics ¶
func (c *Client) FindMetrics(r FindMetricRequest) ([]Metric, error)
FindMetrics perform request to /metrics/find API: http://graphite-api.readthedocs.io/en/latest/api.html#metrics-find It returns slice of Metric if all is OK or RequestError if things goes wrong.
Example ¶
ts := createFindMetricsTestServer() defer ts.Close() client, _ := NewFromString(ts.URL) res, _ := client.FindMetrics( FindMetricRequest{ Query: "cluster.*", }, ) fmt.Printf("%+v", res)
Output: [{Id:cluster.one Text:one Expandable:1 Leaf:0 AllowChildren:1} {Id:cluster.two Text:two Expandable:1 Leaf:0 AllowChildren:1}]
func (*Client) QueryRender ¶
func (c *Client) QueryRender(r RenderRequest) ([]Series, error)
QueryRender performs query to graphite `/render/` api. Normally it should return `[]graphite.Series`, but if things go wrong it will return `graphite.RequestError` error.
Example ¶
ts := createTestServer() defer ts.Close() client, _ := NewFromString(ts.URL) res, _ := client.QueryRender( RenderRequest{ Targets: []string{"main"}, }, ) fmt.Printf(strconv.FormatInt(res[0].Datapoints[0].Timestamp.Unix(), 10))
Output: 1468339853
type ExpandMetricRequest ¶
type FindMetricRequest ¶
FindMetricRequest is struct describing request to /metrics/find api.
type RenderRequest ¶
RenderRequest is struct, describing request to graphite `/render/` api. No fields are required. If field has zero value it'll be just skipped in request. RenderRequest.Targets are slice of strings, were every entry is a path identifying one or several metrics, optionally with functions acting on those metrics.
Warning. While wildcards could be used in Targets one should use them with caution, as using of the simple target like "main.cluster.*.cpu.*" could result in hundreds of series with megabytes of data inside.
type RequestError ¶
RequestError is special error, which not only implements an error interface, but also provides access to `Query` field, containing original query which cause an error.
func (RequestError) Error ¶
func (e RequestError) Error() string
Example ¶
err := RequestError{ Type: "Error type", } fmt.Printf(err.Error())
Output: Error type