Skip to content

Commit

Permalink
refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
cesnietor committed Oct 4, 2023
1 parent 72ffb4b commit 1c7fe48
Showing 1 changed file with 10 additions and 50 deletions.
60 changes: 10 additions & 50 deletions prometheus_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,71 +36,31 @@ const (
//
// The client needs to be configured with the endpoint of the desired node
func (client *MetricsClient) NodeMetrics(ctx context.Context) ([]*prom2json.Family, error) {
reqData := metricsRequestData{
relativePath: "/v2/metrics/node",
}

// Execute GET on /minio/v2/metrics/node
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))
return client.fetchMetrics(ctx, "node")
}

// ClusterMetrics - returns Cluster Metrics in Prometheus format
func (client *MetricsClient) ClusterMetrics(ctx context.Context) ([]*prom2json.Family, error) {
reqData := metricsRequestData{
relativePath: "/v2/metrics/cluster",
}

// Execute GET on /minio/v2/metrics/cluster
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))
return client.fetchMetrics(ctx, "cluster")
}

// BucketMetrics - returns Bucket Metrics in Prometheus format
func (client *MetricsClient) BucketMetrics(ctx context.Context) ([]*prom2json.Family, error) {
reqData := metricsRequestData{
relativePath: "/v2/metrics/bucket",
}

// Execute GET on /minio/v2/metrics/bucket
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))
return client.fetchMetrics(ctx, "bucket")
}

// ResourceMetrics - returns Resource Metrics in Prometheus format
func (client *MetricsClient) ResourceMetrics(ctx context.Context) ([]*prom2json.Family, error) {
return client.fetchMetrics(ctx, "resource")
}

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

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

0 comments on commit 1c7fe48

Please sign in to comment.