Skip to content

Conversation

sinhaashish
Copy link
Contributor

@sinhaashish sinhaashish commented Apr 24, 2018

Description

Changes made as suggested by @SuperQ in PR #5829.
Code modification in minio prometheus

  • updateGeneralMetrics() removed
  • Server Start time defined replacing the server uptime
  • minio_online_disks_total removed
  • minio_total_disk added
  • minio_offline_disks_total renamed to minio_offline_disks
  • minio_network_received_bytes_total and minio_network_sent_bytes_total
    changed from Gauge to Counter

Motivation and Context

As suggested by @SuperQ . It standardize the code wrt to prometheus

How Has This Been Tested?

Run the minio server and the prometheus metric is exposed at /minio/prometheus/metric

Types of changes

  • [] Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added unit tests to cover my changes.
  • I have added/updated functional tests in mint. (If yes, add mint PR # here: )
  • All new and existing tests passed.

cmd/metrics.go Outdated
// Fetch disk space info
objLayer := newObjectLayerFn()
// Service not initialized yet
s := objLayer.StorageInfo(context.Background())
Copy link
Member

Choose a reason for hiding this comment

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

this should be called after the following if condition.

cmd/metrics.go Outdated
if objLayer == nil {
return
}
//Network Sent/Recieved Bytes
Copy link
Member

Choose a reason for hiding this comment

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

A space after //

cmd/metrics.go Outdated
prometheus.GaugeValue,
float64(s.Free),
)
//Set Server Start Time
Copy link
Member

Choose a reason for hiding this comment

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

Same as above..

cmd/metrics.go Outdated
"github.com/prometheus/client_golang/prometheus"
)

// NetworkByte - Network statistics
Copy link
Member

Choose a reason for hiding this comment

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

this comment looks a bit out of place...

cmd/metrics.go Outdated
func updateGeneralMetrics() {
// Increment server uptime
serverUptime.Set(UTCNow().Sub(globalBootTime).Seconds())
// NewNetworkBytesCollector describes the collector
Copy link
Member

Choose a reason for hiding this comment

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

"describes the collector" we need to explain what kind of collector.

@balamurugana
Copy link
Member

@SuperQ
Copy link

SuperQ commented Apr 24, 2018

This is looking pretty good so far.

One thing I missed in the previous review was that you're using the deprecated prometheus.Handler() function. I would suggest you take a look at how we register custom custom collector handlers in the node_exporter.

@nitisht nitisht changed the title Code enhancements in minio promethues Code enhancements in minio prometheus exporter Apr 24, 2018
@codecov
Copy link

codecov bot commented Apr 24, 2018

Codecov Report

Merging #5848 into master will decrease coverage by 0.07%.
The diff coverage is 33%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #5848      +/-   ##
==========================================
- Coverage   59.99%   59.92%   -0.08%     
==========================================
  Files         212      212              
  Lines       30387    30463      +76     
==========================================
+ Hits        18232    18255      +23     
- Misses      10622    10676      +54     
+ Partials     1533     1532       -1
Impacted Files Coverage Δ
cmd/metrics-router.go 100% <100%> (ø) ⬆️
cmd/metrics.go 30.08% <31%> (+0.35%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ca8520f...404e2f6. Read the comment docs.

cmd/metrics.go Outdated
// to define metric and help string
func NewNetworkBytesCollector() *NetworkBytesCollector {
return &NetworkBytesCollector{
counterDesc: prometheus.NewDesc("minio_counters", "Help string", nil, nil),
Copy link
Member

Choose a reason for hiding this comment

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

Can you replace "help string" with something more useful ?

minio_online_disks_total
minio_server_uptime_seconds
```
- ```minio_disk_storage_bytes``` : Total byte count of disk storage available to current Minio server instance
Copy link
Contributor

Choose a reason for hiding this comment

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

Single quotes will work here i.e. minio_disk_storage_bytes

@sinhaashish sinhaashish force-pushed the minio_prometheus branch 3 times, most recently from d66279a to f83d302 Compare April 26, 2018 04:14
@vadmeste
Copy link
Member

@sinhaashish, Travis CI is not passing because there is one misspelled word

cmd/metrics.go:81:17: "Recieved" is a misspelling of "Received"

Can you fix it ?

@sinhaashish sinhaashish force-pushed the minio_prometheus branch 3 times, most recently from 2457d0a to 6a5eb50 Compare April 28, 2018 04:31
@sinhaashish
Copy link
Contributor Author

sinhaashish commented Apr 28, 2018

@SuperQ @harshavardhana @vadmeste . The required changes are done. Please validate

Copy link

@SuperQ SuperQ left a comment

Choose a reason for hiding this comment

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

LGTM, other than minor nits.

)

const (
prometheusMetricsPath = "/prometheus/metrics"
Copy link

Choose a reason for hiding this comment

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

IMO, there's no need to prefix with /prometheus here. /metrics is the default.

Copy link
Member

Choose a reason for hiding this comment

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

The reason is to provide room for other metrics which do not provide in prometheus compatible form.

## Minio Prometheus Metric

Minio server exposes an endpoint for Promethueus to scrape server data at `/minio/metric`.
Minio server exposes an endpoint for Promethueus to scrape server data at `/minio/prometheus/metric`.
Copy link

Choose a reason for hiding this comment

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

Typo /metric here.

Copy link
Member

Choose a reason for hiding this comment

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

@sinhaashish can you address this minor issue ? LGTM otherwise

// Update prometheus metric
networkSentBytes.Set(float64(globalConnStats.getTotalOutputBytes()))
networkReceivedBytes.Set(float64(globalConnStats.getTotalInputBytes()))
// Minio Total Disk/Offline Disk
Copy link
Member

Choose a reason for hiding this comment

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

Although offline/online disks don't make sense in Minio FS mode, I recommend to show a value other than zero for total disks. The following diff fixes the problem:

diff --git a/cmd/metrics.go b/cmd/metrics.go
index 942c247d..66c3cea6 100644
--- a/cmd/metrics.go
+++ b/cmd/metrics.go
@@ -124,6 +124,15 @@ func (c *minioCollector) Collect(ch chan<- prometheus.Metric) {
 		float64(globalBootTime.Unix()),
 	)
 
+	var totalDisks, offlineDisks int
+	if s.Backend.Type == FS {
+		totalDisks = 1
+		offlineDisks = 0
+	} else {
+		offlineDisks = s.Backend.OfflineDisks
+		totalDisks = s.Backend.OfflineDisks + s.Backend.OnlineDisks
+	}
+
 	// Minio Total Disk/Offline Disk
 	ch <- prometheus.MustNewConstMetric(
 		prometheus.NewDesc(
@@ -131,7 +140,7 @@ func (c *minioCollector) Collect(ch chan<- prometheus.Metric) {
 			"Total number of disks for current Minio server instance",
 			nil, nil),
 		prometheus.GaugeValue,
-		float64(s.Backend.OnlineDisks+s.Backend.OfflineDisks),
+		float64(totalDisks),
 	)
 	ch <- prometheus.MustNewConstMetric(
 		prometheus.NewDesc(
@@ -139,7 +148,7 @@ func (c *minioCollector) Collect(ch chan<- prometheus.Metric) {
 			"Total number of offline disks for current Minio server instance",
 			nil, nil),
 		prometheus.GaugeValue,
-		float64(s.Backend.OfflineDisks),
+		float64(offlineDisks),
 	)
 }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Changes made to standardize the code with respect to Prometheus
Ref : minio#5829
@balamurugana
Copy link
Member

Mint Automation

Test Result
mint-xl.sh more...
mint-fs.sh more...
mint-dist-xl.sh more...
mint-gateway-s3.sh more...
mint-gateway-azure.sh more...

5848-404e2f6/mint-gateway-s3.sh.log:

Running with
SERVER_ENDPOINT: minikube:32578
ACCESS_KEY:      AKIAJH7GQKYNU3C2ADXA
SECRET_KEY:      ***REDACTED***
ENABLE_HTTPS:    0
SERVER_REGION:   us-east-1
MINT_DATA_DIR:   /mint/data
MINT_MODE:       core

To get logs, run 'docker cp 09966c624692:/mint/log /tmp/mint-logs'
(1/13) Running aws-sdk-go tests ... done in 5 seconds
(2/13) Running aws-sdk-java tests ... done in 19 seconds
(3/13) Running aws-sdk-php tests ... FAILED in 6 seconds
PHP Fatal error:  Uncaught exception 'Aws\S3\Exception\S3Exception' with message 'Error executing "CreateBucket" on "http://minikube:32578/aws-sdk-php-5ae88127cff63"; AWS HTTP error: Server error: `PUT http://minikube:32578/aws-sdk-php-5ae88127cff63` resulted in a `500 Internal Server Error` response:
<?xml version="1.0" encoding="UTF-8"?>
<Error><Code>InternalError</Code><Message>We encountered an internal error, pleas (truncated...)
 InternalError (server): We encountered an internal error, please try again. - <?xml version="1.0" encoding="UTF-8"?>
<Error><Code>InternalError</Code><Message>We encountered an internal error, please try again.</Message><Key></Key><BucketName></BucketName><Resource>/aws-sdk-php-5ae88127cff63</Resource><RequestId>3L137</RequestId><HostId>3L137</HostId></Error>'

GuzzleHttp\Exception\ServerException: Server error: `PUT http://minikube:32578/aws-sdk-php-5ae88127cff63` resulted in a `500 Internal Server Error` response:
<?xml version="1.0" encoding="UTF-8"?>
<Error><Code>InternalError</Code><Message in /mint/run/core/aws-sdk-php/vendor/aws/aws-sdk-php/src/WrappedHttpHandler.php on line 191

Executed 2 out of 13 tests successfully.

5848-404e2f6/mint-gateway-azure.sh.log:

Running with
SERVER_ENDPOINT: minikube:30395
ACCESS_KEY:      minioazure1
SECRET_KEY:      ***REDACTED***
ENABLE_HTTPS:    0
SERVER_REGION:   us-east-1
MINT_DATA_DIR:   /mint/data
MINT_MODE:       core

To get logs, run 'docker cp c5c981ad1572:/mint/log /tmp/mint-logs'
(1/13) Running aws-sdk-go tests ... done in 10 seconds
(2/13) Running aws-sdk-java tests ... done in 14 seconds
(3/13) Running aws-sdk-php tests ... done in 32 seconds
(4/13) Running aws-sdk-ruby tests ... done in 29 seconds
(5/13) Running awscli tests ... done in 2 minutes and 1 seconds
(6/13) Running mc tests ... done in 6 minutes and 29 seconds
(7/13) Running minio-dotnet tests ... done in 56 seconds
(8/13) Running minio-go tests ... done in 1 seconds
(9/13) Running minio-java tests ... done in 35 seconds
(10/13) Running minio-js tests ... FAILED in 2 minutes and 22 seconds
{
  "name": "minio-js",
  "function": "getBucketPolicy(bucketName, cb)",
  "args": "bucketName:minio-js-test-0556e3f1-9b97-48ad-bb93-12dda17994c5",
  "duration": 322,
  "status": "FAIL",
  "error": "S3Error: The bucket policy does not exist at Object.parseError (node_modules/minio/dist/main/xml-parsers.js:56:11) at /mint/run/core/minio-js/node_modules/minio/dist/main/transformers.js:117:22 at DestroyableTransform._flush (node_modules/minio/dist/main/transformers.js:48:26) at DestroyableTransform.<anonymous> (node_modules/minio/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:135:12) at finishMaybe (node_modules/minio/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:371:12) at endWritable (node_modules/minio/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:378:3) at DestroyableTransform.Writable.end (node_modules/minio/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:356:5) at IncomingMessage.onend (_stream_readable.js:514:10) at endReadableNT (_stream_readable.js:978:12) at _combinedTickCallback (internal/process/next_tick.js:80:11) at process._tickCallback (internal/process/next_tick.js:104:9)"
}

Executed 9 out of 13 tests successfully.

5848-404e2f6/mint-xl.sh.log:

Running with
SERVER_ENDPOINT: minikube:31134
ACCESS_KEY:      minio
SECRET_KEY:      ***REDACTED***
ENABLE_HTTPS:    0
SERVER_REGION:   us-east-1
MINT_DATA_DIR:   /mint/data
MINT_MODE:       core

To get logs, run 'docker cp 54d222ac2dd6:/mint/log /tmp/mint-logs'
(1/13) Running aws-sdk-go tests ... done in 1 seconds
(2/13) Running aws-sdk-java tests ... done in 18 seconds
(3/13) Running aws-sdk-php tests ... FAILED in 11 seconds
{
  "name": "aws-sdk-php",
  "function": "getBucketPolicy ( array $params = [] )",
  "args": {
    "Bucket": "aws-sdk-php-5ae8812509ace"
  },
  "duration": "221",
  "status": "FAIL",
  "error": "bucket policy we got is not we set"
}

Executed 2 out of 13 tests successfully.

5848-404e2f6/mint-fs.sh.log:

Running with
SERVER_ENDPOINT: minikube:31444
ACCESS_KEY:      minio
SECRET_KEY:      ***REDACTED***
ENABLE_HTTPS:    0
SERVER_REGION:   us-east-1
MINT_DATA_DIR:   /mint/data
MINT_MODE:       core

To get logs, run 'docker cp 98c0500741d7:/mint/log /tmp/mint-logs'
(1/13) Running aws-sdk-go tests ... done in 1 seconds
(2/13) Running aws-sdk-java tests ... done in 14 seconds
(3/13) Running aws-sdk-php tests ... FAILED in 11 seconds
{
  "name": "aws-sdk-php",
  "function": "getBucketPolicy ( array $params = [] )",
  "args": {
    "Bucket": "aws-sdk-php-5ae88120c146b"
  },
  "duration": "32",
  "status": "FAIL",
  "error": "bucket policy we got is not we set"
}

Executed 2 out of 13 tests successfully.

5848-404e2f6/mint-dist-xl.sh.log:

Running with
SERVER_ENDPOINT: minikube:32579
ACCESS_KEY:      minio
SECRET_KEY:      ***REDACTED***
ENABLE_HTTPS:    0
SERVER_REGION:   us-east-1
MINT_DATA_DIR:   /mint/data
MINT_MODE:       core

To get logs, run 'docker cp 53edb4e2fee9:/mint/log /tmp/mint-logs'
(1/13) Running aws-sdk-go tests ... done in 13 seconds
(2/13) Running aws-sdk-java tests ... done in 14 seconds
(3/13) Running aws-sdk-php tests ... FAILED in 10 seconds
{
  "name": "aws-sdk-php",
  "function": "getBucketPolicy ( array $params = [] )",
  "args": {
    "Bucket": "aws-sdk-php-5ae8812be34f4"
  },
  "duration": "254",
  "status": "FAIL",
  "error": "bucket policy we got is not we set"
}

Executed 2 out of 13 tests successfully.

Copy link
Member

@vadmeste vadmeste left a comment

Choose a reason for hiding this comment

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

LGTM

@nitisht nitisht merged commit e4dbc64 into minio:master May 9, 2018
harshavardhana pushed a commit that referenced this pull request May 9, 2018
Standardized Minio collectors based on Prometheus 
recommendations.
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.

6 participants