Issue #449 API endpoint for Peer Monitor metrics

Rename method PeerMonitorLatestMetrics to Metrics
Addressing first round of comment as in
https://github.com/ipfs/ipfs-cluster/pull/572#pullrequestreview-165367171

License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
This commit is contained in:
Kishan Sagathiya 2018-10-21 12:04:50 +05:30
parent 3ac7d6c9cc
commit ec4588a5ce
5 changed files with 13 additions and 18 deletions

View File

@ -104,9 +104,9 @@ type Client interface {
// serialized version, strings instead of pids, is returned
GetConnectGraph() (api.ConnectGraphSerial, error)
// PeerMonitorLatestMetrics returns a map with the latest metrics of matching name
// Metrics returns a map with the latest metrics of matching name
// for the current cluster peers.
PeerMonitorLatestMetrics(name string) ([]api.Metric, error)
Metrics(name string) ([]api.Metric, error)
}
// Config allows to configure the parameters to connect

View File

@ -204,11 +204,11 @@ func (c *defaultClient) GetConnectGraph() (api.ConnectGraphSerial, error) {
return graphS, err
}
// PeerMonitorLatestMetrics returns a map with the latest metrics of matching name
// Metrics returns a map with the latest metrics of matching name
// for the current cluster peers.
func (c *defaultClient) PeerMonitorLatestMetrics(name string) ([]api.Metric, error) {
func (c *defaultClient) Metrics(name string) ([]api.Metric, error) {
var metrics []api.Metric
err := c.do("GET", fmt.Sprintf("/health/metrics/%s", name), nil, nil, &metrics)
err := c.do("GET", fmt.Sprintf("/monitor/metrics/%s", name), nil, nil, &metrics)
return metrics, err
}

View File

@ -386,9 +386,9 @@ func (api *API) routes() []route {
api.graphHandler,
},
{
"PeerMonitorLatestMetrics",
"Metrics",
"GET",
"/health/metrics/{name}",
"/monitor/metrics/{name}",
api.metricsHandler,
},
}
@ -522,7 +522,7 @@ func (api *API) metricsHandler(w http.ResponseWriter, r *http.Request) {
"PeerMonitorLatestMetrics",
name,
&metrics)
sendResponse(w, err, metrics)
api.sendResponse(w, autoStatus, err, metrics)
}
func (api *API) addHandler(w http.ResponseWriter, r *http.Request) {

View File

@ -216,12 +216,7 @@ func textFormatPrintAddedOutput(obj *api.AddedOutput) {
}
func textFormatPrintMetric(obj *api.Metric) {
fmt.Printf("{\n")
fmt.Printf(" Peer: %s\n", (obj.Peer).String())
fmt.Printf(" Value: %s\n", obj.Value)
fmt.Printf(" Expire: %d\n", obj.Expire)
fmt.Printf(" Expire: %t\n", obj.Valid)
fmt.Printf("}\n")
fmt.Printf("%s: %s | Expire : %d\n", obj.Peer.Pretty(), obj.Value, obj.Expire)
}
func textFormatPrintError(obj *api.Error) {

View File

@ -764,14 +764,14 @@ graph of the connections. Output is a dot file encoding the cluster's connectio
},
{
Name: "metrics",
Usage: "Get latest metrics of matching name for the current cluster peers.",
Usage: "List latest metrics logged by this peer",
Description: `
This command would show the peers and the last list of metrics logged for each as
returned by the Peer Monitor, in a friendly way.
This commands displays the latest valid metrics of the given type logged
by this peer for all current cluster peers.
`,
ArgsUsage: "Metric name",
Action: func(c *cli.Context) error {
resp, cerr := globalClient.PeerMonitorLatestMetrics(c.Args().First())
resp, cerr := globalClient.Metrics(c.Args().First())
formatResponse(c, resp, cerr)
return nil
},