Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ResourceMetrics method #232

Merged
merged 2 commits into from
Oct 4, 2023
Merged

Conversation

cesnietor
Copy link
Contributor

Similar to #218, this adds the Resource method equivalent to /minio/v2/metrics/resource endpoint.

Also renames a method to be more clear on what it does.

Test Steps:

  • Create a client
  • Run Metrics API
  • Parse the response to string to visualize it
ctx := context.Background()
madminClient, _ := madmin.NewMetricsClient(
		"http://localhost:9000",
		"accesskey",
		"secretKey",
		false,
	)
metrics, _ := metricsClient.ResourceMetrics(ctx)

result, _ := json.MarshalIndent(metrics, "", " ")
log.Println(string(result))

Output would look like:

[
 {
  "name": "someMetrics",
  "help": "Some help",
  "type": "GAUGE",
  "metrics": [
   {
    "value": "1.76933784e+08"
   }
  ]
 },
 {
  "name": "someMetrics",
  "help": "Some other help.",
  "type": "COUNTER",
  "metrics": [
   {
    "value": "2.59015547e+08"
   }
  ]
 },
 ...
 ]

Copy link
Contributor

@anjalshireesh anjalshireesh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. One suggestion to reduce code duplication.

}

// ResourceMetrics - returns Resource Metrics in Prometheus format
func (client *MetricsClient) ResourceMetrics(ctx context.Context) ([]*prom2json.Family, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code for each of these metrics functions seems almost same, except for the relativePath. It can be put into a common function, something like:

// FetchMetrics - returns Metrics of given subsystem in Prometheus format
func (client *MetricsClient) FetchMetrics(ctx context.Context, subSys string) ([]*prom2json.Family, error) {
	reqData := metricsRequestData{
		relativePath: "/v2/metrics/" + subSys,
	}

	// Execute GET on /minio/v2/metrics/<subSys>
	resp, err := client.executeGetRequest(ctx, reqData)
	if err != nil {
		return nil, err
	}
	defer closeResponse(resp)

	if resp.StatusCode != http.StatusOK {
		return nil, httpRespToErrorResponse(resp)
	}

	return parsePrometheusResults(io.LimitReader(resp.Body, metricsRespBodyLimit))
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@anjalshireesh I like it, I've done it, thanks.

@cesnietor cesnietor merged commit 7536cd0 into minio:main Oct 4, 2023
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants