Skip to content

Commit

Permalink
Issue #449 API endpoint for Peer Monitor metrics
Browse files Browse the repository at this point in the history
Rename method PeerMonitorLatestMetrics to Metrics
Addressing first round of comment as in
#572 (review)

License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
  • Loading branch information
kishansagathiya committed Oct 21, 2018
1 parent 4c117ea commit 16cc58a
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 17 deletions.
4 changes: 2 additions & 2 deletions api/rest/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions api/rest/client/methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
4 changes: 2 additions & 2 deletions api/rest/restapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,9 +383,9 @@ func (api *API) routes() []route {
api.graphHandler,
},
{
"PeerMonitorLatestMetrics",
"Metrics",
"GET",
"/health/metrics/{name}",
"/monitor/metrics/{name}",
api.metricsHandler,
},
}
Expand Down
7 changes: 1 addition & 6 deletions cmd/ipfs-cluster-ctl/formatters.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
8 changes: 4 additions & 4 deletions cmd/ipfs-cluster-ctl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
Expand Down

0 comments on commit 16cc58a

Please sign in to comment.