From 80e382f26652159502e4486df685c2a7298e1fd8 Mon Sep 17 00:00:00 2001 From: kaiyan-sheng Date: Tue, 15 Dec 2020 09:38:58 -0700 Subject: [PATCH 1/4] Fix vsphere.datastore.capacity.used.pct value by removing *100 --- metricbeat/docs/fields.asciidoc | 2 +- .../module/vsphere/datastore/_meta/data.json | 23 +++++++++++-------- .../module/vsphere/datastore/_meta/fields.yml | 2 +- .../module/vsphere/datastore/datastore.go | 4 ++-- metricbeat/module/vsphere/fields.go | 2 +- 5 files changed, 18 insertions(+), 15 deletions(-) diff --git a/metricbeat/docs/fields.asciidoc b/metricbeat/docs/fields.asciidoc index 7aaa0f4edca..bcb4524186f 100644 --- a/metricbeat/docs/fields.asciidoc +++ b/metricbeat/docs/fields.asciidoc @@ -46384,7 +46384,7 @@ format: bytes Used percent of the datastore -type: long +type: scaled_float format: percent diff --git a/metricbeat/module/vsphere/datastore/_meta/data.json b/metricbeat/module/vsphere/datastore/_meta/data.json index 75ff4a08405..fb290513a92 100644 --- a/metricbeat/module/vsphere/datastore/_meta/data.json +++ b/metricbeat/module/vsphere/datastore/_meta/data.json @@ -1,27 +1,30 @@ { "@timestamp": "2017-10-12T08:05:34.853Z", - "beat": { - "hostname": "host.example.com", - "name": "host.example.com" + "event": { + "dataset": "vsphere.datastore", + "duration": 115000, + "module": "vsphere" }, "metricset": { - "host": "http://127.0.0.1:36937/sdk", - "module": "vsphere", "name": "datastore", - "rtt": 115 + "period": 10000 + }, + "service": { + "address": "http://127.0.0.1:51027/sdk", + "type": "vsphere" }, "vsphere": { "datastore": { "capacity": { "free": { - "bytes": 50021150720 + "bytes": 267958476800 }, "total": { - "bytes": 63918878720 + "bytes": 484736266240 }, "used": { - "bytes": 13897728000, - "pct": 21 + "bytes": 216777789440, + "pct": 0.44720769733509097 } }, "fstype": "local", diff --git a/metricbeat/module/vsphere/datastore/_meta/fields.yml b/metricbeat/module/vsphere/datastore/_meta/fields.yml index 7a1ff578e3f..632bb13cfe2 100644 --- a/metricbeat/module/vsphere/datastore/_meta/fields.yml +++ b/metricbeat/module/vsphere/datastore/_meta/fields.yml @@ -28,7 +28,7 @@ Used bytes of the datastore format: bytes - name: capacity.used.pct - type: long + type: scaled_float description: > Used percent of the datastore format: percent diff --git a/metricbeat/module/vsphere/datastore/datastore.go b/metricbeat/module/vsphere/datastore/datastore.go index c0699daae77..f794384d453 100644 --- a/metricbeat/module/vsphere/datastore/datastore.go +++ b/metricbeat/module/vsphere/datastore/datastore.go @@ -111,9 +111,9 @@ func (m *MetricSet) Fetch(ctx context.Context, reporter mb.ReporterV2) error { } for _, ds := range dst { - var usedSpacePercent int64 + var usedSpacePercent float64 if ds.Summary.Capacity > 0 { - usedSpacePercent = 100 * (ds.Summary.Capacity - ds.Summary.FreeSpace) / ds.Summary.Capacity + usedSpacePercent = float64(ds.Summary.Capacity-ds.Summary.FreeSpace) / float64(ds.Summary.Capacity) } usedSpaceBytes := ds.Summary.Capacity - ds.Summary.FreeSpace diff --git a/metricbeat/module/vsphere/fields.go b/metricbeat/module/vsphere/fields.go index b0588e42a72..97a810ae68c 100644 --- a/metricbeat/module/vsphere/fields.go +++ b/metricbeat/module/vsphere/fields.go @@ -32,5 +32,5 @@ func init() { // AssetVsphere returns asset data. // This is the base64 encoded gzipped contents of module/vsphere. func AssetVsphere() string { - return "eJzMls1u2zoQhfd+ikH28QNocTe5SLtxWyBNtwYjjSzWooYgRwnUpy9ISoZ+6CapqLZcGLBInfNJ1JzhLZyxy+DZ6goN7gBYco0Z3Dw/+Cs3O4ACbW6kZklNBv/tAAD6WVBUtLW7zWCNwmIGJ7EDKCXWhc380ltohMKxhRvcabfYUKv7KxGXqdBYrBAsLNNFLi55VbafiohMn2MYc4wxivudTAwkZ+xeyBSzuV/wuPH/wLTUHQxL6/TTWd7LGm1nGRUshAfPXGiRS+72TCzq/VPHaKMENTWn99l/dYrgFYFK4AqjG+NGSUYJzmBpv+AsDWJSzHuDmJyytVgkpXy0WGxDqXNOyajR5NjwWyn75ZfZRSBUZHlNFszu/9sx8JEsX0+AXLdhU1T1I+Wm3H15BNnAYaY6tg31n843VP8bjH1Bp/P15fyKrUJFZqsiPXhxZx+Tfr06e7it8jgR3jYxvBauQX4hcz66f3Gw3yraT0EWprKX84803IpaibySzapzy1Wl96eWi729nD/n2uCaCU7M3M9GWTk0k1mWb5XR38I2wCHsw/W4poTf2Nz0s0YjWDYneAhHuH+taYxD9NSi5c2ilEr44AxWh5Zn9R/rhqihUJKkf/rXOukByd6rbwbpYcctYT1r3lomdQyhGSWkp++4OAyHi8cVlX3njSFi/Efb1s8AAAD//5A1D00=" + return "eJzMlsFymzAQhu9+ip3c4wfg0Es6aS9uO5OmV48Ci61asIy0JEOfviMJPCDkximijQ6eMRL//4HYf3ULJ+wyeDbNETVuAFiywgxunh/clZsNQIEm17JhSXUGHzYAAP0sVFS0yt6mUaEwmMFBbABKiaowmVt6C7WocGxhB3eNXaypbforEZep0FisECwM01kuLnlRtp+KiEyfYxghxhjF/k4mBpITdi+ki2DuDzx2fByY5rqDYWmsfjrLe6nQdIaxgpnw4JmLRuSSuy0TC7V96hhNlEBRfXib/XerCE4RqAQ+YnRj7ChJV4IzmNvPOEuNmBTzXiMmp2wNFkkpHw0W61A2OUcZTS4UFvtSkQgXXMPaoM6x5mtp++Xn2VkwHMnwkkwI7v/fcfCZDF9Ogrxp/eZUx18pP6C7b48ga9gFqmNbnwPpfH0KXGHsCjudryvrV2wrrEivVaw7J27tY9KvV2kPt1YuJ8JbJ46XwtXIL6RPe/svDvZXRfvFy8JU9nwOkppboSqRH2W96PxyUentqWVjbyvD51waXIHgxMz+rJSVQzMJsnytjP7htwF2fh8uxzUl/MZC068NasGyPsCDP8q9t6YxDtFDi4ZXi1Iq4ZM1WBxajtV9rCui+kJJkv7pX+ukByR7r64ZpIcdt4TlrHlrmKq9D80oIT39xNmh2F/cL6jsO2cMEeN/2rZ+BwAA//8rvBJ+" } From 59dfd998739746c9b50c9a6ba1ad161851fc58fb Mon Sep 17 00:00:00 2001 From: kaiyan-sheng Date: Tue, 15 Dec 2020 09:42:53 -0700 Subject: [PATCH 2/4] add changelog --- CHANGELOG.next.asciidoc | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.next.asciidoc b/CHANGELOG.next.asciidoc index 4f389b74d2b..e45583f0424 100644 --- a/CHANGELOG.next.asciidoc +++ b/CHANGELOG.next.asciidoc @@ -467,6 +467,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d - Add support for azure light metricset app_stats. {pull}20639[20639] - Fix remote_write flaky test. {pull}21173[21173] - Remove io.time from windows {pull}22237[22237] +- Change vsphere.datastore.capacity.used.pct value to betweeen 0 and 1. {pull}23148[23148] *Packetbeat* From b8e35c75373604b736819526d932ba75a937b7d6 Mon Sep 17 00:00:00 2001 From: kaiyan-sheng Date: Tue, 15 Dec 2020 11:06:05 -0700 Subject: [PATCH 3/4] Fix unit test --- metricbeat/module/vsphere/datastore/datastore_test.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/metricbeat/module/vsphere/datastore/datastore_test.go b/metricbeat/module/vsphere/datastore/datastore_test.go index 30f1d32e8e3..8c1f9488d7a 100644 --- a/metricbeat/module/vsphere/datastore/datastore_test.go +++ b/metricbeat/module/vsphere/datastore/datastore_test.go @@ -58,7 +58,9 @@ func TestFetchEventContents(t *testing.T) { if err != nil { t.Error(err) } else { - isNonNegativeInt64(t, field, value) + if field != "capacity.used.pct" { + isNonNegativeInt64(t, field, value) + } } } } From fb3ee7f5c3ada5ef1872460fc1fa6ff0bbec11bb Mon Sep 17 00:00:00 2001 From: kaiyan-sheng Date: Tue, 15 Dec 2020 12:34:58 -0700 Subject: [PATCH 4/4] remove capacity.used.pct from the fields list --- metricbeat/module/vsphere/datastore/datastore_test.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/metricbeat/module/vsphere/datastore/datastore_test.go b/metricbeat/module/vsphere/datastore/datastore_test.go index 8c1f9488d7a..88f5b772b5a 100644 --- a/metricbeat/module/vsphere/datastore/datastore_test.go +++ b/metricbeat/module/vsphere/datastore/datastore_test.go @@ -52,15 +52,13 @@ func TestFetchEventContents(t *testing.T) { // Values are based on the result 'df -k'. fields := []string{"capacity.total.bytes", "capacity.free.bytes", - "capacity.used.bytes", "capacity.used.pct"} + "capacity.used.bytes"} for _, field := range fields { value, err := event.GetValue(field) if err != nil { t.Error(err) } else { - if field != "capacity.used.pct" { - isNonNegativeInt64(t, field, value) - } + isNonNegativeInt64(t, field, value) } } }