diff --git a/NOTICE.txt b/NOTICE.txt index 9d490eadbf61..1b499fcc5126 100644 --- a/NOTICE.txt +++ b/NOTICE.txt @@ -6490,6 +6490,217 @@ Contents of probable licence file $GOMODCACHE/github.com/elastic/elastic-agent-l limitations under the License. +-------------------------------------------------------------------------------- +Dependency : github.com/elastic/elastic-agent-system-metrics +Version: v0.3.1 +Licence type (autodetected): Apache-2.0 +-------------------------------------------------------------------------------- + +Contents of probable licence file $GOMODCACHE/github.com/elastic/elastic-agent-system-metrics@v0.3.1/LICENSE.txt: + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + -------------------------------------------------------------------------------- Dependency : github.com/elastic/go-concert Version: v0.2.0 @@ -9739,11 +9950,11 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- Dependency : github.com/gofrs/uuid -Version: v4.0.0+incompatible +Version: v4.2.0+incompatible Licence type (autodetected): MIT -------------------------------------------------------------------------------- -Contents of probable licence file $GOMODCACHE/github.com/gofrs/uuid@v4.0.0+incompatible/LICENSE: +Contents of probable licence file $GOMODCACHE/github.com/gofrs/uuid@v4.2.0+incompatible/LICENSE: Copyright (C) 2013-2018 by Maxim Bublis @@ -16990,11 +17201,11 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- Dependency : golang.org/x/sys -Version: v0.0.0-20220209214540-3681064d5158 +Version: v0.0.0-20220405052023-b1e9470b6e64 Licence type (autodetected): BSD-3-Clause -------------------------------------------------------------------------------- -Contents of probable licence file $GOMODCACHE/golang.org/x/sys@v0.0.0-20220209214540-3681064d5158/LICENSE: +Contents of probable licence file $GOMODCACHE/golang.org/x/sys@v0.0.0-20220405052023-b1e9470b6e64/LICENSE: Copyright (c) 2009 The Go Authors. All rights reserved. @@ -36642,11 +36853,11 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- Dependency : go.elastic.co/ecszap -Version: v1.0.0 +Version: v1.0.1 Licence type (autodetected): Apache-2.0 -------------------------------------------------------------------------------- -Contents of probable licence file $GOMODCACHE/go.elastic.co/ecszap@v1.0.0/LICENSE: +Contents of probable licence file $GOMODCACHE/go.elastic.co/ecszap@v1.0.1/LICENSE: Apache License diff --git a/go.mod b/go.mod index 3142bcf1f80e..f29e6accaafe 100644 --- a/go.mod +++ b/go.mod @@ -74,7 +74,7 @@ require ( github.com/godbus/dbus v0.0.0-20190422162347-ade71ed3457e github.com/godror/godror v0.24.2 github.com/gofrs/flock v0.8.1 - github.com/gofrs/uuid v4.0.0+incompatible + github.com/gofrs/uuid v4.2.0+incompatible github.com/gogo/protobuf v1.3.2 github.com/golang/mock v1.6.0 github.com/golang/protobuf v1.5.2 @@ -126,7 +126,7 @@ require ( github.com/urso/sderr v0.0.0-20210525210834-52b04e8f5c71 github.com/vmware/govmomi v0.0.0-20170802214208-2cad15190b41 github.com/xdg/scram v1.0.3 - go.elastic.co/ecszap v1.0.0 // indirect + go.elastic.co/ecszap v1.0.1 // indirect go.elastic.co/go-licence-detector v0.5.0 go.etcd.io/bbolt v1.3.6 go.uber.org/atomic v1.9.0 @@ -138,7 +138,7 @@ require ( golang.org/x/net v0.0.0-20220225172249-27dd8689420f golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8 golang.org/x/sync v0.0.0-20210220032951-036812b2e83c - golang.org/x/sys v0.0.0-20220209214540-3681064d5158 + golang.org/x/sys v0.0.0-20220405052023-b1e9470b6e64 golang.org/x/text v0.3.7 golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac golang.org/x/tools v0.1.9 @@ -162,6 +162,7 @@ require ( github.com/elastic/bayeux v1.0.5 github.com/elastic/elastic-agent-autodiscover v0.1.1 github.com/elastic/elastic-agent-libs v0.2.4 + github.com/elastic/elastic-agent-system-metrics v0.3.1 github.com/shirou/gopsutil/v3 v3.21.12 go.elastic.co/apm/module/apmelasticsearch/v2 v2.0.0 go.elastic.co/apm/module/apmhttp/v2 v2.0.0 diff --git a/go.sum b/go.sum index 48b394dfa284..528e9cd84476 100644 --- a/go.sum +++ b/go.sum @@ -536,6 +536,11 @@ github.com/elastic/elastic-agent-autodiscover v0.1.1/go.mod h1:Gg1fsQI+rVms9FJ2D github.com/elastic/elastic-agent-client/v7 v7.0.0-20210727140539-f0905d9377f6 h1:nFvXHBjYK3e9+xF0WKDeAKK4aOO51uC28s+L9rBmilo= github.com/elastic/elastic-agent-client/v7 v7.0.0-20210727140539-f0905d9377f6/go.mod h1:uh/Gj9a0XEbYoM4NYz4LvaBVARz3QXLmlNjsrKY9fTc= github.com/elastic/elastic-agent-libs v0.0.0-20220303160015-5b4e674da3dd/go.mod h1://82M1l73IHx0wDbS2Tzkq6Fx9fkmytS1KgkIyzvNTM= +github.com/elastic/elastic-agent-libs v0.2.2/go.mod h1:1xDLBhIqBIjhJ7lr2s+xRFFkQHpitSp8q2zzv1Dqg+s= +github.com/elastic/elastic-agent-libs v0.2.4 h1:TOy+vild5MSkn/eTOwrnffAeAntq4GiLpkvWe+uNVms= +github.com/elastic/elastic-agent-libs v0.2.4/go.mod h1:eUiaofWIVdxVOAR4ICGxn2wbFByhrnmR6/kppwYq3qI= +github.com/elastic/elastic-agent-system-metrics v0.3.1 h1:WXdDyIaBr9zIJoyvFNzgZbcFiEnmtaKfazHPJR4DJOM= +github.com/elastic/elastic-agent-system-metrics v0.3.1/go.mod h1:RIYhJOS7mUeyIthfOSqmmbEILYSzaDWLi5zQ70bQo+o= github.com/elastic/elastic-agent-libs v0.2.4 h1:TOy+vild5MSkn/eTOwrnffAeAntq4GiLpkvWe+uNVms= github.com/elastic/elastic-agent-libs v0.2.4/go.mod h1:eUiaofWIVdxVOAR4ICGxn2wbFByhrnmR6/kppwYq3qI= github.com/elastic/fsevents v0.0.0-20181029231046-e1d381a4d270 h1:cWPqxlPtir4RoQVCpGSRXmLqjEHpJKbR60rxh1nQZY4= @@ -796,8 +801,9 @@ github.com/godror/godror v0.10.4/go.mod h1:9MVLtu25FBJBMHkPs0m3Ngf/VmwGcLpM2HS8P github.com/gofrs/flock v0.8.1 h1:+gYjHKf32LDeiEEFhQaotPbLuUXjY5ZqxKgXy7n59aw= github.com/gofrs/flock v0.8.1/go.mod h1:F1TvTiK9OcQqauNUHlbJvyl9Qa1QvF/gOUDKA14jxHU= github.com/gofrs/uuid v3.3.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM= -github.com/gofrs/uuid v4.0.0+incompatible h1:1SD/1F5pU8p29ybwgQSwpQk+mwdRrXCYuPhW6m+TnJw= github.com/gofrs/uuid v4.0.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM= +github.com/gofrs/uuid v4.2.0+incompatible h1:yyYWMnhkhrKwwr8gAOcOCYxOOscHgDS9yZgBrnJfGa0= +github.com/gofrs/uuid v4.2.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM= github.com/gogo/googleapis v1.1.0/go.mod h1:gf4bu3Q80BeJ6H1S1vYPm8/ELATdvryBaNFGgqEef3s= github.com/gogo/googleapis v1.2.0/go.mod h1:Njal3psf3qN6dwBtQfUmBZh2ybovJ0tlu3o/AC7HYjU= github.com/gogo/googleapis v1.4.0/go.mod h1:5YRNX2z1oM5gXdAkurHa942MDgEJyk02w4OecKY87+c= @@ -1683,8 +1689,9 @@ go.elastic.co/apm/module/apmhttp/v2 v2.0.0 h1:GNfmK1LD4nE5fYqbLxROCpg1ucyjSFG5iw go.elastic.co/apm/module/apmhttp/v2 v2.0.0/go.mod h1:5KmxcNN7hkJh8sVW3Ggl/pYgnwiNenygE46bZoUb9RE= go.elastic.co/apm/v2 v2.0.0 h1:5BeBh+oIrVbMwPrW3uO9Uxm4w7HpKy92lYl5Rfj69Kg= go.elastic.co/apm/v2 v2.0.0/go.mod h1:KGQn56LtRmkQjt2qw4+c1Jz8gv9rCBUU/m21uxrqcps= -go.elastic.co/ecszap v1.0.0 h1:PdQkRUeraR3XHJ14T7JMa+ncU0XXrVrcEN/BoRa2nMI= go.elastic.co/ecszap v1.0.0/go.mod h1:HTUi+QRmr3EuZMqxPX+5fyOdMNfUu5iPebgfhgsTJYQ= +go.elastic.co/ecszap v1.0.1 h1:mBxqEJAEXBlpi5+scXdzL7LTFGogbuxipJC0KTZicyA= +go.elastic.co/ecszap v1.0.1/go.mod h1:SVjazT+QgNeHSGOCUHvRgN+ZRj5FkB7IXQQsncdF57A= go.elastic.co/fastjson v1.1.0 h1:3MrGBWWVIxe/xvsbpghtkFoPciPhOCmjsR/HfwEeQR4= go.elastic.co/fastjson v1.1.0/go.mod h1:boNGISWMjQsUPy/t6yqt2/1Wx4YNPSe+mZjlyw9vKKI= go.elastic.co/go-licence-detector v0.5.0 h1:YXPCyt9faKMdJ8uMrkcI4patk8WZ0ME5oaIhYBUsRU4= @@ -2072,8 +2079,9 @@ golang.org/x/sys v0.0.0-20211102192858-4dd72447c267/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20211124211545-fe61309f8881/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211205182925-97ca703d548d/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220209214540-3681064d5158 h1:rm+CHSpPEEW2IsXUib1ThaHIjuBVZjxNgSKmBLFfD4c= golang.org/x/sys v0.0.0-20220209214540-3681064d5158/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220405052023-b1e9470b6e64 h1:D1v9ucDTYBtbz5vNuBbAhIMAGhQhJ6Ym5ah3maMVNX4= +golang.org/x/sys v0.0.0-20220405052023-b1e9470b6e64/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= diff --git a/libbeat/cmd/instance/beat.go b/libbeat/cmd/instance/beat.go index 4be4df89cfb0..47912969a493 100644 --- a/libbeat/cmd/instance/beat.go +++ b/libbeat/cmd/instance/beat.go @@ -44,7 +44,6 @@ import ( "github.com/elastic/beats/v7/libbeat/beat" "github.com/elastic/beats/v7/libbeat/cfgfile" "github.com/elastic/beats/v7/libbeat/cloudid" - "github.com/elastic/beats/v7/libbeat/cmd/instance/metrics" "github.com/elastic/beats/v7/libbeat/common" "github.com/elastic/beats/v7/libbeat/common/reload" "github.com/elastic/beats/v7/libbeat/common/seccomp" @@ -54,7 +53,6 @@ import ( "github.com/elastic/beats/v7/libbeat/instrumentation" "github.com/elastic/beats/v7/libbeat/kibana" "github.com/elastic/beats/v7/libbeat/management" - "github.com/elastic/beats/v7/libbeat/metric/system/host" "github.com/elastic/beats/v7/libbeat/monitoring/report" "github.com/elastic/beats/v7/libbeat/monitoring/report/log" "github.com/elastic/beats/v7/libbeat/outputs" @@ -75,6 +73,8 @@ import ( "github.com/elastic/elastic-agent-libs/monitoring/report/buffer" "github.com/elastic/elastic-agent-libs/paths" libversion "github.com/elastic/elastic-agent-libs/version" + "github.com/elastic/elastic-agent-system-metrics/metric/system/host" + metricreport "github.com/elastic/elastic-agent-system-metrics/report" sysinfo "github.com/elastic/go-sysinfo" "github.com/elastic/go-sysinfo/types" ucfg "github.com/elastic/go-ucfg" @@ -263,7 +263,7 @@ func NewBeat(name, indexPrefix, v string, elasticLicensed bool) (*Beat, error) { ID: id, FirstStart: time.Now(), StartTime: time.Now(), - EphemeralID: metrics.EphemeralID(), + EphemeralID: metricreport.EphemeralID(), }, Fields: fields, } @@ -341,7 +341,7 @@ func (b *Beat) createBeater(bt beat.Creator) (beat.Beater, error) { reg = monitoring.Default.NewRegistry("libbeat") } - err = metrics.SetupMetrics(b.Info.Beat) + err = metricreport.SetupMetrics(logp.NewLogger("metrics"), b.Info.Beat, version.GetDefaultVersion()) if err != nil { return nil, err } diff --git a/libbeat/cmd/instance/metrics/metrics.go b/libbeat/cmd/instance/metrics/metrics.go deleted file mode 100644 index 06d1866c43bf..000000000000 --- a/libbeat/cmd/instance/metrics/metrics.go +++ /dev/null @@ -1,326 +0,0 @@ -// Licensed to Elasticsearch B.V. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Elasticsearch B.V. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -//go:build (darwin && cgo) || (freebsd && cgo) || linux || windows -// +build darwin,cgo freebsd,cgo linux windows - -package metrics - -import ( - "os" - "runtime" - - "github.com/elastic/beats/v7/libbeat/metric/system/cgroup" - "github.com/elastic/beats/v7/libbeat/metric/system/cpu" - "github.com/elastic/beats/v7/libbeat/metric/system/numcpu" - "github.com/elastic/beats/v7/libbeat/metric/system/process" - "github.com/elastic/beats/v7/libbeat/metric/system/resolve" - "github.com/elastic/elastic-agent-libs/logp" - "github.com/elastic/elastic-agent-libs/monitoring" -) - -var ( - beatProcessStats *process.Stats - systemMetrics *monitoring.Registry -) - -// libbeatMonitoringCgroupsHierarchyOverride is an undocumented environment variable which -// overrides the cgroups path under /sys/fs/cgroup, which should be set to "/" when running -// Beats under Docker. -const libbeatMonitoringCgroupsHierarchyOverride = "LIBBEAT_MONITORING_CGROUPS_HIERARCHY_OVERRIDE" - -func init() { - systemMetrics = monitoring.Default.NewRegistry("system") -} - -func SetupMetrics(name string) error { - monitoring.NewFunc(systemMetrics, "cpu", reportSystemCPUUsage, monitoring.Report) - - //if the beat name is longer than 15 characters, truncate it so we don't fail process checks later on - // On *nix, the process name comes from /proc/PID/stat, which uses a comm value of 16 bytes, plus the null byte - if (runtime.GOOS == "linux" || runtime.GOOS == "darwin") && len(name) > 15 { - name = name[:15] - } - - beatProcessStats = &process.Stats{ - Procs: []string{name}, - EnvWhitelist: nil, - CPUTicks: true, - CacheCmdLine: true, - IncludeTop: process.IncludeTopConfig{}, - } - - err := beatProcessStats.Init() - if err != nil { - return err - } - - monitoring.NewFunc(beatMetrics, "memstats", reportMemStats, monitoring.Report) - monitoring.NewFunc(beatMetrics, "cpu", reportBeatCPU, monitoring.Report) - monitoring.NewFunc(beatMetrics, "runtime", reportRuntime, monitoring.Report) - - setupPlatformSpecificMetrics() - - return nil -} - -func setupPlatformSpecificMetrics() { - switch runtime.GOOS { - case "linux": - monitoring.NewFunc(beatMetrics, "cgroup", reportBeatCgroups, monitoring.Report) - case "windows": - setupWindowsHandlesMetrics() - } - - if runtime.GOOS != "windows" { - monitoring.NewFunc(systemMetrics, "load", reportSystemLoadAverage, monitoring.Report) - } - - setupLinuxBSDFDMetrics() -} - -func reportMemStats(m monitoring.Mode, V monitoring.Visitor) { - var stats runtime.MemStats - runtime.ReadMemStats(&stats) - - V.OnRegistryStart() - defer V.OnRegistryFinished() - - monitoring.ReportInt(V, "memory_total", int64(stats.TotalAlloc)) - if m == monitoring.Full { - monitoring.ReportInt(V, "memory_alloc", int64(stats.Alloc)) - monitoring.ReportInt(V, "memory_sys", int64(stats.Sys)) - monitoring.ReportInt(V, "gc_next", int64(stats.NextGC)) - } - - rss, err := getRSSSize() - if err != nil { - logp.Err("Error while getting memory usage: %v", err) - return - } - monitoring.ReportInt(V, "rss", int64(rss)) -} - -func getRSSSize() (uint64, error) { - state, err := beatProcessStats.GetSelf() - if err != nil { - return 0, err - } - - return state.Memory.Rss.Bytes.ValueOr(0), nil -} - -func reportBeatCPU(_ monitoring.Mode, V monitoring.Visitor) { - V.OnRegistryStart() - defer V.OnRegistryFinished() - - state, err := beatProcessStats.GetSelf() - if err != nil { - logp.Err("Error retrieving CPU percentages: %v", err) - return - } - - monitoring.ReportNamespace(V, "user", func() { - monitoring.ReportInt(V, "ticks", int64(state.CPU.User.Ticks.ValueOr(0))) - monitoring.ReportNamespace(V, "time", func() { - monitoring.ReportInt(V, "ms", int64(state.CPU.User.Ticks.ValueOr(0))) - }) - }) - monitoring.ReportNamespace(V, "system", func() { - monitoring.ReportInt(V, "ticks", int64(state.CPU.System.Ticks.ValueOr(0))) - monitoring.ReportNamespace(V, "time", func() { - monitoring.ReportInt(V, "ms", int64(state.CPU.System.Ticks.ValueOr(0))) - }) - }) - monitoring.ReportNamespace(V, "total", func() { - monitoring.ReportFloat(V, "value", state.CPU.Total.Value.ValueOr(0)) - monitoring.ReportInt(V, "ticks", int64(state.CPU.Total.Ticks.ValueOr(0))) - monitoring.ReportNamespace(V, "time", func() { - monitoring.ReportInt(V, "ms", int64(state.CPU.Total.Ticks.ValueOr(0))) - }) - }) -} - -func reportSystemLoadAverage(_ monitoring.Mode, V monitoring.Visitor) { - V.OnRegistryStart() - defer V.OnRegistryFinished() - - load, err := cpu.Load() - if err != nil { - logp.Err("Error retrieving load average: %v", err) - return - } - avgs := load.Averages() - monitoring.ReportFloat(V, "1", avgs.OneMinute) - monitoring.ReportFloat(V, "5", avgs.FiveMinute) - monitoring.ReportFloat(V, "15", avgs.FifteenMinute) - - normAvgs := load.NormalizedAverages() - monitoring.ReportNamespace(V, "norm", func() { - monitoring.ReportFloat(V, "1", normAvgs.OneMinute) - monitoring.ReportFloat(V, "5", normAvgs.FiveMinute) - monitoring.ReportFloat(V, "15", normAvgs.FifteenMinute) - }) -} - -func reportSystemCPUUsage(_ monitoring.Mode, V monitoring.Visitor) { - V.OnRegistryStart() - defer V.OnRegistryFinished() - - monitoring.ReportInt(V, "cores", int64(numcpu.NumCPU())) -} - -func reportRuntime(_ monitoring.Mode, V monitoring.Visitor) { - V.OnRegistryStart() - defer V.OnRegistryFinished() - - monitoring.ReportInt(V, "goroutines", int64(runtime.NumGoroutine())) -} - -func reportBeatCgroups(_ monitoring.Mode, V monitoring.Visitor) { - V.OnRegistryStart() - defer V.OnRegistryFinished() - - // PID shouldn't use hostfs, at least for now. - // containerization schemes should provide their own /proc/ that will serve containerized processess - pid := os.Getpid() - - cgroups, err := cgroup.NewReaderOptions(cgroup.ReaderOptions{ - RootfsMountpoint: resolve.NewTestResolver("/"), - IgnoreRootCgroups: true, - CgroupsHierarchyOverride: os.Getenv(libbeatMonitoringCgroupsHierarchyOverride), - }) - if err != nil { - if err == cgroup.ErrCgroupsMissing { - logp.Warn("cgroup data collection disabled in internal monitoring: %v", err) - } else { - logp.Err("cgroup data collection disabled in internal monitoring: %v", err) - } - return - } - - cgv, err := cgroups.CgroupsVersion(pid) - if err != nil { - logp.Err("error determining cgroups version for internal monitoring: %v", err) - return - } - - if cgv == cgroup.CgroupsV1 { - reportMetricsCGV1(pid, cgroups, V) - } else { - reportMetricsCGV2(pid, cgroups, V) - } - -} - -func reportMetricsCGV1(pid int, cgroups *cgroup.Reader, V monitoring.Visitor) { - selfStats, err := cgroups.GetV1StatsForProcess(pid) - if err != nil { - logp.Err("error getting cgroup stats for V1: %v", err) - } - // GetStatsForProcess returns a nil selfStats and no error when there's no stats - if selfStats == nil { - return - } - - if cpu := selfStats.CPU; cpu != nil { - monitoring.ReportNamespace(V, "cpu", func() { - if cpu.ID != "" { - monitoring.ReportString(V, "id", cpu.ID) - } - monitoring.ReportNamespace(V, "cfs", func() { - monitoring.ReportNamespace(V, "period", func() { - monitoring.ReportInt(V, "us", int64(cpu.CFS.PeriodMicros.Us)) - }) - monitoring.ReportNamespace(V, "quota", func() { - monitoring.ReportInt(V, "us", int64(cpu.CFS.QuotaMicros.Us)) - }) - }) - monitoring.ReportNamespace(V, "stats", func() { - monitoring.ReportInt(V, "periods", int64(cpu.Stats.Periods)) - monitoring.ReportNamespace(V, "throttled", func() { - monitoring.ReportInt(V, "periods", int64(cpu.Stats.Throttled.Periods)) - monitoring.ReportInt(V, "ns", int64(cpu.Stats.Throttled.Us)) - }) - }) - }) - } - - if cpuacct := selfStats.CPUAccounting; cpuacct != nil { - monitoring.ReportNamespace(V, "cpuacct", func() { - if cpuacct.ID != "" { - monitoring.ReportString(V, "id", cpuacct.ID) - } - monitoring.ReportNamespace(V, "total", func() { - monitoring.ReportInt(V, "ns", int64(cpuacct.Total.NS)) - }) - }) - } - - if memory := selfStats.Memory; memory != nil { - monitoring.ReportNamespace(V, "memory", func() { - if memory.ID != "" { - monitoring.ReportString(V, "id", memory.ID) - } - monitoring.ReportNamespace(V, "mem", func() { - monitoring.ReportNamespace(V, "limit", func() { - monitoring.ReportInt(V, "bytes", int64(memory.Mem.Limit.Bytes)) - }) - monitoring.ReportNamespace(V, "usage", func() { - monitoring.ReportInt(V, "bytes", int64(memory.Mem.Usage.Bytes)) - }) - }) - }) - } -} - -func reportMetricsCGV2(pid int, cgroups *cgroup.Reader, V monitoring.Visitor) { - selfStats, err := cgroups.GetV2StatsForProcess(pid) - if err != nil { - logp.Err("error getting cgroup stats for V2: %v", err) - return - } - - if cpu := selfStats.CPU; cpu != nil { - monitoring.ReportNamespace(V, "cpu", func() { - if cpu.ID != "" { - monitoring.ReportString(V, "id", cpu.ID) - } - monitoring.ReportNamespace(V, "stats", func() { - monitoring.ReportInt(V, "periods", int64(cpu.Stats.Periods.ValueOr(0))) - monitoring.ReportNamespace(V, "throttled", func() { - monitoring.ReportInt(V, "periods", int64(cpu.Stats.Throttled.Periods.ValueOr(0))) - monitoring.ReportInt(V, "ns", int64(cpu.Stats.Throttled.Us.ValueOr(0))) - }) - }) - }) - } - - if memory := selfStats.Memory; memory != nil { - monitoring.ReportNamespace(V, "memory", func() { - if memory.ID != "" { - monitoring.ReportString(V, "id", memory.ID) - } - monitoring.ReportNamespace(V, "mem", func() { - monitoring.ReportNamespace(V, "usage", func() { - monitoring.ReportInt(V, "bytes", int64(memory.Mem.Usage.Bytes)) - }) - }) - }) - } - -} diff --git a/libbeat/cmd/instance/metrics/metrics_common.go b/libbeat/cmd/instance/metrics/metrics_common.go deleted file mode 100644 index 98eea0584a9f..000000000000 --- a/libbeat/cmd/instance/metrics/metrics_common.go +++ /dev/null @@ -1,64 +0,0 @@ -// Licensed to Elasticsearch B.V. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Elasticsearch B.V. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package metrics - -import ( - "time" - - "github.com/gofrs/uuid" - - "github.com/elastic/beats/v7/libbeat/monitoring/report/log" - "github.com/elastic/beats/v7/libbeat/version" - "github.com/elastic/elastic-agent-libs/logp" - "github.com/elastic/elastic-agent-libs/monitoring" -) - -var ( - ephemeralID uuid.UUID - beatMetrics *monitoring.Registry -) - -func init() { - beatMetrics = monitoring.Default.NewRegistry("beat") - monitoring.NewFunc(beatMetrics, "info", reportInfo, monitoring.Report) - - var err error - ephemeralID, err = uuid.NewV4() - if err != nil { - logp.Err("Error while generating ephemeral ID for Beat") - } -} - -// EphemeralID returns generated EphemeralID -func EphemeralID() uuid.UUID { - return ephemeralID -} - -func reportInfo(_ monitoring.Mode, V monitoring.Visitor) { - V.OnRegistryStart() - defer V.OnRegistryFinished() - - delta := time.Since(log.StartTime) - uptime := int64(delta / time.Millisecond) - monitoring.ReportNamespace(V, "uptime", func() { - monitoring.ReportInt(V, "ms", uptime) - }) - - monitoring.ReportString(V, "ephemeral_id", ephemeralID.String()) - monitoring.ReportString(V, "version", version.GetDefaultVersion()) -} diff --git a/libbeat/cmd/instance/metrics/metrics_common_test.go b/libbeat/cmd/instance/metrics/metrics_common_test.go deleted file mode 100644 index e81532512930..000000000000 --- a/libbeat/cmd/instance/metrics/metrics_common_test.go +++ /dev/null @@ -1,33 +0,0 @@ -// Licensed to Elasticsearch B.V. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Elasticsearch B.V. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package metrics - -import ( - "testing" - - "github.com/stretchr/testify/assert" - - "github.com/elastic/beats/v7/libbeat/version" - "github.com/elastic/elastic-agent-libs/monitoring" -) - -func TestMonitoring(t *testing.T) { - metrics := monitoring.Default.GetRegistry("beat") - metricsSnapshot := monitoring.CollectFlatSnapshot(metrics, monitoring.Full, true) - assert.Equal(t, version.GetDefaultVersion(), metricsSnapshot.Strings["info.version"]) -} diff --git a/libbeat/cmd/instance/metrics/metrics_file_descriptors.go b/libbeat/cmd/instance/metrics/metrics_file_descriptors.go deleted file mode 100644 index baa468330826..000000000000 --- a/libbeat/cmd/instance/metrics/metrics_file_descriptors.go +++ /dev/null @@ -1,65 +0,0 @@ -// Licensed to Elasticsearch B.V. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Elasticsearch B.V. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -//go:build linux || (freebsd && cgo) -// +build linux freebsd,cgo - -package metrics - -import ( - "github.com/pkg/errors" - - "github.com/elastic/elastic-agent-libs/logp" - "github.com/elastic/elastic-agent-libs/monitoring" -) - -func setupLinuxBSDFDMetrics() { - monitoring.NewFunc(beatMetrics, "handles", reportFDUsage, monitoring.Report) -} - -func reportFDUsage(_ monitoring.Mode, V monitoring.Visitor) { - V.OnRegistryStart() - defer V.OnRegistryFinished() - - open, hardLimit, softLimit, err := getFDUsage() - if err != nil { - logp.Err("Error while retrieving FD information: %v", err) - return - } - - monitoring.ReportInt(V, "open", int64(open)) - monitoring.ReportNamespace(V, "limit", func() { - monitoring.ReportInt(V, "hard", int64(hardLimit)) - monitoring.ReportInt(V, "soft", int64(softLimit)) - }) -} - -func getFDUsage() (open, hardLimit, softLimit uint64, err error) { - - state, err := beatProcessStats.GetSelf() - if err != nil { - return 0, 0, 0, errors.Wrap(err, "error fetching self process") - } - - open = state.FD.Open.ValueOr(0) - - hardLimit = state.FD.Limit.Hard.ValueOr(0) - - softLimit = state.FD.Limit.Soft.ValueOr(0) - - return open, hardLimit, softLimit, nil -} diff --git a/libbeat/cmd/instance/metrics/metrics_file_descriptors_stub.go b/libbeat/cmd/instance/metrics/metrics_file_descriptors_stub.go deleted file mode 100644 index 0a3d3943692d..000000000000 --- a/libbeat/cmd/instance/metrics/metrics_file_descriptors_stub.go +++ /dev/null @@ -1,25 +0,0 @@ -// Licensed to Elasticsearch B.V. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Elasticsearch B.V. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -//go:build !linux && (!freebsd || !cgo) -// +build !linux -// +build !freebsd !cgo - -package metrics - -// FDUsage is only supported on Linux and FreeBSD. -func setupLinuxBSDFDMetrics() {} diff --git a/libbeat/cmd/instance/metrics/metrics_handles.go b/libbeat/cmd/instance/metrics/metrics_handles.go deleted file mode 100644 index 0bd4c550ac8e..000000000000 --- a/libbeat/cmd/instance/metrics/metrics_handles.go +++ /dev/null @@ -1,68 +0,0 @@ -// Licensed to Elasticsearch B.V. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Elasticsearch B.V. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -//go:build windows -// +build windows - -package metrics - -import ( - "github.com/elastic/elastic-agent-libs/logp" - "github.com/elastic/elastic-agent-libs/monitoring" - sysinfo "github.com/elastic/go-sysinfo" - "github.com/elastic/go-sysinfo/types" -) - -const ( - fileHandlesNotReported = "Following metrics will not be reported: beat.handles.open" -) - -var ( - handleCounter types.OpenHandleCounter -) - -func setupWindowsHandlesMetrics() { - beatProcessSysInfo, err := sysinfo.Self() - if err != nil { - logp.Err("Error while getting own process info: %v", err) - logp.Err(fileHandlesNotReported) - return - } - - var ok bool - handleCounter, ok = beatProcessSysInfo.(types.OpenHandleCounter) - if !ok { - logp.Err("Process does not implement types.OpenHandleCounter: %v", beatProcessSysInfo) - logp.Err(fileHandlesNotReported) - return - } - - monitoring.NewFunc(beatMetrics, "handles", reportOpenHandles, monitoring.Report) -} - -func reportOpenHandles(_ monitoring.Mode, V monitoring.Visitor) { - V.OnRegistryStart() - defer V.OnRegistryFinished() - - n, err := handleCounter.OpenHandleCount() - if err != nil { - logp.Err("Error while retrieving the number of open file handles: %v", err) - return - } - - monitoring.ReportInt(V, "open", int64(n)) -} diff --git a/libbeat/cmd/instance/metrics/metrics_handles_stub.go b/libbeat/cmd/instance/metrics/metrics_handles_stub.go deleted file mode 100644 index 5cdfe9fde8cc..000000000000 --- a/libbeat/cmd/instance/metrics/metrics_handles_stub.go +++ /dev/null @@ -1,24 +0,0 @@ -// Licensed to Elasticsearch B.V. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Elasticsearch B.V. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -//go:build !windows -// +build !windows - -package metrics - -// Counting number of open handles is only supported on Windows. -func setupWindowsHandlesMetrics() {} diff --git a/libbeat/cmd/instance/metrics/metrics_other.go b/libbeat/cmd/instance/metrics/metrics_other.go deleted file mode 100644 index 564d6048a048..000000000000 --- a/libbeat/cmd/instance/metrics/metrics_other.go +++ /dev/null @@ -1,33 +0,0 @@ -// Licensed to Elasticsearch B.V. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Elasticsearch B.V. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -//go:build (!darwin || !cgo) && (!freebsd || !cgo) && !linux && !windows -// +build !darwin !cgo -// +build !freebsd !cgo -// +build !linux -// +build !windows - -package metrics - -import ( - "github.com/elastic/elastic-agent-libs/logp" -) - -func SetupMetrics(name string) error { - logp.Warn("Metrics not implemented for this OS.") - return nil -} diff --git a/libbeat/metric/system/cgroup/cgcommon/metrics.go b/libbeat/metric/system/cgroup/cgcommon/metrics.go deleted file mode 100644 index 32d5a31803f2..000000000000 --- a/libbeat/metric/system/cgroup/cgcommon/metrics.go +++ /dev/null @@ -1,87 +0,0 @@ -// Licensed to Elasticsearch B.V. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Elasticsearch B.V. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package cgcommon - -import ( - "bufio" - "fmt" - "os" - - "github.com/pkg/errors" - - "github.com/elastic/beats/v7/libbeat/opt" -) - -// CPUUsage wraps the CPU usage time values for the CPU controller metrics -type CPUUsage struct { - NS uint64 `json:"ns" struct:"ns"` - Pct opt.Float `json:"pct,omitempty" struct:"pct,omitempty"` - Norm opt.PctOpt `json:"norm,omitempty" struct:"norm,omitempty"` -} - -// Pressure contains load metrics for a controller, -// Broken apart into 10, 60, and 300 second samples, -// as well as a total time in US -type Pressure struct { - Ten opt.Pct `json:"10,omitempty" struct:"10,omitempty"` - Sixty opt.Pct `json:"60,omitempty" struct:"60,omitempty"` - ThreeHundred opt.Pct `json:"300,omitempty" struct:"300,omitempty"` - Total opt.Uint `json:"total,omitempty" struct:"total,omitempty"` -} - -// IsZero implements the IsZero interface for Pressure -// This is "all or nothing", as pressure stats don't exist on certain systems -// If `total` doesn't exist, that means there's no pressure metrics. -func (p Pressure) IsZero() bool { - return p.Total.IsZero() -} - -// GetPressure takes the path of a *.pressure file and returns a -// map of the pressure (IO contension) stats for the cgroup -// on CPU controllers, the only key will be "some" -// on IO controllers, the keys will be "some" and "full" -// See https://github.com/torvalds/linux/blob/master/Documentation/accounting/psi.rst -func GetPressure(path string) (map[string]Pressure, error) { - pressureData := make(map[string]Pressure) - f, err := os.Open(path) - // pass along any OS open errors directly - if err != nil { - return pressureData, err - } - defer f.Close() - - sc := bufio.NewScanner(f) - for sc.Scan() { - var stallTime string - data := Pressure{} - var total uint64 - matched, err := fmt.Sscanf(sc.Text(), "%s avg10=%f avg60=%f avg300=%f total=%d", &stallTime, &data.Ten.Pct, &data.Sixty.Pct, &data.ThreeHundred.Pct, &total) - if err != nil { - return pressureData, errors.Wrapf(err, "error scanning file: %s", path) - } - // Assume that if we didn't match at least three numbers, something has gone wrong - if matched < 3 { - return pressureData, fmt.Errorf("Error: only matched %d fields from file %s", matched, path) - } - data.Total = opt.UintWith(total) - pressureData[stallTime] = data - - } - - return pressureData, nil -} diff --git a/libbeat/metric/system/cgroup/cgcommon/metrics_test.go b/libbeat/metric/system/cgroup/cgcommon/metrics_test.go deleted file mode 100644 index 1d9b2de22b8b..000000000000 --- a/libbeat/metric/system/cgroup/cgcommon/metrics_test.go +++ /dev/null @@ -1,51 +0,0 @@ -// Licensed to Elasticsearch B.V. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Elasticsearch B.V. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package cgcommon - -import ( - "path/filepath" - "testing" - - "github.com/stretchr/testify/assert" - - "github.com/elastic/beats/v7/libbeat/opt" -) - -func TestPressure(t *testing.T) { - v2Path := "../testdata/docker/sys/fs/cgroup/system.slice/docker-1c8fa019edd4b9d4b2856f4932c55929c5c118c808ed5faee9a135ca6e84b039.scope" - - pressureData, err := GetPressure(filepath.Join(v2Path, "io.pressure")) - assert.NoError(t, err, "error in getPressure") - - goodP := map[string]Pressure{ - "some": { - Ten: opt.Pct{Pct: 3.00}, - Sixty: opt.Pct{Pct: 2.10}, - ThreeHundred: opt.Pct{Pct: 4.00}, - Total: opt.UintWith(1154482), - }, - "full": { - Ten: opt.Pct{Pct: 10}, - Sixty: opt.Pct{Pct: 30}, - ThreeHundred: opt.Pct{Pct: 0.5}, - Total: opt.UintWith(1154482), - }, - } - - assert.Equal(t, goodP, pressureData, "pressure stats not equal") -} diff --git a/libbeat/metric/system/cgroup/cgcommon/util.go b/libbeat/metric/system/cgroup/cgcommon/util.go deleted file mode 100644 index 364530b3a315..000000000000 --- a/libbeat/metric/system/cgroup/cgcommon/util.go +++ /dev/null @@ -1,84 +0,0 @@ -// Licensed to Elasticsearch B.V. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Elasticsearch B.V. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package cgcommon - -import ( - "bytes" - "errors" - "fmt" - "io/ioutil" - "os" - "path/filepath" - "strconv" - "strings" -) - -var ( - - // ErrInvalidFormat indicates a malformed key/value pair on a line. - ErrInvalidFormat = errors.New("error invalid key/value format") -) - -// ParseUintFromFile reads a single uint value from a file. -func ParseUintFromFile(path ...string) (uint64, error) { - value, err := ioutil.ReadFile(filepath.Join(path...)) - if err != nil { - // Not all features are implemented/enabled by each OS. - if os.IsNotExist(err) { - return 0, nil - } - return 0, err - } - - return ParseUint(value) -} - -// ParseUint reads a single uint value. It will trip any whitespace before -// attempting to parse string. If the value is negative it will return 0. -func ParseUint(value []byte) (uint64, error) { - strValue := string(bytes.TrimSpace(value)) - uintValue, err := strconv.ParseUint(strValue, 10, 64) - if err != nil { - // Munge negative values to 0. - intValue, intErr := strconv.ParseInt(strValue, 10, 64) - if intErr == nil && intValue < 0 { - return 0, nil - } else if intErr != nil && intErr.(*strconv.NumError).Err == strconv.ErrRange && intValue < 0 { - return 0, nil - } - - return 0, err - } - - return uintValue, nil -} - -// ParseCgroupParamKeyValue parses a cgroup param and returns the key name and value. -func ParseCgroupParamKeyValue(t string) (string, uint64, error) { - parts := strings.Fields(t) - if len(parts) != 2 { - return "", 0, ErrInvalidFormat - } - - value, err := ParseUint([]byte(parts[1])) - if err != nil { - return "", 0, fmt.Errorf("unable to convert param value (%q) to uint64: %v", parts[1], err) - } - - return parts[0], value, nil -} diff --git a/libbeat/metric/system/cgroup/cgstats.go b/libbeat/metric/system/cgroup/cgstats.go deleted file mode 100644 index cbff8e3da469..000000000000 --- a/libbeat/metric/system/cgroup/cgstats.go +++ /dev/null @@ -1,153 +0,0 @@ -// Licensed to Elasticsearch B.V. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Elasticsearch B.V. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package cgroup - -import ( - "time" - - "github.com/pkg/errors" - - "github.com/elastic/beats/v7/libbeat/common" - "github.com/elastic/beats/v7/libbeat/common/transform/typeconv" - "github.com/elastic/beats/v7/libbeat/metric/system/numcpu" - "github.com/elastic/beats/v7/libbeat/opt" - "github.com/elastic/elastic-agent-libs/mapstr" -) - -// CGStats in an interface wrapper around the V2 and V1 cgroup stat objects -type CGStats interface { - Format() (mapstr.M, error) - CGVersion() CgroupsVersion - FillPercentages(prev CGStats, curTime, prevTime time.Time) -} - -// CGVersion returns the version of the underlying cgroups stats -func (stat StatsV1) CGVersion() CgroupsVersion { - return CgroupsV1 -} - -//Format converts the stats object to a MapStr that can be sent to Report() -func (stat StatsV1) Format() (mapstr.M, error) { - to := mapstr.M{} - err := typeconv.Convert(&to, stat) - if err != nil { - return to, errors.Wrap(err, "error formatting statsV1 object") - } - - return to, nil -} - -// FillPercentages uses a previous CGStats object to fill out the percentage values -// in the cgroup metrics. The `prev` object must be from the same process. -// curTime and Prev time should be time.Time objects that corrispond to the "scrape time" of when the metrics were gathered. -func (curStat *StatsV1) FillPercentages(prev CGStats, curTime, prevTime time.Time) { - if prev != nil && prev.CGVersion() != CgroupsV1 { - return - } - prevStat := prev.(*StatsV1) - - if prevStat == nil || curStat == nil || curStat.CPUAccounting == nil || prevStat.CPUAccounting == nil { - return - } - - timeDelta := curTime.Sub(prevTime) - timeDeltaNanos := timeDelta / time.Nanosecond - totalCPUDeltaNanos := int64(curStat.CPUAccounting.Total.NS - prevStat.CPUAccounting.Total.NS) - - pct := float64(totalCPUDeltaNanos) / float64(timeDeltaNanos) - var cpuCount int - if len(curStat.CPUAccounting.UsagePerCPU) > 0 { - cpuCount = len(curStat.CPUAccounting.UsagePerCPU) - } else { - cpuCount = numcpu.NumCPU() - } - - // if you look at the raw cgroup stats, the following normalized value is literally an average of per-cpu numbers. - normalizedPct := pct / float64(cpuCount) - userCPUDeltaMillis := int64(curStat.CPUAccounting.Stats.User.NS - prevStat.CPUAccounting.Stats.User.NS) - systemCPUDeltaMillis := int64(curStat.CPUAccounting.Stats.System.NS - prevStat.CPUAccounting.Stats.System.NS) - - userPct := float64(userCPUDeltaMillis) / float64(timeDeltaNanos) - systemPct := float64(systemCPUDeltaMillis) / float64(timeDeltaNanos) - - normalizedUser := userPct / float64(cpuCount) - normalizedSystem := systemPct / float64(cpuCount) - - curStat.CPUAccounting.Total.Pct = opt.FloatWith(common.Round(pct, common.DefaultDecimalPlacesCount)) - curStat.CPUAccounting.Total.Norm.Pct = opt.FloatWith(common.Round(normalizedPct, common.DefaultDecimalPlacesCount)) - curStat.CPUAccounting.Stats.User.Pct = opt.FloatWith(common.Round(userPct, common.DefaultDecimalPlacesCount)) - curStat.CPUAccounting.Stats.User.Norm.Pct = opt.FloatWith(common.Round(normalizedUser, common.DefaultDecimalPlacesCount)) - curStat.CPUAccounting.Stats.System.Pct = opt.FloatWith(common.Round(systemPct, common.DefaultDecimalPlacesCount)) - curStat.CPUAccounting.Stats.System.Norm.Pct = opt.FloatWith(common.Round(normalizedSystem, common.DefaultDecimalPlacesCount)) - -} - -//Format converts the stats object to a MapStr that can be sent to Report() -func (stat StatsV2) Format() (mapstr.M, error) { - to := mapstr.M{} - err := typeconv.Convert(&to, stat) - if err != nil { - return to, errors.Wrap(err, "error formatting statsV2 object") - } - - return to, nil -} - -// CGVersion returns the version of the underlying cgroups stats -func (stat StatsV2) CGVersion() CgroupsVersion { - return CgroupsV2 -} - -// FillPercentages uses a previous CGStats object to fill out the percentage values -// in the cgroup metrics. The `prev` object must be from the same process. -// curTime and Prev time should be time.Time objects that corrispond to the "scrape time" of when the metrics were gathered. -func (curStat *StatsV2) FillPercentages(prev CGStats, curTime, prevTime time.Time) { - if prev != nil && prev.CGVersion() != CgroupsV2 { - return - } - prevStat := prev.(*StatsV2) - - if prevStat == nil || curStat == nil || curStat.CPU == nil || prevStat.CPU == nil { - return - } - timeDelta := curTime.Sub(prevTime) - timeDeltaNanos := timeDelta / time.Nanosecond - totalCPUDeltaNanos := int64(curStat.CPU.Stats.Usage.NS - prevStat.CPU.Stats.Usage.NS) - - pct := float64(totalCPUDeltaNanos) / float64(timeDeltaNanos) - - cpuCount := numcpu.NumCPU() - - // if you look at the raw cgroup stats, the following normalized value is literally an average of per-cpu numbers. - normalizedPct := pct / float64(cpuCount) - userCPUDeltaMillis := int64(curStat.CPU.Stats.User.NS - prevStat.CPU.Stats.User.NS) - systemCPUDeltaMillis := int64(curStat.CPU.Stats.System.NS - prevStat.CPU.Stats.System.NS) - - userPct := float64(userCPUDeltaMillis) / float64(timeDeltaNanos) - systemPct := float64(systemCPUDeltaMillis) / float64(timeDeltaNanos) - - normalizedUser := userPct / float64(cpuCount) - normalizedSystem := systemPct / float64(cpuCount) - - curStat.CPU.Stats.Usage.Pct = opt.FloatWith(common.Round(pct, common.DefaultDecimalPlacesCount)) - curStat.CPU.Stats.Usage.Norm.Pct = opt.FloatWith(common.Round(normalizedPct, common.DefaultDecimalPlacesCount)) - curStat.CPU.Stats.User.Pct = opt.FloatWith(common.Round(userPct, common.DefaultDecimalPlacesCount)) - curStat.CPU.Stats.User.Norm.Pct = opt.FloatWith(common.Round(normalizedUser, common.DefaultDecimalPlacesCount)) - curStat.CPU.Stats.System.Pct = opt.FloatWith(common.Round(systemPct, common.DefaultDecimalPlacesCount)) - curStat.CPU.Stats.System.Norm.Pct = opt.FloatWith(common.Round(normalizedSystem, common.DefaultDecimalPlacesCount)) -} diff --git a/libbeat/metric/system/cgroup/cgv1/blkio.go b/libbeat/metric/system/cgroup/cgv1/blkio.go deleted file mode 100644 index 4a022a195b03..000000000000 --- a/libbeat/metric/system/cgroup/cgv1/blkio.go +++ /dev/null @@ -1,308 +0,0 @@ -// Licensed to Elasticsearch B.V. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Elasticsearch B.V. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package cgv1 - -import ( - "bufio" - "os" - "path/filepath" - "strconv" - "strings" - "unicode" - - "github.com/pkg/errors" - - "github.com/elastic/beats/v7/libbeat/metric/system/cgroup/cgcommon" -) - -// BlockIOSubsystem contains limits and metrics from the "blkio" subsystem. The -// blkio subsystem controls and monitors access to I/O on block devices by tasks -// in a cgroup. -// -// https://www.kernel.org/doc/Documentation/cgroup-v1/blkio-controller.txt -type BlockIOSubsystem struct { - ID string `json:"id,omitempty"` // ID of the cgroup. - Path string `json:"path,omitempty"` // Path to the cgroup relative to the cgroup subsystem's mountpoint. - Total TotalIOs `json:"total,omitempty" struct:"total"` // Throttle limits for upper IO rates and metrics. - //CFQ CFQScheduler `json:"cfq,omitempty"` // Completely fair queue scheduler limits and metrics. -} - -// TotalIOs wraps the totals for blkio -type TotalIOs struct { - Bytes uint64 `json:"bytes,omitrmpty" struct:"bytes,omitempty"` - Ios uint64 `json:"ios,omitrmpty" struct:"ios,omitempty"` -} - -// CFQScheduler contains limits and metrics for the proportional weight time -// based division of disk policy. It is implemented in CFQ. Hence this policy -// takes effect only on leaf nodes when CFQ is being used. -// -// https://www.kernel.org/doc/Documentation/block/cfq-iosched.txt -type CFQScheduler struct { - Weight uint64 `json:"weight"` // Default weight for all devices unless overridden. Allowed range of weights is from 10 to 1000. - Devices []CFQDevice `json:"devices,omitempty"` -} - -// CFQDevice contains CFQ limits and metrics associated with a single device. -type CFQDevice struct { - DeviceID DeviceID `json:"device_id"` // ID of the device. - - // Proportional weight for the device. 0 means a per device weight is not set and - // that the blkio.weight value is used. - Weight uint64 `json:"weight"` - - TimeMs uint64 `json:"time_ms"` // Disk time allocated to cgroup per device in milliseconds. - Sectors uint64 `json:"sectors"` // Number of sectors transferred to/from disk by the cgroup. - Bytes OperationValues `json:"io_service_bytes"` // Number of bytes transferred to/from the disk by the cgroup. - IOs OperationValues `json:"io_serviced"` // Number of IO operations issued to the disk by the cgroup. - ServiceTimeNanos OperationValues `json:"io_service_time"` // Amount of time between request dispatch and request completion for the IOs done by this cgroup. - WaitTimeNanos OperationValues `json:"io_wait_time"` // Amount of time the IOs for this cgroup spent waiting in the scheduler queues for service. - Merges OperationValues `json:"io_merged"` // Total number of bios/requests merged into requests belonging to this cgroup. -} - -// ThrottleDevice contains throttle limits and metrics associated with a single device. -type ThrottleDevice struct { - DeviceID DeviceID `json:"device_id"` // ID of the device. - - ReadLimitBPS uint64 `json:"read_bps_device"` // Read limit in bytes per second (BPS). Zero means no limit. - WriteLimitBPS uint64 `json:"write_bps_device"` // Write limit in bytes per second (BPS). Zero mean no limit. - ReadLimitIOPS uint64 `json:"read_iops_device"` // Read limit in IOPS. Zero means no limit. - WriteLimitIOPS uint64 `json:"write_iops_device"` // Write limit in IOPS. Zero means no limit. - - Bytes OperationValues `json:"io_service_bytes"` // Number of bytes transferred to/from the disk by the cgroup. - IOs OperationValues `json:"io_serviced"` // Number of IO operations issued to the disk by the cgroup. -} - -// OperationValues contains the I/O limits or metrics associated with read, -// write, sync, and async operations. -type OperationValues struct { - Read uint64 `json:"read"` - Write uint64 `json:"write"` - Async uint64 `json:"async"` - Sync uint64 `json:"sync"` -} - -// DeviceID identifies a Linux block device. -type DeviceID struct { - Major uint64 - Minor uint64 -} - -// blkioValue holds a single blkio value associated with a device. -type blkioValue struct { - DeviceID - Operation string - Value uint64 -} - -// Get reads metrics from the "blkio" subsystem. path is the filepath to the -// cgroup hierarchy to read. -func (blkio *BlockIOSubsystem) Get(path string) error { - if err := blkioThrottle(path, blkio); err != nil { - return errors.Wrapf(err, "error reading throttle data from %s", path) - } - - return nil -} - -// blkioThrottle reads all of the limits and metrics associated with blkio -// throttling policy. -func blkioThrottle(path string, blkio *BlockIOSubsystem) error { - devices := map[DeviceID]*ThrottleDevice{} - - getDevice := func(id DeviceID) *ThrottleDevice { - td := devices[id] - if td == nil { - td = &ThrottleDevice{DeviceID: id} - devices[id] = td - } - return td - } - - values, err := readBlkioValues(path, "blkio.throttle.io_service_bytes") - if err != nil { - return errors.Wrap(err, "error reading blkio.throttle.io_service_bytes") - } - if values != nil { - for id, opValues := range collectOpValues(values) { - getDevice(id).Bytes = *opValues - } - } - - values, err = readBlkioValues(path, "blkio.throttle.io_serviced") - if err != nil { - return errors.Wrap(err, "error reading blkio.throttle.io_serviced") - } - if values != nil { - for id, opValues := range collectOpValues(values) { - getDevice(id).IOs = *opValues - } - } - - values, err = readBlkioValues(path, "blkio.throttle.read_bps_device") - if err != nil { - return errors.Wrap(err, "error reading blkio.throttle.read_bps_device") - } - if values != nil { - for _, bv := range values { - getDevice(bv.DeviceID).ReadLimitBPS = bv.Value - } - } - - values, err = readBlkioValues(path, "blkio.throttle.write_bps_device") - if err != nil { - return errors.Wrap(err, "error reading blkio.throttle.write_bps_device") - } - if values != nil { - for _, bv := range values { - getDevice(bv.DeviceID).WriteLimitBPS = bv.Value - } - } - - values, err = readBlkioValues(path, "blkio.throttle.read_iops_device") - if err != nil { - return errors.Wrap(err, "error reading blkio.throttle.read_iops_device") - } - if values != nil { - for _, bv := range values { - getDevice(bv.DeviceID).ReadLimitIOPS = bv.Value - } - } - - values, err = readBlkioValues(path, "blkio.throttle.write_iops_device") - if err != nil { - return errors.Wrap(err, "error reading blkio.throttle.write_iops_device") - } - if values != nil { - for _, bv := range values { - getDevice(bv.DeviceID).WriteLimitIOPS = bv.Value - } - } - - for _, dev := range devices { - blkio.Total.Bytes += dev.Bytes.Read + dev.Bytes.Write - blkio.Total.Ios += dev.IOs.Read + dev.IOs.Write - } - return nil -} - -// collectOpValues collects the discreet I/O values (e.g. read, write, sync, -// async) for a given device into a single OperationValues object. It returns a -// mapping of device ID to OperationValues. -func collectOpValues(values []blkioValue) map[DeviceID]*OperationValues { - opValues := map[DeviceID]*OperationValues{} - for _, bv := range values { - opValue := opValues[bv.DeviceID] - if opValue == nil { - opValue = &OperationValues{} - opValues[bv.DeviceID] = opValue - } - - switch bv.Operation { - case "read": - opValue.Read = bv.Value - case "write": - opValue.Write = bv.Value - case "async": - opValue.Async = bv.Value - case "sync": - opValue.Sync = bv.Value - } - } - - return opValues -} - -// readDeviceValues reads values from a single blkio file. -// It expects to read values like "245:1 read 18880" or "254:1 1909". It returns -// an array containing an entry for each valid line read. -func readBlkioValues(path ...string) ([]blkioValue, error) { - f, err := os.Open(filepath.Join(path...)) - if err != nil { - if os.IsNotExist(err) { - return nil, nil - } - return nil, err - } - defer f.Close() - - var values []blkioValue - sc := bufio.NewScanner(f) - for sc.Scan() { - line := strings.TrimSpace(sc.Text()) - if len(line) == 0 { - continue - } - // Valid lines start with a device ID. - if !unicode.IsNumber(rune(line[0])) { - continue - } - - v, err := parseBlkioValue(sc.Text()) - if err != nil { - return nil, err - } - - values = append(values, v) - } - - return values, sc.Err() -} - -func isColonOrSpace(r rune) bool { - return unicode.IsSpace(r) || r == ':' -} - -func parseBlkioValue(line string) (blkioValue, error) { - fields := strings.FieldsFunc(line, isColonOrSpace) - if len(fields) != 3 && len(fields) != 4 { - return blkioValue{}, cgcommon.ErrInvalidFormat - } - - major, err := strconv.ParseUint(fields[0], 10, 64) - if err != nil { - return blkioValue{}, err - } - - minor, err := strconv.ParseUint(fields[1], 10, 64) - if err != nil { - return blkioValue{}, err - } - - var value uint64 - var operation string - if len(fields) == 3 { - value, err = cgcommon.ParseUint([]byte(fields[2])) - if err != nil { - return blkioValue{}, err - } - } else { - operation = strings.ToLower(fields[2]) - - value, err = cgcommon.ParseUint([]byte(fields[3])) - if err != nil { - return blkioValue{}, err - } - } - - return blkioValue{ - DeviceID: DeviceID{major, minor}, - Operation: operation, - Value: value, - }, nil -} diff --git a/libbeat/metric/system/cgroup/cgv1/blkio_test.go b/libbeat/metric/system/cgroup/cgv1/blkio_test.go deleted file mode 100644 index 0a863403614b..000000000000 --- a/libbeat/metric/system/cgroup/cgv1/blkio_test.go +++ /dev/null @@ -1,85 +0,0 @@ -// Licensed to Elasticsearch B.V. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Elasticsearch B.V. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package cgv1 - -import ( - "encoding/json" - "testing" - - "github.com/stretchr/testify/assert" -) - -const blkioPath = "../testdata/docker/sys/fs/cgroup/blkio/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242" - -func TestParseBlkioValueWithOp(t *testing.T) { - line := `253:1 Async 1638912` - opValue, err := parseBlkioValue(line) - if err != nil { - t.Fatal(err) - } - - assert.Equal(t, uint64(253), opValue.Major) - assert.Equal(t, uint64(1), opValue.Minor) - assert.Equal(t, "async", opValue.Operation) - assert.Equal(t, uint64(1638912), opValue.Value) -} - -func TestParseBlkioValueWithoutOp(t *testing.T) { - line := `1:2 10088` - opValue, err := parseBlkioValue(line) - if err != nil { - t.Fatal(err) - } - - assert.Equal(t, uint64(1), opValue.Major) - assert.Equal(t, uint64(2), opValue.Minor) - assert.Equal(t, "", opValue.Operation) - assert.Equal(t, uint64(10088), opValue.Value) -} - -func TestBlkioThrottle(t *testing.T) { - blkio := BlockIOSubsystem{} - err := blkioThrottle(blkioPath, &blkio) - if err != nil { - t.Fatal(err) - } - assert.Equal(t, uint64(46), blkio.Total.Ios) - assert.Equal(t, uint64(1648128), blkio.Total.Bytes) - -} - -func TestBlockIOSubsystemGet(t *testing.T) { - blkio := BlockIOSubsystem{} - if err := blkio.Get(blkioPath); err != nil { - t.Fatal(err) - } -} - -func TestBlockIOSubsystemJSON(t *testing.T) { - blkio := BlockIOSubsystem{} - if err := blkio.Get(blkioPath); err != nil { - t.Fatal(err) - } - - json, err := json.MarshalIndent(blkio, "", " ") - if err != nil { - t.Fatal(err) - } - - t.Log(string(json)) -} diff --git a/libbeat/metric/system/cgroup/cgv1/cpu.go b/libbeat/metric/system/cgroup/cgv1/cpu.go deleted file mode 100644 index fe8f265caa23..000000000000 --- a/libbeat/metric/system/cgroup/cgv1/cpu.go +++ /dev/null @@ -1,165 +0,0 @@ -// Licensed to Elasticsearch B.V. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Elasticsearch B.V. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package cgv1 - -import ( - "bufio" - "os" - "path/filepath" - - "github.com/pkg/errors" - - "github.com/elastic/beats/v7/libbeat/metric/system/cgroup/cgcommon" - "github.com/elastic/beats/v7/libbeat/opt" -) - -// CPUSubsystem contains metrics and limits from the "cpu" subsystem. This -// subsystem is used to guarantee a minimum number of cpu shares to the cgroup -// when the system is busy. This subsystem does not track CPU usage, for that -// information see the "cpuacct" subsystem. -type CPUSubsystem struct { - ID string `json:"id,omitempty"` // ID of the cgroup. - Path string `json:"path,omitempty"` // Path to the cgroup relative to the cgroup subsystem's mountpoint. - // Completely Fair Scheduler (CFS) settings. - CFS CFS `json:"cfs,omitempty"` - // Real-time (RT) Scheduler settings. - RT RT `json:"rt,omitempty"` - // CPU time statistics for tasks in this cgroup. - Stats CPUStats `json:"stats,omitempty"` -} - -// RT contains the tunable parameters for the real-time scheduler. -type RT struct { - // Period of time in microseconds for how regularly the cgroup's access to - // CPU resources should be reallocated. - Period opt.Us `json:"period" struct:"period"` - // Period of time in microseconds for the longest continuous period in which - // the tasks in the cgroup have access to CPU resources. - Runtime opt.Us `json:"runtime" struct:"runtime"` -} - -// CFS contains the tunable parameters for the completely fair scheduler. -type CFS struct { - // Period of time in microseconds for how regularly the cgroup's access to - // CPU resources should be reallocated. - PeriodMicros opt.Us `json:"period" struct:"period"` - // Total amount of time in microseconds for which all tasks in the cgroup - // can run during one period. - QuotaMicros opt.Us `json:"quota" struct:"quota"` - // Relative share of CPU time available to tasks the cgroup. The value is - // an integer greater than or equal to 2. - Shares uint64 `json:"shares"` -} - -// CPUStats contains stats that indicate the extent to which this cgroup's -// CPU usage was throttled. -type CPUStats struct { - // Number of periods with throttling active. - Periods uint64 `json:"periods,omitempty"` - Throttled ThrottledField `json:"throttled" struct:"throttled"` -} - -// ThrottledField contains the `throttled` information for the CPU stats -type ThrottledField struct { - Us uint64 `json:"us" struct:"us"` - Periods uint64 `json:"periods" struct:"periods"` -} - -// Get reads metrics from the "cpu" subsystem. path is the filepath to the -// cgroup hierarchy to read. -func (cpu *CPUSubsystem) Get(path string) error { - if err := cpuCFS(path, cpu); err != nil { - return errors.Wrap(err, "error fetching CFS data") - } - - if err := cpuRT(path, cpu); err != nil { - return errors.Wrap(err, "error fetching RT data") - } - - if err := cpuStat(path, cpu); err != nil { - return errors.Wrap(err, "error fetching CPU stats") - } - - return nil -} - -func cpuStat(path string, cpu *CPUSubsystem) error { - f, err := os.Open(filepath.Join(path, "cpu.stat")) - if err != nil { - if os.IsNotExist(err) { - return nil - } - return err - } - defer f.Close() - - sc := bufio.NewScanner(f) - for sc.Scan() { - t, v, err := cgcommon.ParseCgroupParamKeyValue(sc.Text()) - if err != nil { - return err - } - switch t { - case "nr_periods": - cpu.Stats.Periods = v - - case "nr_throttled": - cpu.Stats.Throttled.Periods = v - - case "throttled_time": - cpu.Stats.Throttled.Us = v - } - } - - return sc.Err() -} - -func cpuCFS(path string, cpu *CPUSubsystem) error { - var err error - cpu.CFS.PeriodMicros.Us, err = cgcommon.ParseUintFromFile(path, "cpu.cfs_period_us") - if err != nil { - return err - } - - cpu.CFS.QuotaMicros.Us, err = cgcommon.ParseUintFromFile(path, "cpu.cfs_quota_us") - if err != nil { - return err - } - - cpu.CFS.Shares, err = cgcommon.ParseUintFromFile(path, "cpu.shares") - if err != nil { - return err - } - - return nil -} - -func cpuRT(path string, cpu *CPUSubsystem) error { - var err error - cpu.RT.Period.Us, err = cgcommon.ParseUintFromFile(path, "cpu.rt_period_us") - if err != nil { - return err - } - - cpu.RT.Runtime.Us, err = cgcommon.ParseUintFromFile(path, "cpu.rt_runtime_us") - if err != nil { - return err - } - - return nil -} diff --git a/libbeat/metric/system/cgroup/cgv1/cpu_test.go b/libbeat/metric/system/cgroup/cgv1/cpu_test.go deleted file mode 100644 index 5b36750d83ac..000000000000 --- a/libbeat/metric/system/cgroup/cgv1/cpu_test.go +++ /dev/null @@ -1,84 +0,0 @@ -// Licensed to Elasticsearch B.V. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Elasticsearch B.V. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package cgv1 - -import ( - "encoding/json" - "testing" - - "github.com/stretchr/testify/assert" -) - -const cpuPath = "../testdata/docker/sys/fs/cgroup/cpu/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242" - -func TestCpuStats(t *testing.T) { - cpu := CPUSubsystem{} - if err := cpuStat(cpuPath, &cpu); err != nil { - t.Fatal(err) - } - - assert.Equal(t, uint64(769021), cpu.Stats.Periods) - assert.Equal(t, uint64(1046), cpu.Stats.Throttled.Periods) - assert.Equal(t, uint64(352597023453), cpu.Stats.Throttled.Us) -} - -func TestCpuCFS(t *testing.T) { - cpu := CPUSubsystem{} - if err := cpuCFS(cpuPath, &cpu); err != nil { - t.Fatal(err) - } - - assert.Equal(t, uint64(100000), cpu.CFS.PeriodMicros.Us) - assert.Equal(t, uint64(0), cpu.CFS.QuotaMicros.Us) // -1 is changed to 0. - assert.Equal(t, uint64(1024), cpu.CFS.Shares) -} - -func TestCpuRT(t *testing.T) { - cpu := CPUSubsystem{} - if err := cpuRT(cpuPath, &cpu); err != nil { - t.Fatal(err) - } - - assert.Equal(t, uint64(1000000), cpu.RT.Period.Us) - assert.Equal(t, uint64(0), cpu.RT.Runtime.Us) -} - -func TestCpuSubsystemGet(t *testing.T) { - cpu := CPUSubsystem{} - if err := cpu.Get(cpuPath); err != nil { - t.Fatal(err) - } - - assert.Equal(t, uint64(769021), cpu.Stats.Periods) - assert.Equal(t, uint64(100000), cpu.CFS.PeriodMicros.Us) - assert.Equal(t, uint64(1000000), cpu.RT.Period.Us) -} - -func TestCpuSubsystemJSON(t *testing.T) { - cpu := CPUSubsystem{} - if err := cpu.Get(cpuPath); err != nil { - t.Fatal(err) - } - - json, err := json.MarshalIndent(cpu, "", " ") - if err != nil { - t.Fatal(err) - } - - t.Log(string(json)) -} diff --git a/libbeat/metric/system/cgroup/cgv1/cpuacct.go b/libbeat/metric/system/cgroup/cgv1/cpuacct.go deleted file mode 100644 index c7dff62245d0..000000000000 --- a/libbeat/metric/system/cgroup/cgv1/cpuacct.go +++ /dev/null @@ -1,138 +0,0 @@ -// Licensed to Elasticsearch B.V. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Elasticsearch B.V. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package cgv1 - -import ( - "bufio" - "bytes" - "fmt" - "io/ioutil" - "os" - "path/filepath" - "time" - - "github.com/pkg/errors" - - "github.com/elastic/beats/v7/libbeat/metric/system/cgroup/cgcommon" - "github.com/elastic/gosigar/sys/linux" -) - -var clockTicks = uint64(linux.GetClockTicks()) - -// CPUAccountingSubsystem contains metrics from the "cpuacct" subsystem. -// Note that percentage values are not taken from cgroup metrics, but derived via FillPercentages() -type CPUAccountingSubsystem struct { - ID string `json:"id,omitempty"` // ID of the cgroup. - Path string `json:"path,omitempty"` // Path to the cgroup relative to the cgroup subsystem's mountpoint. - Total cgcommon.CPUUsage `json:"total_nanos"` - UsagePerCPU map[string]uint64 `json:"percpu" struct:"percpu"` - // CPU time statistics for tasks in this cgroup. - Stats CPUAccountingStats `json:"stats,omitempty"` -} - -// CPUAccountingStats contains the stats reported from the cpuacct subsystem. -type CPUAccountingStats struct { - User cgcommon.CPUUsage `json:"user" struct:"user"` - System cgcommon.CPUUsage `json:"system" struct:"system"` -} - -// Get reads metrics from the "cpuacct" subsystem. path is the filepath to the -// cgroup hierarchy to read. -func (cpuacct *CPUAccountingSubsystem) Get(path string) error { - cpuacct.UsagePerCPU = make(map[string]uint64) - if err := cpuacctStat(path, cpuacct); err != nil { - return errors.Wrap(err, "error fetching cpuacct stats") - } - - if err := cpuacctUsage(path, cpuacct); err != nil { - return errors.Wrap(err, "error fetching cpuacct usage") - } - - if err := cpuacctUsagePerCPU(path, cpuacct); err != nil { - return errors.Wrap(err, "error fetching per_cpu data") - } - - return nil -} - -func cpuacctStat(path string, cpuacct *CPUAccountingSubsystem) error { - f, err := os.Open(filepath.Join(path, "cpuacct.stat")) - if err != nil { - if os.IsNotExist(err) { - return nil - } - return err - } - defer f.Close() - - sc := bufio.NewScanner(f) - for sc.Scan() { - t, v, err := cgcommon.ParseCgroupParamKeyValue(sc.Text()) - if err != nil { - return err - } - switch t { - case "user": - cpuacct.Stats.User.NS = convertJiffiesToNanos(v) - case "system": - cpuacct.Stats.System.NS = convertJiffiesToNanos(v) - } - } - - return sc.Err() -} - -func cpuacctUsage(path string, cpuacct *CPUAccountingSubsystem) error { - var err error - cpuacct.Total.NS, err = cgcommon.ParseUintFromFile(path, "cpuacct.usage") - if err != nil { - return err - } - - return nil -} - -func cpuacctUsagePerCPU(path string, cpuacct *CPUAccountingSubsystem) error { - contents, err := ioutil.ReadFile(filepath.Join(path, "cpuacct.usage_percpu")) - if err != nil { - if os.IsNotExist(err) { - return nil - } - return err - } - - values := make(map[string]uint64) - usages := bytes.Fields(contents) - for cpu, usage := range usages { - value, err := cgcommon.ParseUint(usage) - if err != nil { - return err - } - - // For backwards compatibility, We start the CPU count at 1 - cpuStr := fmt.Sprintf("%d", cpu+1) - values[cpuStr] = value - } - cpuacct.UsagePerCPU = values - - return nil -} - -func convertJiffiesToNanos(j uint64) uint64 { - return (j * uint64(time.Second)) / clockTicks -} diff --git a/libbeat/metric/system/cgroup/cgv1/cpuacct_test.go b/libbeat/metric/system/cgroup/cgv1/cpuacct_test.go deleted file mode 100644 index 98f146736175..000000000000 --- a/libbeat/metric/system/cgroup/cgv1/cpuacct_test.go +++ /dev/null @@ -1,80 +0,0 @@ -// Licensed to Elasticsearch B.V. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Elasticsearch B.V. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package cgv1 - -import ( - "encoding/json" - "testing" - - "github.com/stretchr/testify/assert" -) - -const cpuacctPath = "../testdata/docker/sys/fs/cgroup/cpuacct/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242" - -func TestCPUAccountingStats(t *testing.T) { - cpuacct := CPUAccountingSubsystem{} - if err := cpuacctStat(cpuacctPath, &cpuacct); err != nil { - t.Fatal(err) - } - - assert.Equal(t, uint64(61950000000), cpuacct.Stats.User.NS) - assert.Equal(t, uint64(7730000000), cpuacct.Stats.System.NS) -} - -func TestCpuacctUsage(t *testing.T) { - cpuacct := CPUAccountingSubsystem{} - if err := cpuacctUsage(cpuacctPath, &cpuacct); err != nil { - t.Fatal(err) - } - - assert.Equal(t, uint64(95996653175), cpuacct.Total.NS) -} - -func TestCpuacctUsagePerCPU(t *testing.T) { - cpuacct := CPUAccountingSubsystem{} - if err := cpuacctUsagePerCPU(cpuacctPath, &cpuacct); err != nil { - t.Fatal(err) - } - - assert.Equal(t, map[string]uint64{"1": 0x62fcde13c, "2": 0x565f2fcaa, "3": 0x5a8736ea1, "4": 0x51b92ac82}, cpuacct.UsagePerCPU) -} - -func TestCPUAccountingSubsystem_Get(t *testing.T) { - cpuacct := CPUAccountingSubsystem{} - if err := cpuacct.Get(cpuacctPath); err != nil { - t.Fatal(err) - } - - assert.Equal(t, uint64(61950000000), cpuacct.Stats.User.NS) - assert.Equal(t, uint64(95996653175), cpuacct.Total.NS) - assert.Len(t, cpuacct.UsagePerCPU, 4) -} - -func TestCPUAccountingSubsystemJSON(t *testing.T) { - cpuacct := CPUAccountingSubsystem{} - if err := cpuacct.Get(cpuacctPath); err != nil { - t.Fatal(err) - } - - json, err := json.MarshalIndent(cpuacct, "", " ") - if err != nil { - t.Fatal(err) - } - - t.Log(string(json)) -} diff --git a/libbeat/metric/system/cgroup/cgv1/memory.go b/libbeat/metric/system/cgroup/cgv1/memory.go deleted file mode 100644 index a062050b3a38..000000000000 --- a/libbeat/metric/system/cgroup/cgv1/memory.go +++ /dev/null @@ -1,197 +0,0 @@ -// Licensed to Elasticsearch B.V. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Elasticsearch B.V. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package cgv1 - -import ( - "bufio" - "os" - "path/filepath" - - "github.com/pkg/errors" - - "github.com/elastic/beats/v7/libbeat/metric/system/cgroup/cgcommon" - "github.com/elastic/beats/v7/libbeat/opt" -) - -// MemorySubsystem contains the metrics and limits from the "memory" subsystem. -type MemorySubsystem struct { - ID string `json:"id,omitempty"` // ID of the cgroup. - Path string `json:"path,omitempty"` // Path to the cgroup relative to the cgroup subsystem's mountpoint. - - Mem MemoryData `json:"mem" struct:"mem"` // Memory usage by tasks in this cgroup. - MemSwap MemoryData `json:"memsw" struct:"memsw"` // Memory plus swap usage by tasks in this cgroup. - Kernel MemoryData `json:"kmem" struct:"kmem"` // Kernel memory used by tasks in this cgroup. - KernelTCP MemoryData `json:"kmem_tcp" struct:"kmem_tcp"` // Kernel TCP buffer memory used by tasks in this cgroup. - Stats MemoryStat `json:"stats" struct:"stats"` // A wide range of memory statistics. -} - -// MemoryData groups related memory usage metrics and limits. -type MemoryData struct { - Usage MemSubsystemUsage `json:"usage" struct:"usage"` // Usage in bytes. - Limit opt.Bytes `json:"limit" struct:"limit"` // Limit in bytes. - Failures uint64 `json:"failures" struct:"failures"` // Number of times the memory limit has been reached. -} - -// MemSubsystemUsage groups fields used in memory.SUBSYSTEM.usage -type MemSubsystemUsage struct { - Bytes uint64 `json:"bytes" struct:"bytes"` - Max opt.Bytes `json:"max" struct:"max"` -} - -// MemoryStat contains various memory statistics and accounting information -// associated with a cgroup. -type MemoryStat struct { - // Page cache, including tmpfs (shmem), in bytes. - Cache opt.Bytes `json:"cache" struct:"cache"` - // Anonymous and swap cache, not including tmpfs (shmem), in bytes. - RSS opt.Bytes `json:"rss" struct:"rss"` - // Anonymous transparent hugepages in bytes. - RSSHuge opt.Bytes `json:"rss_huge" struct:"rss_huge"` - // Size of memory-mapped mapped files, including tmpfs (shmem), in bytes. - MappedFile opt.Bytes `json:"mapped_file" struct:"mapped_file"` - // Number of pages paged into memory. - PagesIn uint64 `json:"pages_in" struct:"pages_in"` - // Number of pages paged out of memory. - PagesOut uint64 `json:"pages_out" struct:"pages_out"` - // Number of times a task in the cgroup triggered a page fault. - PageFaults uint64 `json:"page_faults" struct:"page_faults"` - // Number of times a task in the cgroup triggered a major page fault. - MajorPageFaults uint64 `json:"major_page_faults" struct:"major_page_faults"` - // Swap usage in bytes. - Swap opt.Bytes `json:"swap"` - // Anonymous and swap cache on active least-recently-used (LRU) list, including tmpfs (shmem), in bytes. - ActiveAnon opt.Bytes `json:"active_anon" struct:"active_anon"` - // Anonymous and swap cache on inactive LRU list, including tmpfs (shmem), in bytes. - InactiveAnon opt.Bytes `json:"inactive_anon" struct:"inactive_anon"` - // File-backed memory on active LRU list, in bytes. - ActiveFile opt.Bytes `json:"active_file" struct:"active_file"` - // File-backed memory on inactive LRU list, in bytes. - InactiveFile opt.Bytes `json:"inactive_file" struct:"inactive_file"` - // Memory that cannot be reclaimed, in bytes. - Unevictable opt.Bytes `json:"unevictable" struct:"unevictable"` - // Memory limit for the hierarchy that contains the memory cgroup, in bytes. - HierarchicalMemoryLimit opt.Bytes `json:"hierarchical_memory_limit" struct:"hierarchical_memory_limit"` - // Memory plus swap limit for the hierarchy that contains the memory cgroup, in bytes. - HierarchicalMemswLimit opt.Bytes `json:"hierarchical_memsw_limit" struct:"hierarchical_memsw_limit"` -} - -// Get reads metrics from the "memory" subsystem. path is the filepath to the -// cgroup hierarchy to read. -func (mem *MemorySubsystem) Get(path string) error { - if err := memoryData(path, "memory", &mem.Mem); err != nil { - return errors.Wrap(err, "error fetching memory stats") - } - - if err := memoryData(path, "memory.memsw", &mem.MemSwap); err != nil { - return errors.Wrap(err, "error fetching memsw stats") - } - - if err := memoryData(path, "memory.kmem", &mem.Kernel); err != nil { - return errors.Wrap(err, "error fetching kmem stats") - } - - if err := memoryData(path, "memory.kmem.tcp", &mem.KernelTCP); err != nil { - return errors.Wrap(err, "error fetching kmem.tcp stats") - } - - if err := memoryStats(path, mem); err != nil { - return errors.Wrap(err, "error fetching memory.stat metrics") - } - - return nil -} - -func memoryData(path, prefix string, data *MemoryData) error { - var err error - data.Usage.Bytes, err = cgcommon.ParseUintFromFile(path, prefix+".usage_in_bytes") - if err != nil { - return errors.Wrap(err, "error fetching usage_in_bytes") - } - - data.Usage.Max.Bytes, err = cgcommon.ParseUintFromFile(path, prefix+".max_usage_in_bytes") - if err != nil { - return errors.Wrap(err, "error fetching max_usage_in_bytes") - } - - data.Limit.Bytes, err = cgcommon.ParseUintFromFile(path, prefix+".limit_in_bytes") - if err != nil { - return errors.Wrap(err, "error fetching limit_in_bytes") - } - - data.Failures, err = cgcommon.ParseUintFromFile(path, prefix+".failcnt") - if err != nil { - return errors.Wrap(err, "error fetching failcnt") - } - - return nil -} - -func memoryStats(path string, mem *MemorySubsystem) error { - f, err := os.Open(filepath.Join(path, "memory.stat")) - if err != nil { - if os.IsNotExist(err) { - return nil - } - return err - } - defer f.Close() - - sc := bufio.NewScanner(f) - for sc.Scan() { - t, v, err := cgcommon.ParseCgroupParamKeyValue(sc.Text()) - if err != nil { - return err - } - switch t { - case "cache": - mem.Stats.Cache.Bytes = v - case "rss": - mem.Stats.RSS.Bytes = v - case "rss_huge": - mem.Stats.RSSHuge.Bytes = v - case "mapped_file": - mem.Stats.MappedFile.Bytes = v - case "pgpgin": - mem.Stats.PagesIn = v - case "pgpgout": - mem.Stats.PagesOut = v - case "pgfault": - mem.Stats.PageFaults = v - case "pgmajfault": - mem.Stats.MajorPageFaults = v - case "swap": - mem.Stats.Swap.Bytes = v - case "active_anon": - mem.Stats.ActiveAnon.Bytes = v - case "inactive_anon": - mem.Stats.InactiveAnon.Bytes = v - case "active_file": - mem.Stats.ActiveFile.Bytes = v - case "inactive_file": - mem.Stats.InactiveFile.Bytes = v - case "unevictable": - mem.Stats.Unevictable.Bytes = v - case "hierarchical_memory_limit": - mem.Stats.HierarchicalMemoryLimit.Bytes = v - case "hierarchical_memsw_limit": - mem.Stats.HierarchicalMemswLimit.Bytes = v - } - } - - return sc.Err() -} diff --git a/libbeat/metric/system/cgroup/cgv1/memory_test.go b/libbeat/metric/system/cgroup/cgv1/memory_test.go deleted file mode 100644 index 601307c763ec..000000000000 --- a/libbeat/metric/system/cgroup/cgv1/memory_test.go +++ /dev/null @@ -1,126 +0,0 @@ -// Licensed to Elasticsearch B.V. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Elasticsearch B.V. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package cgv1 - -import ( - "encoding/json" - "testing" - - "github.com/stretchr/testify/assert" -) - -const memoryPath = "../testdata/docker/sys/fs/cgroup/memory/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242" - -func TestMemoryStat(t *testing.T) { - mem := MemorySubsystem{} - if err := memoryStats(memoryPath, &mem); err != nil { - t.Fatal(err) - } - - assert.Equal(t, uint64(65101824), mem.Stats.Cache.Bytes) - assert.Equal(t, uint64(230662144), mem.Stats.RSS.Bytes) - assert.Equal(t, uint64(174063616), mem.Stats.RSSHuge.Bytes) - assert.Equal(t, uint64(17633280), mem.Stats.MappedFile.Bytes) - assert.Equal(t, uint64(0), mem.Stats.Swap.Bytes) - assert.Equal(t, uint64(103258), mem.Stats.PagesIn) - assert.Equal(t, uint64(77551), mem.Stats.PagesOut) - assert.Equal(t, uint64(91651), mem.Stats.PageFaults) - assert.Equal(t, uint64(166), mem.Stats.MajorPageFaults) - assert.Equal(t, uint64(28672), mem.Stats.InactiveAnon.Bytes) - assert.Equal(t, uint64(230780928), mem.Stats.ActiveAnon.Bytes) - assert.Equal(t, uint64(40108032), mem.Stats.InactiveFile.Bytes) - assert.Equal(t, uint64(24813568), mem.Stats.ActiveFile.Bytes) - assert.Equal(t, uint64(0), mem.Stats.Unevictable.Bytes) - assert.Equal(t, uint64(9223372036854771712), mem.Stats.HierarchicalMemoryLimit.Bytes) - assert.Equal(t, uint64(9223372036854771712), mem.Stats.HierarchicalMemswLimit.Bytes) -} - -func TestMemoryData(t *testing.T) { - usage := MemoryData{} - if err := memoryData(memoryPath, "memory", &usage); err != nil { - t.Fatal(err) - } - - assert.Equal(t, uint64(295997440), usage.Usage.Bytes) - assert.Equal(t, uint64(298532864), usage.Usage.Max.Bytes) - assert.Equal(t, uint64(9223372036854771712), usage.Limit.Bytes) - assert.Equal(t, uint64(0), usage.Failures) -} - -func TestMemoryDataSwap(t *testing.T) { - usage := MemoryData{} - if err := memoryData(memoryPath, "memory.memsw", &usage); err != nil { - t.Fatal(err) - } - - assert.Equal(t, uint64(295997440), usage.Usage.Bytes) - assert.Equal(t, uint64(298532864), usage.Usage.Max.Bytes) - assert.Equal(t, uint64(9223372036854771712), usage.Limit.Bytes) - assert.Equal(t, uint64(0), usage.Failures) -} - -func TestMemoryDataKernel(t *testing.T) { - usage := MemoryData{} - if err := memoryData(memoryPath, "memory.kmem", &usage); err != nil { - t.Fatal(err) - } - - assert.Equal(t, uint64(40), usage.Usage.Bytes) - assert.Equal(t, uint64(50), usage.Usage.Max.Bytes) - assert.Equal(t, uint64(9223372036854771712), usage.Limit.Bytes) - assert.Equal(t, uint64(0), usage.Failures) -} - -func TestMemoryDataKernelTCP(t *testing.T) { - usage := MemoryData{} - if err := memoryData(memoryPath, "memory.kmem.tcp", &usage); err != nil { - t.Fatal(err) - } - - assert.Equal(t, uint64(10), usage.Usage.Bytes) - assert.Equal(t, uint64(70), usage.Usage.Max.Bytes) - assert.Equal(t, uint64(9223372036854771712), usage.Limit.Bytes) - assert.Equal(t, uint64(0), usage.Failures) -} - -func TestMemorySubsystemGet(t *testing.T) { - mem := MemorySubsystem{} - if err := mem.Get(memoryPath); err != nil { - t.Fatal(err) - } - - assert.Equal(t, uint64(65101824), mem.Stats.Cache.Bytes) - assert.Equal(t, uint64(295997440), mem.Mem.Usage.Bytes) - assert.Equal(t, uint64(295997440), mem.MemSwap.Usage.Bytes) - assert.Equal(t, uint64(40), mem.Kernel.Usage.Bytes) - assert.Equal(t, uint64(10), mem.KernelTCP.Usage.Bytes) -} - -func TestMemorySubsystemJSON(t *testing.T) { - mem := MemorySubsystem{} - if err := mem.Get(memoryPath); err != nil { - t.Fatal(err) - } - - json, err := json.MarshalIndent(mem, "", " ") - if err != nil { - t.Fatal(err) - } - - t.Log(string(json)) -} diff --git a/libbeat/metric/system/cgroup/cgv2/cpu.go b/libbeat/metric/system/cgroup/cgv2/cpu.go deleted file mode 100644 index 36b5cc56260f..000000000000 --- a/libbeat/metric/system/cgroup/cgv2/cpu.go +++ /dev/null @@ -1,119 +0,0 @@ -// Licensed to Elasticsearch B.V. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Elasticsearch B.V. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package cgv2 - -import ( - "bufio" - "os" - "path/filepath" - - "github.com/pkg/errors" - - "github.com/elastic/beats/v7/libbeat/metric/system/cgroup/cgcommon" - "github.com/elastic/beats/v7/libbeat/opt" -) - -// CPUSubsystem contains metrics and limits from the "cpu" subsystem. -// in cgroupsV2, this merges both the 'cpu' and 'cpuacct' controllers. -type CPUSubsystem struct { - ID string `json:"id,omitempty"` // ID of the cgroup. - Path string `json:"path,omitempty"` // Path to the cgroup relative to the cgroup subsystem's mountpoint. - // Shows pressure stall information for CPU. - Pressure map[string]cgcommon.Pressure `json:"pressure,omitempty" struct:"pressure,omitempty"` - // Stats shows overall counters for the CPU controller - Stats CPUStats -} - -// CPUStats carries the information from the cpu.stat cgroup file -type CPUStats struct { - //The following three metrics are only available when the controller is enabled. - Throttled ThrottledField `json:"throttled,omitempty" struct:"throttled,omitempty"` - Periods opt.Uint `json:"periods,omitempty" struct:"periods,omitempty"` - Usage cgcommon.CPUUsage `json:"usage" struct:"usage"` - User cgcommon.CPUUsage `json:"user" struct:"user"` - System cgcommon.CPUUsage `json:"system" struct:"system"` -} - -// ThrottledField contains the `throttled` information for the CPU stats -type ThrottledField struct { - Us opt.Uint `json:"us,omitempty" struct:"us,omitempty"` - Periods opt.Uint `json:"periods,omitempty" struct:"periods,omitempty"` -} - -// IsZero implements the IsZero interface for ThrottledField -func (t ThrottledField) IsZero() bool { - return t.Us.IsZero() && t.Periods.IsZero() -} - -// Get fetches memory subsystem metrics for V2 cgroups -func (cpu *CPUSubsystem) Get(path string) error { - - var err error - cpu.Pressure, err = cgcommon.GetPressure(filepath.Join(path, "cpu.pressure")) - // Not all systems have pressure stats. Treat this as a soft error. - if os.IsNotExist(err) { - return nil - } - if err != nil { - return errors.Wrap(err, "error fetching Pressure data") - } - - cpu.Stats, err = getStats(path) - if err != nil { - return errors.Wrap(err, "error fetching CPU stat data") - } - - return nil -} - -// getStats returns the cpu.stats data -func getStats(path string) (CPUStats, error) { - f, err := os.Open(filepath.Join(path, "cpu.stat")) - if err != nil { - if os.IsNotExist(err) { - return CPUStats{}, nil - } - return CPUStats{}, errors.Wrap(err, "error reading cpu.stat") - } - defer f.Close() - - sc := bufio.NewScanner(f) - data := CPUStats{} - for sc.Scan() { - key, val, err := cgcommon.ParseCgroupParamKeyValue(sc.Text()) - if err != nil { - return data, errors.Wrap(err, "error parsing cpu.stat file") - } - switch key { - case "usage_usec": - data.Usage.NS = val - case "user_usec": - data.User.NS = val - case "system_usec": - data.System.NS = val - case "nr_periods": - data.Periods = opt.UintWith(val) - case "nr_throttled": - data.Throttled.Periods = opt.UintWith(val) - case "throttled_usec": - data.Throttled.Us = opt.UintWith(val) - } - } - - return data, nil -} diff --git a/libbeat/metric/system/cgroup/cgv2/io.go b/libbeat/metric/system/cgroup/cgv2/io.go deleted file mode 100644 index ca61a38f6d4b..000000000000 --- a/libbeat/metric/system/cgroup/cgv2/io.go +++ /dev/null @@ -1,119 +0,0 @@ -// Licensed to Elasticsearch B.V. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Elasticsearch B.V. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package cgv2 - -import ( - "bufio" - "fmt" - "os" - "path/filepath" - - "github.com/pkg/errors" - - "github.com/elastic/beats/v7/libbeat/metric/system/cgroup/cgcommon" - "github.com/elastic/elastic-agent-libs/logp" -) - -//IOSubsystem is the replacement for the bulkio controller in cgroupsV1 -type IOSubsystem struct { - ID string `json:"id,omitempty"` // ID of the cgroup. - Path string `json:"path,omitempty"` // Path to the cgroup relative to the cgroup subsystem's mountpoint. - - Stats map[string]IOStat `json:"stats" struct:"stats"` - Pressure map[string]cgcommon.Pressure `json:"pressure" struct:"pressure"` -} - -// IOStat carries io.Stat data for the controllers -// This data is broken down per-device, based on the maj-minor device ID -type IOStat struct { - Read IOMetric `json:"read" struct:"read"` - Write IOMetric `json:"write" struct:"write"` - Discarded IOMetric `json:"discarded" struct:"discarded"` -} - -// IOMetric groups together the common IO sub-metrics by bytes and IOOps count -type IOMetric struct { - Bytes uint64 `json:"bytes" struct:"bytes"` - IOs uint64 `json:"ios" struct:"ios"` -} - -// Get fetches metrics for the IO subsystem -// resolveDevIDs determines if Get will try to resolve the major-minor ID pairs reported by io.stat -// are resolved to a device name -func (io *IOSubsystem) Get(path string, resolveDevIDs bool) error { - var err error - io.Stats, err = getIOStats(path, resolveDevIDs) - if err != nil { - return errors.Wrapf(err, "error getting io.stats for path %s", path) - } - - //Pressure doesn't exist on certain V2 implementations. - _, err = os.Stat(filepath.Join(path, "io.pressure")) - if errors.Is(err, os.ErrNotExist) { - logp.L().Debugf("io.pressure does not exist. Skipping.") - return nil - } - - io.Pressure, err = cgcommon.GetPressure(filepath.Join(path, "io.pressure")) - if err != nil { - return errors.Wrapf(err, "error fetching io.pressure for path %s:", path) - } - - return nil -} - -// getIOStats fetches and formats the io.stats object -func getIOStats(path string, resolveDevIDs bool) (map[string]IOStat, error) { - stats := make(map[string]IOStat) - file := filepath.Join(path, "io.stat") - f, err := os.Open(file) - if err != nil { - return stats, errors.Wrap(err, "error reading cpu.stat") - } - defer f.Close() - - sc := bufio.NewScanner(f) - for sc.Scan() { - devMetric := IOStat{} - var major, minor uint64 - _, err := fmt.Sscanf(sc.Text(), "%d:%d rbytes=%d wbytes=%d rios=%d wios=%d dbytes=%d dios=%d", &major, &minor, &devMetric.Read.Bytes, &devMetric.Write.Bytes, &devMetric.Read.IOs, &devMetric.Write.IOs, &devMetric.Discarded.Bytes, &devMetric.Discarded.IOs) - if err != nil { - return stats, errors.Wrapf(err, "error scanning file: %s", file) - } - - // try to find the device name associated with the major/minor pair - // This isn't guarenteed to work, for a number of reasons, so we'll need to fall back - var found bool - var devName string - if resolveDevIDs { - found, devName, err = fetchDeviceName(major, minor) - if err != nil { - return nil, errors.Wrapf(err, "error looking up device ID %d:%d", major, minor) - } - } - - if found { - stats[devName] = devMetric - } else { - idKey := fmt.Sprintf("%d:%d", major, minor) - stats[idKey] = devMetric - } - } - - return stats, nil -} diff --git a/libbeat/metric/system/cgroup/cgv2/io_helper_linux.go b/libbeat/metric/system/cgroup/cgv2/io_helper_linux.go deleted file mode 100644 index b62709c73526..000000000000 --- a/libbeat/metric/system/cgroup/cgv2/io_helper_linux.go +++ /dev/null @@ -1,75 +0,0 @@ -// Licensed to Elasticsearch B.V. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Elasticsearch B.V. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -//go:build linux -// +build linux - -package cgv2 - -import ( - "io/fs" - "path/filepath" - "syscall" - - "github.com/pkg/errors" -) - -// fetchDeviceName will attempt to find a device name associated with a major/minor pair -// the bool indicates if a device was found. -func fetchDeviceName(major uint64, minor uint64) (bool, string, error) { - // iterate over /dev/ and pull major and minor values - found := false - var devName string - var curMajor uint64 - var curMinor uint64 - var devID uint64 - walkFunc := func(path string, d fs.DirEntry, err error) error { - if d.IsDir() && path != "/dev/" { - return fs.SkipDir - } - if d.Type() != fs.ModeDevice { - return nil - } - fInfo, err := d.Info() - if err != nil { - return nil - } - infoT, ok := fInfo.Sys().(*syscall.Stat_t) - if !ok { - return nil - } - devID = uint64(infoT.Rdev) - - // do some bitmapping to extract the major and minor device values - // The odd duplicated logic here is to deal with 32 and 64 bit values. - // see bits/sysmacros.h - curMajor = ((devID & 0xfffff00000000000) >> 32) | ((devID & 0x00000000000fff00) >> 8) - curMinor = ((devID & 0x00000000000000ff) >> 0) | ((devID & 0x00000ffffff00000) >> 12) - if curMajor == major && curMinor == minor { - found = true - devName = d.Name() - } - return nil - } - - err := filepath.WalkDir("/dev/", walkFunc) - if err != nil { - return false, "", errors.Wrap(err, "error walking /dev/") - } - - return found, devName, nil -} diff --git a/libbeat/metric/system/cgroup/cgv2/io_helper_other.go b/libbeat/metric/system/cgroup/cgv2/io_helper_other.go deleted file mode 100644 index 0897c0e883c3..000000000000 --- a/libbeat/metric/system/cgroup/cgv2/io_helper_other.go +++ /dev/null @@ -1,29 +0,0 @@ -// Licensed to Elasticsearch B.V. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Elasticsearch B.V. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -//go:build !linux -// +build !linux - -package cgv2 - -import "errors" - -// getIOStats fetches and formats the io.stats object -func fetchDeviceName(major, minor uint64) (bool, string, error) { - - return false, "", errors.New("getIOStats is linux-only") -} diff --git a/libbeat/metric/system/cgroup/cgv2/memory.go b/libbeat/metric/system/cgroup/cgv2/memory.go deleted file mode 100644 index 96e29d36a7d4..000000000000 --- a/libbeat/metric/system/cgroup/cgv2/memory.go +++ /dev/null @@ -1,320 +0,0 @@ -// Licensed to Elasticsearch B.V. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Elasticsearch B.V. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package cgv2 - -import ( - "bufio" - "bytes" - "io/ioutil" - "os" - "path/filepath" - "reflect" - "strings" - - "github.com/pkg/errors" - - "github.com/elastic/beats/v7/libbeat/metric/system/cgroup/cgcommon" - "github.com/elastic/beats/v7/libbeat/opt" -) - -// MemorySubsystem contains the metrics and limits from the "memory" subsystem. -type MemorySubsystem struct { - ID string `json:"id,omitempty"` // ID of the cgroup. - Path string `json:"path,omitempty"` // Path to the cgroup relative to the cgroup subsystem's mountpoint. - - Mem MemoryData `json:"mem" struct:"mem"` // Memory usage by tasks in this cgroup. - MemSwap MemoryData `json:"memsw" struct:"memsw"` // Memory plus swap usage by tasks in this cgroup. - Stats MemoryStat `json:"stats" struct:"stats"` // A wide range of memory statistics. -} - -// MemoryData contains basic metrics for the V2 controller -type MemoryData struct { - Events Events `json:"events" struct:"events"` - Usage opt.Bytes `json:"usage" struct:"usage"` - Low opt.Bytes `json:"low" struct:"low"` - High opt.BytesOpt `json:"high,omitempty" struct:"high,omitempty"` - Max opt.BytesOpt `json:"max,omitempty" struct:"max,omitempty"` -} - -// Events contains the data from *.events in the memory controller -type Events struct { - Low opt.Uint `json:"low,omitempty" struct:"low,omitempty"` - High uint64 `json:"high" struct:"high"` - Max uint64 `json:"max" struct:"max"` - OOM opt.Uint `json:"oom,omitempty" struct:"oom,omitempty"` - OOMKill opt.Uint `json:"oom_kill,omitempty" struct:"oom_kill,omitempty"` - Fail opt.Uint `json:"fail,omitempty" struct:"fail,omitempty"` -} - -// MemoryStat holds detailed stats for the memory controller -type MemoryStat struct { - //Amount of memory used in anonymous mappings - Anon opt.Bytes `json:"anon" struct:"anon" orig:"anon"` - //Amount of memory used to cache filesystem data, including tmpfs and shared memory. - File opt.Bytes `json:"file" struct:"file" orig:"file"` - // Amount of memory allocated to kernel stacks. - KernelStack opt.Bytes `json:"kernel_stack" struct:"kernel_stack" orig:"kernel_stack"` - //Amount of memory allocated for page tables. - Pagetables opt.Bytes `json:"page_tables" struct:"page_tables" orig:"pagetables"` - // Amount of memory used for storing per-cpu kernel data structures. - PerCPU opt.Bytes `json:"per_cpu" struct:"per_cpu" orig:"percpu"` - // Amount of memory used in network transmission buffers - Sock opt.Bytes `json:"sock" struct:"sock" orig:"sock"` - // Amount of cached filesystem data that is swap-backed, such as tmpfs, shm segments, shared anonymous mmap()s - Shmem opt.Bytes `json:"shmem" struct:"shmem" orig:"shmem"` - // Amount of cached filesystem data mapped with mmap() - FileMapped opt.Bytes `json:"file_mapped" struct:"file_mapped" orig:"file_mapped"` - //Amount of cached filesystem data that was modified but not yet written back to disk - FileDirty opt.Bytes `json:"file_dirty" struct:"file_dirty" orig:"file_dirty"` - // Amount of cached filesystem data that was modified and is currently being written back to disk - FileWriteback opt.Bytes `json:"file_writeback" struct:"file_writeback" orig:"file_writeback"` - // Amount of swap cached in memory. The swapcache is accounted against both memory and swap usage. - SwapCached opt.Bytes `json:"swap_cached" struct:"swap_cached" orig:"swapcached"` - // Amount of memory used in anonymous mappings backed by transparent hugepages - AnonTHP opt.Bytes `json:"anon_thp" struct:"anon_thp" orig:"anon_thp"` - // Amount of cached filesystem data backed by transparent hugepages - FileTHP opt.Bytes `json:"file_thp" struct:"file_thp" orig:"file_thp"` - // Amount of shm, tmpfs, shared anonymous mmap()s backed by transparent hugepages - ShmemTHP opt.Bytes `json:"shmem_thp" struct:"shmem_thp" orig:"shmem_thp"` - // Anonymous and swap cache on inactive LRU list, including tmpfs (shmem), in bytes. - InactiveAnon opt.Bytes `json:"inactive_anon" struct:"inactive_anon" orig:"inactive_anon"` - // Anonymous and swap cache on active least-recently-used (LRU) list, including tmpfs (shmem), in bytes. - ActiveAnon opt.Bytes `json:"active_anon" struct:"active_anon" orig:"active_anon"` - // File-backed memory on inactive LRU list, in bytes. - InactiveFile opt.Bytes `json:"inactive_file" struct:"inactive_file" orig:"inactive_file"` - // File-backed memory on active LRU list, in bytes. - ActiveFile opt.Bytes `json:"active_file" struct:"active_file" orig:"active_file"` - // Memory that cannot be reclaimed, in bytes. - Unevictable opt.Bytes `json:"unevictable" struct:"unevictable" orig:"unevictable"` - // Part of "slab" that might be reclaimed, such as dentries and inodes. - SlabReclaimable opt.Bytes `json:"slab_reclaimable" struct:"slab_reclaimable" orig:"slab_reclaimable"` - // Part of "slab" that cannot be reclaimed on memory pressure. - SlabUnreclaimable opt.Bytes `json:"slab_unreclaimable" struct:"slab_unreclaimable" orig:"slab_unreclaimable"` - // Amount of memory used for storing in-kernel data structures. - Slab opt.Bytes `json:"slab" struct:"slab" orig:"slab"` - // Number of refaults of previously evicted anonymous pages. - WorkingSetRefaultAnon uint64 `json:"workingset_refault_anon" struct:"workingset_refault_anon" orig:"workingset_refault_anon"` - // Number of refaults of previously evicted file pages. - WorkingSetRefaultFile uint64 `json:"workingset_refault_file" struct:"workingset_refault_file" orig:"workingset_refault_file"` - // Number of refaulted anonymous pages that were immediately activated. - WorkingSetActivateAnon uint64 `json:"workingset_activate_anon" struct:"workingset_activate_anon" orig:"workingset_activate_anon"` - // Number of refaulted file pages that were immediately activated. - WorkingSetActivateFile uint64 `json:"workingset_activate_file" struct:"workingset_activate_file" orig:"workingset_activate_file"` - // Number of restored anonymous pages which have been detected as an active workingset before they got reclaimed. - WorkingSetRestoreAnon uint64 `json:"workingset_restore_anon" struct:"workingset_restore_anon" orig:"workingset_restore_anon"` - // Number of restored file pages which have been detected as an active workingset before they got reclaimed. - WorkingSetRestoreFile uint64 `json:"workingset_restore_file" struct:"workingset_restore_file" orig:"workingset_restore_file"` - // Number of times a shadow node has been reclaimed - WorkingSetNodeReclaim uint64 `json:"workingset_node_reclaim" struct:"workingset_node_reclaim" orig:"workingset_nodereclaim"` - //Total number of page faults incurred - PageFaults uint64 `json:"page_faults" struct:"page_faults" orig:"pgfault"` - // Number of times a task in the cgroup triggered a major page fault. - MajorPageFaults uint64 `json:"major_page_faults" struct:"major_page_faults" orig:"pgmajfault"` - // Amount of scanned pages (in an active LRU list) - PageRefill uint64 `json:"page_refill" struct:"page_refill" orig:"pgrefill"` - // Amount of scanned pages (in an inactive LRU list) - PageScan uint64 `json:"page_scan" struct:"page_scan" orig:"pgscan"` - // Amount of reclaimed pages - PageSteal uint64 `json:"page_steal" struct:"page_steal" orig:"pgsteal"` - //Amount of pages moved to the active LRU list - PageActivate uint64 `json:"page_activate" struct:"page_activate" orig:"pgactivate"` - // Amount of pages moved to the inactive LRU list - PageDeactivate uint64 `json:"page_deactivate" struct:"page_deactivate" orig:"pgdeactivate"` - // Amount of pages postponed to be freed under memory pressure - PageLazyFree uint64 `json:"page_lazy_free" struct:"page_lazy_free" orig:"pglazyfree"` - // Amount of reclaimed lazyfree pages - PageLazyFreed uint64 `json:"page_lazy_freed" struct:"page_lazy_freed" orig:"pglazyfreed"` - // Number of transparent hugepages which were allocated to satisfy a page fault. - THPFaultAlloc uint64 `json:"thp_fault_alloc" struct:"thp_fault_alloc" orig:"thp_fault_alloc"` - // Number of transparent hugepages which were allocated to allow collapsing an existing range of pages. - THPCollapseAlloc uint64 `json:"htp_collapse_alloc" struct:"htp_collapse_alloc" orig:"thp_collapse_alloc"` -} - -// Get fetches memory subsystem metrics for V2 cgroups -func (mem *MemorySubsystem) Get(path string) error { - - var err error - mem.Mem, err = memoryData(path, "memory") - if err != nil { - return errors.Wrap(err, "error reading memory stats") - } - - mem.MemSwap, err = memoryData(path, "memory.swap") - if err != nil { - return errors.Wrap(err, "error reading memory.swap stats") - } - - mem.Stats, err = fillStatStruct(path) - if err != nil { - return errors.Wrap(err, "error fetching memory.stat") - } - - return nil -} - -// memoryData reads off the the auxillary memory stats from the memory controller -func memoryData(path, file string) (MemoryData, error) { - - // root cgroups won't have these files. - // If .high doesn't exist, assume the rest don't either. - _, err := os.Stat(filepath.Join(path, file+".high")) - if errors.Is(err, os.ErrNotExist) { - return MemoryData{}, nil - } - - data := MemoryData{} - // High and max can be set to "max", which means "off" - lowMetric, err := cgcommon.ParseUintFromFile(filepath.Join(path, file+".low")) - if err != nil { - return data, errors.Wrapf(err, "error reading %s.low file", file) - } - - highMetric, err := maxOrValue(path, file+".high") - if err != nil { - return data, errors.Wrapf(err, "error parsing %s.high file", file) - } - - maxMetric, err := maxOrValue(path, file+".max") - if err != nil { - return data, errors.Wrapf(err, "error parsing %s.max file", file) - } - - currentMetric, err := cgcommon.ParseUintFromFile(filepath.Join(path, file+".current")) - if err != nil { - return data, errors.Wrapf(err, "error reading %s.current file", file) - } - - data.Low.Bytes = lowMetric - data.High.Bytes = highMetric - data.Max.Bytes = maxMetric - data.Usage.Bytes = currentMetric - data.Events, err = fetchEventsFile(path, file+".events") - if err != nil { - return data, errors.Wrapf(err, "error fetching events file for %s", file) - } - - return data, nil -} - -// fetch memory.events contents -func fetchEventsFile(path, file string) (Events, error) { - evt := Events{} - toRead := filepath.Join(path, file) - f, err := os.Open(toRead) - if err != nil { - return evt, errors.Wrapf(err, "error reading %s", toRead) - } - defer f.Close() - - sc := bufio.NewScanner(f) - for sc.Scan() { - key, val, err := cgcommon.ParseCgroupParamKeyValue(sc.Text()) - if err != nil { - return evt, errors.Wrap(err, "error parsing key from events") - } - switch key { - case "low": - evt.Low = opt.UintWith(val) - case "high": - evt.High = val - case "max": - evt.Max = val - case "oom": - evt.OOM = opt.UintWith(val) - case "oom_kill": - evt.OOMKill = opt.UintWith(val) - case "fail": - evt.Fail = opt.UintWith(val) - } - } - - return evt, nil -} - -// Some values, such as mem.max and mem.high, can be set to "max," which disables the metric. -func maxOrValue(path, file string) (opt.Uint, error) { - var finalMetric opt.Uint - highRaw, err := ioutil.ReadFile(filepath.Join(path, file)) - if err != nil { - return finalMetric, errors.Wrapf(err, "error reading %s.high file", path) - } - - if strings.TrimSpace(string(highRaw)) == "max" { - finalMetric = opt.NewUintNone() - } else { - highUint, err := cgcommon.ParseUint(highRaw) - if err != nil { - return finalMetric, errors.Wrapf(err, "error parsing raw high value: %v", highRaw) - } - finalMetric = opt.UintWith(highUint) - } - - return finalMetric, nil -} - -// fillStatStruct iteratively fills out the MemoryStat struct -// This works via reflection, and it's a tad ugly, but we also have a lot of fields to fill -// Note that this assumes all the values in the struct are either `uint64`, `opt.Bytes` or `opt.BytesOpt` -func fillStatStruct(path string) (MemoryStat, error) { - statPath := filepath.Join(path, "memory.stat") - raw, err := ioutil.ReadFile(statPath) - if err != nil { - return MemoryStat{}, errors.Wrap(err, "error reading memory.stat") - } - - stats := MemoryStat{} - refValues := reflect.ValueOf(&stats).Elem() - refTypes := reflect.TypeOf(stats) - - sc := bufio.NewScanner(bytes.NewReader(raw)) - for sc.Scan() { - //break apart the lines - parts := bytes.SplitN(sc.Bytes(), []byte(" "), 2) - if len(parts) != 2 { - continue - } - intVal, err := cgcommon.ParseUint(parts[1]) - if err != nil { - return stats, errors.Wrapf(err, "error parsing value %v", parts[1]) - } - for i := 0; i < refValues.NumField(); i++ { - idxVal := refValues.Field(i) - idxType := refTypes.Field(i) - tagStr := idxType.Tag.Get("orig") - if tagStr == string(parts[0]) { - if idxVal.CanSet() { - if idxVal.Kind() == reflect.Uint64 { - idxVal.SetUint(intVal) - } else if idxType.Type == reflect.TypeOf(opt.Bytes{}) { - byteVal := opt.Bytes{Bytes: intVal} - byteRef := reflect.ValueOf(byteVal) - idxVal.Set(byteRef) - } else if idxType.Type == reflect.TypeOf(opt.BytesOpt{}) { - byteVal := opt.BytesOpt{Bytes: opt.UintWith(intVal)} - byteRef := reflect.ValueOf(byteVal) - idxVal.Set(byteRef) - } - - } - } - } - - } - - return stats, nil -} diff --git a/libbeat/metric/system/cgroup/cgv2/v2_test.go b/libbeat/metric/system/cgroup/cgv2/v2_test.go deleted file mode 100644 index 60edbfd3ff2b..000000000000 --- a/libbeat/metric/system/cgroup/cgv2/v2_test.go +++ /dev/null @@ -1,69 +0,0 @@ -// Licensed to Elasticsearch B.V. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Elasticsearch B.V. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package cgv2 - -import ( - "testing" - - "github.com/stretchr/testify/assert" -) - -const v2Path = "../testdata/docker/sys/fs/cgroup/system.slice/docker-1c8fa019edd4b9d4b2856f4932c55929c5c118c808ed5faee9a135ca6e84b039.scope" - -func TestGetIO(t *testing.T) { - ioTest := IOSubsystem{} - err := ioTest.Get(v2Path, false) - assert.NoError(t, err, "error in Get") - - goodStat := map[string]IOStat{ - "253:0": { - Read: IOMetric{Bytes: 1024, IOs: 1}, - Write: IOMetric{Bytes: 4096, IOs: 1}, - Discarded: IOMetric{Bytes: 6, IOs: 8}, - }, - "8:0": { - Read: IOMetric{Bytes: 512, IOs: 100}, - Write: IOMetric{Bytes: 4096, IOs: 1}, - Discarded: IOMetric{Bytes: 5, IOs: 23}, - }, - } - - assert.Equal(t, goodStat, ioTest.Stats) -} - -func TestGetMem(t *testing.T) { - mem := MemorySubsystem{} - err := mem.Get(v2Path) - assert.NoError(t, err, "error in GetV2") - - assert.Equal(t, uint64(3), mem.Mem.Events.High) - assert.Equal(t, uint64(4), mem.Mem.Low.Bytes) - assert.Equal(t, uint64(9125888), mem.Mem.Usage.Bytes) - - assert.Equal(t, uint64(17756400), mem.Stats.SlabReclaimable.Bytes) - assert.Equal(t, uint64(12), mem.Stats.THPFaultAlloc) -} - -func TestGetCPU(t *testing.T) { - cpu := CPUSubsystem{} - err := cpu.Get(v2Path) - assert.NoError(t, err, "error in Get") - - assert.Equal(t, uint64(26772130245), cpu.Stats.Usage.NS) - assert.Equal(t, uint64(5793060316), cpu.Stats.System.NS) -} diff --git a/libbeat/metric/system/cgroup/doc.go b/libbeat/metric/system/cgroup/doc.go deleted file mode 100644 index c64f6073a90a..000000000000 --- a/libbeat/metric/system/cgroup/doc.go +++ /dev/null @@ -1,28 +0,0 @@ -// Licensed to Elasticsearch B.V. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Elasticsearch B.V. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -// Package cgroup reads metrics and other tunable parameters associated with -// control groups, a Linux kernel feature for grouping tasks to track and limit -// resource usage. -// -// Terminology -// -// A cgroup is a collection of processes that are bound to a set of limits. -// -// A subsystem is a kernel component the modifies the behavior of processes -// in a cgroup. -package cgroup diff --git a/libbeat/metric/system/cgroup/reader.go b/libbeat/metric/system/cgroup/reader.go deleted file mode 100644 index c8ea95bb371f..000000000000 --- a/libbeat/metric/system/cgroup/reader.go +++ /dev/null @@ -1,357 +0,0 @@ -// Licensed to Elasticsearch B.V. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Elasticsearch B.V. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package cgroup - -import ( - "fmt" - "io/ioutil" - "path/filepath" - "strconv" - "strings" - - "github.com/pkg/errors" - - "github.com/elastic/beats/v7/libbeat/metric/system/cgroup/cgv1" - "github.com/elastic/beats/v7/libbeat/metric/system/cgroup/cgv2" - "github.com/elastic/beats/v7/libbeat/metric/system/resolve" -) - -// StatsV1 contains metrics and limits from each of the cgroup subsystems. -type StatsV1 struct { - ID string `json:"id,omitempty" struct:"id,omitempty"` // ID of the cgroup. - Path string `json:"path,omitempty" struct:"path,omitempty"` // Path to the cgroup relative to the cgroup subsystem's mountpoint. - CPU *cgv1.CPUSubsystem `json:"cpu,omitempty" struct:"cpu,omitempty"` - CPUAccounting *cgv1.CPUAccountingSubsystem `json:"cpuacct,omitempty" struct:"cpuacct,omitempty"` - Memory *cgv1.MemorySubsystem `json:"memory,omitempty" struct:"memory,omitempty"` - BlockIO *cgv1.BlockIOSubsystem `json:"blkio,omitempty" struct:"blkio,omitempty"` - Version CgroupsVersion `json:"cgroups_version,omitempty" struct:"cgroups_version,omitempty"` -} - -// StatsV2 contains metrics and limits from each of the cgroup subsystems. -type StatsV2 struct { - ID string `json:"id,omitempty"` // ID of the cgroup. - Path string `json:"path,omitempty"` // Path to the cgroup relative to the cgroup subsystem's mountpoint. - CPU *cgv2.CPUSubsystem `json:"cpu,omitempty" struct:"cpu,omitempty"` - Memory *cgv2.MemorySubsystem `json:"memory,omitempty" struct:"memory,omitempty"` - IO *cgv2.IOSubsystem `json:"io,omitempty" struct:"io,omitempty"` - Version CgroupsVersion `json:"cgroups_version,omitempty" struct:"cgroups_version,omitempty"` -} - -// CgroupsVersion is a version tag that defines what version of cgroups is attached to a process -type CgroupsVersion int - -// CgroupsV1 indicates that a process is cgroupsv1 -const CgroupsV1 CgroupsVersion = 1 - -// CgroupsV2 indicates that a process is cgroupsv2 -const CgroupsV2 CgroupsVersion = 2 - -type mount struct { - subsystem string // Subsystem name (e.g. cpuacct). - mountpoint string // Mountpoint of the subsystem (e.g. /cgroup/cpuacct). - path string // Relative path to the cgroup (e.g. /docker/). - id string // ID of the cgroup. - fullPath string // Absolute path to the cgroup. It's the mountpoint joined with the path. -} - -// Reader reads cgroup metrics and limits. -type Reader struct { - // Mountpoint of the root filesystem. Defaults to / if not set. This can be - // useful for example if you mount / as /rootfs inside of a container. - rootfsMountpoint resolve.Resolver - ignoreRootCgroups bool // Ignore a cgroup when its path is "/". - cgroupsHierarchyOverride string - cgroupMountpoints Mountpoints // Mountpoints for each subsystem (e.g. cpu, cpuacct, memory, blkio). -} - -// ReaderOptions holds options for NewReaderOptions. -type ReaderOptions struct { - // RootfsMountpoint holds the mountpoint of the root filesystem. - // - // pass - RootfsMountpoint resolve.Resolver - - // IgnoreRootCgroups ignores cgroup subsystem with the path "/". - IgnoreRootCgroups bool - - // CgroupsHierarchyOverride is an optional path override for cgroup - // subsystem paths. If non-empty, this will be used instead of the - // paths specified in /proc//cgroup. - // - // This should be set to "/" when running within a Docker container, - // where the paths in /proc//cgroup do not correspond to any - // paths under /sys/fs/cgroup. - CgroupsHierarchyOverride string -} - -// NewReader creates and returns a new Reader. -func NewReader(rootfsMountpoint resolve.Resolver, ignoreRootCgroups bool) (*Reader, error) { - return NewReaderOptions(ReaderOptions{ - RootfsMountpoint: rootfsMountpoint, - IgnoreRootCgroups: ignoreRootCgroups, - }) -} - -// NewReaderOptions creates and returns a new Reader with the given options. -func NewReaderOptions(opts ReaderOptions) (*Reader, error) { - // Determine what subsystems are supported by the kernel. - subsystems, err := SupportedSubsystems(opts.RootfsMountpoint) - // We can return a not-quite-an-error ErrCgroupsMissing here, so return the bare error. - if err != nil { - return nil, err - } - - // Locate the mountpoints of those subsystems. - mountpoints, err := SubsystemMountpoints(opts.RootfsMountpoint, subsystems) - if err != nil { - return nil, errors.Wrap(err, "error finding mountpoints") - } - - return &Reader{ - rootfsMountpoint: opts.RootfsMountpoint, - ignoreRootCgroups: opts.IgnoreRootCgroups, - cgroupsHierarchyOverride: opts.CgroupsHierarchyOverride, - cgroupMountpoints: mountpoints, - }, nil -} - -// CgroupsVersion reports if the given PID is attached to a V1 or V2 controller -func (r *Reader) CgroupsVersion(pid int) (CgroupsVersion, error) { - cgPath := filepath.Join("/proc/", strconv.Itoa(pid), "cgroup") - cgPath = r.rootfsMountpoint.ResolveHostFS(cgPath) - cgraw, err := ioutil.ReadFile(cgPath) - if err != nil { - return CgroupsV1, errors.Wrapf(err, "error reading %s", cgPath) - } - cgstring := string(cgraw) - //V2 cgroups always begin with 0::/ - // Some distros will "mix" V1 and V2 by adding an unused V2 controller - // Check to see if we're actually using V2. - // This is cautious code, as different distros seem to mix V2 and V1 events in weird ways. - if strings.Contains(cgstring, "0::/") { - // This is a V2-only cgroup - if len(strings.Split(strings.TrimSpace(cgstring), "\n")) == 1 { - return CgroupsV2, nil - } - // Otherwise, check to see what's in the controllers file - controllers, err := readControllerList(cgstring, r.cgroupMountpoints.V2Loc) - if err != nil { - return CgroupsV1, errors.Wrapf(err, "error fetching cgroup controller list for pid %d", pid) - } - // The logic here is a tad opinionated. If we're at this point in the code, it's because we have both - // V1 and V2 controllers on a cgroup. If the V2 controller has no actual controllers associated with it, - // We revert to V1. If it does, report V2. In the future, we may want to "combine" V2 and V1 metrics somehow. - if len(controllers) > 0 { - fmt.Printf("fetching V2 controller: %#v for pid %d\n", controllers, pid) - return CgroupsV2, nil - } - return CgroupsV1, nil - } - return CgroupsV1, nil -} - -// GetStatsForPid is a generic method that returns a CGStats interface for V1 and V2 -// cgroup statistics. For applications that require raw metrics, use GetV*StatsForProcess() -func (r *Reader) GetStatsForPid(pid int) (CGStats, error) { - v, err := r.CgroupsVersion(pid) - if err != nil { - return nil, errors.Wrapf(err, "error finding cgroup version for pid %d", pid) - } - if v == CgroupsV1 { - return r.GetV1StatsForProcess(pid) - } - return r.GetV2StatsForProcess(pid) -} - -// GetV1StatsForProcess returns cgroup metrics and limits associated with a process. -func (r *Reader) GetV1StatsForProcess(pid int) (*StatsV1, error) { - // Read /proc/[pid]/cgroup to get the paths to the cgroup metrics. - paths, err := r.ProcessCgroupPaths(pid) - if err != nil { - return nil, err - } - - stats := StatsV1{} - stats.Path, stats.ID = getCommonCgroupMetadata(paths.V1) - stats.Version = CgroupsV1 - for conName, cgPath := range paths.V1 { - if r.ignoreRootCgroups && (cgPath.ControllerPath == "/" && r.cgroupsHierarchyOverride != cgPath.ControllerPath) { - continue - } - err := getStatsV1(cgPath, conName, &stats) - if err != nil { - return nil, errors.Wrapf(err, "error fetching stats for controller %s", conName) - } - } - - return &stats, nil -} - -// GetV2StatsForProcess returns cgroup metrics and limits associated with a process. -func (r *Reader) GetV2StatsForProcess(pid int) (*StatsV2, error) { - // Read /proc/[pid]/cgroup to get the paths to the cgroup metrics. - paths, err := r.ProcessCgroupPaths(pid) - if err != nil { - return nil, err - } - stats := StatsV2{} - stats.Path, stats.ID = getCommonCgroupMetadata(paths.V2) - stats.Version = CgroupsV2 - for conName, cgPath := range paths.V2 { - if r.ignoreRootCgroups && (cgPath.ControllerPath == "/" && r.cgroupsHierarchyOverride != cgPath.ControllerPath) { - continue - } - err := getStatsV2(cgPath, conName, &stats) - if err != nil { - return nil, errors.Wrapf(err, "error fetching stats for controller %s", conName) - } - } - return &stats, nil -} - -// ProcessCgroupPaths is a wrapper around Reader.ProcessCgroupPaths for libraries that only need the slimmer functionality from -// the gosigar cgroups code. This does not have the same function signature, and consumers still need to distinguish between v1 and v2 cgroups. -func ProcessCgroupPaths(hostfs resolve.Resolver, pid int) (PathList, error) { - reader, err := NewReader(hostfs, false) - if err != nil { - return PathList{}, errors.Wrap(err, "error creating cgroups reader") - } - return reader.ProcessCgroupPaths(pid) -} - -func getStatsV2(path ControllerPath, name string, stats *StatsV2) error { - id := filepath.Base(path.ControllerPath) - - switch name { - case "cpu": - stats.CPU = &cgv2.CPUSubsystem{} - err := stats.CPU.Get(path.FullPath) - if err != nil { - return errors.Wrap(err, "error fetching CPU stats") - } - stats.CPU.ID = id - stats.CPU.Path = path.ControllerPath - case "memory": - stats.Memory = &cgv2.MemorySubsystem{} - err := stats.Memory.Get(path.FullPath) - if err != nil { - return errors.Wrap(err, "error fetching Memory stats") - } - stats.Memory.ID = id - stats.Memory.Path = path.ControllerPath - case "io": - stats.IO = &cgv2.IOSubsystem{} - err := stats.IO.Get(path.FullPath, true) - if err != nil { - return errors.Wrap(err, "error fetching IO stats") - } - stats.IO.ID = id - stats.IO.Path = path.ControllerPath - } - - return nil -} - -func getStatsV1(path ControllerPath, name string, stats *StatsV1) error { - id := filepath.Base(path.ControllerPath) - - switch name { - case "blkio": - stats.BlockIO = &cgv1.BlockIOSubsystem{} - err := stats.BlockIO.Get(path.FullPath) - if err != nil { - return errors.Wrap(err, "error fetching BlockIO stats") - } - stats.BlockIO.ID = id - stats.BlockIO.Path = path.ControllerPath - case "cpu": - stats.CPU = &cgv1.CPUSubsystem{} - err := stats.CPU.Get(path.FullPath) - if err != nil { - return errors.Wrap(err, "error fetching cpu stats") - } - stats.CPU.ID = id - stats.CPU.Path = path.ControllerPath - case "cpuacct": - stats.CPUAccounting = &cgv1.CPUAccountingSubsystem{} - err := stats.CPUAccounting.Get(path.FullPath) - if err != nil { - return errors.Wrap(err, "error fetching cpuacct stats") - } - stats.CPUAccounting.ID = id - stats.CPUAccounting.Path = path.ControllerPath - case "memory": - stats.Memory = &cgv1.MemorySubsystem{} - err := stats.Memory.Get(path.FullPath) - if err != nil { - return errors.Wrap(err, "error fetching memory stats") - } - stats.Memory.ID = id - stats.Memory.Path = path.ControllerPath - } - - return nil -} - -// getCommonCgroupMetadata returns Metadata containing the cgroup path and ID -// iff all subsystems share a common path and ID. This is common for -// containerized processes. If there is no common path and ID then the returned -// values are empty strings. -func getCommonCgroupMetadata(mounts map[string]ControllerPath) (string, string) { - var path string - for _, m := range mounts { - if path == "" { - path = m.ControllerPath - } else if path != m.ControllerPath { - // All paths are not the same. - return "", "" - } - } - - return path, filepath.Base(path) -} - -// Read a cgroup.controllers list from a v2 cgroup -func readControllerList(cgroupsFile string, v2path string) ([]string, error) { - // edge case: There's no V2 controller - if v2path == "" { - return []string{}, nil - } - controllers := strings.Split(cgroupsFile, "\n") - var cgpath string - for _, controller := range controllers { - if strings.Contains(controller, "0::/") { - fields := strings.Split(controller, ":") - cgpath = fields[2] - } - } - // no v2 controllers - if cgpath == "" { - return []string{}, nil - } - file := filepath.Join(v2path, cgpath, "cgroup.controllers") - controllersRaw, err := ioutil.ReadFile(file) - if err != nil { - return nil, errors.Wrapf(err, "error reading %s", file) - } - - if len(controllersRaw) == 0 { - return []string{}, nil - } - return strings.Split(string(controllersRaw), " "), nil -} diff --git a/libbeat/metric/system/cgroup/reader_test.go b/libbeat/metric/system/cgroup/reader_test.go deleted file mode 100644 index d6f707086ed5..000000000000 --- a/libbeat/metric/system/cgroup/reader_test.go +++ /dev/null @@ -1,136 +0,0 @@ -// Licensed to Elasticsearch B.V. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Elasticsearch B.V. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package cgroup - -import ( - "encoding/json" - "testing" - - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - - "github.com/elastic/beats/v7/libbeat/metric/system/resolve" -) - -const ( - path = "/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242" - id = "b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242" -) - -func TestReaderGetStatsV1(t *testing.T) { - reader, err := NewReader(resolve.NewTestResolver("testdata/docker"), true) - assert.NoError(t, err, "error in NewReader") - - stats, err := reader.GetV1StatsForProcess(985) - assert.NoError(t, err, "error in GetV1StatsForProcess") - - if stats == nil { - t.Fatal("no cgroup stats found") - } - - assert.Equal(t, id, stats.ID) - assert.Equal(t, id, stats.BlockIO.ID) - assert.Equal(t, id, stats.CPU.ID) - assert.Equal(t, id, stats.CPUAccounting.ID) - assert.Equal(t, id, stats.Memory.ID) - - assert.NotZero(t, stats.CPU.CFS.PeriodMicros.Us) - assert.NotZero(t, stats.CPUAccounting.Total.NS) - assert.NotZero(t, stats.Memory.Mem.Usage.Bytes) - assert.NotZero(t, stats.BlockIO.Total.Bytes) - - assert.Equal(t, path, stats.Path) - assert.Equal(t, path, stats.BlockIO.Path) - assert.Equal(t, path, stats.CPU.Path) - assert.Equal(t, path, stats.CPUAccounting.Path) - assert.Equal(t, path, stats.Memory.Path) - - json, err := json.MarshalIndent(stats, "", " ") - if err != nil { - t.Fatal(err) - } - - t.Log(string(json)) -} - -func TestReaderGetStatsV2(t *testing.T) { - reader, err := NewReader(resolve.NewTestResolver("testdata/docker"), true) - assert.NoError(t, err, "error in NewReader") - - stats, err := reader.GetV2StatsForProcess(312) - assert.NoError(t, err, "error in GetV2StatsForProcess") - - require.NotNil(t, stats.CPU) - require.NotNil(t, stats.Memory) - require.NotNil(t, stats.IO) - - require.NotZero(t, stats.CPU.Stats.Usage.NS) - require.NotZero(t, stats.Memory.Mem.Usage.Bytes) - require.NotZero(t, stats.IO.Pressure["some"].Sixty.Pct) - -} - -func TestReaderGetStatsHierarchyOverride(t *testing.T) { - // In testdata/docker, process 1's cgroup paths have - // no corresponding paths under /sys/fs/cgroup/. - // - // Setting CgroupsHierarchyOverride means that we use - // the root cgroup path instead. This is intended to test - // the scenario where we're reading cgroup metrics from - // within a Docker container. - - reader, err := NewReaderOptions(ReaderOptions{ - RootfsMountpoint: resolve.NewTestResolver("testdata/docker"), - IgnoreRootCgroups: false, - CgroupsHierarchyOverride: "/", - }) - if err != nil { - t.Fatal(err) - } - - stats, err := reader.GetV1StatsForProcess(1) - if err != nil { - t.Fatal(err) - } - if stats == nil { - t.Fatal("no cgroup stats found") - } - - require.NotNil(t, stats.CPU) - assert.NotZero(t, stats.CPU.CFS.Shares) - - reader2, err := NewReaderOptions(ReaderOptions{ - RootfsMountpoint: resolve.NewTestResolver("testdata/docker"), - IgnoreRootCgroups: true, - CgroupsHierarchyOverride: "/system.slice/", - }) - if err != nil { - t.Fatal(err) - } - - stats2, err := reader2.GetV2StatsForProcess(312) - if err != nil { - t.Fatal(err) - } - if stats == nil { - t.Fatal("no cgroup stats found") - } - - require.NotNil(t, stats2.CPU) - require.NotZero(t, stats2.CPU.Stats.Usage.NS) -} diff --git a/libbeat/metric/system/cgroup/testdata/docker.zip b/libbeat/metric/system/cgroup/testdata/docker.zip deleted file mode 100755 index 66ca734e3a1f..000000000000 Binary files a/libbeat/metric/system/cgroup/testdata/docker.zip and /dev/null differ diff --git a/libbeat/metric/system/cgroup/testdata/docker/proc/1/cgroup b/libbeat/metric/system/cgroup/testdata/docker/proc/1/cgroup deleted file mode 100644 index 59154291798a..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/proc/1/cgroup +++ /dev/null @@ -1,10 +0,0 @@ -10:net_prio:/docker/123 -9:perf_event:/docker/123 -8:net_cls:/docker/123 -7:freezer:/docker/123 -6:devices:/docker/123 -5:memory:/docker/123 -4:blkio:/docker/123 -3:cpuacct:/docker/123 -2:cpu:/docker/123 -1:cpuset:/docker/123 diff --git a/libbeat/metric/system/cgroup/testdata/docker/proc/312/cgroup b/libbeat/metric/system/cgroup/testdata/docker/proc/312/cgroup deleted file mode 100644 index 0219290ccbca..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/proc/312/cgroup +++ /dev/null @@ -1 +0,0 @@ -0::/system.slice/docker-1c8fa019edd4b9d4b2856f4932c55929c5c118c808ed5faee9a135ca6e84b039.scope \ No newline at end of file diff --git a/libbeat/metric/system/cgroup/testdata/docker/proc/985/cgroup b/libbeat/metric/system/cgroup/testdata/docker/proc/985/cgroup deleted file mode 100755 index 958cb283aa57..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/proc/985/cgroup +++ /dev/null @@ -1,10 +0,0 @@ -10:net_prio:/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242 -9:perf_event:/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242 -8:net_cls:/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242 -7:freezer:/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242 -6:devices:/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242 -5:memory:/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242 -4:blkio:/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242 -3:cpuacct:/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242 -2:cpu:/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242 -1:cpuset:/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242 diff --git a/libbeat/metric/system/cgroup/testdata/docker/proc/cgroups b/libbeat/metric/system/cgroup/testdata/docker/proc/cgroups deleted file mode 100644 index 15630d3f8e90..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/proc/cgroups +++ /dev/null @@ -1,13 +0,0 @@ -#subsys_name hierarchy num_cgroups enabled -cpuset 4 3 1 -cpu 2 3 1 -cpuacct 3 3 1 -blkio 1 3 1 -memory 8 3 1 -devices 5 3 1 -freezer 6 3 1 -net_cls 0 1 1 -perf_event 9 3 1 -net_prio 0 1 1 -hugetlb 7 3 0 -pids 0 1 1 diff --git a/libbeat/metric/system/cgroup/testdata/docker/proc/self/mountinfo b/libbeat/metric/system/cgroup/testdata/docker/proc/self/mountinfo deleted file mode 100644 index fff9d95b6aa3..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/proc/self/mountinfo +++ /dev/null @@ -1,30 +0,0 @@ -77 54 253:1 /rootfs / rw,relatime - xfs /dev/mapper/docker-202:1-268139-f9bccb869bc226abe82d0ba0e4cb0eb15c01fdcf2fb38c5ec9176b762a4b3a90 rw,nouuid,attr2,inode64,logbsize=64k,sunit=128,swidth=128,noquota -78 77 0:30 / /proc rw,nosuid,nodev,noexec,relatime - proc proc rw -79 77 0:31 / /dev rw,nosuid - tmpfs tmpfs rw,mode=755 -80 79 0:32 / /dev/pts rw,nosuid,noexec,relatime - devpts devpts rw,gid=5,mode=620,ptmxmode=666 -81 77 0:33 / /sys ro,nosuid,nodev,noexec,relatime - sysfs sysfs ro -82 81 0:34 / /sys/fs/cgroup ro,nosuid,nodev,noexec,relatime - tmpfs tmpfs ro,mode=755 -83 82 0:19 /docker/3fc95ce32f84e9346c5fbd3bce38045e478aa5b067603955555cbff8445ba74f testdata/docker/sys/fs/cgroup/blkio ro,nosuid,nodev,noexec,relatime - cgroup cgroup rw,blkio -84 82 0:20 /docker/3fc95ce32f84e9346c5fbd3bce38045e478aa5b067603955555cbff8445ba74f testdata/docker/sys/fs/cgroup/cpu ro,nosuid,nodev,noexec,relatime - cgroup cgroup rw,cpu -85 82 0:21 /docker/3fc95ce32f84e9346c5fbd3bce38045e478aa5b067603955555cbff8445ba74f testdata/docker/sys/fs/cgroup/cpuacct ro,nosuid,nodev,noexec,relatime - cgroup cgroup rw,cpuacct -86 82 0:22 /docker/3fc95ce32f84e9346c5fbd3bce38045e478aa5b067603955555cbff8445ba74f testdata/docker/sys/fs/cgroup/cpuset ro,nosuid,nodev,noexec,relatime - cgroup cgroup rw,cpuset -87 82 0:23 /docker/3fc95ce32f84e9346c5fbd3bce38045e478aa5b067603955555cbff8445ba74f testdata/docker/sys/fs/cgroup/devices ro,nosuid,nodev,noexec,relatime - cgroup cgroup rw,devices -88 82 0:24 /docker/3fc95ce32f84e9346c5fbd3bce38045e478aa5b067603955555cbff8445ba74f testdata/docker/sys/fs/cgroup/freezer ro,nosuid,nodev,noexec,relatime - cgroup cgroup rw,freezer -89 82 0:25 /docker/3fc95ce32f84e9346c5fbd3bce38045e478aa5b067603955555cbff8445ba74f testdata/docker/sys/fs/cgroup/hugetlb ro,nosuid,nodev,noexec,relatime - cgroup cgroup rw,hugetlb -90 82 0:26 /docker/3fc95ce32f84e9346c5fbd3bce38045e478aa5b067603955555cbff8445ba74f testdata/docker/sys/fs/cgroup/memory ro,nosuid,nodev,noexec,relatime - cgroup cgroup rw,memory -91 82 0:27 /docker/3fc95ce32f84e9346c5fbd3bce38045e478aa5b067603955555cbff8445ba74f testdata/docker/sys/fs/cgroup/perf_event ro,nosuid,nodev,noexec,relatime - cgroup cgroup rw,perf_event -30 24 0:27 / testdata/docker/sys/fs/cgroup rw,nosuid,nodev,noexec,relatime shared:4 - cgroup2 cgroup2 rw,seclabel,nsdelegate,memory_recursiveprot -92 79 0:29 / /dev/mqueue rw,nosuid,nodev,noexec,relatime - mqueue mqueue rw -93 77 202:1 /var/lib/docker/containers/3fc95ce32f84e9346c5fbd3bce38045e478aa5b067603955555cbff8445ba74f/resolv.conf /etc/resolv.conf rw,noatime - ext4 /dev/xvda1 rw,data=ordered -94 77 202:1 /var/lib/docker/containers/3fc95ce32f84e9346c5fbd3bce38045e478aa5b067603955555cbff8445ba74f/hostname /etc/hostname rw,noatime - ext4 /dev/xvda1 rw,data=ordered -95 77 202:1 /var/lib/docker/containers/3fc95ce32f84e9346c5fbd3bce38045e478aa5b067603955555cbff8445ba74f/hosts /etc/hosts rw,noatime - ext4 /dev/xvda1 rw,data=ordered -96 79 0:28 / /dev/shm rw,nosuid,nodev,noexec,relatime - tmpfs shm rw,size=65536k -55 78 0:30 /bus /proc/bus ro,nosuid,nodev,noexec,relatime - proc proc rw -57 78 0:30 /fs /proc/fs ro,nosuid,nodev,noexec,relatime - proc proc rw -58 78 0:30 /irq /proc/irq ro,nosuid,nodev,noexec,relatime - proc proc rw -59 78 0:30 /sys /proc/sys ro,nosuid,nodev,noexec,relatime - proc proc rw -60 78 0:30 /sysrq-trigger /proc/sysrq-trigger ro,nosuid,nodev,noexec,relatime - proc proc rw -61 78 0:31 /null /proc/kcore rw,nosuid - tmpfs tmpfs rw,mode=755 -62 78 0:31 /null /proc/latency_stats rw,nosuid - tmpfs tmpfs rw,mode=755 -63 78 0:31 /null /proc/timer_stats rw,nosuid - tmpfs tmpfs rw,mode=755 -64 78 0:31 /null /proc/sched_debug rw,nosuid - tmpfs tmpfs rw,mode=755 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/blkio/blkio.reset_stats b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/blkio/blkio.reset_stats deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/blkio/cgroup.procs b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/blkio/cgroup.procs deleted file mode 100644 index 5a5566a91869..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/blkio/cgroup.procs +++ /dev/null @@ -1,138 +0,0 @@ -1 -2 -3 -5 -7 -8 -9 -10 -11 -13 -14 -15 -16 -18 -19 -20 -22 -23 -24 -25 -26 -27 -28 -29 -30 -31 -32 -33 -34 -35 -36 -37 -38 -40 -41 -42 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 -70 -71 -72 -73 -74 -75 -76 -77 -78 -79 -80 -81 -82 -83 -84 -85 -86 -87 -88 -89 -90 -91 -92 -93 -94 -95 -96 -97 -98 -99 -100 -101 -102 -103 -104 -105 -106 -107 -108 -109 -110 -111 -112 -113 -114 -115 -116 -117 -118 -119 -120 -123 -124 -151 -152 -155 -156 -157 -158 -171 -202 -272 -322 -323 -388 -519 -574 -575 -576 -620 -648 -659 -734 -748 -771 -772 -773 -777 -778 -795 -816 -885 -886 -909 -911 -912 -969 -975 -1293 -1294 -1296 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/blkio/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/blkio.reset_stats b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/blkio/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/blkio.reset_stats deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/blkio/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/blkio.throttle.io_service_bytes b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/blkio/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/blkio.throttle.io_service_bytes deleted file mode 100644 index c3fb43daa769..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/blkio/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/blkio.throttle.io_service_bytes +++ /dev/null @@ -1,16 +0,0 @@ -7:0 Read 4608 -7:0 Write 0 -7:0 Sync 0 -7:0 Async 4608 -7:0 Total 4608 -253:0 Read 4608 -253:0 Write 0 -253:0 Sync 0 -253:0 Async 4608 -253:0 Total 4608 -253:1 Read 1638912 -253:1 Write 0 -253:1 Sync 0 -253:1 Async 1638912 -253:1 Total 1638912 -Total 1648128 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/blkio/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/blkio.throttle.io_serviced b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/blkio/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/blkio.throttle.io_serviced deleted file mode 100644 index fa5ec53d7f36..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/blkio/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/blkio.throttle.io_serviced +++ /dev/null @@ -1,16 +0,0 @@ -7:0 Read 2 -7:0 Write 0 -7:0 Sync 0 -7:0 Async 2 -7:0 Total 2 -253:0 Read 2 -253:0 Write 0 -253:0 Sync 0 -253:0 Async 2 -253:0 Total 2 -253:1 Read 42 -253:1 Write 0 -253:1 Sync 0 -253:1 Async 42 -253:1 Total 42 -Total 46 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/blkio/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/blkio.throttle.read_bps_device b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/blkio/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/blkio.throttle.read_bps_device deleted file mode 100644 index 52071f6555ae..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/blkio/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/blkio.throttle.read_bps_device +++ /dev/null @@ -1 +0,0 @@ -7:0 1000 \ No newline at end of file diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/blkio/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/blkio.throttle.read_iops_device b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/blkio/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/blkio.throttle.read_iops_device deleted file mode 100644 index e05e306b1920..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/blkio/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/blkio.throttle.read_iops_device +++ /dev/null @@ -1 +0,0 @@ -7:0 2000 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/blkio/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/blkio.throttle.write_bps_device b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/blkio/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/blkio.throttle.write_bps_device deleted file mode 100644 index bf816b800f47..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/blkio/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/blkio.throttle.write_bps_device +++ /dev/null @@ -1 +0,0 @@ -7:0 3000 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/blkio/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/blkio.throttle.write_iops_device b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/blkio/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/blkio.throttle.write_iops_device deleted file mode 100644 index c3f292a55e7d..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/blkio/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/blkio.throttle.write_iops_device +++ /dev/null @@ -1 +0,0 @@ -7:0 4000 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/blkio/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/cgroup.clone_children b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/blkio/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/cgroup.clone_children deleted file mode 100644 index 573541ac9702..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/blkio/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/cgroup.clone_children +++ /dev/null @@ -1 +0,0 @@ -0 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/blkio/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/cgroup.procs b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/blkio/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/cgroup.procs deleted file mode 100644 index 2ab15755dfe0..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/blkio/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/cgroup.procs +++ /dev/null @@ -1 +0,0 @@ -11668 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/blkio/docker/blkio.reset_stats b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/blkio/docker/blkio.reset_stats deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/blkio/docker/blkio.tar b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/blkio/docker/blkio.tar deleted file mode 100644 index 5f32077ae740..000000000000 Binary files a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/blkio/docker/blkio.tar and /dev/null differ diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/blkio/docker/cgroup.clone_children b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/blkio/docker/cgroup.clone_children deleted file mode 100644 index 573541ac9702..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/blkio/docker/cgroup.clone_children +++ /dev/null @@ -1 +0,0 @@ -0 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/blkio/docker/cgroup.procs b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/blkio/docker/cgroup.procs deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpu/cgroup.procs b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpu/cgroup.procs deleted file mode 100644 index 5a5566a91869..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpu/cgroup.procs +++ /dev/null @@ -1,138 +0,0 @@ -1 -2 -3 -5 -7 -8 -9 -10 -11 -13 -14 -15 -16 -18 -19 -20 -22 -23 -24 -25 -26 -27 -28 -29 -30 -31 -32 -33 -34 -35 -36 -37 -38 -40 -41 -42 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 -70 -71 -72 -73 -74 -75 -76 -77 -78 -79 -80 -81 -82 -83 -84 -85 -86 -87 -88 -89 -90 -91 -92 -93 -94 -95 -96 -97 -98 -99 -100 -101 -102 -103 -104 -105 -106 -107 -108 -109 -110 -111 -112 -113 -114 -115 -116 -117 -118 -119 -120 -123 -124 -151 -152 -155 -156 -157 -158 -171 -202 -272 -322 -323 -388 -519 -574 -575 -576 -620 -648 -659 -734 -748 -771 -772 -773 -777 -778 -795 -816 -885 -886 -909 -911 -912 -969 -975 -1293 -1294 -1296 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpu/cpu.cfs_period_us b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpu/cpu.cfs_period_us deleted file mode 100644 index f7393e847d34..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpu/cpu.cfs_period_us +++ /dev/null @@ -1 +0,0 @@ -100000 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpu/cpu.cfs_quota_us b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpu/cpu.cfs_quota_us deleted file mode 100644 index 3a2e3f4984a0..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpu/cpu.cfs_quota_us +++ /dev/null @@ -1 +0,0 @@ --1 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpu/cpu.rt_period_us b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpu/cpu.rt_period_us deleted file mode 100644 index 749fce669df1..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpu/cpu.rt_period_us +++ /dev/null @@ -1 +0,0 @@ -1000000 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpu/cpu.rt_runtime_us b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpu/cpu.rt_runtime_us deleted file mode 100644 index 4527860f6ded..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpu/cpu.rt_runtime_us +++ /dev/null @@ -1 +0,0 @@ -950000 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpu/cpu.shares b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpu/cpu.shares deleted file mode 100644 index d7b1c440c0f3..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpu/cpu.shares +++ /dev/null @@ -1 +0,0 @@ -1024 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpu/cpu.stat b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpu/cpu.stat deleted file mode 100644 index dc3ac3ccee77..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpu/cpu.stat +++ /dev/null @@ -1,3 +0,0 @@ -nr_periods 0 -nr_throttled 0 -throttled_time 0 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpu/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/cgroup.clone_children b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpu/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/cgroup.clone_children deleted file mode 100644 index 573541ac9702..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpu/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/cgroup.clone_children +++ /dev/null @@ -1 +0,0 @@ -0 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpu/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/cgroup.procs b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpu/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/cgroup.procs deleted file mode 100644 index a8a1a9650ce8..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpu/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/cgroup.procs +++ /dev/null @@ -1 +0,0 @@ -985 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpu/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/cpu.cfs_period_us b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpu/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/cpu.cfs_period_us deleted file mode 100644 index f7393e847d34..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpu/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/cpu.cfs_period_us +++ /dev/null @@ -1 +0,0 @@ -100000 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpu/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/cpu.cfs_quota_us b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpu/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/cpu.cfs_quota_us deleted file mode 100644 index 3a2e3f4984a0..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpu/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/cpu.cfs_quota_us +++ /dev/null @@ -1 +0,0 @@ --1 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpu/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/cpu.rt_period_us b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpu/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/cpu.rt_period_us deleted file mode 100644 index 749fce669df1..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpu/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/cpu.rt_period_us +++ /dev/null @@ -1 +0,0 @@ -1000000 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpu/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/cpu.rt_runtime_us b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpu/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/cpu.rt_runtime_us deleted file mode 100644 index 573541ac9702..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpu/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/cpu.rt_runtime_us +++ /dev/null @@ -1 +0,0 @@ -0 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpu/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/cpu.shares b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpu/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/cpu.shares deleted file mode 100644 index d7b1c440c0f3..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpu/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/cpu.shares +++ /dev/null @@ -1 +0,0 @@ -1024 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpu/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/cpu.stat b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpu/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/cpu.stat deleted file mode 100644 index 2c96a158bb0c..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpu/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/cpu.stat +++ /dev/null @@ -1,3 +0,0 @@ -nr_periods 769021 -nr_throttled 1046 -throttled_time 352597023453 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpu/docker/cgroup.clone_children b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpu/docker/cgroup.clone_children deleted file mode 100644 index 573541ac9702..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpu/docker/cgroup.clone_children +++ /dev/null @@ -1 +0,0 @@ -0 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpu/docker/cgroup.procs b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpu/docker/cgroup.procs deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpu/docker/cpu.cfs_period_us b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpu/docker/cpu.cfs_period_us deleted file mode 100644 index f7393e847d34..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpu/docker/cpu.cfs_period_us +++ /dev/null @@ -1 +0,0 @@ -100000 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpu/docker/cpu.cfs_quota_us b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpu/docker/cpu.cfs_quota_us deleted file mode 100644 index 3a2e3f4984a0..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpu/docker/cpu.cfs_quota_us +++ /dev/null @@ -1 +0,0 @@ --1 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpu/docker/cpu.rt_period_us b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpu/docker/cpu.rt_period_us deleted file mode 100644 index 749fce669df1..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpu/docker/cpu.rt_period_us +++ /dev/null @@ -1 +0,0 @@ -1000000 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpu/docker/cpu.rt_runtime_us b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpu/docker/cpu.rt_runtime_us deleted file mode 100644 index 573541ac9702..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpu/docker/cpu.rt_runtime_us +++ /dev/null @@ -1 +0,0 @@ -0 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpu/docker/cpu.shares b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpu/docker/cpu.shares deleted file mode 100644 index d7b1c440c0f3..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpu/docker/cpu.shares +++ /dev/null @@ -1 +0,0 @@ -1024 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpu/docker/cpu.stat b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpu/docker/cpu.stat deleted file mode 100644 index dc3ac3ccee77..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpu/docker/cpu.stat +++ /dev/null @@ -1,3 +0,0 @@ -nr_periods 0 -nr_throttled 0 -throttled_time 0 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuacct/cgroup.procs b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuacct/cgroup.procs deleted file mode 100644 index 5a5566a91869..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuacct/cgroup.procs +++ /dev/null @@ -1,138 +0,0 @@ -1 -2 -3 -5 -7 -8 -9 -10 -11 -13 -14 -15 -16 -18 -19 -20 -22 -23 -24 -25 -26 -27 -28 -29 -30 -31 -32 -33 -34 -35 -36 -37 -38 -40 -41 -42 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 -70 -71 -72 -73 -74 -75 -76 -77 -78 -79 -80 -81 -82 -83 -84 -85 -86 -87 -88 -89 -90 -91 -92 -93 -94 -95 -96 -97 -98 -99 -100 -101 -102 -103 -104 -105 -106 -107 -108 -109 -110 -111 -112 -113 -114 -115 -116 -117 -118 -119 -120 -123 -124 -151 -152 -155 -156 -157 -158 -171 -202 -272 -322 -323 -388 -519 -574 -575 -576 -620 -648 -659 -734 -748 -771 -772 -773 -777 -778 -795 -816 -885 -886 -909 -911 -912 -969 -975 -1293 -1294 -1296 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuacct/cpuacct.stat b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuacct/cpuacct.stat deleted file mode 100644 index b663e4b31a06..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuacct/cpuacct.stat +++ /dev/null @@ -1,2 +0,0 @@ -user 6448 -system 1985 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuacct/cpuacct.usage b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuacct/cpuacct.usage deleted file mode 100644 index 464b8ca8525b..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuacct/cpuacct.usage +++ /dev/null @@ -1 +0,0 @@ -120001431605 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuacct/cpuacct.usage_percpu b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuacct/cpuacct.usage_percpu deleted file mode 100644 index 368991d586c0..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuacct/cpuacct.usage_percpu +++ /dev/null @@ -1 +0,0 @@ -34836133912 28229343655 28639675815 28193475900 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuacct/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/cgroup.clone_children b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuacct/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/cgroup.clone_children deleted file mode 100644 index 573541ac9702..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuacct/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/cgroup.clone_children +++ /dev/null @@ -1 +0,0 @@ -0 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuacct/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/cgroup.procs b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuacct/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/cgroup.procs deleted file mode 100644 index a8a1a9650ce8..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuacct/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/cgroup.procs +++ /dev/null @@ -1 +0,0 @@ -985 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuacct/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/cpuacct.stat b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuacct/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/cpuacct.stat deleted file mode 100644 index 22b5ff90a48e..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuacct/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/cpuacct.stat +++ /dev/null @@ -1,2 +0,0 @@ -user 6195 -system 773 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuacct/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/cpuacct.usage b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuacct/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/cpuacct.usage deleted file mode 100644 index 277fadba2887..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuacct/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/cpuacct.usage +++ /dev/null @@ -1 +0,0 @@ -95996653175 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuacct/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/cpuacct.usage_percpu b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuacct/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/cpuacct.usage_percpu deleted file mode 100644 index 2b5fe1e770a7..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuacct/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/cpuacct.usage_percpu +++ /dev/null @@ -1 +0,0 @@ -26571825468 23185259690 24300973729 21937433730 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuacct/docker/cgroup.clone_children b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuacct/docker/cgroup.clone_children deleted file mode 100644 index 573541ac9702..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuacct/docker/cgroup.clone_children +++ /dev/null @@ -1 +0,0 @@ -0 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuacct/docker/cgroup.procs b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuacct/docker/cgroup.procs deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuacct/docker/cpuacct.stat b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuacct/docker/cpuacct.stat deleted file mode 100644 index 22b5ff90a48e..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuacct/docker/cpuacct.stat +++ /dev/null @@ -1,2 +0,0 @@ -user 6195 -system 773 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuacct/docker/cpuacct.usage b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuacct/docker/cpuacct.usage deleted file mode 100644 index 92d53ba05513..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuacct/docker/cpuacct.usage +++ /dev/null @@ -1 +0,0 @@ -95996728295 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuacct/docker/cpuacct.usage_percpu b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuacct/docker/cpuacct.usage_percpu deleted file mode 100644 index 862194aae9a8..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuacct/docker/cpuacct.usage_percpu +++ /dev/null @@ -1 +0,0 @@ -26571825468 23184917033 24300973729 21937433730 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/cgroup.clone_children b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/cgroup.clone_children deleted file mode 100644 index 573541ac9702..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/cgroup.clone_children +++ /dev/null @@ -1 +0,0 @@ -0 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/cgroup.procs b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/cgroup.procs deleted file mode 100644 index 5a5566a91869..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/cgroup.procs +++ /dev/null @@ -1,138 +0,0 @@ -1 -2 -3 -5 -7 -8 -9 -10 -11 -13 -14 -15 -16 -18 -19 -20 -22 -23 -24 -25 -26 -27 -28 -29 -30 -31 -32 -33 -34 -35 -36 -37 -38 -40 -41 -42 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 -70 -71 -72 -73 -74 -75 -76 -77 -78 -79 -80 -81 -82 -83 -84 -85 -86 -87 -88 -89 -90 -91 -92 -93 -94 -95 -96 -97 -98 -99 -100 -101 -102 -103 -104 -105 -106 -107 -108 -109 -110 -111 -112 -113 -114 -115 -116 -117 -118 -119 -120 -123 -124 -151 -152 -155 -156 -157 -158 -171 -202 -272 -322 -323 -388 -519 -574 -575 -576 -620 -648 -659 -734 -748 -771 -772 -773 -777 -778 -795 -816 -885 -886 -909 -911 -912 -969 -975 -1293 -1294 -1296 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/cpuset.cpu_exclusive b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/cpuset.cpu_exclusive deleted file mode 100644 index d00491fd7e5b..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/cpuset.cpu_exclusive +++ /dev/null @@ -1 +0,0 @@ -1 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/cpuset.cpus b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/cpuset.cpus deleted file mode 100644 index 40c7bb2f1a2a..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/cpuset.cpus +++ /dev/null @@ -1 +0,0 @@ -0-3 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/cpuset.effective_cpus b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/cpuset.effective_cpus deleted file mode 100644 index 40c7bb2f1a2a..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/cpuset.effective_cpus +++ /dev/null @@ -1 +0,0 @@ -0-3 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/cpuset.effective_mems b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/cpuset.effective_mems deleted file mode 100644 index 573541ac9702..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/cpuset.effective_mems +++ /dev/null @@ -1 +0,0 @@ -0 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/cpuset.mem_exclusive b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/cpuset.mem_exclusive deleted file mode 100644 index d00491fd7e5b..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/cpuset.mem_exclusive +++ /dev/null @@ -1 +0,0 @@ -1 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/cpuset.mem_hardwall b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/cpuset.mem_hardwall deleted file mode 100644 index 573541ac9702..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/cpuset.mem_hardwall +++ /dev/null @@ -1 +0,0 @@ -0 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/cpuset.memory_migrate b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/cpuset.memory_migrate deleted file mode 100644 index 573541ac9702..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/cpuset.memory_migrate +++ /dev/null @@ -1 +0,0 @@ -0 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/cpuset.memory_pressure b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/cpuset.memory_pressure deleted file mode 100644 index 573541ac9702..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/cpuset.memory_pressure +++ /dev/null @@ -1 +0,0 @@ -0 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/cpuset.memory_pressure_enabled b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/cpuset.memory_pressure_enabled deleted file mode 100644 index 573541ac9702..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/cpuset.memory_pressure_enabled +++ /dev/null @@ -1 +0,0 @@ -0 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/cpuset.memory_spread_page b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/cpuset.memory_spread_page deleted file mode 100644 index 573541ac9702..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/cpuset.memory_spread_page +++ /dev/null @@ -1 +0,0 @@ -0 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/cpuset.memory_spread_slab b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/cpuset.memory_spread_slab deleted file mode 100644 index 573541ac9702..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/cpuset.memory_spread_slab +++ /dev/null @@ -1 +0,0 @@ -0 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/cpuset.mems b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/cpuset.mems deleted file mode 100644 index 573541ac9702..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/cpuset.mems +++ /dev/null @@ -1 +0,0 @@ -0 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/cpuset.sched_load_balance b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/cpuset.sched_load_balance deleted file mode 100644 index d00491fd7e5b..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/cpuset.sched_load_balance +++ /dev/null @@ -1 +0,0 @@ -1 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/cpuset.sched_relax_domain_level b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/cpuset.sched_relax_domain_level deleted file mode 100644 index 3a2e3f4984a0..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/cpuset.sched_relax_domain_level +++ /dev/null @@ -1 +0,0 @@ --1 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/cgroup.clone_children b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/cgroup.clone_children deleted file mode 100644 index 573541ac9702..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/cgroup.clone_children +++ /dev/null @@ -1 +0,0 @@ -0 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/cgroup.procs b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/cgroup.procs deleted file mode 100644 index a8a1a9650ce8..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/cgroup.procs +++ /dev/null @@ -1 +0,0 @@ -985 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/cpuset.cpu_exclusive b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/cpuset.cpu_exclusive deleted file mode 100644 index 573541ac9702..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/cpuset.cpu_exclusive +++ /dev/null @@ -1 +0,0 @@ -0 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/cpuset.cpus b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/cpuset.cpus deleted file mode 100644 index 40c7bb2f1a2a..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/cpuset.cpus +++ /dev/null @@ -1 +0,0 @@ -0-3 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/cpuset.effective_cpus b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/cpuset.effective_cpus deleted file mode 100644 index 40c7bb2f1a2a..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/cpuset.effective_cpus +++ /dev/null @@ -1 +0,0 @@ -0-3 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/cpuset.effective_mems b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/cpuset.effective_mems deleted file mode 100644 index 573541ac9702..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/cpuset.effective_mems +++ /dev/null @@ -1 +0,0 @@ -0 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/cpuset.mem_exclusive b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/cpuset.mem_exclusive deleted file mode 100644 index 573541ac9702..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/cpuset.mem_exclusive +++ /dev/null @@ -1 +0,0 @@ -0 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/cpuset.mem_hardwall b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/cpuset.mem_hardwall deleted file mode 100644 index 573541ac9702..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/cpuset.mem_hardwall +++ /dev/null @@ -1 +0,0 @@ -0 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/cpuset.memory_migrate b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/cpuset.memory_migrate deleted file mode 100644 index 573541ac9702..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/cpuset.memory_migrate +++ /dev/null @@ -1 +0,0 @@ -0 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/cpuset.memory_pressure b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/cpuset.memory_pressure deleted file mode 100644 index 573541ac9702..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/cpuset.memory_pressure +++ /dev/null @@ -1 +0,0 @@ -0 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/cpuset.memory_spread_page b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/cpuset.memory_spread_page deleted file mode 100644 index 573541ac9702..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/cpuset.memory_spread_page +++ /dev/null @@ -1 +0,0 @@ -0 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/cpuset.memory_spread_slab b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/cpuset.memory_spread_slab deleted file mode 100644 index 573541ac9702..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/cpuset.memory_spread_slab +++ /dev/null @@ -1 +0,0 @@ -0 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/cpuset.mems b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/cpuset.mems deleted file mode 100644 index 573541ac9702..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/cpuset.mems +++ /dev/null @@ -1 +0,0 @@ -0 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/cpuset.sched_load_balance b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/cpuset.sched_load_balance deleted file mode 100644 index d00491fd7e5b..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/cpuset.sched_load_balance +++ /dev/null @@ -1 +0,0 @@ -1 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/cpuset.sched_relax_domain_level b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/cpuset.sched_relax_domain_level deleted file mode 100644 index 3a2e3f4984a0..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/cpuset.sched_relax_domain_level +++ /dev/null @@ -1 +0,0 @@ --1 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/docker/cgroup.clone_children b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/docker/cgroup.clone_children deleted file mode 100644 index 573541ac9702..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/docker/cgroup.clone_children +++ /dev/null @@ -1 +0,0 @@ -0 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/docker/cgroup.procs b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/docker/cgroup.procs deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/docker/cpuset.cpu_exclusive b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/docker/cpuset.cpu_exclusive deleted file mode 100644 index 573541ac9702..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/docker/cpuset.cpu_exclusive +++ /dev/null @@ -1 +0,0 @@ -0 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/docker/cpuset.cpus b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/docker/cpuset.cpus deleted file mode 100644 index 40c7bb2f1a2a..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/docker/cpuset.cpus +++ /dev/null @@ -1 +0,0 @@ -0-3 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/docker/cpuset.effective_cpus b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/docker/cpuset.effective_cpus deleted file mode 100644 index 40c7bb2f1a2a..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/docker/cpuset.effective_cpus +++ /dev/null @@ -1 +0,0 @@ -0-3 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/docker/cpuset.effective_mems b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/docker/cpuset.effective_mems deleted file mode 100644 index 573541ac9702..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/docker/cpuset.effective_mems +++ /dev/null @@ -1 +0,0 @@ -0 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/docker/cpuset.mem_exclusive b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/docker/cpuset.mem_exclusive deleted file mode 100644 index 573541ac9702..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/docker/cpuset.mem_exclusive +++ /dev/null @@ -1 +0,0 @@ -0 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/docker/cpuset.mem_hardwall b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/docker/cpuset.mem_hardwall deleted file mode 100644 index 573541ac9702..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/docker/cpuset.mem_hardwall +++ /dev/null @@ -1 +0,0 @@ -0 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/docker/cpuset.memory_migrate b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/docker/cpuset.memory_migrate deleted file mode 100644 index 573541ac9702..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/docker/cpuset.memory_migrate +++ /dev/null @@ -1 +0,0 @@ -0 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/docker/cpuset.memory_pressure b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/docker/cpuset.memory_pressure deleted file mode 100644 index 573541ac9702..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/docker/cpuset.memory_pressure +++ /dev/null @@ -1 +0,0 @@ -0 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/docker/cpuset.memory_spread_page b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/docker/cpuset.memory_spread_page deleted file mode 100644 index 573541ac9702..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/docker/cpuset.memory_spread_page +++ /dev/null @@ -1 +0,0 @@ -0 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/docker/cpuset.memory_spread_slab b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/docker/cpuset.memory_spread_slab deleted file mode 100644 index 573541ac9702..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/docker/cpuset.memory_spread_slab +++ /dev/null @@ -1 +0,0 @@ -0 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/docker/cpuset.mems b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/docker/cpuset.mems deleted file mode 100644 index 573541ac9702..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/docker/cpuset.mems +++ /dev/null @@ -1 +0,0 @@ -0 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/docker/cpuset.sched_load_balance b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/docker/cpuset.sched_load_balance deleted file mode 100644 index d00491fd7e5b..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/docker/cpuset.sched_load_balance +++ /dev/null @@ -1 +0,0 @@ -1 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/docker/cpuset.sched_relax_domain_level b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/docker/cpuset.sched_relax_domain_level deleted file mode 100644 index 3a2e3f4984a0..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/cpuset/docker/cpuset.sched_relax_domain_level +++ /dev/null @@ -1 +0,0 @@ --1 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/cgroup.procs b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/cgroup.procs deleted file mode 100644 index 5a5566a91869..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/cgroup.procs +++ /dev/null @@ -1,138 +0,0 @@ -1 -2 -3 -5 -7 -8 -9 -10 -11 -13 -14 -15 -16 -18 -19 -20 -22 -23 -24 -25 -26 -27 -28 -29 -30 -31 -32 -33 -34 -35 -36 -37 -38 -40 -41 -42 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 -70 -71 -72 -73 -74 -75 -76 -77 -78 -79 -80 -81 -82 -83 -84 -85 -86 -87 -88 -89 -90 -91 -92 -93 -94 -95 -96 -97 -98 -99 -100 -101 -102 -103 -104 -105 -106 -107 -108 -109 -110 -111 -112 -113 -114 -115 -116 -117 -118 -119 -120 -123 -124 -151 -152 -155 -156 -157 -158 -171 -202 -272 -322 -323 -388 -519 -574 -575 -576 -620 -648 -659 -734 -748 -771 -772 -773 -777 -778 -795 -816 -885 -886 -909 -911 -912 -969 -975 -1293 -1294 -1296 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/cgroup.clone_children b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/cgroup.clone_children deleted file mode 100644 index 573541ac9702..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/cgroup.clone_children +++ /dev/null @@ -1 +0,0 @@ -0 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/cgroup.event_control b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/cgroup.event_control deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/cgroup.procs b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/cgroup.procs deleted file mode 100644 index a8a1a9650ce8..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/cgroup.procs +++ /dev/null @@ -1 +0,0 @@ -985 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/memory.failcnt b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/memory.failcnt deleted file mode 100644 index 573541ac9702..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/memory.failcnt +++ /dev/null @@ -1 +0,0 @@ -0 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/memory.force_empty b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/memory.force_empty deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/memory.kmem.failcnt b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/memory.kmem.failcnt deleted file mode 100644 index 573541ac9702..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/memory.kmem.failcnt +++ /dev/null @@ -1 +0,0 @@ -0 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/memory.kmem.limit_in_bytes b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/memory.kmem.limit_in_bytes deleted file mode 100644 index 564113cfaffa..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/memory.kmem.limit_in_bytes +++ /dev/null @@ -1 +0,0 @@ -9223372036854771712 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/memory.kmem.max_usage_in_bytes b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/memory.kmem.max_usage_in_bytes deleted file mode 100644 index e373ee695f6e..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/memory.kmem.max_usage_in_bytes +++ /dev/null @@ -1 +0,0 @@ -50 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/memory.kmem.slabinfo b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/memory.kmem.slabinfo deleted file mode 100644 index 337dfb28586b..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/memory.kmem.slabinfo +++ /dev/null @@ -1,2 +0,0 @@ -slabinfo - version: 2.1 -# name : tunables : slabdata diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/memory.kmem.tcp.failcnt b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/memory.kmem.tcp.failcnt deleted file mode 100644 index 573541ac9702..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/memory.kmem.tcp.failcnt +++ /dev/null @@ -1 +0,0 @@ -0 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/memory.kmem.tcp.limit_in_bytes b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/memory.kmem.tcp.limit_in_bytes deleted file mode 100644 index 564113cfaffa..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/memory.kmem.tcp.limit_in_bytes +++ /dev/null @@ -1 +0,0 @@ -9223372036854771712 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/memory.kmem.tcp.max_usage_in_bytes b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/memory.kmem.tcp.max_usage_in_bytes deleted file mode 100644 index 2bbd69c2e548..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/memory.kmem.tcp.max_usage_in_bytes +++ /dev/null @@ -1 +0,0 @@ -70 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/memory.kmem.tcp.usage_in_bytes b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/memory.kmem.tcp.usage_in_bytes deleted file mode 100644 index f599e28b8ab0..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/memory.kmem.tcp.usage_in_bytes +++ /dev/null @@ -1 +0,0 @@ -10 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/memory.kmem.usage_in_bytes b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/memory.kmem.usage_in_bytes deleted file mode 100644 index 425151f3a411..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/memory.kmem.usage_in_bytes +++ /dev/null @@ -1 +0,0 @@ -40 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/memory.limit_in_bytes b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/memory.limit_in_bytes deleted file mode 100644 index 564113cfaffa..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/memory.limit_in_bytes +++ /dev/null @@ -1 +0,0 @@ -9223372036854771712 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/memory.max_usage_in_bytes b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/memory.max_usage_in_bytes deleted file mode 100644 index 1711106a7da4..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/memory.max_usage_in_bytes +++ /dev/null @@ -1 +0,0 @@ -298532864 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/memory.memsw.failcnt b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/memory.memsw.failcnt deleted file mode 100644 index 573541ac9702..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/memory.memsw.failcnt +++ /dev/null @@ -1 +0,0 @@ -0 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/memory.memsw.limit_in_bytes b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/memory.memsw.limit_in_bytes deleted file mode 100644 index 564113cfaffa..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/memory.memsw.limit_in_bytes +++ /dev/null @@ -1 +0,0 @@ -9223372036854771712 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/memory.memsw.max_usage_in_bytes b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/memory.memsw.max_usage_in_bytes deleted file mode 100644 index 1711106a7da4..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/memory.memsw.max_usage_in_bytes +++ /dev/null @@ -1 +0,0 @@ -298532864 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/memory.memsw.usage_in_bytes b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/memory.memsw.usage_in_bytes deleted file mode 100644 index 01ae50941009..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/memory.memsw.usage_in_bytes +++ /dev/null @@ -1 +0,0 @@ -295997440 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/memory.move_charge_at_immigrate b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/memory.move_charge_at_immigrate deleted file mode 100644 index 573541ac9702..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/memory.move_charge_at_immigrate +++ /dev/null @@ -1 +0,0 @@ -0 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/memory.oom_control b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/memory.oom_control deleted file mode 100644 index 830834a9d9bc..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/memory.oom_control +++ /dev/null @@ -1,2 +0,0 @@ -oom_kill_disable 0 -under_oom 0 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/memory.pressure_level b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/memory.pressure_level deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/memory.soft_limit_in_bytes b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/memory.soft_limit_in_bytes deleted file mode 100644 index 564113cfaffa..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/memory.soft_limit_in_bytes +++ /dev/null @@ -1 +0,0 @@ -9223372036854771712 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/memory.stat b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/memory.stat deleted file mode 100644 index 528efd0e223c..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/memory.stat +++ /dev/null @@ -1,32 +0,0 @@ -cache 65101824 -rss 230662144 -rss_huge 174063616 -mapped_file 17633280 -writeback 0 -swap 0 -pgpgin 103258 -pgpgout 77551 -pgfault 91651 -pgmajfault 166 -inactive_anon 28672 -active_anon 230780928 -inactive_file 40108032 -active_file 24813568 -unevictable 0 -hierarchical_memory_limit 9223372036854771712 -hierarchical_memsw_limit 9223372036854771712 -total_cache 65101824 -total_rss 230662144 -total_rss_huge 174063616 -total_mapped_file 17633280 -total_writeback 0 -total_swap 0 -total_pgpgin 103258 -total_pgpgout 77551 -total_pgfault 91651 -total_pgmajfault 166 -total_inactive_anon 28672 -total_active_anon 230780928 -total_inactive_file 40108032 -total_active_file 24813568 -total_unevictable 0 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/memory.swappiness b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/memory.swappiness deleted file mode 100644 index abdfb053e41e..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/memory.swappiness +++ /dev/null @@ -1 +0,0 @@ -60 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/memory.usage_in_bytes b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/memory.usage_in_bytes deleted file mode 100644 index 01ae50941009..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/memory.usage_in_bytes +++ /dev/null @@ -1 +0,0 @@ -295997440 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/memory.use_hierarchy b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/memory.use_hierarchy deleted file mode 100644 index 573541ac9702..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242/memory.use_hierarchy +++ /dev/null @@ -1 +0,0 @@ -0 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/cgroup.clone_children b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/cgroup.clone_children deleted file mode 100644 index 573541ac9702..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/cgroup.clone_children +++ /dev/null @@ -1 +0,0 @@ -0 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/cgroup.event_control b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/cgroup.event_control deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/cgroup.procs b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/cgroup.procs deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/memory.failcnt b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/memory.failcnt deleted file mode 100644 index 573541ac9702..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/memory.failcnt +++ /dev/null @@ -1 +0,0 @@ -0 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/memory.force_empty b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/memory.force_empty deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/memory.kmem.failcnt b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/memory.kmem.failcnt deleted file mode 100644 index 573541ac9702..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/memory.kmem.failcnt +++ /dev/null @@ -1 +0,0 @@ -0 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/memory.kmem.limit_in_bytes b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/memory.kmem.limit_in_bytes deleted file mode 100644 index 564113cfaffa..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/memory.kmem.limit_in_bytes +++ /dev/null @@ -1 +0,0 @@ -9223372036854771712 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/memory.kmem.max_usage_in_bytes b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/memory.kmem.max_usage_in_bytes deleted file mode 100644 index 573541ac9702..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/memory.kmem.max_usage_in_bytes +++ /dev/null @@ -1 +0,0 @@ -0 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/memory.kmem.slabinfo b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/memory.kmem.slabinfo deleted file mode 100644 index 337dfb28586b..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/memory.kmem.slabinfo +++ /dev/null @@ -1,2 +0,0 @@ -slabinfo - version: 2.1 -# name : tunables : slabdata diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/memory.kmem.tcp.failcnt b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/memory.kmem.tcp.failcnt deleted file mode 100644 index 573541ac9702..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/memory.kmem.tcp.failcnt +++ /dev/null @@ -1 +0,0 @@ -0 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/memory.kmem.tcp.limit_in_bytes b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/memory.kmem.tcp.limit_in_bytes deleted file mode 100644 index 564113cfaffa..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/memory.kmem.tcp.limit_in_bytes +++ /dev/null @@ -1 +0,0 @@ -9223372036854771712 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/memory.kmem.tcp.max_usage_in_bytes b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/memory.kmem.tcp.max_usage_in_bytes deleted file mode 100644 index 573541ac9702..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/memory.kmem.tcp.max_usage_in_bytes +++ /dev/null @@ -1 +0,0 @@ -0 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/memory.kmem.tcp.usage_in_bytes b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/memory.kmem.tcp.usage_in_bytes deleted file mode 100644 index 573541ac9702..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/memory.kmem.tcp.usage_in_bytes +++ /dev/null @@ -1 +0,0 @@ -0 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/memory.kmem.usage_in_bytes b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/memory.kmem.usage_in_bytes deleted file mode 100644 index 573541ac9702..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/memory.kmem.usage_in_bytes +++ /dev/null @@ -1 +0,0 @@ -0 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/memory.limit_in_bytes b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/memory.limit_in_bytes deleted file mode 100644 index 564113cfaffa..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/memory.limit_in_bytes +++ /dev/null @@ -1 +0,0 @@ -9223372036854771712 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/memory.max_usage_in_bytes b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/memory.max_usage_in_bytes deleted file mode 100644 index 573541ac9702..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/memory.max_usage_in_bytes +++ /dev/null @@ -1 +0,0 @@ -0 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/memory.memsw.failcnt b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/memory.memsw.failcnt deleted file mode 100644 index 573541ac9702..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/memory.memsw.failcnt +++ /dev/null @@ -1 +0,0 @@ -0 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/memory.memsw.limit_in_bytes b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/memory.memsw.limit_in_bytes deleted file mode 100644 index 564113cfaffa..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/memory.memsw.limit_in_bytes +++ /dev/null @@ -1 +0,0 @@ -9223372036854771712 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/memory.memsw.max_usage_in_bytes b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/memory.memsw.max_usage_in_bytes deleted file mode 100644 index 573541ac9702..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/memory.memsw.max_usage_in_bytes +++ /dev/null @@ -1 +0,0 @@ -0 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/memory.memsw.usage_in_bytes b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/memory.memsw.usage_in_bytes deleted file mode 100644 index 573541ac9702..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/memory.memsw.usage_in_bytes +++ /dev/null @@ -1 +0,0 @@ -0 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/memory.move_charge_at_immigrate b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/memory.move_charge_at_immigrate deleted file mode 100644 index 573541ac9702..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/memory.move_charge_at_immigrate +++ /dev/null @@ -1 +0,0 @@ -0 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/memory.oom_control b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/memory.oom_control deleted file mode 100644 index 830834a9d9bc..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/memory.oom_control +++ /dev/null @@ -1,2 +0,0 @@ -oom_kill_disable 0 -under_oom 0 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/memory.pressure_level b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/memory.pressure_level deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/memory.soft_limit_in_bytes b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/memory.soft_limit_in_bytes deleted file mode 100644 index 564113cfaffa..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/memory.soft_limit_in_bytes +++ /dev/null @@ -1 +0,0 @@ -9223372036854771712 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/memory.stat b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/memory.stat deleted file mode 100644 index ae9efcefeb03..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/memory.stat +++ /dev/null @@ -1,32 +0,0 @@ -cache 0 -rss 0 -rss_huge 0 -mapped_file 0 -writeback 0 -swap 0 -pgpgin 0 -pgpgout 0 -pgfault 0 -pgmajfault 0 -inactive_anon 0 -active_anon 0 -inactive_file 0 -active_file 0 -unevictable 0 -hierarchical_memory_limit 9223372036854771712 -hierarchical_memsw_limit 9223372036854771712 -total_cache 0 -total_rss 0 -total_rss_huge 0 -total_mapped_file 0 -total_writeback 0 -total_swap 0 -total_pgpgin 0 -total_pgpgout 0 -total_pgfault 0 -total_pgmajfault 0 -total_inactive_anon 0 -total_active_anon 0 -total_inactive_file 0 -total_active_file 0 -total_unevictable 0 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/memory.swappiness b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/memory.swappiness deleted file mode 100644 index abdfb053e41e..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/memory.swappiness +++ /dev/null @@ -1 +0,0 @@ -60 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/memory.usage_in_bytes b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/memory.usage_in_bytes deleted file mode 100644 index 573541ac9702..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/memory.usage_in_bytes +++ /dev/null @@ -1 +0,0 @@ -0 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/memory.use_hierarchy b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/memory.use_hierarchy deleted file mode 100644 index 573541ac9702..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/docker/memory.use_hierarchy +++ /dev/null @@ -1 +0,0 @@ -0 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/memory.failcnt b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/memory.failcnt deleted file mode 100644 index 573541ac9702..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/memory.failcnt +++ /dev/null @@ -1 +0,0 @@ -0 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/memory.kmem.failcnt b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/memory.kmem.failcnt deleted file mode 100644 index 573541ac9702..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/memory.kmem.failcnt +++ /dev/null @@ -1 +0,0 @@ -0 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/memory.kmem.limit_in_bytes b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/memory.kmem.limit_in_bytes deleted file mode 100644 index 564113cfaffa..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/memory.kmem.limit_in_bytes +++ /dev/null @@ -1 +0,0 @@ -9223372036854771712 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/memory.kmem.max_usage_in_bytes b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/memory.kmem.max_usage_in_bytes deleted file mode 100644 index 573541ac9702..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/memory.kmem.max_usage_in_bytes +++ /dev/null @@ -1 +0,0 @@ -0 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/memory.kmem.slabinfo b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/memory.kmem.slabinfo deleted file mode 100644 index 337dfb28586b..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/memory.kmem.slabinfo +++ /dev/null @@ -1,2 +0,0 @@ -slabinfo - version: 2.1 -# name : tunables : slabdata diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/memory.kmem.tcp.failcnt b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/memory.kmem.tcp.failcnt deleted file mode 100644 index 573541ac9702..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/memory.kmem.tcp.failcnt +++ /dev/null @@ -1 +0,0 @@ -0 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/memory.kmem.tcp.limit_in_bytes b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/memory.kmem.tcp.limit_in_bytes deleted file mode 100644 index 8fbcdbec32c2..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/memory.kmem.tcp.limit_in_bytes +++ /dev/null @@ -1 +0,0 @@ -2251799813685247 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/memory.kmem.tcp.max_usage_in_bytes b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/memory.kmem.tcp.max_usage_in_bytes deleted file mode 100644 index 573541ac9702..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/memory.kmem.tcp.max_usage_in_bytes +++ /dev/null @@ -1 +0,0 @@ -0 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/memory.kmem.tcp.usage_in_bytes b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/memory.kmem.tcp.usage_in_bytes deleted file mode 100644 index 252cb6691949..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/memory.kmem.tcp.usage_in_bytes +++ /dev/null @@ -1 +0,0 @@ -8192 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/memory.kmem.usage_in_bytes b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/memory.kmem.usage_in_bytes deleted file mode 100644 index 573541ac9702..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/memory.kmem.usage_in_bytes +++ /dev/null @@ -1 +0,0 @@ -0 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/memory.limit_in_bytes b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/memory.limit_in_bytes deleted file mode 100644 index 564113cfaffa..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/memory.limit_in_bytes +++ /dev/null @@ -1 +0,0 @@ -9223372036854771712 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/memory.max_usage_in_bytes b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/memory.max_usage_in_bytes deleted file mode 100644 index 573541ac9702..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/memory.max_usage_in_bytes +++ /dev/null @@ -1 +0,0 @@ -0 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/memory.memsw.failcnt b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/memory.memsw.failcnt deleted file mode 100644 index 573541ac9702..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/memory.memsw.failcnt +++ /dev/null @@ -1 +0,0 @@ -0 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/memory.memsw.limit_in_bytes b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/memory.memsw.limit_in_bytes deleted file mode 100644 index 564113cfaffa..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/memory.memsw.limit_in_bytes +++ /dev/null @@ -1 +0,0 @@ -9223372036854771712 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/memory.memsw.max_usage_in_bytes b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/memory.memsw.max_usage_in_bytes deleted file mode 100644 index 573541ac9702..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/memory.memsw.max_usage_in_bytes +++ /dev/null @@ -1 +0,0 @@ -0 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/memory.memsw.usage_in_bytes b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/memory.memsw.usage_in_bytes deleted file mode 100644 index d976c30229db..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/memory.memsw.usage_in_bytes +++ /dev/null @@ -1 +0,0 @@ -484511744 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/memory.oom_control b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/memory.oom_control deleted file mode 100644 index 830834a9d9bc..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/memory.oom_control +++ /dev/null @@ -1,2 +0,0 @@ -oom_kill_disable 0 -under_oom 0 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/memory.pressure_level b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/memory.pressure_level deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/memory.soft_limit_in_bytes b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/memory.soft_limit_in_bytes deleted file mode 100644 index 564113cfaffa..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/memory.soft_limit_in_bytes +++ /dev/null @@ -1 +0,0 @@ -9223372036854771712 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/memory.stat b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/memory.stat deleted file mode 100644 index 0e93ebae41c8..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/memory.stat +++ /dev/null @@ -1,32 +0,0 @@ -cache 170680320 -rss 18067456 -rss_huge 8388608 -mapped_file 23158784 -writeback 0 -swap 0 -pgpgin 121472 -pgpgout 79990 -pgfault 109100 -pgmajfault 0 -inactive_anon 87015424 -active_anon 51908608 -inactive_file 598016 -active_file 49184768 -unevictable 0 -hierarchical_memory_limit 9223372036854771712 -hierarchical_memsw_limit 9223372036854771712 -total_cache 235782144 -total_rss 248729600 -total_rss_huge 182452224 -total_mapped_file 40792064 -total_writeback 0 -total_swap 0 -total_pgpgin 224730 -total_pgpgout 157541 -total_pgfault 200751 -total_pgmajfault 166 -total_inactive_anon 87044096 -total_active_anon 282689536 -total_inactive_file 40706048 -total_active_file 73998336 -total_unevictable 0 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/memory.swappiness b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/memory.swappiness deleted file mode 100644 index abdfb053e41e..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/memory.swappiness +++ /dev/null @@ -1 +0,0 @@ -60 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/memory.usage_in_bytes b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/memory.usage_in_bytes deleted file mode 100644 index 0228a9adaddc..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/memory/memory.usage_in_bytes +++ /dev/null @@ -1 +0,0 @@ -484491264 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/cpu.max b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/cpu.max deleted file mode 100644 index 1c1d3e7c303f..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/cpu.max +++ /dev/null @@ -1 +0,0 @@ -max 100000 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/cpu.pressure b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/cpu.pressure deleted file mode 100644 index a2ee5c822d35..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/cpu.pressure +++ /dev/null @@ -1 +0,0 @@ -some avg10=0.00 avg60=0.04 avg300=0.00 total=2798967170 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/cpu.stat b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/cpu.stat deleted file mode 100644 index 03e2c5102994..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/cpu.stat +++ /dev/null @@ -1,6 +0,0 @@ -usage_usec 738173847375 -user_usec 512367519674 -system_usec 225806327701 -nr_periods 0 -nr_throttled 0 -throttled_usec 0 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/docker-1c8fa019edd4b9d4b2856f4932c55929c5c118c808ed5faee9a135ca6e84b039.scope/cgroup.stat b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/docker-1c8fa019edd4b9d4b2856f4932c55929c5c118c808ed5faee9a135ca6e84b039.scope/cgroup.stat deleted file mode 100755 index d5539a574a1e..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/docker-1c8fa019edd4b9d4b2856f4932c55929c5c118c808ed5faee9a135ca6e84b039.scope/cgroup.stat +++ /dev/null @@ -1,2 +0,0 @@ -nr_descendants 0 -nr_dying_descendants 0 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/docker-1c8fa019edd4b9d4b2856f4932c55929c5c118c808ed5faee9a135ca6e84b039.scope/cpu.pressure b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/docker-1c8fa019edd4b9d4b2856f4932c55929c5c118c808ed5faee9a135ca6e84b039.scope/cpu.pressure deleted file mode 100644 index dd673d9a7261..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/docker-1c8fa019edd4b9d4b2856f4932c55929c5c118c808ed5faee9a135ca6e84b039.scope/cpu.pressure +++ /dev/null @@ -1 +0,0 @@ -some avg10=4.30 avg60=3.20 avg300=1.11 total=1676316 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/docker-1c8fa019edd4b9d4b2856f4932c55929c5c118c808ed5faee9a135ca6e84b039.scope/cpu.stat b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/docker-1c8fa019edd4b9d4b2856f4932c55929c5c118c808ed5faee9a135ca6e84b039.scope/cpu.stat deleted file mode 100755 index bf52161426d5..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/docker-1c8fa019edd4b9d4b2856f4932c55929c5c118c808ed5faee9a135ca6e84b039.scope/cpu.stat +++ /dev/null @@ -1,6 +0,0 @@ -usage_usec 26772130245 -user_usec 20979069928 -system_usec 5793060316 -nr_periods 1 -nr_throttled 4 -throttled_usec 10 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/docker-1c8fa019edd4b9d4b2856f4932c55929c5c118c808ed5faee9a135ca6e84b039.scope/io.pressure b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/docker-1c8fa019edd4b9d4b2856f4932c55929c5c118c808ed5faee9a135ca6e84b039.scope/io.pressure deleted file mode 100644 index d7ecfee11332..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/docker-1c8fa019edd4b9d4b2856f4932c55929c5c118c808ed5faee9a135ca6e84b039.scope/io.pressure +++ /dev/null @@ -1,2 +0,0 @@ -some avg10=3.00 avg60=2.10 avg300=4.00 total=1154482 -full avg10=10.00 avg60=30.00 avg300=0.50 total=1154482 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/docker-1c8fa019edd4b9d4b2856f4932c55929c5c118c808ed5faee9a135ca6e84b039.scope/io.stat b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/docker-1c8fa019edd4b9d4b2856f4932c55929c5c118c808ed5faee9a135ca6e84b039.scope/io.stat deleted file mode 100755 index 9e9d5d68ca91..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/docker-1c8fa019edd4b9d4b2856f4932c55929c5c118c808ed5faee9a135ca6e84b039.scope/io.stat +++ /dev/null @@ -1,2 +0,0 @@ -8:0 rbytes=512 wbytes=4096 rios=100 wios=1 dbytes=5 dios=23 -253:0 rbytes=1024 wbytes=4096 rios=1 wios=1 dbytes=6 dios=8 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/docker-1c8fa019edd4b9d4b2856f4932c55929c5c118c808ed5faee9a135ca6e84b039.scope/memory.current b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/docker-1c8fa019edd4b9d4b2856f4932c55929c5c118c808ed5faee9a135ca6e84b039.scope/memory.current deleted file mode 100755 index b3b9271eddf3..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/docker-1c8fa019edd4b9d4b2856f4932c55929c5c118c808ed5faee9a135ca6e84b039.scope/memory.current +++ /dev/null @@ -1 +0,0 @@ -9125888 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/docker-1c8fa019edd4b9d4b2856f4932c55929c5c118c808ed5faee9a135ca6e84b039.scope/memory.events b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/docker-1c8fa019edd4b9d4b2856f4932c55929c5c118c808ed5faee9a135ca6e84b039.scope/memory.events deleted file mode 100755 index 22aa1c57bb56..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/docker-1c8fa019edd4b9d4b2856f4932c55929c5c118c808ed5faee9a135ca6e84b039.scope/memory.events +++ /dev/null @@ -1,5 +0,0 @@ -low 10 -high 3 -max 2 -oom 1 -oom_kill 1 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/docker-1c8fa019edd4b9d4b2856f4932c55929c5c118c808ed5faee9a135ca6e84b039.scope/memory.events.local b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/docker-1c8fa019edd4b9d4b2856f4932c55929c5c118c808ed5faee9a135ca6e84b039.scope/memory.events.local deleted file mode 100755 index 5d252aed09bd..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/docker-1c8fa019edd4b9d4b2856f4932c55929c5c118c808ed5faee9a135ca6e84b039.scope/memory.events.local +++ /dev/null @@ -1,5 +0,0 @@ -low 0 -high 0 -max 0 -oom 0 -oom_kill 0 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/docker-1c8fa019edd4b9d4b2856f4932c55929c5c118c808ed5faee9a135ca6e84b039.scope/memory.high b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/docker-1c8fa019edd4b9d4b2856f4932c55929c5c118c808ed5faee9a135ca6e84b039.scope/memory.high deleted file mode 100755 index 355295a05af4..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/docker-1c8fa019edd4b9d4b2856f4932c55929c5c118c808ed5faee9a135ca6e84b039.scope/memory.high +++ /dev/null @@ -1 +0,0 @@ -max diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/docker-1c8fa019edd4b9d4b2856f4932c55929c5c118c808ed5faee9a135ca6e84b039.scope/memory.low b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/docker-1c8fa019edd4b9d4b2856f4932c55929c5c118c808ed5faee9a135ca6e84b039.scope/memory.low deleted file mode 100755 index b8626c4cff28..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/docker-1c8fa019edd4b9d4b2856f4932c55929c5c118c808ed5faee9a135ca6e84b039.scope/memory.low +++ /dev/null @@ -1 +0,0 @@ -4 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/docker-1c8fa019edd4b9d4b2856f4932c55929c5c118c808ed5faee9a135ca6e84b039.scope/memory.max b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/docker-1c8fa019edd4b9d4b2856f4932c55929c5c118c808ed5faee9a135ca6e84b039.scope/memory.max deleted file mode 100755 index 355295a05af4..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/docker-1c8fa019edd4b9d4b2856f4932c55929c5c118c808ed5faee9a135ca6e84b039.scope/memory.max +++ /dev/null @@ -1 +0,0 @@ -max diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/docker-1c8fa019edd4b9d4b2856f4932c55929c5c118c808ed5faee9a135ca6e84b039.scope/memory.min b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/docker-1c8fa019edd4b9d4b2856f4932c55929c5c118c808ed5faee9a135ca6e84b039.scope/memory.min deleted file mode 100755 index 573541ac9702..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/docker-1c8fa019edd4b9d4b2856f4932c55929c5c118c808ed5faee9a135ca6e84b039.scope/memory.min +++ /dev/null @@ -1 +0,0 @@ -0 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/docker-1c8fa019edd4b9d4b2856f4932c55929c5c118c808ed5faee9a135ca6e84b039.scope/memory.pressure b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/docker-1c8fa019edd4b9d4b2856f4932c55929c5c118c808ed5faee9a135ca6e84b039.scope/memory.pressure deleted file mode 100755 index 30c03cc4048b..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/docker-1c8fa019edd4b9d4b2856f4932c55929c5c118c808ed5faee9a135ca6e84b039.scope/memory.pressure +++ /dev/null @@ -1,2 +0,0 @@ -some avg10=0.00 avg60=0.00 avg300=0.00 total=0 -full avg10=0.00 avg60=0.00 avg300=0.00 total=0 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/docker-1c8fa019edd4b9d4b2856f4932c55929c5c118c808ed5faee9a135ca6e84b039.scope/memory.stat b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/docker-1c8fa019edd4b9d4b2856f4932c55929c5c118c808ed5faee9a135ca6e84b039.scope/memory.stat deleted file mode 100755 index edcfc6a46c8e..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/docker-1c8fa019edd4b9d4b2856f4932c55929c5c118c808ed5faee9a135ca6e84b039.scope/memory.stat +++ /dev/null @@ -1,40 +0,0 @@ -anon 411045888 -file 0 -kernel_stack 589824 -pagetables 12029952 -percpu 1152 -sock 0 -shmem 0 -file_mapped 0 -file_dirty 0 -file_writeback 0 -swapcached 0 -anon_thp 0 -file_thp 0 -shmem_thp 0 -inactive_anon 411316224 -active_anon 270336 -inactive_file 270336 -active_file 0 -unevictable 10 -slab_reclaimable 17756400 -slab_unreclaimable 2177424 -slab 19933824 -workingset_refault_anon 5 -workingset_refault_file 5 -workingset_activate_anon 5 -workingset_activate_file 5 -workingset_restore_anon 5 -workingset_restore_file 5 -workingset_nodereclaim 5 -pgfault 580970907 -pgmajfault 0 -pgrefill 0 -pgscan 0 -pgsteal 0 -pgactivate 46794 -pgdeactivate 0 -pglazyfree 119427 -pglazyfreed 0 -thp_fault_alloc 12 -thp_collapse_alloc 0 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/docker-1c8fa019edd4b9d4b2856f4932c55929c5c118c808ed5faee9a135ca6e84b039.scope/memory.swap.current b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/docker-1c8fa019edd4b9d4b2856f4932c55929c5c118c808ed5faee9a135ca6e84b039.scope/memory.swap.current deleted file mode 100755 index 573541ac9702..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/docker-1c8fa019edd4b9d4b2856f4932c55929c5c118c808ed5faee9a135ca6e84b039.scope/memory.swap.current +++ /dev/null @@ -1 +0,0 @@ -0 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/docker-1c8fa019edd4b9d4b2856f4932c55929c5c118c808ed5faee9a135ca6e84b039.scope/memory.swap.events b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/docker-1c8fa019edd4b9d4b2856f4932c55929c5c118c808ed5faee9a135ca6e84b039.scope/memory.swap.events deleted file mode 100755 index c64576a3cc23..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/docker-1c8fa019edd4b9d4b2856f4932c55929c5c118c808ed5faee9a135ca6e84b039.scope/memory.swap.events +++ /dev/null @@ -1,3 +0,0 @@ -high 4 -max 5 -fail 1 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/docker-1c8fa019edd4b9d4b2856f4932c55929c5c118c808ed5faee9a135ca6e84b039.scope/memory.swap.high b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/docker-1c8fa019edd4b9d4b2856f4932c55929c5c118c808ed5faee9a135ca6e84b039.scope/memory.swap.high deleted file mode 100755 index 355295a05af4..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/docker-1c8fa019edd4b9d4b2856f4932c55929c5c118c808ed5faee9a135ca6e84b039.scope/memory.swap.high +++ /dev/null @@ -1 +0,0 @@ -max diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/docker-1c8fa019edd4b9d4b2856f4932c55929c5c118c808ed5faee9a135ca6e84b039.scope/memory.swap.max b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/docker-1c8fa019edd4b9d4b2856f4932c55929c5c118c808ed5faee9a135ca6e84b039.scope/memory.swap.max deleted file mode 100755 index 355295a05af4..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/docker-1c8fa019edd4b9d4b2856f4932c55929c5c118c808ed5faee9a135ca6e84b039.scope/memory.swap.max +++ /dev/null @@ -1 +0,0 @@ -max diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/io.latency b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/io.latency deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/io.max b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/io.max deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/io.pressure b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/io.pressure deleted file mode 100644 index cd3cee6c2f36..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/io.pressure +++ /dev/null @@ -1,2 +0,0 @@ -some avg10=0.00 avg60=0.00 avg300=0.00 total=105680790 -full avg10=0.00 avg60=0.00 avg300=0.00 total=103282599 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/io.stat b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/io.stat deleted file mode 100644 index dc8243a661de..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/io.stat +++ /dev/null @@ -1,3 +0,0 @@ -252:0 rbytes=4096 wbytes=4096 rios=1 wios=1 dbytes=0 dios=0 -8:0 rbytes=14598439936 wbytes=613809529856 rios=151279 wios=47321130 dbytes=0 dios=0 -253:0 rbytes=14590931456 wbytes=613804409344 rios=150746 wios=44621629 dbytes=0 dios=0 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/io.weight b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/io.weight deleted file mode 100644 index 14c210f6f3d2..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/io.weight +++ /dev/null @@ -1 +0,0 @@ -default 100 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/memory.current b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/memory.current deleted file mode 100644 index 4339c0994475..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/memory.current +++ /dev/null @@ -1 +0,0 @@ -11583053824 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/memory.events b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/memory.events deleted file mode 100644 index 5d252aed09bd..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/memory.events +++ /dev/null @@ -1,5 +0,0 @@ -low 0 -high 0 -max 0 -oom 0 -oom_kill 0 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/memory.high b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/memory.high deleted file mode 100644 index 355295a05af4..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/memory.high +++ /dev/null @@ -1 +0,0 @@ -max diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/memory.low b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/memory.low deleted file mode 100644 index 573541ac9702..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/memory.low +++ /dev/null @@ -1 +0,0 @@ -0 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/memory.max b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/memory.max deleted file mode 100644 index 355295a05af4..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/memory.max +++ /dev/null @@ -1 +0,0 @@ -max diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/memory.min b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/memory.min deleted file mode 100644 index 573541ac9702..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/memory.min +++ /dev/null @@ -1 +0,0 @@ -0 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/memory.pressure b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/memory.pressure deleted file mode 100644 index 30c03cc4048b..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/memory.pressure +++ /dev/null @@ -1,2 +0,0 @@ -some avg10=0.00 avg60=0.00 avg300=0.00 total=0 -full avg10=0.00 avg60=0.00 avg300=0.00 total=0 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/memory.stat b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/memory.stat deleted file mode 100644 index c2117d135591..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/memory.stat +++ /dev/null @@ -1,40 +0,0 @@ -anon 3531862016 -file 7489388544 -kernel_stack 22315008 -pagetables 39469056 -percpu 15005856 -sock 1482752 -shmem 675840 -file_mapped 730177536 -file_dirty 1757184 -file_writeback 0 -swapcached 0 -anon_thp 12582912 -file_thp 0 -shmem_thp 0 -inactive_anon 3454943232 -active_anon 3108864 -inactive_file 6605029376 -active_file 968343552 -unevictable 0 -slab_reclaimable 443891040 -slab_unreclaimable 67280688 -slab 511171728 -workingset_refault_anon 0 -workingset_refault_file 0 -workingset_activate_anon 0 -workingset_activate_file 0 -workingset_restore_anon 0 -workingset_restore_file 0 -workingset_nodereclaim 0 -pgfault 24359248243 -pgmajfault 5713 -pgrefill 0 -pgscan 0 -pgsteal 0 -pgactivate 68040709 -pgdeactivate 0 -pglazyfree 1896099 -pglazyfreed 0 -thp_fault_alloc 300 -thp_collapse_alloc 43 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/memory.swap.current b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/memory.swap.current deleted file mode 100644 index 573541ac9702..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/memory.swap.current +++ /dev/null @@ -1 +0,0 @@ -0 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/memory.swap.events b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/memory.swap.events deleted file mode 100644 index e9cc0ab2491e..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/memory.swap.events +++ /dev/null @@ -1,3 +0,0 @@ -high 0 -max 0 -fail 0 diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/memory.swap.high b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/memory.swap.high deleted file mode 100644 index 355295a05af4..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/memory.swap.high +++ /dev/null @@ -1 +0,0 @@ -max diff --git a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/memory.swap.max b/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/memory.swap.max deleted file mode 100644 index 355295a05af4..000000000000 --- a/libbeat/metric/system/cgroup/testdata/docker/sys/fs/cgroup/system.slice/memory.swap.max +++ /dev/null @@ -1 +0,0 @@ -max diff --git a/libbeat/metric/system/cgroup/util.go b/libbeat/metric/system/cgroup/util.go deleted file mode 100644 index 7ddf49d701e7..000000000000 --- a/libbeat/metric/system/cgroup/util.go +++ /dev/null @@ -1,307 +0,0 @@ -// Licensed to Elasticsearch B.V. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Elasticsearch B.V. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package cgroup - -import ( - "bufio" - "fmt" - "io/ioutil" - "os" - "path/filepath" - "strconv" - "strings" - - "github.com/pkg/errors" - - "github.com/elastic/beats/v7/libbeat/metric/system/resolve" - "github.com/elastic/elastic-agent-libs/logp" -) - -var ( - // ErrCgroupsMissing indicates the /proc/cgroups was not found. This means - // that cgroups were disabled at compile time (CONFIG_CGROUPS=n) or that - // an invalid rootfs path was given. - ErrCgroupsMissing = errors.New("cgroups not found or unsupported by OS") -) - -// mountinfo represents a subset of the fields containing /proc/[pid]/mountinfo. -type mountinfo struct { - mountpoint string - filesystemType string - superOptions []string -} - -// Mountpoints organizes info about V1 and V2 cgroup mountpoints -// V2 uses a "unified" hierarchy, so we have less to keep track of -type Mountpoints struct { - V1Mounts map[string]string - V2Loc string -} - -// ControllerPath wraps the controller path -type ControllerPath struct { - ControllerPath string - FullPath string - IsV2 bool -} - -// PathList contains the V1 and V2 controller paths in a process -// Separate the V1 and V2 cgroups so we don't have hybrid cgroups fighting for one namespace -type PathList struct { - V1 map[string]ControllerPath - V2 map[string]ControllerPath -} - -// Flatten combines the V1 and V2 cgroups in cases where we don't need a map with keys -func (pl PathList) Flatten() []ControllerPath { - list := []ControllerPath{} - for _, v1 := range pl.V1 { - list = append(list, v1) - } - for _, v2 := range pl.V2 { - list = append(list, v2) - } - - return list -} - -// parseMountinfoLine parses a line from the /proc/[pid]/mountinfo file on -// Linux. The format of the line is specified in section 3.5 of -// https://www.kernel.org/doc/Documentation/filesystems/proc.txt. -func parseMountinfoLine(line string) (mountinfo, error) { - mount := mountinfo{} - - fields := strings.Fields(line) - if len(fields) < 10 { - return mount, fmt.Errorf("invalid mountinfo line, expected at least "+ - "10 fields but got %d from line='%s'", len(fields), line) - } - - mount.mountpoint = fields[4] - - var seperatorIndex int - for i, value := range fields { - if value == "-" { - seperatorIndex = i - break - } - } - if fields[seperatorIndex] != "-" { - return mount, fmt.Errorf("invalid mountinfo line, separator ('-') not "+ - "found in line='%s'", line) - } - - if len(fields)-seperatorIndex-1 < 3 { - return mount, fmt.Errorf("invalid mountinfo line, expected at least "+ - "3 fields after seperator but got %d from line='%s'", - len(fields)-seperatorIndex-1, line) - } - - fields = fields[seperatorIndex+1:] - mount.filesystemType = fields[0] - mount.superOptions = strings.Split(fields[2], ",") - return mount, nil -} - -// SupportedSubsystems returns the subsystems that are supported by the -// kernel. The returned map contains a entry for each subsystem. -func SupportedSubsystems(rootfs resolve.Resolver) (map[string]struct{}, error) { - cgroups, err := os.Open(rootfs.ResolveHostFS("/proc/cgroups")) - if err != nil { - if os.IsNotExist(err) { - return nil, ErrCgroupsMissing - } - return nil, err - } - defer cgroups.Close() - - subsystemSet := map[string]struct{}{} - sc := bufio.NewScanner(cgroups) - for sc.Scan() { - line := sc.Text() - - // Ignore the header. - if len(line) > 0 && line[0] == '#' { - continue - } - - // Parse the cgroup subsystems. - // Format: subsys_name hierarchy num_cgroups enabled - // Example: cpuset 4 1 1 - fields := strings.Fields(line) - if len(fields) == 0 { - continue - } - - // Check the enabled flag. - if len(fields) > 3 { - enabled := fields[3] - if enabled == "0" { - // Ignore cgroup subsystems that are disabled (via the - // cgroup_disable kernel command-line boot parameter). - continue - } - } - - subsystem := fields[0] - subsystemSet[subsystem] = struct{}{} - } - - return subsystemSet, sc.Err() -} - -// SubsystemMountpoints returns the mountpoints for each of the given subsystems. -// The returned map contains the subsystem name as a key and the value is the -// mountpoint. -func SubsystemMountpoints(rootfs resolve.Resolver, subsystems map[string]struct{}) (Mountpoints, error) { - - mountinfo, err := os.Open(rootfs.ResolveHostFS("/proc/self/mountinfo")) - if err != nil { - return Mountpoints{}, err - } - defer mountinfo.Close() - - mounts := map[string]string{} - mountInfo := Mountpoints{} - sc := bufio.NewScanner(mountinfo) - for sc.Scan() { - // https://www.kernel.org/doc/Documentation/filesystems/proc.txt - // Example: - // 25 21 0:20 / /cgroup/cpu rw,relatime - cgroup cgroup rw,cpu - line := strings.TrimSpace(sc.Text()) - if line == "" { - continue - } - - mount, err := parseMountinfoLine(line) - if err != nil { - return Mountpoints{}, err - } - - // if the mountpoint from the subsystem has a different root than ours, it probably belongs to something else. - if !strings.HasPrefix(mount.mountpoint, rootfs.ResolveHostFS("")) { - continue - } - - // cgroupv1 option - if mount.filesystemType == "cgroup" { - for _, opt := range mount.superOptions { - // Sometimes the subsystem name is written like "name=blkio". - fields := strings.SplitN(opt, "=", 2) - if len(fields) > 1 { - opt = fields[1] - } - - // Test if option is a subsystem name. - if _, found := subsystems[opt]; found { - // Add the subsystem mount if it does not already exist. - if _, exists := mounts[opt]; !exists { - mounts[opt] = mount.mountpoint - } - } - } - } - - // V2 option - if mount.filesystemType == "cgroup2" { - mountInfo.V2Loc = mount.mountpoint - } - - } - - mountInfo.V1Mounts = mounts - - return mountInfo, sc.Err() -} - -// ProcessCgroupPaths returns the cgroups to which a process belongs and the -// pathname of the cgroup relative to the mountpoint of the subsystem. -func (r Reader) ProcessCgroupPaths(pid int) (PathList, error) { - cgroupPath := filepath.Join("proc", strconv.Itoa(pid), "cgroup") - cgroup, err := os.Open(r.rootfsMountpoint.ResolveHostFS(cgroupPath)) - if err != nil { - return PathList{}, err //return a blank error so other events can use any file not found errors - } - defer cgroup.Close() - - cPaths := PathList{V1: map[string]ControllerPath{}, V2: map[string]ControllerPath{}} - sc := bufio.NewScanner(cgroup) - for sc.Scan() { - // http://man7.org/linux/man-pages/man7/cgroups.7.html - // Format: hierarchy-ID:subsystem-list:cgroup-path - // Example: - // 2:cpu:/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242 - line := sc.Text() - - fields := strings.Split(line, ":") - if len(fields) != 3 { - continue - } - - path := fields[2] - if r.cgroupsHierarchyOverride != "" { - path = r.cgroupsHierarchyOverride - } - // cgroup V2 - // cgroup v2 controllers will always start with this string - if strings.Contains(line, "0::/") { - // if you're running inside a container - // that's operating with a hybrid cgroups config, - // the containerized process won't see the V2 mount - // inside /proc/self/mountinfo if docker is using cgroups V1 - // For this very annoying edge case, revert to the hostfs flag - // If it's not set, warn the user that they've hit this. - controllerPath := filepath.Join(r.cgroupMountpoints.V2Loc, path) - if r.cgroupMountpoints.V2Loc == "" && !r.rootfsMountpoint.IsSet() { - logp.L().Debugf(`PID %d contains a cgroups V2 path (%s) but no V2 mountpoint was found. -This may be because metricbeat is running inside a container on a hybrid system. -To monitor cgroups V2 processess in this way, mount the unified (V2) hierarchy inside -the container as /sys/fs/cgroup/unified and start the system module with the hostfs setting.`, pid, line) - continue - } else if r.cgroupMountpoints.V2Loc == "" && r.rootfsMountpoint.IsSet() { - controllerPath = r.rootfsMountpoint.ResolveHostFS(filepath.Join("/sys/fs/cgroup/unified", path)) - } - - cgpaths, err := ioutil.ReadDir(controllerPath) - if err != nil { - return cPaths, errors.Wrapf(err, "error fetching cgroupV2 controllers for cgroup location '%s' and path line '%s'", r.cgroupMountpoints.V2Loc, line) - } - // In order to produce the same kind of data for cgroups V1 and V2 controllers, - // We iterate over the group, and look for controllers, since the V2 unified system doesn't list them under the PID - for _, singlePath := range cgpaths { - if strings.Contains(singlePath.Name(), "stat") { - controllerName := strings.TrimSuffix(singlePath.Name(), ".stat") - cPaths.V2[controllerName] = ControllerPath{ControllerPath: path, FullPath: controllerPath, IsV2: true} - } - } - // cgroup v1 - } else { - subsystems := strings.Split(fields[1], ",") - for _, subsystem := range subsystems { - fullPath := filepath.Join(r.cgroupMountpoints.V1Mounts[subsystem], path) - cPaths.V1[subsystem] = ControllerPath{ControllerPath: path, FullPath: fullPath, IsV2: false} - } - } - } - - if sc.Err() != nil { - return cPaths, errors.Wrap(sc.Err(), "error scanning cgroup file") - } - - return cPaths, nil -} diff --git a/libbeat/metric/system/cgroup/util_test.go b/libbeat/metric/system/cgroup/util_test.go deleted file mode 100644 index 24ee57849894..000000000000 --- a/libbeat/metric/system/cgroup/util_test.go +++ /dev/null @@ -1,231 +0,0 @@ -// Licensed to Elasticsearch B.V. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Elasticsearch B.V. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package cgroup - -import ( - "archive/zip" - "fmt" - "io" - "os" - "path/filepath" - "testing" - - "github.com/stretchr/testify/assert" - - "github.com/elastic/beats/v7/libbeat/metric/system/resolve" -) - -const dockerTestData = "testdata/docker.zip" - -func TestMain(m *testing.M) { - err := extractTestData(dockerTestData) - if err != nil { - fmt.Println(err) - os.Exit(1) - } - os.Exit(m.Run()) -} - -// extractTestData from zip file and write it in the same dir as the zip file. -func extractTestData(path string) error { - r, err := zip.OpenReader(path) - if err != nil { - return err - } - defer r.Close() - - dest := filepath.Dir(path) - - extractAndWriteFile := func(f *zip.File) error { - rc, err := f.Open() - if err != nil { - return err - } - defer rc.Close() - - path := filepath.Join(dest, f.Name) - if found, err := exists(path); err != nil || found { - return err - } - - if f.FileInfo().IsDir() { - os.MkdirAll(path, f.Mode()) - } else { - destFile, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, os.FileMode(0700)) - if err != nil { - return err - } - defer destFile.Close() - - _, err = io.Copy(destFile, rc) - if err != nil { - return err - } - - os.Chmod(path, f.Mode()) - } - return nil - } - - for _, f := range r.File { - err := extractAndWriteFile(f) - if err != nil { - return err - } - } - - return nil -} - -// exists returns whether the given file or directory exists or not -func exists(path string) (bool, error) { - _, err := os.Stat(path) - if err == nil { - return true, nil - } - if os.IsNotExist(err) { - return false, nil - } - return true, err -} - -func TestSupportedSubsystems(t *testing.T) { - subsystems, err := SupportedSubsystems(resolve.NewTestResolver("testdata/docker")) - if err != nil { - t.Fatal(err) - } - - assert.Len(t, subsystems, 11) - assertContains(t, subsystems, "cpuset") - assertContains(t, subsystems, "cpu") - assertContains(t, subsystems, "cpuacct") - assertContains(t, subsystems, "blkio") - assertContains(t, subsystems, "memory") - assertContains(t, subsystems, "devices") - assertContains(t, subsystems, "freezer") - assertContains(t, subsystems, "net_cls") - assertContains(t, subsystems, "perf_event") - assertContains(t, subsystems, "net_prio") - assertContains(t, subsystems, "pids") - - _, found := subsystems["hugetlb"] - assert.False(t, found, "hugetlb should be missing because it's disabled") -} - -func TestSupportedSubsystemsErrCgroupsMissing(t *testing.T) { - _, err := SupportedSubsystems(resolve.NewTestResolver("testdata/doesnotexist")) - if err != ErrCgroupsMissing { - t.Fatalf("expected ErrCgroupsMissing, but got %v", err) - } -} - -func TestSubsystemMountpoints(t *testing.T) { - subsystems := map[string]struct{}{} - subsystems["blkio"] = struct{}{} - subsystems["cpu"] = struct{}{} - subsystems["cpuacct"] = struct{}{} - subsystems["cpuset"] = struct{}{} - subsystems["devices"] = struct{}{} - subsystems["freezer"] = struct{}{} - subsystems["hugetlb"] = struct{}{} - subsystems["memory"] = struct{}{} - subsystems["perf_event"] = struct{}{} - - mountpoints, err := SubsystemMountpoints(resolve.NewTestResolver("testdata/docker"), subsystems) - if err != nil { - t.Fatal(err) - } - - assert.Equal(t, "testdata/docker/sys/fs/cgroup/blkio", mountpoints.V1Mounts["blkio"]) - assert.Equal(t, "testdata/docker/sys/fs/cgroup/cpu", mountpoints.V1Mounts["cpu"]) - assert.Equal(t, "testdata/docker/sys/fs/cgroup/cpuacct", mountpoints.V1Mounts["cpuacct"]) - assert.Equal(t, "testdata/docker/sys/fs/cgroup/cpuset", mountpoints.V1Mounts["cpuset"]) - assert.Equal(t, "testdata/docker/sys/fs/cgroup/devices", mountpoints.V1Mounts["devices"]) - assert.Equal(t, "testdata/docker/sys/fs/cgroup/freezer", mountpoints.V1Mounts["freezer"]) - assert.Equal(t, "testdata/docker/sys/fs/cgroup/hugetlb", mountpoints.V1Mounts["hugetlb"]) - assert.Equal(t, "testdata/docker/sys/fs/cgroup/memory", mountpoints.V1Mounts["memory"]) - assert.Equal(t, "testdata/docker/sys/fs/cgroup/perf_event", mountpoints.V1Mounts["perf_event"]) -} - -func TestProcessCgroupPaths(t *testing.T) { - reader, err := NewReader(resolve.NewTestResolver("testdata/docker"), false) - if err != nil { - t.Fatalf("error in NewReader: %s", err) - } - paths, err := reader.ProcessCgroupPaths(985) - if err != nil { - t.Fatalf("error in ProcessCgroupPaths: %s", err) - } - - path := "/docker/b29faf21b7eff959f64b4192c34d5d67a707fe8561e9eaa608cb27693fba4242" - assert.Equal(t, path, paths.V1["blkio"].ControllerPath) - assert.Equal(t, path, paths.V1["cpu"].ControllerPath) - assert.Equal(t, path, paths.V1["cpuacct"].ControllerPath) - assert.Equal(t, path, paths.V1["cpuset"].ControllerPath) - assert.Equal(t, path, paths.V1["devices"].ControllerPath) - assert.Equal(t, path, paths.V1["freezer"].ControllerPath) - assert.Equal(t, path, paths.V1["memory"].ControllerPath) - assert.Equal(t, path, paths.V1["net_cls"].ControllerPath) - assert.Equal(t, path, paths.V1["net_prio"].ControllerPath) - assert.Equal(t, path, paths.V1["perf_event"].ControllerPath) - assert.Len(t, paths.Flatten(), 10) -} - -func TestProcessCgroupPathsV2(t *testing.T) { - reader, err := NewReader(resolve.NewTestResolver("testdata/docker"), false) - if err != nil { - t.Fatalf("error in NewReader: %s", err) - } - - paths, err := reader.ProcessCgroupPaths(312) - if err != nil { - t.Fatalf("error in ProcessCgroupPaths: %s", err) - } - - assert.Equal(t, "testdata/docker/sys/fs/cgroup/system.slice/docker-1c8fa019edd4b9d4b2856f4932c55929c5c118c808ed5faee9a135ca6e84b039.scope", paths.V2["cgroup"].FullPath) - assert.Equal(t, "testdata/docker/sys/fs/cgroup/system.slice/docker-1c8fa019edd4b9d4b2856f4932c55929c5c118c808ed5faee9a135ca6e84b039.scope", paths.V2["cpu"].FullPath) - assert.Equal(t, "testdata/docker/sys/fs/cgroup/system.slice/docker-1c8fa019edd4b9d4b2856f4932c55929c5c118c808ed5faee9a135ca6e84b039.scope", paths.V2["io"].FullPath) - assert.Equal(t, "testdata/docker/sys/fs/cgroup/system.slice/docker-1c8fa019edd4b9d4b2856f4932c55929c5c118c808ed5faee9a135ca6e84b039.scope", paths.V2["memory"].FullPath) -} - -func assertContains(t testing.TB, m map[string]struct{}, key string) { - _, contains := m[key] - if !contains { - t.Errorf("map is missing key %v, map=%+v", key, m) - } -} - -func TestParseMountinfoLine(t *testing.T) { - lines := []string{ - "30 24 0:25 / /sys/fs/cgroup/blkio rw,nosuid,nodev,noexec,relatime - cgroup cgroup rw,blkio", - "30 24 0:25 / /sys/fs/cgroup/blkio rw,nosuid,nodev,noexec,relatime shared:13 - cgroup cgroup rw,blkio", - "30 24 0:25 / /sys/fs/cgroup/blkio rw,nosuid,nodev,noexec,relatime shared:13 master:1 - cgroup cgroup rw,blkio", - "30 24 0:25 / /sys/fs/cgroup/blkio rw,nosuid,nodev,noexec,relatime shared:13 - cgroup cgroup rw,name=blkio", - } - - for _, line := range lines { - mount, err := parseMountinfoLine(line) - if err != nil { - t.Fatal(err) - } - - assert.Equal(t, "/sys/fs/cgroup/blkio", mount.mountpoint) - assert.Equal(t, "cgroup", mount.filesystemType) - assert.Len(t, mount.superOptions, 2) - } -} diff --git a/libbeat/metric/system/cpu/cpu.go b/libbeat/metric/system/cpu/cpu.go deleted file mode 100644 index eee30555e831..000000000000 --- a/libbeat/metric/system/cpu/cpu.go +++ /dev/null @@ -1,71 +0,0 @@ -// Licensed to Elasticsearch B.V. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Elasticsearch B.V. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -//go:build darwin || freebsd || linux || openbsd || windows || aix -// +build darwin freebsd linux openbsd windows aix - -package cpu - -import ( - "github.com/elastic/beats/v7/libbeat/common" - "github.com/elastic/beats/v7/libbeat/metric/system/numcpu" - sigar "github.com/elastic/gosigar" -) - -// Load returns CPU load information for the previous 1, 5, and 15 minute -// periods. -func Load() (*LoadMetrics, error) { - load := &sigar.LoadAverage{} - if err := load.Get(); err != nil { - return nil, err - } - - return &LoadMetrics{load}, nil -} - -// LoadMetrics stores the sampled load average values of the host. -type LoadMetrics struct { - sample *sigar.LoadAverage -} - -// LoadAverages stores the values of load averages of the last 1, 5 and 15 minutes. -type LoadAverages struct { - OneMinute float64 - FiveMinute float64 - FifteenMinute float64 -} - -// Averages return the CPU load averages. These values should range from -// 0 to NumCPU. -func (m *LoadMetrics) Averages() LoadAverages { - return LoadAverages{ - OneMinute: common.Round(m.sample.One, common.DefaultDecimalPlacesCount), - FiveMinute: common.Round(m.sample.Five, common.DefaultDecimalPlacesCount), - FifteenMinute: common.Round(m.sample.Fifteen, common.DefaultDecimalPlacesCount), - } -} - -// NormalizedAverages return the CPU load averages normalized by the NumCPU. -// These values should range from 0 to 1. -func (m *LoadMetrics) NormalizedAverages() LoadAverages { - cpus := numcpu.NumCPU() - return LoadAverages{ - OneMinute: common.Round(m.sample.One/float64(cpus), common.DefaultDecimalPlacesCount), - FiveMinute: common.Round(m.sample.Five/float64(cpus), common.DefaultDecimalPlacesCount), - FifteenMinute: common.Round(m.sample.Fifteen/float64(cpus), common.DefaultDecimalPlacesCount), - } -} diff --git a/libbeat/metric/system/cpu/doc.go b/libbeat/metric/system/cpu/doc.go deleted file mode 100644 index ce8f92d5dc68..000000000000 --- a/libbeat/metric/system/cpu/doc.go +++ /dev/null @@ -1,18 +0,0 @@ -// Licensed to Elasticsearch B.V. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Elasticsearch B.V. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package cpu diff --git a/libbeat/metric/system/diskio/disk_performance_386.go b/libbeat/metric/system/diskio/disk_performance_386.go deleted file mode 100644 index e05dc8250046..000000000000 --- a/libbeat/metric/system/diskio/disk_performance_386.go +++ /dev/null @@ -1,43 +0,0 @@ -// Licensed to Elasticsearch B.V. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Elasticsearch B.V. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -//go:build windows -// +build windows - -package diskio - -// diskPerformance struct provides disk performance information. It is used by the IOCTL_DISK_PERFORMANCE control code. -// DeviceIoControl() will fail with ERROR_INSUFFICIENT_BUFFER (The data area passed to a system call is too small) on 32 bit systems. -// The memory layout is different for 32 bit vs 64 bit so an alignment (AlignmentPadding) is necessary in order to increase the buffer size -type diskPerformance struct { - BytesRead int64 - BytesWritten int64 - // Contains a cumulative time, expressed in increments of 100 nanoseconds (or ticks). - ReadTime int64 - // Contains a cumulative time, expressed in increments of 100 nanoseconds (or ticks). - WriteTime int64 - //Contains a cumulative time, expressed in increments of 100 nanoseconds (or ticks). - IdleTime int64 - ReadCount uint32 - WriteCount uint32 - QueueDepth uint32 - SplitCount uint32 - QueryTime int64 - StorageDeviceNumber uint32 - StorageManagerName [8]uint16 - AlignmentPadding uint32 -} diff --git a/libbeat/metric/system/diskio/disk_performance_amd64.go b/libbeat/metric/system/diskio/disk_performance_amd64.go deleted file mode 100644 index d925d99d19c1..000000000000 --- a/libbeat/metric/system/diskio/disk_performance_amd64.go +++ /dev/null @@ -1,40 +0,0 @@ -// Licensed to Elasticsearch B.V. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Elasticsearch B.V. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -//go:build windows -// +build windows - -package diskio - -// diskPerformance struct provides disk performance information. It is used by the IOCTL_DISK_PERFORMANCE control code. -type diskPerformance struct { - BytesRead int64 - BytesWritten int64 - // Contains a cumulative time, expressed in increments of 100 nanoseconds (or ticks). - ReadTime int64 - // Contains a cumulative time, expressed in increments of 100 nanoseconds (or ticks). - WriteTime int64 - //Contains a cumulative time, expressed in increments of 100 nanoseconds (or ticks). - IdleTime int64 - ReadCount uint32 - WriteCount uint32 - QueueDepth uint32 - SplitCount uint32 - QueryTime int64 - StorageDeviceNumber uint32 - StorageManagerName [8]uint16 -} diff --git a/libbeat/metric/system/diskio/diskstat.go b/libbeat/metric/system/diskio/diskstat.go deleted file mode 100644 index 598e3ca7b83e..000000000000 --- a/libbeat/metric/system/diskio/diskstat.go +++ /dev/null @@ -1,55 +0,0 @@ -// Licensed to Elasticsearch B.V. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Elasticsearch B.V. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -//go:build darwin || freebsd || linux || windows || aix -// +build darwin freebsd linux windows aix - -package diskio - -import ( - "github.com/shirou/gopsutil/v3/disk" - - sigar "github.com/elastic/gosigar" -) - -// IOMetric contains mapping fields which are outputed by `iostat -x` on linux -// -// Device: rrqm/s wrqm/s r/s w/s rsec/s wsec/s avgrq-sz avgqu-sz await r_await w_await svctm %util -// sda 0.06 0.78 0.09 0.27 9.42 8.06 48.64 0.00 1.34 0.99 1.45 0.77 0.03 -type IOMetric struct { - ReadRequestMergeCountPerSec float64 `json:"rrqmCps"` - WriteRequestMergeCountPerSec float64 `json:"wrqmCps"` - ReadRequestCountPerSec float64 `json:"rrqCps"` - WriteRequestCountPerSec float64 `json:"wrqCps"` - // using bytes instead of sector - ReadBytesPerSec float64 `json:"rBps"` - WriteBytesPerSec float64 `json:"wBps"` - AvgRequestSize float64 `json:"avgrqSz"` - AvgQueueSize float64 `json:"avgquSz"` - AvgAwaitTime float64 `json:"await"` - AvgReadAwaitTime float64 `json:"r_await"` - AvgWriteAwaitTime float64 `json:"w_await"` - AvgServiceTime float64 `json:"svctm"` - BusyPct float64 `json:"busy"` -} - -// IOStat carries disk statistics for all devices -type IOStat struct { - lastDiskIOCounters map[string]disk.IOCountersStat - lastCPU sigar.Cpu - curCPU sigar.Cpu -} diff --git a/libbeat/metric/system/diskio/diskstat_linux.go b/libbeat/metric/system/diskio/diskstat_linux.go deleted file mode 100644 index 83245090d554..000000000000 --- a/libbeat/metric/system/diskio/diskstat_linux.go +++ /dev/null @@ -1,156 +0,0 @@ -// Licensed to Elasticsearch B.V. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Elasticsearch B.V. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -//go:build linux -// +build linux - -package diskio - -import ( - "math" - - "github.com/pkg/errors" - "github.com/shirou/gopsutil/v3/disk" - - "github.com/elastic/beats/v7/libbeat/common" - "github.com/elastic/beats/v7/libbeat/metric/system/numcpu" -) - -// GetCLKTCK emulates the _SC_CLK_TCK syscall -func GetCLKTCK() uint32 { - // return uint32(C.sysconf(C._SC_CLK_TCK)) - // NOTE: _SC_CLK_TCK should be fetched from sysconf using cgo - return uint32(100) -} - -// IOCounters should map functionality to disk package for linux os. -func IOCounters(names ...string) (map[string]disk.IOCountersStat, error) { - return disk.IOCounters(names...) -} - -// NewDiskIOStat :init DiskIOStat object. -func NewDiskIOStat() *IOStat { - return &IOStat{ - lastDiskIOCounters: map[string]disk.IOCountersStat{}, - } -} - -// OpenSampling creates current cpu sampling -// need call as soon as get IOCounters. -func (stat *IOStat) OpenSampling() error { - return stat.curCPU.Get() -} - -// a few of the diskio counters are actually 32-bit on the kernel side, which means they can roll over fairly easily. -// Here we try to reconstruct the values by calculating the pre-rollover delta from unt32 max, then adding. -// If you want to get technical, this could be a tad unsafe, as we don't actually have any way of knowing if the word size changes in a future kernel, and we've rolled over at UINT64_MAX - -// See https://docs.kernel.org/admin-guide/iostats.html and https://github.com/torvalds/linux/blob/master/block/genhd.c diskstats_show() -func returnOrFix32BitRollover(current, prev uint64) uint64 { - var maxUint32 uint64 = math.MaxUint32 //4_294_967_295 Max value in uint32/unsigned int - - if current >= prev { - return current - prev - } - // we're at a uint64 if we hit this - if prev > maxUint32 { - return 0 - } - - delta := maxUint32 - prev - - return delta + current - -} - -// CalcIOStatistics calculates IO statistics. -func (stat *IOStat) CalcIOStatistics(counter disk.IOCountersStat) (IOMetric, error) { - var last disk.IOCountersStat - var ok bool - - // if last counter not found, create one and return all 0 - if last, ok = stat.lastDiskIOCounters[counter.Name]; !ok { - stat.lastDiskIOCounters[counter.Name] = counter - return IOMetric{}, nil - } - - // calculate the delta ms between the CloseSampling and OpenSampling - deltams := 1000.0 * float64(stat.curCPU.Total()-stat.lastCPU.Total()) / float64(numcpu.NumCPU()) / float64(GetCLKTCK()) - if deltams <= 0 { - return IOMetric{}, errors.New("The delta cpu time between close sampling and open sampling is less or equal to 0") - } - - rdIOs := counter.ReadCount - last.ReadCount - rdMerges := counter.MergedReadCount - last.MergedReadCount - rdBytes := counter.ReadBytes - last.ReadBytes - rdTicks := returnOrFix32BitRollover(counter.ReadTime, last.ReadTime) - wrIOs := counter.WriteCount - last.WriteCount - wrMerges := counter.MergedWriteCount - last.MergedWriteCount - wrBytes := counter.WriteBytes - last.WriteBytes - wrTicks := returnOrFix32BitRollover(counter.WriteTime, last.WriteTime) - ticks := returnOrFix32BitRollover(counter.IoTime, last.IoTime) - aveq := returnOrFix32BitRollover(counter.WeightedIO, last.WeightedIO) - - nIOs := rdIOs + wrIOs - nTicks := rdTicks + wrTicks - nBytes := rdBytes + wrBytes - size := float64(0) - wait := float64(0) - svct := float64(0) - - if nIOs > 0 { - size = float64(nBytes) / float64(nIOs) - wait = float64(nTicks) / float64(nIOs) - svct = float64(ticks) / float64(nIOs) - } - - queue := float64(aveq) / deltams - perSec := func(x uint64) float64 { - return common.Round(1000.0*float64(x)/deltams, common.DefaultDecimalPlacesCount) - } - - result := IOMetric{} - result.ReadRequestMergeCountPerSec = perSec(rdMerges) - result.WriteRequestMergeCountPerSec = perSec(wrMerges) - result.ReadRequestCountPerSec = perSec(rdIOs) - result.WriteRequestCountPerSec = perSec(wrIOs) - result.ReadBytesPerSec = perSec(rdBytes) - result.WriteBytesPerSec = perSec(wrBytes) - result.AvgRequestSize = common.Round(size, common.DefaultDecimalPlacesCount) - result.AvgQueueSize = common.Round(queue, common.DefaultDecimalPlacesCount) - result.AvgAwaitTime = common.Round(wait, common.DefaultDecimalPlacesCount) - if rdIOs > 0 { - result.AvgReadAwaitTime = common.Round(float64(rdTicks)/float64(rdIOs), common.DefaultDecimalPlacesCount) - } - if wrIOs > 0 { - result.AvgWriteAwaitTime = common.Round(float64(wrTicks)/float64(wrIOs), common.DefaultDecimalPlacesCount) - } - result.AvgServiceTime = common.Round(svct, common.DefaultDecimalPlacesCount) - result.BusyPct = common.Round(100.0*float64(ticks)/deltams, common.DefaultDecimalPlacesCount) - if result.BusyPct > 100.0 { - result.BusyPct = 100.0 - } - - stat.lastDiskIOCounters[counter.Name] = counter - return result, nil - -} - -// CloseSampling closes the disk sampler -func (stat *IOStat) CloseSampling() { - stat.lastCPU = stat.curCPU -} diff --git a/libbeat/metric/system/diskio/diskstat_linux_test.go b/libbeat/metric/system/diskio/diskstat_linux_test.go deleted file mode 100644 index 5061d310533d..000000000000 --- a/libbeat/metric/system/diskio/diskstat_linux_test.go +++ /dev/null @@ -1,93 +0,0 @@ -// Licensed to Elasticsearch B.V. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Elasticsearch B.V. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -//go:build !integration && linux -// +build !integration,linux - -package diskio - -import ( - "math" - "testing" - - "github.com/shirou/gopsutil/v3/disk" - "github.com/stretchr/testify/assert" - - "github.com/elastic/beats/v7/libbeat/common" - sigar "github.com/elastic/gosigar" -) - -func Test_GetCLKTCK(t *testing.T) { - //usually the tick is 100 - assert.Equal(t, uint32(100), GetCLKTCK()) -} - -func Test32BitRollover(t *testing.T) { - var maxUint32 uint64 = math.MaxUint32 // 4_294_967_295 - - var prev = maxUint32 - 100_000 - - // A rolled-over value - var current32 uint64 = 1000 - // Theoretical un-rolled over value - var current64 = (maxUint32 + current32) - - var correct = current64 - prev - assert.Equal(t, returnOrFix32BitRollover(current32, prev), returnOrFix32BitRollover(current64, prev)) - assert.Equal(t, correct, returnOrFix32BitRollover(current32, prev)) - - assert.Equal(t, uint64(0), returnOrFix32BitRollover(current32, current32)) -} - -func TestDiskIOStat_CalIOStatistics(t *testing.T) { - counter := disk.IOCountersStat{ - ReadCount: 13, - WriteCount: 17, - ReadTime: 19, - WriteTime: 23, - Name: "iostat", - } - - stat := &IOStat{ - lastDiskIOCounters: map[string]disk.IOCountersStat{ - "iostat": { - ReadCount: 3, - WriteCount: 5, - ReadTime: 7, - WriteTime: 11, - Name: "iostat", - }, - }, - lastCPU: sigar.Cpu{Idle: 100}, - curCPU: sigar.Cpu{Idle: 1}, - } - - expected := IOMetric{ - AvgAwaitTime: common.Round(24.0/22.0, common.DefaultDecimalPlacesCount), - AvgReadAwaitTime: 1.2, - AvgWriteAwaitTime: 1, - } - - got, err := stat.CalcIOStatistics(counter) - if err != nil { - t.Fatal(err) - } - - assert.Equal(t, expected.AvgAwaitTime, got.AvgAwaitTime) - assert.Equal(t, expected.AvgReadAwaitTime, got.AvgReadAwaitTime) - assert.Equal(t, expected.AvgWriteAwaitTime, got.AvgWriteAwaitTime) -} diff --git a/libbeat/metric/system/diskio/diskstat_other.go b/libbeat/metric/system/diskio/diskstat_other.go deleted file mode 100644 index ec1e243e6413..000000000000 --- a/libbeat/metric/system/diskio/diskstat_other.go +++ /dev/null @@ -1,51 +0,0 @@ -// Licensed to Elasticsearch B.V. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Elasticsearch B.V. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -//go:build (darwin && cgo) || freebsd -// +build darwin,cgo freebsd - -package diskio - -import ( - "github.com/pkg/errors" - "github.com/shirou/gopsutil/v3/disk" -) - -// NewDiskIOStat :init DiskIOStat object. -func NewDiskIOStat() *IOStat { - return &IOStat{ - lastDiskIOCounters: map[string]disk.IOCountersStat{}, - } -} - -// OpenSampling stub for linux implementation. -func (stat *IOStat) OpenSampling() error { - return nil -} - -// CalcIOStatistics stub for linux implementation. -func (stat *IOStat) CalcIOStatistics(rcounter disk.IOCountersStat) (IOMetric, error) { - return IOMetric{}, errors.New("not implemented out of linux") -} - -// CloseSampling stub for linux implementation. -func (stat *IOStat) CloseSampling() {} - -// IOCounters should map functionality to disk package for linux os. -func IOCounters(names ...string) (map[string]disk.IOCountersStat, error) { - return disk.IOCounters(names...) -} diff --git a/libbeat/metric/system/diskio/diskstat_windows.go b/libbeat/metric/system/diskio/diskstat_windows.go deleted file mode 100644 index 7f181d7bc7b6..000000000000 --- a/libbeat/metric/system/diskio/diskstat_windows.go +++ /dev/null @@ -1,51 +0,0 @@ -// Licensed to Elasticsearch B.V. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Elasticsearch B.V. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -//go:build windows -// +build windows - -package diskio - -import ( - "github.com/pkg/errors" - "github.com/shirou/gopsutil/v3/disk" -) - -// NewDiskIOStat :init DiskIOStat object. -func NewDiskIOStat() *IOStat { - return &IOStat{ - lastDiskIOCounters: map[string]disk.IOCountersStat{}, - } -} - -// OpenSampling stub for linux implementation. -func (stat *IOStat) OpenSampling() error { - return nil -} - -// CalcIOStatistics stub for linux implementation. -func (stat *IOStat) CalcIOStatistics(counter disk.IOCountersStat) (IOMetric, error) { - return IOMetric{}, errors.New("iostat is not implement for Windows") -} - -// CloseSampling stub for linux implementation. -func (stat *IOStat) CloseSampling() {} - -// IOCounters should map functionality to disk package for linux os. -func IOCounters(names ...string) (map[string]disk.IOCountersStat, error) { - return ioCounters(names...) -} diff --git a/libbeat/metric/system/diskio/diskstat_windows_helper.go b/libbeat/metric/system/diskio/diskstat_windows_helper.go deleted file mode 100644 index 394141161bec..000000000000 --- a/libbeat/metric/system/diskio/diskstat_windows_helper.go +++ /dev/null @@ -1,260 +0,0 @@ -// Licensed to Elasticsearch B.V. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Elasticsearch B.V. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -//go:build windows -// +build windows - -package diskio - -import ( - "strings" - "syscall" - "unsafe" - - "github.com/pkg/errors" - "github.com/shirou/gopsutil/v3/disk" - "golang.org/x/sys/windows" - "golang.org/x/sys/windows/registry" - - "github.com/elastic/elastic-agent-libs/logp" -) - -const ( - errorSuccess syscall.Errno = 0 - // ioctlDiskPerformance is used to enable performance counters that provide disk performance information. - ioctlDiskPerformance = 0x70020 - // ioctlDiskPerformanceOff used to disable performance counters that provide disk performance information. - ioctlDiskPerformanceOff = 0x70060 -) - -var ( - modkernel32 = windows.NewLazySystemDLL("kernel32.dll") - procGetLogicalDriveStringsW = modkernel32.NewProc("GetLogicalDriveStringsW") - procGetDriveTypeW = modkernel32.NewProc("GetDriveTypeW") -) - -type logicalDrive struct { - Name string - UNCPath string -} - -// ioCounters gets the diskio counters and maps them to the list of counterstat objects. -func ioCounters(names ...string) (map[string]disk.IOCountersStat, error) { - if err := enablePerformanceCounters(); err != nil { - return nil, err - } - logicalDisks, err := getLogicalDriveStrings() - if err != nil || len(logicalDisks) == 0 { - return nil, err - } - ret := make(map[string]disk.IOCountersStat) - for _, drive := range logicalDisks { - // not get _Total or Harddrive - if len(drive.Name) > 3 { - continue - } - // filter by included devices - if len(names) > 0 && !containsDrive(names, drive.Name) { - continue - } - var counter diskPerformance - err = ioCounter(drive.UNCPath, &counter) - if err != nil { - logp.Err("Could not return any performance counter values for %s .Error: %v", drive.UNCPath, err) - continue - } - ret[drive.Name] = disk.IOCountersStat{ - Name: drive.Name, - ReadCount: uint64(counter.ReadCount), - WriteCount: uint64(counter.WriteCount), - ReadBytes: uint64(counter.BytesRead), - WriteBytes: uint64(counter.BytesWritten), - // Ticks (which is equal to 100 nanoseconds) will be converted to milliseconds for consistency reasons for both ReadTime and WriteTime (https://docs.microsoft.com/en-us/dotnet/api/system.timespan.ticks?redirectedfrom=MSDN&view=netframework-4.8#remarks) - ReadTime: uint64(counter.ReadTime / 10000), - WriteTime: uint64(counter.WriteTime / 10000), - } - } - return ret, nil -} - -// ioCounter calls syscall func CreateFile to generate a handler then executes the DeviceIoControl func in order to retrieve the metrics. -func ioCounter(path string, diskPerformance *diskPerformance) error { - utfPath, err := syscall.UTF16PtrFromString(path) - if err != nil { - return err - } - hFile, err := syscall.CreateFile(utfPath, - syscall.GENERIC_READ|syscall.GENERIC_WRITE, - syscall.FILE_SHARE_READ|syscall.FILE_SHARE_WRITE, - nil, - syscall.OPEN_EXISTING, - syscall.FILE_FLAG_BACKUP_SEMANTICS, - 0) - - if err != nil { - return err - } - defer syscall.CloseHandle(hFile) - var diskPerformanceSize uint32 - return syscall.DeviceIoControl(hFile, - ioctlDiskPerformance, - nil, - 0, - (*byte)(unsafe.Pointer(diskPerformance)), - uint32(unsafe.Sizeof(*diskPerformance)), - &diskPerformanceSize, - nil) -} - -// enablePerformanceCounters will enable performance counters by adding the EnableCounterForIoctl registry key -func enablePerformanceCounters() error { - key, err := registry.OpenKey(registry.LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Services\\partmgr", registry.READ|registry.WRITE) - // closing handler for the registry key. If the key is not one of the predefined registry keys (which is the case here), a call the RegCloseKey function should be executed after using the handle. - defer func() { - if key != 0 { - clErr := key.Close() - if clErr != nil { - logp.L().Named("diskio").Errorf("cannot close handler for HKLM:SYSTEM\\CurrentControlSet\\Services\\Partmgr\\EnableCounterForIoctl key in the registry: %s", clErr) - } - } - }() - - if err != nil { - return errors.Errorf("cannot open new key in the registry in order to enable the performance counters: %s", err) - } - val, _, err := key.GetIntegerValue("EnableCounterForIoctl") - if val != 1 || err != nil { - if err = key.SetDWordValue("EnableCounterForIoctl", 1); err != nil { - return errors.Errorf("cannot create HKLM:SYSTEM\\CurrentControlSet\\Services\\Partmgr\\EnableCounterForIoctl key in the registry in order to enable the performance counters: %s", err) - } - logp.L().Named("diskio").Info("The registry key EnableCounterForIoctl at HKLM:SYSTEM\\CurrentControlSet\\Services\\Partmgr has been created in order to enable the performance counters") - } - - return nil -} - -// disablePerformanceCounters will disable performance counters using the IOCTL_DISK_PERFORMANCE_OFF IOCTL control code -func disablePerformanceCounters(path string) error { - utfPath, err := syscall.UTF16PtrFromString(path) - if err != nil { - return err - } - hFile, err := syscall.CreateFile(utfPath, - syscall.GENERIC_READ|syscall.GENERIC_WRITE, - syscall.FILE_SHARE_READ|syscall.FILE_SHARE_WRITE, - nil, - syscall.OPEN_EXISTING, - syscall.FILE_FLAG_BACKUP_SEMANTICS, - 0) - - if err != nil { - return err - } - defer syscall.CloseHandle(hFile) - var diskPerformanceSize uint32 - return syscall.DeviceIoControl(hFile, - ioctlDiskPerformanceOff, - nil, - 0, - nil, - 0, - &diskPerformanceSize, - nil) -} - -// getLogicalDriveStrings calls the syscall GetLogicalDriveStrings in order to get the list of logical drives -func getLogicalDriveStrings() ([]logicalDrive, error) { - lpBuffer := make([]byte, 254) - r1, _, e1 := syscall.Syscall(procGetLogicalDriveStringsW.Addr(), 2, uintptr(len(lpBuffer)), uintptr(unsafe.Pointer(&lpBuffer[0])), 0) - if r1 == 0 { - err := e1 - if e1 != errorSuccess { - err = syscall.EINVAL - } - return nil, err - } - var logicalDrives []logicalDrive - for _, v := range lpBuffer { - if v >= 65 && v <= 90 { - s := string(v) - if s == "A" || s == "B" { - continue - } - path := s + ":" - drive := logicalDrive{path, `\\.\` + path} - if isValidLogicalDrive(path) { - logicalDrives = append(logicalDrives, drive) - } - } - } - return logicalDrives, nil -} - -func containsDrive(devices []string, disk string) bool { - for _, vv := range devices { - if vv == disk { - return true - } - } - return false -} - -// isValidLogicalDrive should filter CD-ROM type drives based on https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-getdrivetypew -func isValidLogicalDrive(path string) bool { - utfPath, err := syscall.UTF16PtrFromString(path + `\`) - if err != nil { - return false - } - ret, _, err := syscall.Syscall(procGetDriveTypeW.Addr(), 1, uintptr(unsafe.Pointer(utfPath)), 0, 0) - - //DRIVE_NO_ROOT_DIR = 1 DRIVE_CDROM = 5 DRIVE_UNKNOWN = 0 DRIVE_RAMDISK = 6 - if ret == 1 || ret == 5 || ret == 0 || ret == 6 || err != errorSuccess { - return false - } - - //check for ramdisk label as the drive type is fixed in this case - volumeLabel, err := GetVolumeLabel(utfPath) - if err != nil { - return false - } - if strings.ToLower(volumeLabel) == "ramdisk" { - return false - } - return true -} - -// GetVolumeLabel function will retrieve the volume label -func GetVolumeLabel(path *uint16) (string, error) { - lpVolumeNameBuffer := make([]uint16, 256) - lpVolumeSerialNumber := uint32(0) - lpMaximumComponentLength := uint32(0) - lpFileSystemFlags := uint32(0) - lpFileSystemNameBuffer := make([]uint16, 256) - err := windows.GetVolumeInformation( - path, - &lpVolumeNameBuffer[0], - uint32(len(lpVolumeNameBuffer)), - &lpVolumeSerialNumber, - &lpMaximumComponentLength, - &lpFileSystemFlags, - &lpFileSystemNameBuffer[0], - uint32(len(lpFileSystemNameBuffer))) - if err != nil { - return "", err - } - return syscall.UTF16ToString(lpVolumeNameBuffer), nil -} diff --git a/libbeat/metric/system/diskio/diskstat_windows_test.go b/libbeat/metric/system/diskio/diskstat_windows_test.go deleted file mode 100644 index 15b347aff396..000000000000 --- a/libbeat/metric/system/diskio/diskstat_windows_test.go +++ /dev/null @@ -1,84 +0,0 @@ -// Licensed to Elasticsearch B.V. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Elasticsearch B.V. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -//go:build !integration && windows -// +build !integration,windows - -package diskio - -import ( - "testing" - - "github.com/stretchr/testify/assert" - - mbtest "github.com/elastic/beats/v7/metricbeat/mb/testing" - "github.com/elastic/elastic-agent-libs/mapstr" -) - -func TestCDriveFilterOnWindowsTestEnv(t *testing.T) { - // Test if flakey. - t.Skip("See https://github.com/elastic/beats/issues/17126") - - conf := map[string]interface{}{ - "module": "system", - "metricsets": []string{"diskio"}, - "diskio.include_devices": []string{"C:"}, - } - - f := mbtest.NewReportingMetricSetV2Error(t, conf) - data, errs := mbtest.ReportingFetchV2Error(f) - assert.Empty(t, errs) - assert.Equal(t, 1, len(data)) - assert.Equal(t, data[0].MetricSetFields["name"], "C:") - reads := data[0].MetricSetFields["read"].(mapstr.M) - writes := data[0].MetricSetFields["write"].(mapstr.M) - // Check values - readCount := reads["count"].(uint64) - readBytes := reads["bytes"].(uint64) - readTime := reads["time"].(uint64) - writeCount := writes["count"].(uint64) - writeBytes := writes["bytes"].(uint64) - writeTime := writes["time"].(uint64) - - assert.True(t, readCount > 0) - assert.True(t, readBytes > 0) - assert.True(t, readTime > 0) - - assert.True(t, writeCount > 0) - assert.True(t, writeBytes > 0) - assert.True(t, writeTime > 0) - err := disablePerformanceCounters(`\\.\C:`) - assert.NoError(t, err) -} - -func TestAllDrivesOnWindowsTestEnv(t *testing.T) { - conf := map[string]interface{}{ - "module": "system", - "metricsets": []string{"diskio"}, - } - - f := mbtest.NewReportingMetricSetV2Error(t, conf) - data, errs := mbtest.ReportingFetchV2Error(f) - assert.Empty(t, errs) - assert.True(t, len(data) >= 1) - drives, err := getLogicalDriveStrings() - assert.NoError(t, err) - for _, drive := range drives { - err := disablePerformanceCounters(drive.UNCPath) - assert.NoError(t, err) - } -} diff --git a/libbeat/metric/system/diskio/doc.go b/libbeat/metric/system/diskio/doc.go deleted file mode 100644 index 53b3bc0ecf5d..000000000000 --- a/libbeat/metric/system/diskio/doc.go +++ /dev/null @@ -1,18 +0,0 @@ -// Licensed to Elasticsearch B.V. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Elasticsearch B.V. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package diskio diff --git a/libbeat/metric/system/host/host.go b/libbeat/metric/system/host/host.go deleted file mode 100644 index a61c39ee11dc..000000000000 --- a/libbeat/metric/system/host/host.go +++ /dev/null @@ -1,96 +0,0 @@ -// Licensed to Elasticsearch B.V. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Elasticsearch B.V. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package host - -import ( - "github.com/elastic/elastic-agent-libs/mapstr" - "github.com/elastic/elastic-agent-libs/monitoring" - "github.com/elastic/go-sysinfo" - "github.com/elastic/go-sysinfo/types" -) - -// MapHostInfo converts the HostInfo to a MapStr based on ECS. -func MapHostInfo(info types.HostInfo) mapstr.M { - data := mapstr.M{ - "host": mapstr.M{ - "hostname": info.Hostname, - "architecture": info.Architecture, - "os": mapstr.M{ - "platform": info.OS.Platform, - "version": info.OS.Version, - "family": info.OS.Family, - "name": info.OS.Name, - "kernel": info.KernelVersion, - }, - }, - } - - // Optional params - if info.UniqueID != "" { - data.Put("host.id", info.UniqueID) - } - if info.Containerized != nil { - data.Put("host.containerized", *info.Containerized) - } - if info.OS.Codename != "" { - data.Put("host.os.codename", info.OS.Codename) - } - if info.OS.Build != "" { - data.Put("host.os.build", info.OS.Build) - } - if info.OS.Type != "" { - data.Put("host.os.type", info.OS.Type) - } - return data -} - -// ReportInfo reports the HostInfo to monitoring. -func ReportInfo(_ monitoring.Mode, V monitoring.Visitor) { - V.OnRegistryStart() - defer V.OnRegistryFinished() - - h, err := sysinfo.Host() - if err != nil { - return - } - info := h.Info() - - monitoring.ReportString(V, "hostname", info.Hostname) - monitoring.ReportString(V, "architecture", info.Architecture) - monitoring.ReportNamespace(V, "os", func() { - monitoring.ReportString(V, "platform", info.OS.Platform) - monitoring.ReportString(V, "version", info.OS.Version) - monitoring.ReportString(V, "family", info.OS.Family) - monitoring.ReportString(V, "name", info.OS.Name) - monitoring.ReportString(V, "kernel", info.KernelVersion) - - if info.OS.Codename != "" { - monitoring.ReportString(V, "codename", info.OS.Codename) - } - if info.OS.Build != "" { - monitoring.ReportString(V, "build", info.OS.Build) - } - }) - - if info.UniqueID != "" { - monitoring.ReportString(V, "id", info.UniqueID) - } - if info.Containerized != nil { - monitoring.ReportBool(V, "containerized", *info.Containerized) - } -} diff --git a/libbeat/metric/system/network/helpers.go b/libbeat/metric/system/network/helpers.go deleted file mode 100644 index 652ce05855a8..000000000000 --- a/libbeat/metric/system/network/helpers.go +++ /dev/null @@ -1,60 +0,0 @@ -// Licensed to Elasticsearch B.V. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Elasticsearch B.V. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package network - -import ( - "github.com/elastic/elastic-agent-libs/mapstr" - sysinfotypes "github.com/elastic/go-sysinfo/types" -) - -// MapProcNetCounters converts the NetworkCountersInfo struct into a MapStr acceptable for sending upstream -func MapProcNetCounters(raw *sysinfotypes.NetworkCountersInfo) mapstr.M { - - eventByProto := mapstr.M{ - "ip": combineMap(raw.Netstat.IPExt, raw.SNMP.IP), - "tcp": combineMap(raw.Netstat.TCPExt, raw.SNMP.TCP), - "udp": raw.SNMP.UDP, - "udp_lite": raw.SNMP.UDPLite, - "icmp": combineMap(raw.SNMP.ICMPMsg, raw.SNMP.ICMP), - } - - return eventByProto -} - -// combineMap concatinates two given maps -func combineMap(map1, map2 map[string]uint64) map[string]interface{} { - var compMap = make(map[string]interface{}) - - for k, v := range map1 { - compMap[k] = checkMaxConn(k, v) - } - for k, v := range map2 { - compMap[k] = checkMaxConn(k, v) - } - return compMap -} - -// checkMaxConn deals with the "oddball" MaxConn value, which is defined by RFC2012 as a integer -// while the other values are going to be unsigned counters -func checkMaxConn(inKey string, in uint64) interface{} { - - if inKey == "MaxConn" { - return int64(in) - } - return in -} diff --git a/libbeat/metric/system/numcpu/cpu_bsd.go b/libbeat/metric/system/numcpu/cpu_bsd.go deleted file mode 100644 index a3dcb2f82ee1..000000000000 --- a/libbeat/metric/system/numcpu/cpu_bsd.go +++ /dev/null @@ -1,56 +0,0 @@ -// Licensed to Elasticsearch B.V. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Elasticsearch B.V. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -//go:build openbsd || freebsd -// +build openbsd freebsd - -package numcpu - -/* -#include -#include -#include -#include -#include -*/ -import "C" - -import ( - "syscall" - "unsafe" -) - -// getCPU implements NumCPU on openbsd -// This is just using the HW_NCPU sysctl value. -func getCPU() (int, bool, error) { - - // Get count of available CPUs - ncpuMIB := [2]int32{C.CTL_HW, C.HW_NCPU} - callSize := uintptr(0) - var ncpu int - // Get size of return value. - _, _, errno := syscall.Syscall6(syscall.SYS___SYSCTL, uintptr(unsafe.Pointer(&ncpuMIB[0])), 2, 0, uintptr(unsafe.Pointer(&callSize)), 0, 0) - - if errno != 0 || callSize == 0 { - return -1, false, errno - } - - // Get CPU count - _, _, errno = syscall.Syscall6(syscall.SYS___SYSCTL, uintptr(unsafe.Pointer(&ncpuMIB[0])), 2, uintptr(unsafe.Pointer(&ncpu)), uintptr(unsafe.Pointer(&callSize)), 0, 0) - - return ncpu, true, nil -} diff --git a/libbeat/metric/system/numcpu/cpu_cgo.go b/libbeat/metric/system/numcpu/cpu_cgo.go deleted file mode 100644 index 0fded10405cb..000000000000 --- a/libbeat/metric/system/numcpu/cpu_cgo.go +++ /dev/null @@ -1,27 +0,0 @@ -// Licensed to Elasticsearch B.V. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Elasticsearch B.V. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -//go:build (freebsd && !cgo) || (openbsd && !cgo) -// +build freebsd,!cgo openbsd,!cgo - -package numcpu - -// getCPU is the fallback for unimplemented platforms -func getCPU() (int, bool, error) { - - return -1, false, nil -} diff --git a/libbeat/metric/system/numcpu/cpu_linux.go b/libbeat/metric/system/numcpu/cpu_linux.go deleted file mode 100644 index af5a80f51a13..000000000000 --- a/libbeat/metric/system/numcpu/cpu_linux.go +++ /dev/null @@ -1,89 +0,0 @@ -// Licensed to Elasticsearch B.V. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Elasticsearch B.V. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package numcpu - -import ( - "fmt" - "io/ioutil" - "os" - "strings" - - "github.com/pkg/errors" -) - -// getCPU implements NumCPU on linux -// see https://www.kernel.org/doc/Documentation/admin-guide/cputopology.rst -func getCPU() (int, bool, error) { - - // These are the files that LSCPU looks for - // This will report online CPUs, which are are the logical CPUS - // that are currently online and scheduleable by the system. - // Some users may expect a "present" count, which reflects what - // CPUs are available to the OS, online or off. - // These two values will only differ in cases where CPU hotplugging is in affect. - // This env var swaps between them. - _, isPresent := os.LookupEnv("LINUX_CPU_COUNT_PRESENT") - var cpuPath = "/sys/devices/system/cpu/online" - if isPresent { - cpuPath = "/sys/devices/system/cpu/present" - } - - rawFile, err := ioutil.ReadFile(cpuPath) - // if the file doesn't exist, assume it's a support issue and not a bug - if errors.Is(err, os.ErrNotExist) { - return -1, false, nil - } - if err != nil { - return -1, false, errors.Wrapf(err, "error reading file %s", cpuPath) - } - - cpuCount, err := parseCPUList(string(rawFile)) - if err != nil { - return -1, false, errors.Wrapf(err, "error parsing file %s", cpuPath) - } - return cpuCount, true, nil -} - -// parse the weird list files we get from sysfs -func parseCPUList(raw string) (int, error) { - - listPart := strings.Split(raw, ",") - count := 0 - for _, v := range listPart { - if strings.Contains(v, "-") { - rangeC, err := parseCPURange(v) - if err != nil { - return 0, errors.Wrapf(err, "error parsing line %s", v) - } - count = count + rangeC - } else { - count++ - } - } - return count, nil -} - -func parseCPURange(cpuRange string) (int, error) { - var first, last int - _, err := fmt.Sscanf(cpuRange, "%d-%d", &first, &last) - if err != nil { - return 0, errors.Wrapf(err, "error reading from range %s", cpuRange) - } - - return (last - first) + 1, nil -} diff --git a/libbeat/metric/system/numcpu/cpu_linux_test.go b/libbeat/metric/system/numcpu/cpu_linux_test.go deleted file mode 100644 index af761ad70c98..000000000000 --- a/libbeat/metric/system/numcpu/cpu_linux_test.go +++ /dev/null @@ -1,49 +0,0 @@ -// Licensed to Elasticsearch B.V. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Elasticsearch B.V. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package numcpu - -import ( - "testing" - - "github.com/stretchr/testify/assert" -) - -func TestCPUParse(t *testing.T) { - - type cpuInput struct { - input string - platform string - expected int - } - - cpuList := []cpuInput{ - {input: "0-23", platform: "basic X86", expected: 24}, - {input: "0-1", platform: "ARMv7", expected: 2}, - {input: "0-63", platform: "POWER7", expected: 64}, - {input: "0", platform: "QEMU", expected: 1}, - {input: "0-1,3", platform: "Kernel docs example 1", expected: 3}, - {input: "2,4-31,32-63", platform: "Kernel docs example 2", expected: 61}, - } - - for _, cpuTest := range cpuList { - res, err := parseCPUList(cpuTest.input) - assert.NoError(t, err, cpuTest.platform) - assert.Equal(t, cpuTest.expected, res, cpuTest.platform) - } - -} diff --git a/libbeat/metric/system/numcpu/cpu_other.go b/libbeat/metric/system/numcpu/cpu_other.go deleted file mode 100644 index 5737d423382a..000000000000 --- a/libbeat/metric/system/numcpu/cpu_other.go +++ /dev/null @@ -1,27 +0,0 @@ -// Licensed to Elasticsearch B.V. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Elasticsearch B.V. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -//go:build !linux && !freebsd && !openbsd && !windows -// +build !linux,!freebsd,!openbsd,!windows - -package numcpu - -// getCPU is the fallback for unimplemented platforms -func getCPU() (int, bool, error) { - - return -1, false, nil -} diff --git a/libbeat/metric/system/numcpu/cpu_windows.go b/libbeat/metric/system/numcpu/cpu_windows.go deleted file mode 100644 index b5ddd7669680..000000000000 --- a/libbeat/metric/system/numcpu/cpu_windows.go +++ /dev/null @@ -1,38 +0,0 @@ -// Licensed to Elasticsearch B.V. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Elasticsearch B.V. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package numcpu - -import ( - "github.com/pkg/errors" - - "github.com/elastic/gosigar/sys/windows" -) - -// getCPU implements NumCPU on windows -// For now, this is a bit of a hack that just asks for per-CPU performance data, and reports the CPU count -func getCPU() (int, bool, error) { - - // get per-cpu data - cpus, err := windows.NtQuerySystemProcessorPerformanceInformation() - if err != nil { - return -1, false, errors.Wrap(err, "NtQuerySystemProcessorPerformanceInformation failed") - } - - return len(cpus), true, nil - -} diff --git a/libbeat/metric/system/numcpu/numcpu.go b/libbeat/metric/system/numcpu/numcpu.go deleted file mode 100644 index b9dd1287f9b1..000000000000 --- a/libbeat/metric/system/numcpu/numcpu.go +++ /dev/null @@ -1,46 +0,0 @@ -// Licensed to Elasticsearch B.V. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Elasticsearch B.V. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package numcpu - -import ( - "runtime" - - "github.com/elastic/elastic-agent-libs/logp" -) - -// NumCPU is a drop-in replacement for runtime.NumCPU for accurate system config reporting. -// runtime.NumCPU doesn't query any kind of hardware or OS state, -// but merely uses affinity APIs to count what CPUs the given go process is available to run on. -// Most of the time this works okay for reporting metrics, but under certain conditions, such as cases where -// affinity masks are being manually set to manage the go process, or certain job controllers/VMs/etc, -// this number will not reflect the system config. -// Because this is drop-in, it will not return an error. -// if it can't fetch the CPU count the "correct" way, it'll fallback to runtime.NumCPU(). -func NumCPU() int { - count, exists, err := getCPU() - if err != nil { - logp.L().Debugf("Error fetching CPU count: %s", err) - return runtime.NumCPU() - } - if !exists { - logp.L().Debugf("Accurate CPU counts not available on platform, falling back to runtime.NumCPU for metrics") - return runtime.NumCPU() - } - - return count -} diff --git a/libbeat/metric/system/numcpu/numcpu_test.go b/libbeat/metric/system/numcpu/numcpu_test.go deleted file mode 100644 index 12ceba745120..000000000000 --- a/libbeat/metric/system/numcpu/numcpu_test.go +++ /dev/null @@ -1,40 +0,0 @@ -// Licensed to Elasticsearch B.V. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Elasticsearch B.V. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package numcpu - -import ( - "testing" - - "github.com/stretchr/testify/assert" -) - -func TestGetCPU(t *testing.T) { - cpuCount, exists, err := getCPU() - assert.NoError(t, err, "getCPU") - if exists { - assert.Greater(t, cpuCount, 0) - t.Logf("Got actual CPU counts.") - } - t.Logf("CPU Count: %d", cpuCount) -} - -func TestNumCPU(t *testing.T) { - cpuCount := NumCPU() - assert.NotEqual(t, -1, cpuCount) - t.Logf("CPU Count: %d", cpuCount) -} diff --git a/libbeat/metric/system/process/config.go b/libbeat/metric/system/process/config.go deleted file mode 100644 index 4fd2ba2c5056..000000000000 --- a/libbeat/metric/system/process/config.go +++ /dev/null @@ -1,26 +0,0 @@ -// Licensed to Elasticsearch B.V. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Elasticsearch B.V. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package process - -// IncludeTopConfig is the configuration for the "top N processes -// filtering" feature -type IncludeTopConfig struct { - Enabled bool `config:"enabled"` - ByCPU int `config:"by_cpu"` - ByMemory int `config:"by_memory"` -} diff --git a/libbeat/metric/system/process/helpers.go b/libbeat/metric/system/process/helpers.go deleted file mode 100644 index d2e72a874d19..000000000000 --- a/libbeat/metric/system/process/helpers.go +++ /dev/null @@ -1,100 +0,0 @@ -// Licensed to Elasticsearch B.V. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Elasticsearch B.V. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package process - -import ( - "math" - "time" - - "github.com/elastic/beats/v7/libbeat/common" - "github.com/elastic/beats/v7/libbeat/metric/system/numcpu" - "github.com/elastic/beats/v7/libbeat/opt" -) - -// unixTimeMsToTime converts a unix time given in milliseconds since Unix epoch -// to a common.Time value. -func unixTimeMsToTime(unixTimeMs uint64) string { - return common.Time(time.Unix(0, int64(unixTimeMs*1000000))).String() -} - -func stripNullByte(buf []byte) string { //nolint:deadcode,unused // used by platform-specific code - return string(buf[0 : len(buf)-1]) -} - -func stripNullByteRaw(buf []byte) []byte { //nolint:deadcode,unused // used by platform-specific code - return buf[0 : len(buf)-1] -} - -// GetProcMemPercentage returns process memory usage as a percent of total memory usage -func GetProcMemPercentage(proc ProcState, totalPhyMem uint64) opt.Float { - if totalPhyMem == 0 { - return opt.NewFloatNone() - } - - perc := (float64(proc.Memory.Rss.Bytes.ValueOr(0)) / float64(totalPhyMem)) - - return opt.FloatWith(common.Round(perc, 4)) -} - -// isProcessInSlice looks up proc in the processes slice and returns if -// found or not -func isProcessInSlice(processes []ProcState, proc ProcState) bool { - for _, p := range processes { - if p.Pid == proc.Pid { - return true - } - } - return false -} - -// GetProcCPUPercentage returns the percentage of total CPU time consumed by -// the process during the period between the given samples. Two percentages are -// returned (these must be multiplied by 100). The first is a normalized based -// on the number of cores such that the value ranges on [0, 1]. The second is -// not normalized and the value ranges on [0, number_of_cores]. -// -// Implementation note: The total system CPU time (including idle) is not -// provided so this method will resort to using the difference in wall-clock -// time multiplied by the number of cores as the total amount of CPU time -// available between samples. This could result in incorrect percentages if the -// wall-clock is adjusted (prior to Go 1.9) or the machine is suspended. -func GetProcCPUPercentage(s0, s1 ProcState) ProcState { - // Skip if we're missing the total ticks - if s0.CPU.Total.Ticks.IsZero() || s1.CPU.Total.Ticks.IsZero() { - return s1 - } - - timeDelta := s1.SampleTime.Sub(s0.SampleTime) - timeDeltaMillis := float64(timeDelta / time.Millisecond) - totalCPUDeltaMillis := int64(s1.CPU.Total.Ticks.ValueOr(0) - s0.CPU.Total.Ticks.ValueOr(0)) - - pct := float64(totalCPUDeltaMillis) / timeDeltaMillis - // In theory this can only happen if the time delta is 0, which is unlikely but possible. - // With all the type conversion and non-integer math, this is probably the safest way to check. - if math.IsNaN(pct) { - return s1 - } - normalizedPct := pct / float64(numcpu.NumCPU()) - - s1.CPU.Total.Norm.Pct = opt.FloatWith(common.Round(normalizedPct, common.DefaultDecimalPlacesCount)) - s1.CPU.Total.Pct = opt.FloatWith(common.Round(pct, common.DefaultDecimalPlacesCount)) - s1.CPU.Total.Value = opt.FloatWith(common.Round(float64(s1.CPU.Total.Ticks.ValueOr(0)), common.DefaultDecimalPlacesCount)) - - return s1 - -} diff --git a/libbeat/metric/system/process/process.go b/libbeat/metric/system/process/process.go deleted file mode 100644 index 00361e6c7072..000000000000 --- a/libbeat/metric/system/process/process.go +++ /dev/null @@ -1,443 +0,0 @@ -// Licensed to Elasticsearch B.V. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Elasticsearch B.V. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -//go:build darwin || freebsd || linux || windows || aix -// +build darwin freebsd linux windows aix - -package process - -import ( - "errors" - "fmt" - "os" - "sort" - "strings" - "time" - - "github.com/elastic/elastic-agent-libs/mapstr" - "github.com/elastic/go-sysinfo/types" - - "github.com/elastic/beats/v7/libbeat/common/match" - "github.com/elastic/beats/v7/libbeat/common/transform/typeconv" - "github.com/elastic/beats/v7/libbeat/metric/system/cgroup" - "github.com/elastic/beats/v7/libbeat/metric/system/resolve" - "github.com/elastic/beats/v7/libbeat/opt" - "github.com/elastic/elastic-agent-libs/logp" - sysinfo "github.com/elastic/go-sysinfo" -) - -// ProcsMap is a map where the keys are the names of processes and the value is the Process with that name -type ProcsMap map[int]ProcState - -// ProcCallback is a function that FetchPid* methods can call at various points to do OS-agnostic processing -type ProcCallback func(in ProcState) (ProcState, error) - -// CgroupPctStats stores rendered percent values from cgroup CPU data -type CgroupPctStats struct { - CPUTotalPct float64 - CPUTotalPctNorm float64 - CPUUserPct float64 - CPUUserPctNorm float64 - CPUSystemPct float64 - CPUSystemPctNorm float64 -} - -// Stats stores the stats of processes on the host. -type Stats struct { - Hostfs resolve.Resolver - Procs []string - ProcsMap ProcsMap - CPUTicks bool - EnvWhitelist []string - CacheCmdLine bool - IncludeTop IncludeTopConfig - CgroupOpts cgroup.ReaderOptions - EnableCgroups bool - - skipExtended bool - procRegexps []match.Matcher // List of regular expressions used to whitelist processes. - envRegexps []match.Matcher // List of regular expressions used to whitelist env vars. - cgroups *cgroup.Reader - logger *logp.Logger - host types.Host -} - -//PidState are the constants for various PID states -type PidState string - -var ( - //Dead state, on linux this is both "x" and "X" - Dead PidState = "dead" - //Running state - Running PidState = "running" - //Sleeping state - Sleeping PidState = "sleeping" - //Idle state. On linux this is "D" - Idle PidState = "idle" - //Stopped state. - Stopped PidState = "stopped" - //Zombie state. - Zombie PidState = "zombie" - //WakeKill is a linux state only found on kernels 2.6.33-3.13 - WakeKill PidState = "wakekill" - //Waking is a linux state only found on kernels 2.6.33-3.13 - Waking PidState = "waking" - //Parked is a linux state. On the proc man page, it says it's available on 3.9-3.13, but it appears to still be in the code. - Parked PidState = "parked" - //Unknown state - Unknown PidState = "unknown" -) - -// PidStates is a Map of all pid states, mostly applicable to linux -var PidStates = map[byte]PidState{ - 'S': Sleeping, - 'R': Running, - 'D': Idle, // Waiting in uninterruptible disk sleep, on some kernels this is marked as I below - 'I': Idle, // in the scheduler, TASK_IDLE is defined as (TASK_UNINTERRUPTIBLE | TASK_NOLOAD) - 'T': Stopped, - 'Z': Zombie, - 'X': Dead, - 'x': Dead, - 'K': WakeKill, - 'W': Waking, - 'P': Parked, -} - -// ListStates is a wrapper that returns a list of processess with only the basic PID info filled out. -func ListStates(hostfs resolve.Resolver) ([]ProcState, error) { - init := Stats{ - Hostfs: hostfs, - Procs: []string{".*"}, - EnableCgroups: false, - skipExtended: true, - } - err := init.Init() - if err != nil { - return nil, fmt.Errorf("error initializing process collectors: %w", err) - } - - // actually fetch the PIDs from the OS-specific code - _, plist, err := init.FetchPids() //nolint:typecheck // platform-specific code - if err != nil { - return nil, fmt.Errorf("error gathering PIDs: %w", err) - } - - return plist, nil -} - -// Init initializes a Stats instance. It returns errors if the provided process regexes -// cannot be compiled. -func (procStats *Stats) Init() error { - procStats.logger = logp.NewLogger("processes") - var err error - procStats.host, err = sysinfo.Host() - if err != nil { - procStats.host = nil - procStats.logger.Warnf("Getting host details: %v", err) - } - - //footcannon prevention - if procStats.Hostfs == nil { - procStats.Hostfs = resolve.NewTestResolver("/") - } - - procStats.ProcsMap = make(ProcsMap) - - if len(procStats.Procs) == 0 { - return nil - } - - procStats.procRegexps = []match.Matcher{} - for _, pattern := range procStats.Procs { - reg, err := match.Compile(pattern) - if err != nil { - return fmt.Errorf("failed to compile regexp [%s]: %w", pattern, err) - } - procStats.procRegexps = append(procStats.procRegexps, reg) - } - - procStats.envRegexps = make([]match.Matcher, 0, len(procStats.EnvWhitelist)) - for _, pattern := range procStats.EnvWhitelist { - reg, err := match.Compile(pattern) - if err != nil { - return fmt.Errorf("failed to compile env whitelist regexp [%v]: %w", pattern, err) - } - procStats.envRegexps = append(procStats.envRegexps, reg) - } - - if procStats.EnableCgroups { - cgReader, err := cgroup.NewReaderOptions(procStats.CgroupOpts) - if errors.Is(err, cgroup.ErrCgroupsMissing) { - logp.Warn("cgroup data collection will be disabled: %v", err) - } else if err != nil { - return fmt.Errorf("error initializing cgroup reader: %w", err) - } - procStats.cgroups = cgReader - } - return nil -} - -// Get fetches the configured processes and returns a list of formatted events and root ECS fields -func (procStats *Stats) Get() ([]mapstr.M, []mapstr.M, error) { - //If the user hasn't configured any kind of process glob, return - if len(procStats.Procs) == 0 { - return nil, nil, nil - } - - // actually fetch the PIDs from the OS-specific code - pidMap, plist, err := procStats.FetchPids() //nolint:typecheck // platform-specific code - - if err != nil { - return nil, nil, fmt.Errorf("error gathering PIDs: %w", err) - } - // We use this to track processes over time. - procStats.ProcsMap = pidMap - - // filter the process list that will be passed down to users - plist = procStats.includeTopProcesses(plist) - - // This is a holdover until we migrate this library to metricbeat/internal - // At which point we'll use the memory code there. - var totalPhyMem uint64 - if procStats.host != nil { - memStats, err := procStats.host.Memory() - if err != nil { - procStats.logger.Warnf("Getting memory details: %v", err) - } else { - totalPhyMem = memStats.Total - } - - } - - //Format the list to the MapStr type used by the outputs - procs := []mapstr.M{} - rootEvents := []mapstr.M{} - - // bulk of data collection done, now convert to the various data formats expected by the output - for _, process := range plist { - // Add the RSS pct memory first - process.Memory.Rss.Pct = GetProcMemPercentage(process, totalPhyMem) - //Create the root event - root := process.FormatForRoot() - rootMap := mapstr.M{} - err := typeconv.Convert(&rootMap, root) - if err != nil { - return nil, nil, fmt.Errorf("error converting process for pid %d: %w", process.Pid.ValueOr(0), err) - } - - proc, err := procStats.getProcessEvent(process) - if err != nil { - return nil, nil, fmt.Errorf("error fetching process event for pid %d: %w", process.Pid.ValueOr(0), err) - } - - procs = append(procs, proc) - rootEvents = append(rootEvents, rootMap) - } - - return procs, rootEvents, nil -} - -// GetOne fetches process data for a given PID if its name matches the regexes provided from the host. -func (procStats *Stats) GetOne(pid int) (mapstr.M, error) { - pidStat, _, err := procStats.pidFill(pid, false) - if err != nil { - return nil, fmt.Errorf("error fetching PID %d: %w", pid, err) - } - newMap := make(ProcsMap) - newMap[pid] = pidStat - procStats.ProcsMap = newMap - - return procStats.getProcessEvent(pidStat) -} - -// GetSelf gets process info for the beat itself -func (procStats *Stats) GetSelf() (ProcState, error) { - self := os.Getpid() - - pidStat, _, err := procStats.pidFill(self, false) - if err != nil { - return ProcState{}, fmt.Errorf("error fetching PID %d: %w", self, err) - } - - return pidStat, nil -} - -// pidIter wraps a few lines of generic code that all OS-specific FetchPids() functions must call. -// this also handles the process of adding to the maps/lists in order to limit the code duplication in all the OS implementations -func (procStats *Stats) pidIter(pid int, procMap map[int]ProcState, proclist []ProcState) (map[int]ProcState, []ProcState) { - status, saved, err := procStats.pidFill(pid, true) - if err != nil { - procStats.logger.Debugf("Error fetching PID info for %d, skipping: %s", pid, err) - return procMap, proclist - } - if !saved { - procStats.logger.Debugf("Process name does not match the provided regex; PID=%d; name=%s", pid, status.Name) - return procMap, proclist - } - procMap[pid] = status - proclist = append(proclist, status) - - return procMap, proclist -} - -// pidFill is an entrypoint used by OS-specific code to fill out a pid. -// This in turn calls various OS-specific code to fill out the various bits of PID data -// This is done to minimize the code duplication between different OS implementations -// The second return value will only be false if an event has been filtered out -func (procStats *Stats) pidFill(pid int, filter bool) (ProcState, bool, error) { - // Fetch proc state so we can get the name for filtering based on user's filter. - - // OS-specific entrypoint, get basic info so we can at least run matchProcess - status, err := GetInfoForPid(procStats.Hostfs, pid) //nolint:typecheck // platform-specific code - if err != nil { - return status, true, fmt.Errorf("GetInfoForPid: %w", err) - } - if procStats.skipExtended { - return status, true, nil - } - status = procStats.cacheCmdLine(status) - - // Filter based on user-supplied func - if filter { - if !procStats.matchProcess(status.Name) { - return status, false, nil - } - } - - //If we've passed the filter, continue to fill out the rest of the metrics - status, err = FillPidMetrics(procStats.Hostfs, pid, status, procStats.isWhitelistedEnvVar) //nolint:typecheck // platform-specific code - if err != nil { - return status, true, fmt.Errorf("FillPidMetrics: %w", err) - } - if len(status.Args) > 0 && status.Cmdline == "" { - status.Cmdline = strings.Join(status.Args, " ") - } - - //postprocess with cgroups and percentages - last, ok := procStats.ProcsMap[status.Pid.ValueOr(0)] - status.SampleTime = time.Now() - if procStats.EnableCgroups { - cgStats, err := procStats.cgroups.GetStatsForPid(status.Pid.ValueOr(0)) - if err != nil { - return status, true, fmt.Errorf("cgroups.GetStatsForPid: %w", err) - } - status.Cgroup = cgStats - if ok { - status.Cgroup.FillPercentages(last.Cgroup, status.SampleTime, last.SampleTime) - } - } // end cgroups processor - - if ok { - status = GetProcCPUPercentage(last, status) - } - - return status, true, nil -} - -// cacheCmdLine fills out Env and arg metrics from any stored previous metrics for the pid -func (procStats *Stats) cacheCmdLine(in ProcState) ProcState { - if previousProc, ok := procStats.ProcsMap[in.Pid.ValueOr(0)]; ok { - if procStats.CacheCmdLine { - in.Args = previousProc.Args - in.Cmdline = previousProc.Cmdline - } - env := previousProc.Env - in.Env = env - } - return in -} - -// return a formatted MapStr of the process metrics -func (procStats *Stats) getProcessEvent(process ProcState) (mapstr.M, error) { - - // Remove CPUTicks if needed - if !procStats.CPUTicks { - process.CPU.User.Ticks = opt.NewUintNone() - process.CPU.System.Ticks = opt.NewUintNone() - process.CPU.Total.Ticks = opt.NewUintNone() - } - - proc := mapstr.M{} - err := typeconv.Convert(&proc, process) - - return proc, err -} - -// matchProcess checks if the provided process name matches any of the process regexes -func (procStats *Stats) matchProcess(name string) bool { - for _, reg := range procStats.procRegexps { - if reg.MatchString(name) { - return true - } - } - return false -} - -// includeTopProcesses filters down the metrics based on top CPU or top Memory settings -func (procStats *Stats) includeTopProcesses(processes []ProcState) []ProcState { - if !procStats.IncludeTop.Enabled || - (procStats.IncludeTop.ByCPU == 0 && procStats.IncludeTop.ByMemory == 0) { - - return processes - } - - var result []ProcState - if procStats.IncludeTop.ByCPU > 0 { - numProcs := procStats.IncludeTop.ByCPU - if len(processes) < procStats.IncludeTop.ByCPU { - numProcs = len(processes) - } - - sort.Slice(processes, func(i, j int) bool { - return processes[i].CPU.Total.Pct.ValueOr(0) > processes[j].CPU.Total.Pct.ValueOr(0) - }) - result = append(result, processes[:numProcs]...) - } - - if procStats.IncludeTop.ByMemory > 0 { - numProcs := procStats.IncludeTop.ByMemory - if len(processes) < procStats.IncludeTop.ByMemory { - numProcs = len(processes) - } - - sort.Slice(processes, func(i, j int) bool { - return processes[i].Memory.Rss.Bytes.ValueOr(0) > processes[j].Memory.Rss.Bytes.ValueOr(0) - }) - for _, proc := range processes[:numProcs] { - if !isProcessInSlice(result, proc) { - result = append(result, proc) - } - } - } - - return result -} - -// isWhitelistedEnvVar returns true if the given variable name is a match for -// the whitelist. If the whitelist is empty it returns false. -func (procStats Stats) isWhitelistedEnvVar(varName string) bool { - if len(procStats.envRegexps) == 0 { - return false - } - - for _, p := range procStats.envRegexps { - if p.MatchString(varName) { - return true - } - } - return false -} diff --git a/libbeat/metric/system/process/process_aix.go b/libbeat/metric/system/process/process_aix.go deleted file mode 100644 index fdd35ba1f958..000000000000 --- a/libbeat/metric/system/process/process_aix.go +++ /dev/null @@ -1,189 +0,0 @@ -// Licensed to Elasticsearch B.V. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Elasticsearch B.V. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package process - -import ( - "bytes" - "fmt" - "io" - "os" - "os/user" - "strconv" - "syscall" - "unsafe" - - "github.com/elastic/beats/v7/libbeat/metric/system/resolve" - "github.com/elastic/beats/v7/libbeat/opt" -) - -// FetchPids returns a map and array of pids -func (procStats *Stats) FetchPids() (ProcsMap, []ProcState, error) { - - info := C.struct_procsinfo64{} - pid := C.pid_t(0) - - procMap := make(ProcsMap, 0) - var plist []ProcState - for { - // getprocs first argument is a void* - num, err := C.getprocs(unsafe.Pointer(&info), C.sizeof_struct_procsinfo64, nil, 0, &pid, 1) - if err != nil { - return nil, nil, fmt.Errorf("error fetching PIDs: %w", err) - } - procMap, plist = procStats.pidIter(int(info.pi_pid), procMap, plist) - - if num == 0 { - break - } - } - return procMap, plist, nil -} - -// GetInfoForPid returns basic info for the process -func GetInfoForPid(_ resolve.Resolver, pid int) (ProcState, error) { - info := C.struct_procsinfo64{} - cpid := C.pid_t(pid) - - num, err := C.getprocs(unsafe.Pointer(&info), C.sizeof_struct_procsinfo64, nil, 0, &cpid, 1) - if err != nil { - return ProcState{}, fmt.Errorf("error in getprocs: %w", err) - } - if num != 1 { - return ProcState{}, syscall.ESRCH - } - - state := ProcState{} - state.Pid = opt.IntWith(pid) - - state.Name = C.GoString(&info.pi_comm[0]) - state.Ppid = opt.IntWith(int(info.pi_ppid)) - state.Pgid = opt.IntWith(int(info.pi_pgrp)) - - switch info.pi_state { - case C.SACTIVE: - state.State = Running - case C.SIDL: - state.State = Idle - case C.SSTOP: - state.State = Stopped - case C.SZOMB: - state.State = Zombie - case C.SSWAP: - state.State = Sleeping - default: - state.State = Unknown - } - - // Get process username. Fallback to UID if username is not available. - uid := strconv.Itoa(int(info.pi_uid)) - userID, err := user.LookupId(uid) - if err == nil && userID.Username != "" { - state.Username = userID.Username - } else { - state.Username = uid - } - - return state, nil -} - -// FillPidMetrics is the aix implementation -func FillPidMetrics(_ resolve.Resolver, pid int, state ProcState, filter func(string) bool) (ProcState, error) { - pagesize := uint64(os.Getpagesize()) - info := C.struct_procsinfo64{} - cpid := C.pid_t(pid) - - num, err := C.getprocs(unsafe.Pointer(&info), C.sizeof_struct_procsinfo64, nil, 0, &cpid, 1) - if err != nil { - return state, fmt.Errorf("error in getprocs: %w", err) - } - if num != 1 { - return state, syscall.ESRCH - } - - state.Memory.Size = opt.UintWith(uint64(info.pi_size) * pagesize) - state.Memory.Share = opt.UintWith(uint64(info.pi_sdsize) * pagesize) - state.Memory.Rss.Bytes = opt.UintWith(uint64(info.pi_drss+info.pi_trss) * pagesize) - - state.CPU.StartTime = unixTimeMsToTime(uint64(info.pi_start) * 1000) - state.CPU.User.Ticks = opt.UintWith(uint64(info.pi_utime) * 1000) - state.CPU.System.Ticks = opt.UintWith(uint64(info.pi_stime) * 1000) - state.CPU.Total.Ticks = opt.UintWith(opt.SumOptUint(state.CPU.User.Ticks, state.CPU.System.Ticks)) - - // Get Proc Args - /* If buffer is not large enough, args are truncated */ - buf := make([]byte, 8192) - info.pi_pid = C.pid_t(pid) - - if _, err := C.getargs(unsafe.Pointer(&info), C.sizeof_struct_procsinfo64, (*C.char)(&buf[0]), 8192); err != nil { - return state, fmt.Errorf("error in gitargs: %w", err) - } - - bbuf := bytes.NewBuffer(buf) - var args []string - - for { - arg, err := bbuf.ReadBytes(0) - if err == io.EOF || arg[0] == 0 { - break - } - if err != nil { - return state, fmt.Errorf("error reading args buffer: %w", err) - } - - args = append(args, stripNullByte(arg)) - } - state.Args = args - state.Exe = args[0] - - // get env vars - buf = make([]byte, 8192) - - if _, err := C.getevars(unsafe.Pointer(&info), C.sizeof_struct_procsinfo64, (*C.char)(&buf[0]), 8192); err != nil { - return state, fmt.Errorf("error in getevars: %w", err) - } - - if state.Env != nil { - return state, nil - } - - bbuf = bytes.NewBuffer(buf) - delim := []byte{61} // "=" - vars := map[string]string{} - for { - line, err := bbuf.ReadBytes(0) - if err == io.EOF || line[0] == 0 { - break - } - if err != nil { - return state, fmt.Errorf("error: %w", err) - } - - pair := bytes.SplitN(stripNullByteRaw(line), delim, 2) - if len(pair) != 2 { - return state, fmt.Errorf("error reading environment: %w", err) - } - eKey := string(pair[0]) - if filter == nil || filter(eKey) { - vars[string(pair[0])] = string(pair[1]) - } - - } - state.Env = vars - - return state, nil -} diff --git a/libbeat/metric/system/process/process_darwin.go b/libbeat/metric/system/process/process_darwin.go deleted file mode 100644 index e63bb856a9c6..000000000000 --- a/libbeat/metric/system/process/process_darwin.go +++ /dev/null @@ -1,252 +0,0 @@ -// Licensed to Elasticsearch B.V. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Elasticsearch B.V. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package process - -/* -#include -#include -#include -#include -#include -#include -#include -#include -#include -*/ -import "C" -import ( - "bytes" - "encoding/binary" - "fmt" - "io" - "os/user" - "strconv" - "syscall" - "time" - "unsafe" - - "github.com/elastic/beats/v7/libbeat/metric/system/resolve" - "github.com/elastic/beats/v7/libbeat/opt" - "github.com/elastic/elastic-agent-libs/mapstr" -) - -// FetchPids returns a map and array of pids -func (procStats *Stats) FetchPids() (ProcsMap, []ProcState, error) { - n := C.proc_listpids(C.PROC_ALL_PIDS, 0, nil, 0) - if n <= 0 { - return nil, nil, syscall.EINVAL - } - buf := make([]byte, n) - n = C.proc_listpids(C.PROC_ALL_PIDS, 0, unsafe.Pointer(&buf[0]), n) - if n <= 0 { - return nil, nil, syscall.ENOMEM - } - - var pid int32 - num := int(n) / binary.Size(pid) - - bbuf := bytes.NewBuffer(buf) - - procMap := make(ProcsMap, 0) - var plist []ProcState - - for i := 0; i < num; i++ { - if err := binary.Read(bbuf, binary.LittleEndian, &pid); err != nil { - procStats.logger.Debugf("Errror reading from PROC_ALL_PIDS buffer: %s", err) - continue - } - if pid == 0 { - continue - } - procMap, plist = procStats.pidIter(int(pid), procMap, plist) - } - - return procMap, plist, nil -} - -// GetInfoForPid returns basic info for the process -func GetInfoForPid(_ resolve.Resolver, pid int) (ProcState, error) { - info := C.struct_proc_taskallinfo{} - - err := taskInfo(pid, &info) - if err != nil { - return ProcState{}, fmt.Errorf("Could not read task for pid %d", pid) - } - - status := ProcState{} - - status.Name = C.GoString(&info.pbsd.pbi_comm[0]) - - switch info.pbsd.pbi_status { - case C.SIDL: - status.State = Idle - case C.SRUN: - status.State = Running - case C.SSLEEP: - status.State = Sleeping - case C.SSTOP: - status.State = Stopped - case C.SZOMB: - status.State = Zombie - default: - status.State = Unknown - } - - status.Ppid = opt.IntWith(int(info.pbsd.pbi_ppid)) - status.Pid = opt.IntWith(pid) - status.Pgid = opt.IntWith(int(info.pbsd.pbi_pgid)) - - // Get process username. Fallback to UID if username is not available. - uid := strconv.Itoa(int(info.pbsd.pbi_uid)) - user, err := user.LookupId(uid) - if err == nil && user.Username != "" { - status.Username = user.Username - } else { - status.Username = uid - } - - // grab memory info + process time while we have it from struct_proc_taskallinfo - status.Memory.Size = opt.UintWith(uint64(info.ptinfo.pti_virtual_size)) - status.Memory.Rss.Bytes = opt.UintWith(uint64(info.ptinfo.pti_resident_size)) - - status.CPU.User.Ticks = opt.UintWith(uint64(info.ptinfo.pti_total_user) / uint64(time.Millisecond)) - status.CPU.System.Ticks = opt.UintWith(uint64(info.ptinfo.pti_total_system) / uint64(time.Millisecond)) - status.CPU.Total.Ticks = opt.UintWith(opt.SumOptUint(status.CPU.User.Ticks, status.CPU.System.Ticks)) - status.CPU.StartTime = unixTimeMsToTime((uint64(info.pbsd.pbi_start_tvsec) * 1000) + (uint64(info.pbsd.pbi_start_tvusec) / 1000)) - - return status, nil -} - -// FillPidMetrics is the darwin implementation -func FillPidMetrics(_ resolve.Resolver, pid int, state ProcState, filter func(string) bool) (ProcState, error) { - - args, exe, env, err := getProcArgs(pid, filter) - if err != nil { - return state, fmt.Errorf("error fetching string data from process: %w", err) - } - - state.Args = args - state.Exe = exe - if state.Env == nil { - state.Env = env - } - - return state, nil -} - -func getProcArgs(pid int, filter func(string) bool) ([]string, string, mapstr.M, error) { - - exeName := "" - - mib := []C.int{C.CTL_KERN, C.KERN_PROCARGS2, C.int(pid)} - argmax := uintptr(C.ARG_MAX) - buf := make([]byte, argmax) - err := sysctl(mib, &buf[0], &argmax, nil, 0) - if err != nil { - return nil, "", nil, fmt.Errorf("error in sysctl: %w", err) - } - - bbuf := bytes.NewBuffer(buf) - bbuf.Truncate(int(argmax)) - - var argc int32 // raw buffer - binary.Read(bbuf, binary.LittleEndian, &argc) // read length - - path, err := bbuf.ReadBytes(0) - if err != nil { - return nil, "", nil, fmt.Errorf("error reading the executable name: %w", err) - } - - exeName = stripNullByte(path) - - // skip trailing nul bytes - for { - c, err := bbuf.ReadByte() - if err != nil { - return nil, "", nil, fmt.Errorf("error skipping nul values in KERN_PROCARGS2 buffer: %w", err) - } - if c != 0 { - bbuf.UnreadByte() - break - } - } - - // read CLI args - var argv []string - for i := 0; i < int(argc); i++ { - arg, err := bbuf.ReadBytes(0) - if err == io.EOF { - break - } - if err != nil { - return nil, exeName, nil, fmt.Errorf("error reading args from KERN_PROCARGS2: %w", err) - } - argv = append(argv, stripNullByte(arg)) - } - - delim := []byte{61} // "=" for key value pairs - - envVars := mapstr.M{} - for { - line, err := bbuf.ReadBytes(0) - if err == io.EOF || line[0] == 0 { - break - } - if err != nil { - return argv, exeName, nil, fmt.Errorf("error reading args from KERN_PROCARGS2 buffer: %w", err) - } - pair := bytes.SplitN(stripNullByteRaw(line), delim, 2) - - if len(pair) != 2 { - return argv, exeName, nil, fmt.Errorf("error reading process information from KERN_PROCARGS2: %w", err) - } - eKey := string(pair[0]) - if filter == nil || filter(eKey) { - envVars[string(pair[0])] = string(pair[1]) - } - - } - - return argv, exeName, envVars, nil -} - -func taskInfo(pid int, info *C.struct_proc_taskallinfo) error { - size := C.int(unsafe.Sizeof(*info)) - ptr := unsafe.Pointer(info) - - n := C.proc_pidinfo(C.int(pid), C.PROC_PIDTASKALLINFO, 0, ptr, size) - if n != size { - return fmt.Errorf("could not read process info for pid %d", pid) - } - - return nil -} - -func sysctl(mib []C.int, old *byte, oldlen *uintptr, - new *byte, newlen uintptr) (err error) { - var p0 unsafe.Pointer - p0 = unsafe.Pointer(&mib[0]) - _, _, e1 := syscall.Syscall6(syscall.SYS___SYSCTL, uintptr(p0), - uintptr(len(mib)), - uintptr(unsafe.Pointer(old)), uintptr(unsafe.Pointer(oldlen)), - uintptr(unsafe.Pointer(new)), uintptr(newlen)) - if e1 != 0 { - err = e1 - } - return -} diff --git a/libbeat/metric/system/process/process_linux_common.go b/libbeat/metric/system/process/process_linux_common.go deleted file mode 100644 index 9ac5d8b11ddb..000000000000 --- a/libbeat/metric/system/process/process_linux_common.go +++ /dev/null @@ -1,446 +0,0 @@ -// Licensed to Elasticsearch B.V. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Elasticsearch B.V. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -//go:build freebsd || linux -// +build freebsd linux - -package process - -import ( - "bytes" - "fmt" - "io" - "io/ioutil" - "os" - "os/user" - "strconv" - "strings" - "syscall" - - "github.com/elastic/beats/v7/libbeat/metric/system/resolve" - "github.com/elastic/beats/v7/libbeat/opt" - "github.com/elastic/elastic-agent-libs/logp" - "github.com/elastic/elastic-agent-libs/mapstr" -) - -// Indulging in one non-const global variable for the sake of storing boot time -// This value obviously won't change while this code is running. -var bootTime uint64 - -// system tick multiplier, see C.sysconf(C._SC_CLK_TCK) -const ticks = 100 - -// FetchPids is the linux implementation of FetchPids -func (procStats *Stats) FetchPids() (ProcsMap, []ProcState, error) { - dir, err := os.Open(procStats.Hostfs.ResolveHostFS("proc")) - if err != nil { - return nil, nil, fmt.Errorf("error reading from procfs %s: %w", procStats.Hostfs.ResolveHostFS("proc"), err) - } - defer dir.Close() - - const readAllDirnames = -1 // see os.File.Readdirnames doc - - names, err := dir.Readdirnames(readAllDirnames) - if err != nil { - return nil, nil, fmt.Errorf("error reading directory names: %w", err) - } - - procMap := make(ProcsMap, 0) - var plist []ProcState - - // Iterate over the directory, fetch just enough info so we can filter based on user input. - logger := logp.L() - for _, name := range names { - - if !dirIsPid(name) { - continue - } - // Will this actually fail? - pid, err := strconv.Atoi(name) - if err != nil { - logger.Debugf("Error converting PID name %s", name) - continue - } - procMap, plist = procStats.pidIter(pid, procMap, plist) - } - - return procMap, plist, nil -} - -// FillPidMetrics is the linux implementation of the extended PID metrics fetcher -func FillPidMetrics(hostfs resolve.Resolver, pid int, state ProcState, filter func(string) bool) (ProcState, error) { - // Memory Data - var err error - state.Memory, err = getMemData(hostfs, pid) - if err != nil { - return state, fmt.Errorf("error getting memory data for pid %d: %w", pid, err) - } - - // CPU Data - state.CPU, err = getCPUTime(hostfs, pid) - if err != nil { - return state, fmt.Errorf("error getting CPU data for pid %d: %w", pid, err) - } - - // CLI args - if len(state.Args) == 0 { - state.Args, err = getArgs(hostfs, pid) - if err != nil { - return state, fmt.Errorf("error getting CLI args for pid %d: %w", pid, err) - } - - } - - // FD metrics - state.FD, err = getFDStats(hostfs, pid) - if err != nil { - return state, fmt.Errorf("error getting FD metrics for pid %d: %w", pid, err) - } - - if state.Env == nil { - // env vars - state.Env, err = getEnvData(hostfs, pid, filter) - if err != nil { - return state, fmt.Errorf("error getting env data for pid %d: %w", pid, err) - } - } - - state.Exe, state.Cwd, err = getProcStringData(hostfs, pid) - if err != nil { - return state, fmt.Errorf("error getting metadata for pid %d: %w", pid, err) - } - - //username - state.Username, err = getUser(hostfs, pid) - if err != nil { - return state, fmt.Errorf("error creating username for pid %d: %w", pid, err) - } - return state, nil -} - -// GetInfoForPid fetches the basic hostinfo from /proc/[PID]/stat -func GetInfoForPid(hostfs resolve.Resolver, pid int) (ProcState, error) { - path := hostfs.Join("proc", strconv.Itoa(pid), "stat") - data, err := ioutil.ReadFile(path) - // Transform the error into a more sensible error in cases where the directory doesn't exist, i.e the process is gone - if err != nil { - if os.IsNotExist(err) { - return ProcState{}, syscall.ESRCH - } - return ProcState{}, fmt.Errorf("error reading procdir %s: %w", path, err) - - } - - state := ProcState{} - - // Extract the comm value with is surrounded by parentheses. - lIdx := bytes.Index(data, []byte("(")) - rIdx := bytes.LastIndex(data, []byte(")")) - if lIdx < 0 || rIdx < 0 || lIdx >= rIdx || rIdx+2 >= len(data) { - return state, fmt.Errorf("failed to extract comm for pid %d from '%v'", pid, string(data)) - } - state.Name = string(data[lIdx+1 : rIdx]) - - // Extract the rest of the fields that we are interested in. - fields := bytes.Fields(data[rIdx+2:]) - if len(fields) <= 36 { - return state, fmt.Errorf("expected more stat fields for pid %d from '%v'", pid, string(data)) - } - - interests := bytes.Join([][]byte{ - fields[0], // state - fields[1], // ppid - fields[2], // pgrp - }, []byte(" ")) - - var procState string - var ppid, pgid int - - _, err = fmt.Fscan(bytes.NewBuffer(interests), - &procState, - &ppid, - &pgid, - ) - if err != nil { - return state, fmt.Errorf("failed to parse stat fields for pid %d from '%v': %w", pid, string(data), err) - } - state.State = getProcState(procState[0]) - state.Ppid = opt.IntWith(ppid) - state.Pgid = opt.IntWith(pgid) - state.Pid = opt.IntWith(pid) - - return state, nil -} - -func getProcStringData(hostfs resolve.Resolver, pid int) (string, string, error) { - exe, err := os.Readlink(hostfs.Join("proc", strconv.Itoa(pid), "exe")) - if err != nil { - return "", "", fmt.Errorf("error fetching exe from pid %d: %w", pid, err) - } - - cwd, err := os.Readlink(hostfs.Join("proc", strconv.Itoa(pid), "cwd")) - if err != nil { - return "", "", fmt.Errorf("error fetching cwd for pid %d: %w", pid, err) - } - - return exe, cwd, nil -} - -func dirIsPid(name string) bool { - if name[0] < '0' || name[0] > '9' { - return false - } - return true -} - -func getUser(hostfs resolve.Resolver, pid int) (string, error) { - status, err := getProcStatus(hostfs, pid) - if err != nil { - return "", fmt.Errorf("error fetching user ID for pid %d: %w", pid, err) - } - uidValues, ok := status["Uid"] - if !ok { - return "", fmt.Errorf("uid not found in proc status") - } - uidStrings := strings.Fields(uidValues) - var userFinal string - user, err := user.LookupId(uidStrings[0]) - if err == nil { - userFinal = user.Username - } else { - userFinal = uidStrings[0] - } - - return userFinal, nil -} - -func getEnvData(hostfs resolve.Resolver, pid int, filter func(string) bool) (mapstr.M, error) { - path := hostfs.Join("proc", strconv.Itoa(pid), "environ") - data, err := ioutil.ReadFile(path) - if err != nil { - return nil, fmt.Errorf("error opening file %s: %w", path, err) - } - env := mapstr.M{} - - pairs := bytes.Split(data, []byte{0}) - for _, kv := range pairs { - parts := bytes.SplitN(kv, []byte{'='}, 2) - if len(parts) != 2 { - continue - } - - key := string(bytes.TrimSpace(parts[0])) - if key == "" { - continue - } - - if filter == nil || filter(key) { - env[key] = string(bytes.TrimSpace(parts[1])) - } - } - return env, nil -} - -func getMemData(hostfs resolve.Resolver, pid int) (ProcMemInfo, error) { - // Memory data - state := ProcMemInfo{} - path := hostfs.Join("proc", strconv.Itoa(pid), "statm") - data, err := ioutil.ReadFile(path) - if err != nil { - return state, fmt.Errorf("error opening file %s: %w", path, err) - } - - fields := strings.Fields(string(data)) - - size, err := strconv.ParseUint(fields[0], 10, 64) - if err != nil { - return state, fmt.Errorf("error parsing memory size %s: %w", fields[0], err) - } - state.Size = opt.UintWith(size << 12) - - rss, err := strconv.ParseUint(fields[1], 10, 64) - if err != nil { - return state, fmt.Errorf("error parsing memory rss %s: %w", fields[1], err) - } - state.Rss.Bytes = opt.UintWith(rss << 12) - - share, err := strconv.ParseUint(fields[2], 10, 64) - if err != nil { - return state, fmt.Errorf("error parsing memory share %s: %w", fields[1], err) - } - state.Share = opt.UintWith(share << 12) - - return state, nil -} - -func getCPUTime(hostfs resolve.Resolver, pid int) (ProcCPUInfo, error) { - state := ProcCPUInfo{} - - pathCPU := hostfs.Join("proc", strconv.Itoa(pid), "stat") - data, err := ioutil.ReadFile(pathCPU) - if err != nil { - return state, fmt.Errorf("error opening file %s: %w", pathCPU, err) - } - fields := strings.Fields(string(data)) - - user, err := strconv.ParseUint(fields[13], 10, 64) - if err != nil { - return state, fmt.Errorf("error parsing user CPU times for pid %d: %w", pid, err) - } - sys, err := strconv.ParseUint(fields[14], 10, 64) - if err != nil { - return state, fmt.Errorf("error parsing system CPU times for pid %d: %w", pid, err) - } - - btime, err := getLinuxBootTime(hostfs) - if err != nil { - return state, fmt.Errorf("error feting boot time for pid %d: %w", pid, err) - } - - // convert to milliseconds from USER_HZ - // This effectively means our definition of "ticks" throughout the process code is a millisecond - state.User.Ticks = opt.UintWith(user * (1000 / ticks)) - state.System.Ticks = opt.UintWith(sys * (1000 / ticks)) - state.Total.Ticks = opt.UintWith(opt.SumOptUint(state.User.Ticks, state.System.Ticks)) - - startTime, err := strconv.ParseUint(fields[21], 10, 64) - if err != nil { - return state, fmt.Errorf("error parsing start time value %s for pid %d: %w", fields[21], pid, err) - } - - startTime /= ticks - startTime += btime - startTime *= 1000 - - state.StartTime = unixTimeMsToTime(startTime) - return state, nil -} - -func getArgs(hostfs resolve.Resolver, pid int) ([]string, error) { - path := hostfs.Join("proc", strconv.Itoa(pid), "cmdline") - data, err := ioutil.ReadFile(path) - if err != nil { - return nil, fmt.Errorf("error opening file %s: %w", path, err) - } - bbuf := bytes.NewBuffer(data) - - var args []string - - for { - arg, err := bbuf.ReadBytes(0) - if err == io.EOF { - break - } - trimmedArg := string(arg[0 : len(arg)-1]) - args = append(args, trimmedArg) - } - - return args, nil -} - -func getFDStats(hostfs resolve.Resolver, pid int) (ProcFDInfo, error) { - state := ProcFDInfo{} - - path := hostfs.Join("proc", strconv.Itoa(pid), "limits") - data, err := ioutil.ReadFile(path) - if err != nil { - return state, fmt.Errorf("error opening file %s: %w", path, err) - } - - for _, line := range strings.Split(string(data), "\n") { - if strings.HasPrefix(line, "Max open files") { - fields := strings.Fields(line) - if len(fields) == 6 { - - softLimit, err := strconv.ParseUint(fields[3], 10, 64) - if err != nil { - return state, fmt.Errorf("error parsing limits value %s for pid %d: %w", fields[3], pid, err) - } - state.Limit.Soft = opt.UintWith(softLimit) - - hardLimit, err := strconv.ParseUint(fields[4], 10, 64) - if err != nil { - return state, fmt.Errorf("error parsing limits value %s for pid %d: %w", fields[3], pid, err) - } - state.Limit.Hard = opt.UintWith(hardLimit) - } - - } - } - - pathFD := hostfs.Join("proc", strconv.Itoa(pid), "fd") - fds, err := ioutil.ReadDir(pathFD) - if err != nil { - return state, fmt.Errorf("error reading FD directory for pid %d: %w", pid, err) - } - state.Open = opt.UintWith(uint64(len(fds))) - return state, nil -} - -// getLinuxBootTime fetches the static unix time for when the system was booted. -func getLinuxBootTime(hostfs resolve.Resolver) (uint64, error) { - if bootTime != 0 { - return bootTime, nil - } - - path := hostfs.Join("proc", "stat") - // grab system boot time - data, err := ioutil.ReadFile(path) - if err != nil { - return 0, fmt.Errorf("error opening file %s: %w", path, err) - } - - statVals := strings.Split(string(data), "\n") - - for _, line := range statVals { - if strings.HasPrefix(line, "btime") { - btime, err := strconv.ParseUint(line[6:], 10, 64) - if err != nil { - return 0, fmt.Errorf("error reading boot time: %w", err) - } - bootTime = btime - return btime, nil - } - } - - return 0, fmt.Errorf("no boot time find in file %s: %w", path, err) -} - -func getProcStatus(hostfs resolve.Resolver, pid int) (map[string]string, error) { - status := make(map[string]string, 42) - path := hostfs.Join("proc", strconv.Itoa(pid), "status") - data, err := ioutil.ReadFile(path) - if err != nil { - return nil, fmt.Errorf("error opening file %s: %w", path, err) - } - for _, line := range strings.Split(string(data), "\n") { - fields := strings.SplitN(line, ":", 2) - if len(fields) == 2 { - status[fields[0]] = strings.TrimSpace(fields[1]) - } - } - - return status, err -} - -func getProcState(b byte) PidState { - state, ok := PidStates[b] - if ok { - return state - } - return Unknown -} diff --git a/libbeat/metric/system/process/process_test.go b/libbeat/metric/system/process/process_test.go deleted file mode 100644 index 948090314ebb..000000000000 --- a/libbeat/metric/system/process/process_test.go +++ /dev/null @@ -1,509 +0,0 @@ -// Licensed to Elasticsearch B.V. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Elasticsearch B.V. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -//go:build darwin || freebsd || linux || windows -// +build darwin freebsd linux windows - -package process - -import ( - "os" - "runtime" - "sort" - "testing" - "time" - - "github.com/stretchr/testify/assert" - - "github.com/elastic/beats/v7/libbeat/common" - "github.com/elastic/beats/v7/libbeat/metric/system/cgroup" - "github.com/elastic/beats/v7/libbeat/metric/system/resolve" - "github.com/elastic/beats/v7/libbeat/opt" - "github.com/elastic/elastic-agent-libs/logp" - "github.com/elastic/elastic-agent-libs/mapstr" -) - -func TestGetOne(t *testing.T) { - testConfig := Stats{ - Procs: []string{".*"}, - Hostfs: resolve.NewTestResolver("/"), - CPUTicks: false, - CacheCmdLine: true, - EnvWhitelist: []string{".*"}, - IncludeTop: IncludeTopConfig{ - Enabled: true, - ByCPU: 4, - ByMemory: 0, - }, - EnableCgroups: false, - CgroupOpts: cgroup.ReaderOptions{ - RootfsMountpoint: resolve.NewTestResolver("/"), - IgnoreRootCgroups: true, - }, - } - err := testConfig.Init() - assert.NoError(t, err, "Init") - - _, _, err = testConfig.Get() - assert.NoError(t, err, "GetOne") - - time.Sleep(time.Second * 2) - - procData, _, err := testConfig.Get() - assert.NoError(t, err, "GetOne") - - t.Logf("Proc: %s", procData[0].StringToPrint()) -} - -func TestFilter(t *testing.T) { - //The logic itself is os-independent, so we'll only test this on the platform least likly to have CI issues - if runtime.GOOS != "linux" { - t.Skip("Run on Linux only") - } - testConfig := Stats{ - Procs: []string{".*"}, - Hostfs: resolve.NewTestResolver("/"), - IncludeTop: IncludeTopConfig{ - Enabled: true, - ByCPU: 1, - ByMemory: 1, - }, - } - err := testConfig.Init() - assert.NoError(t, err, "Init") - - procData, _, err := testConfig.Get() - assert.NoError(t, err, "GetOne") - assert.Equal(t, 2, len(procData)) - - testZero := Stats{ - Procs: []string{".*"}, - Hostfs: resolve.NewTestResolver("/"), - IncludeTop: IncludeTopConfig{ - Enabled: true, - ByCPU: 0, - ByMemory: 1, - }, - } - - err = testZero.Init() - assert.NoError(t, err, "Init") - - oneData, _, err := testZero.Get() - assert.NoError(t, err, "GetOne with one event") - assert.Equal(t, 1, len(oneData)) -} - -func TestProcessList(t *testing.T) { - plist, err := ListStates(resolve.NewTestResolver("/")) - assert.NoError(t, err, "ListStates") - - for _, proc := range plist { - assert.NotEmpty(t, proc.State) - assert.True(t, proc.Pid.Exists()) - } -} - -func TestGetProcess(t *testing.T) { - stat, err := initTestResolver() - assert.NoError(t, err, "Init()") - process, err := stat.GetSelf() - assert.NoError(t, err, "FetchPid") - - assert.True(t, (process.Pid.ValueOr(0) > 0)) - assert.True(t, (process.Ppid.ValueOr(0) >= 0)) - assert.True(t, (process.Pgid.ValueOr(0) >= 0)) - assert.True(t, (len(process.Name) > 0)) - assert.True(t, (len(process.Username) > 0)) - assert.NotEqual(t, "unknown", process.State) - - // Memory Checks - assert.True(t, process.Memory.Size.Exists()) - assert.True(t, (process.Memory.Rss.Bytes.ValueOr(0) > 0)) - assert.True(t, process.Memory.Share.Exists()) - - // CPU Checks - assert.True(t, (process.CPU.Total.Value.ValueOr(0) >= 0)) - assert.True(t, process.CPU.User.Ticks.Exists()) - assert.True(t, process.CPU.System.Ticks.Exists()) - - assert.True(t, (process.SampleTime.Unix() <= time.Now().Unix())) - - switch runtime.GOOS { - case "darwin", "linux", "freebsd": - assert.True(t, len(process.Env) > 0, "empty environment") - } - - switch runtime.GOOS { - case "linux": - assert.True(t, (len(process.Cwd) > 0)) - } -} - -func TestMatchProcs(t *testing.T) { - var procStats = Stats{} - - procStats.Procs = []string{".*"} - err := procStats.Init() - assert.NoError(t, err) - - assert.True(t, procStats.matchProcess("metricbeat")) - - procStats.Procs = []string{"metricbeat"} - err = procStats.Init() - assert.NoError(t, err) - assert.False(t, procStats.matchProcess("burn")) - - // match no processes - procStats.Procs = []string{"$^"} - err = procStats.Init() - assert.NoError(t, err) - assert.False(t, procStats.matchProcess("burn")) -} - -func TestProcMemPercentage(t *testing.T) { - procStats := Stats{} - - p := ProcState{ - Pid: opt.IntWith(3456), - Memory: ProcMemInfo{ - Rss: MemBytePct{Bytes: opt.UintWith(1416)}, - Size: opt.UintWith(145164088), - }, - } - - procStats.ProcsMap = make(ProcsMap) - procStats.ProcsMap[p.Pid.ValueOr(0)] = p - - rssPercent := GetProcMemPercentage(p, 10000) - assert.Equal(t, rssPercent.ValueOr(0), 0.1416) -} - -func TestProcCpuPercentage(t *testing.T) { - p1 := ProcState{ - CPU: ProcCPUInfo{ - User: CPUTicks{Ticks: opt.UintWith(11345)}, - System: CPUTicks{Ticks: opt.UintWith(37)}, - Total: CPUTotal{ - Ticks: opt.UintWith(11382), - }, - }, - SampleTime: time.Now(), - } - - p2 := ProcState{ - CPU: ProcCPUInfo{ - User: CPUTicks{Ticks: opt.UintWith(14794)}, - System: CPUTicks{Ticks: opt.UintWith(47)}, - Total: CPUTotal{ - Ticks: opt.UintWith(14841), - }, - }, - SampleTime: p1.SampleTime.Add(time.Second), - } - - newState := GetProcCPUPercentage(p1, p2) - //GetProcCPUPercentage wil return a number that varies based on the host, due to NumCPU() - // So "un-normalize" it, then re-normalized with a constant. - cpu := float64(runtime.NumCPU()) - unNormalized := newState.CPU.Total.Norm.Pct.ValueOr(0) * cpu - normalizedTest := common.Round(unNormalized/48, common.DefaultDecimalPlacesCount) - - assert.EqualValues(t, 0.0721, normalizedTest) - assert.EqualValues(t, 3.459, newState.CPU.Total.Pct.ValueOr(0)) - assert.EqualValues(t, 14841, newState.CPU.Total.Value.ValueOr(0)) -} - -// BenchmarkGetProcess runs a benchmark of the GetProcess method with caching -// of the command line and environment variables. -func BenchmarkGetProcess(b *testing.B) { - stat, err := initTestResolver() - if err != nil { - b.Fatalf("Failed init: %s", err) - } - procs := make(map[int]mapstr.M, 1) - pid := os.Getpid() - b.ResetTimer() - for i := 0; i < b.N; i++ { - - process, err := stat.GetOne(pid) - if err != nil { - continue - } - - procs[pid] = process - } -} - -func BenchmarkGetTop(b *testing.B) { - stat, err := initTestResolver() - if err != nil { - b.Fatalf("Failed init: %s", err) - } - procs := make(map[int][]mapstr.M) - - for i := 0; i < b.N; i++ { - list, _, err := stat.Get() - if err != nil { - b.Fatalf("error: %s", err) - } - procs[i] = list - } -} - -func TestIncludeTopProcesses(t *testing.T) { - processes := []ProcState{ - { - Pid: opt.IntWith(1), - CPU: ProcCPUInfo{ - Total: CPUTotal{ - Pct: opt.FloatWith(10), - }, - }, - Memory: ProcMemInfo{ - Rss: MemBytePct{ - Bytes: opt.UintWith(3000), - }, - }, - }, - { - Pid: opt.IntWith(2), - CPU: ProcCPUInfo{ - Total: CPUTotal{ - Pct: opt.FloatWith(5), - }, - }, - Memory: ProcMemInfo{ - Rss: MemBytePct{ - Bytes: opt.UintWith(4000), - }, - }, - }, - { - Pid: opt.IntWith(3), - CPU: ProcCPUInfo{ - Total: CPUTotal{ - Pct: opt.FloatWith(7), - }, - }, - Memory: ProcMemInfo{ - Rss: MemBytePct{ - Bytes: opt.UintWith(2000), - }, - }, - }, - { - Pid: opt.IntWith(4), - CPU: ProcCPUInfo{ - Total: CPUTotal{ - Pct: opt.FloatWith(5), - }, - }, - Memory: ProcMemInfo{ - Rss: MemBytePct{ - Bytes: opt.UintWith(8000), - }, - }, - }, - { - Pid: opt.IntWith(5), - CPU: ProcCPUInfo{ - Total: CPUTotal{ - Pct: opt.FloatWith(12), - }, - }, - Memory: ProcMemInfo{ - Rss: MemBytePct{ - Bytes: opt.UintWith(9000), - }, - }, - }, - { - Pid: opt.IntWith(6), - CPU: ProcCPUInfo{ - Total: CPUTotal{ - Pct: opt.FloatWith(5), - }, - }, - Memory: ProcMemInfo{ - Rss: MemBytePct{ - Bytes: opt.UintWith(7000), - }, - }, - }, - { - Pid: opt.IntWith(7), - CPU: ProcCPUInfo{ - Total: CPUTotal{ - Pct: opt.FloatWith(80), - }, - }, - Memory: ProcMemInfo{ - Rss: MemBytePct{ - Bytes: opt.UintWith(11000), - }, - }, - }, - { - Pid: opt.IntWith(8), - CPU: ProcCPUInfo{ - Total: CPUTotal{ - Pct: opt.FloatWith(50), - }, - }, - Memory: ProcMemInfo{ - Rss: MemBytePct{ - Bytes: opt.UintWith(13000), - }, - }, - }, - { - Pid: opt.IntWith(9), - CPU: ProcCPUInfo{ - Total: CPUTotal{ - Pct: opt.FloatWith(15), - }, - }, - Memory: ProcMemInfo{ - Rss: MemBytePct{ - Bytes: opt.UintWith(1000), - }, - }, - }, - { - Pid: opt.IntWith(10), - CPU: ProcCPUInfo{ - Total: CPUTotal{ - Pct: opt.FloatWith(60), - }, - }, - Memory: ProcMemInfo{ - Rss: MemBytePct{ - Bytes: opt.UintWith(500), - }, - }, - }, - } - - tests := []struct { - Name string - Cfg IncludeTopConfig - ExpectedPids []int - }{ - { - Name: "top 2 processes by CPU", - Cfg: IncludeTopConfig{Enabled: true, ByCPU: 2}, - ExpectedPids: []int{7, 10}, - }, - { - Name: "top 4 processes by CPU", - Cfg: IncludeTopConfig{Enabled: true, ByCPU: 4}, - ExpectedPids: []int{7, 10, 8, 9}, - }, - { - Name: "top 2 processes by memory", - Cfg: IncludeTopConfig{Enabled: true, ByMemory: 2}, - ExpectedPids: []int{8, 7}, - }, - { - Name: "top 4 processes by memory", - Cfg: IncludeTopConfig{Enabled: true, ByMemory: 4}, - ExpectedPids: []int{8, 7, 5, 4}, - }, - { - Name: "top 2 processes by CPU + top 2 by memory", - Cfg: IncludeTopConfig{Enabled: true, ByCPU: 2, ByMemory: 2}, - ExpectedPids: []int{7, 10, 8}, - }, - { - Name: "top 4 processes by CPU + top 4 by memory", - Cfg: IncludeTopConfig{Enabled: true, ByCPU: 4, ByMemory: 4}, - ExpectedPids: []int{7, 10, 8, 9, 5, 4}, - }, - { - Name: "enabled false", - Cfg: IncludeTopConfig{Enabled: false, ByCPU: 4, ByMemory: 4}, - ExpectedPids: []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, - }, - { - Name: "enabled true but cpu & mem not configured", - Cfg: IncludeTopConfig{Enabled: true}, - ExpectedPids: []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, - }, - { - Name: "top 12 by cpu (out of 10)", - Cfg: IncludeTopConfig{Enabled: true, ByCPU: 12}, - ExpectedPids: []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, - }, - { - Name: "top 12 by cpu and top 14 memory (out of 10)", - Cfg: IncludeTopConfig{Enabled: true, ByCPU: 12, ByMemory: 14}, - ExpectedPids: []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, - }, - { - Name: "top 14 by cpu and top 12 memory (out of 10)", - Cfg: IncludeTopConfig{Enabled: true, ByCPU: 14, ByMemory: 12}, - ExpectedPids: []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, - }, - { - Name: "top 1 by cpu and top 3 memory", - Cfg: IncludeTopConfig{Enabled: true, ByCPU: 1, ByMemory: 3}, - ExpectedPids: []int{5, 7, 8}, - }, - { - Name: "top 3 by cpu and top 1 memory", - Cfg: IncludeTopConfig{Enabled: true, ByCPU: 3, ByMemory: 1}, - ExpectedPids: []int{7, 8, 10}, - }, - } - - for _, test := range tests { - procStats := Stats{IncludeTop: test.Cfg} - res := procStats.includeTopProcesses(processes) - - resPids := []int{} - for _, p := range res { - resPids = append(resPids, p.Pid.ValueOr(0)) - } - sort.Ints(test.ExpectedPids) - sort.Ints(resPids) - assert.Equal(t, resPids, test.ExpectedPids, test.Name) - } -} - -func initTestResolver() (Stats, error) { - _ = logp.DevelopmentSetup() - testConfig := Stats{ - Procs: []string{".*"}, - Hostfs: resolve.NewTestResolver("/"), - CPUTicks: true, - CacheCmdLine: true, - EnvWhitelist: []string{".*"}, - IncludeTop: IncludeTopConfig{ - Enabled: true, - ByCPU: 5, - ByMemory: 5, - }, - EnableCgroups: true, - CgroupOpts: cgroup.ReaderOptions{ - RootfsMountpoint: resolve.NewTestResolver("/"), - IgnoreRootCgroups: true, - }, - } - err := testConfig.Init() - return testConfig, err -} diff --git a/libbeat/metric/system/process/process_types.go b/libbeat/metric/system/process/process_types.go deleted file mode 100644 index 5db44072aa3d..000000000000 --- a/libbeat/metric/system/process/process_types.go +++ /dev/null @@ -1,188 +0,0 @@ -// Licensed to Elasticsearch B.V. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Elasticsearch B.V. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package process - -import ( - "time" - - "github.com/elastic/beats/v7/libbeat/metric/system/cgroup" - "github.com/elastic/beats/v7/libbeat/opt" - "github.com/elastic/elastic-agent-libs/mapstr" -) - -// ProcState is the main struct for process information and metrics. -type ProcState struct { - // Basic Process data - Name string `struct:"name,omitempty"` - State PidState `struct:"state,omitempty"` - Username string `struct:"username,omitempty"` - Pid opt.Int `struct:"pid,omitempty"` - Ppid opt.Int `struct:"ppid,omitempty"` - Pgid opt.Int `struct:"pgid,omitempty"` - - // Extended Process Data - Args []string `struct:"args,omitempty"` - Cmdline string `struct:"cmdline,omitempty"` - Cwd string `struct:"cwd,omitempty"` - Exe string `struct:"exe,omitempty"` - Env mapstr.M `struct:"env,omitempty"` - - // Resource Metrics - Memory ProcMemInfo `struct:"memory,omitempty"` - CPU ProcCPUInfo `struct:"cpu,omitempty"` - FD ProcFDInfo `struct:"fd,omitempty"` - - // cgroups - Cgroup cgroup.CGStats `struct:"cgroup,omitempty"` - - // meta - SampleTime time.Time `struct:"-,omitempty"` -} - -// ProcCPUInfo is the main struct for CPU metrics -type ProcCPUInfo struct { - StartTime string `struct:"start_time,omitempty"` - Total CPUTotal `struct:"total,omitempty"` - // Optional Tick values - User CPUTicks `struct:"user,omitempty"` - System CPUTicks `struct:"system,omitempty"` -} - -// CPUTicks is a formatting wrapper for `tick` metric values -type CPUTicks struct { - Ticks opt.Uint `struct:"ticks,omitempty"` -} - -// CPUTotal is the struct for cpu.total metrics -type CPUTotal struct { - Value opt.Float `struct:"value,omitempty"` - Ticks opt.Uint `struct:"ticks,omitempty"` - Pct opt.Float `struct:"pct,omitempty"` - Norm opt.PctOpt `struct:"norm,omitempty"` -} - -// ProcMemInfo is the struct for cpu.memory metrics -type ProcMemInfo struct { - Size opt.Uint `struct:"size,omitempty"` - Share opt.Uint `struct:"share,omitempty"` - Rss MemBytePct `struct:"rss,omitempty"` -} - -// MemBytePct is the formatting struct for wrapping pct/byte metrics -type MemBytePct struct { - Bytes opt.Uint `struct:"bytes,omitempty"` - Pct opt.Float `struct:"pct,omitempty"` -} - -// ProcFDInfo is the struct for process.fd metrics -type ProcFDInfo struct { - Open opt.Uint `struct:"open,omitempty"` - Limit ProcLimits `struct:"limit,omitempty"` -} - -// ProcLimits wraps the fd.limit metrics -type ProcLimits struct { - Soft opt.Uint `struct:"soft,omitempty"` - Hard opt.Uint `struct:"hard,omitempty"` -} - -// Implementations - -// IsZero returns true if the underlying value nil -func (t CPUTicks) IsZero() bool { - return t.Ticks.IsZero() -} - -// IsZero returns true if the underlying value nil -func (t ProcFDInfo) IsZero() bool { - return t.Open.IsZero() && t.Limit.Hard.IsZero() && t.Limit.Soft.IsZero() -} - -// FormatForRoot shuffles around events to fit in the ECS root fields -func (p *ProcState) FormatForRoot() ProcStateRootEvent { - root := ProcStateRootEvent{} - - root.Process.Name = p.Name - p.Name = "" - - root.Process.Pid = p.Pid - p.Pid = opt.NewIntNone() - - root.Process.Parent.Pid = p.Ppid - p.Ppid = opt.NewIntNone() - - root.Process.Pgid = p.Pgid - p.Pgid = opt.NewIntNone() - - root.User.Name = p.Username - p.Username = "" - - root.Process.Cmdline = p.Cmdline - root.Process.State = p.State - root.Process.CPU.StartTime = p.CPU.StartTime - root.Process.CPU.Pct = p.CPU.Total.Norm.Pct - root.Process.Memory.Pct = p.Memory.Rss.Pct - - root.Process.Cwd = p.Cwd - p.Cwd = "" - - root.Process.Exe = p.Exe - p.Exe = "" - - root.Process.Args = p.Args - p.Args = nil - - return root -} - -// ProcStateRootEvent represents the "root" beat/agent ECS event fields that are copied from the integration-level event. -type ProcStateRootEvent struct { - Process ProcRoot `struct:"process,omitempty"` - User Name `struct:"user,omitempty"` -} - -// ProcRoot wraps the process metrics for the root ECS fields -type ProcRoot struct { - Cmdline string `struct:"command_line,omitempty"` - State PidState `struct:"state,omitempty"` - CPU RootCPUFields `struct:"cpu,omitempty"` - Memory opt.PctOpt `struct:"memory,omitempty"` - Cwd string `struct:"working_directory,omitempty"` - Exe string `struct:"executable,omitempty"` - Args []string `struct:"args,omitempty"` - Name string `struct:"name,omitempty"` - Pid opt.Int `struct:"pid,omitempty"` - Parent Parent `struct:"parent,omitempty"` - Pgid opt.Int `struct:"pgid,omitempty"` -} - -// Parent is the wrapper struct for the parent.pid field -type Parent struct { - Pid opt.Int `struct:"pid,omitempty"` -} - -// Name is the wrapper struct for the name.pid field -type Name struct { - Name string `struct:"name,omitempty"` -} - -// RootCPUFields is the wrapper for the cpu.* root fields -type RootCPUFields struct { - StartTime string `struct:"start_time,omitempty"` - Pct opt.Float `struct:"pct,omitempty"` -} diff --git a/libbeat/metric/system/process/process_windows.go b/libbeat/metric/system/process/process_windows.go deleted file mode 100644 index 7eb3731758a4..000000000000 --- a/libbeat/metric/system/process/process_windows.go +++ /dev/null @@ -1,269 +0,0 @@ -// Licensed to Elasticsearch B.V. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Elasticsearch B.V. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package process - -import ( - "fmt" - "path/filepath" - "syscall" - - "github.com/elastic/beats/v7/libbeat/metric/system/resolve" - "github.com/elastic/beats/v7/libbeat/opt" - "github.com/elastic/gosigar/sys/windows" -) - -var ( - processQueryLimitedInfoAccess = windows.PROCESS_QUERY_LIMITED_INFORMATION -) - -// FetchPids returns a map and array of pids -func (procStats *Stats) FetchPids() (ProcsMap, []ProcState, error) { - pids, err := windows.EnumProcesses() - if err != nil { - return nil, nil, fmt.Errorf("enumProcesses failed: %w", err) - } - - procMap := make(ProcsMap, 0) - var plist []ProcState - // This is probably the only implementation that doesn't benefit from our little fillPid callback system. We'll need to iterate over everything manually. - for _, pid := range pids { - procMap, plist = procStats.pidIter(int(pid), procMap, plist) - } - - return procMap, plist, nil -} - -// GetInfoForPid returns basic info for the process -func GetInfoForPid(_ resolve.Resolver, pid int) (ProcState, error) { - state := ProcState{} - - name, err := getProcName(pid) - if err != nil { - return state, fmt.Errorf("error fetching name: %w", err) - } - state.Name = name - state.Pid = opt.IntWith(pid) - - // system/process doesn't need this here, but system/process_summary does. - status, err := getPidStatus(pid) - if err != nil { - return state, fmt.Errorf("error fetching status: %w", err) - } - state.State = status - - return state, nil -} - -// FillPidMetrics is the windows implementation -func FillPidMetrics(_ resolve.Resolver, pid int, state ProcState, _ func(string) bool) (ProcState, error) { - user, err := getProcCredName(pid) - if err != nil { - return state, fmt.Errorf("error fetching username: %w", err) - } - state.Username = user - - ppid, err := getParentPid(pid) - if err != nil { - return state, fmt.Errorf("error fetching parent pid: %w", err) - } - state.Ppid = opt.IntWith(ppid) - - wss, size, err := procMem(pid) - if err != nil { - return state, fmt.Errorf("error fetching memory: %w", err) - } - state.Memory.Rss.Bytes = opt.UintWith(wss) - state.Memory.Size = opt.UintWith(size) - - userTime, sysTime, startTime, err := getProcTimes(pid) - if err != nil { - return state, fmt.Errorf("error getting CPU times: %w", err) - } - - state.CPU.System.Ticks = opt.UintWith(sysTime) - state.CPU.User.Ticks = opt.UintWith(userTime) - state.CPU.Total.Ticks = opt.UintWith(userTime + sysTime) - - state.CPU.StartTime = unixTimeMsToTime(startTime) - - argList, err := getProcArgs(pid) - if err != nil { - return state, fmt.Errorf("error fetching process args: %w", err) - } - state.Args = argList - return state, nil -} - -func getProcArgs(pid int) ([]string, error) { - - handle, err := syscall.OpenProcess(processQueryLimitedInfoAccess|windows.PROCESS_VM_READ, false, uint32(pid)) - if err != nil { - return nil, fmt.Errorf("openProcess failed: %w", err) - } - defer func() { - _ = syscall.CloseHandle(handle) - }() - pbi, err := windows.NtQueryProcessBasicInformation(handle) - if err != nil { - return nil, fmt.Errorf("ntQueryProcessBasicInformation failed: %w", err) - } - - userProcParams, err := windows.GetUserProcessParams(handle, pbi) - if err != nil { - return nil, fmt.Errorf("getUserProcessParams failed: %w", err) - } - argsW, err := windows.ReadProcessUnicodeString(handle, &userProcParams.CommandLine) - if err != nil { - return nil, fmt.Errorf("readProcessUnicodeString failed, %w", err) - } - - procList, err := windows.ByteSliceToStringSlice(argsW) - if err != nil { - return nil, fmt.Errorf("byteSliceToStringSlice failed: %w", err) - } - return procList, nil -} - -func getProcTimes(pid int) (uint64, uint64, uint64, error) { - handle, err := syscall.OpenProcess(processQueryLimitedInfoAccess, false, uint32(pid)) - if err != nil { - return 0, 0, 0, fmt.Errorf("openProcess failed for pid=%v: %w", pid, err) - } - defer func() { - _ = syscall.CloseHandle(handle) - }() - - var cpu syscall.Rusage - if err := syscall.GetProcessTimes(handle, &cpu.CreationTime, &cpu.ExitTime, &cpu.KernelTime, &cpu.UserTime); err != nil { - return 0, 0, 0, fmt.Errorf("getProcessTimes failed for pid=%v: %w", pid, err) - } - - // Everything expects ticks, so we need to go some math. - return uint64(windows.FiletimeToDuration(&cpu.UserTime).Nanoseconds() / 1e6), uint64(windows.FiletimeToDuration(&cpu.KernelTime).Nanoseconds() / 1e6), uint64(cpu.CreationTime.Nanoseconds() / 1e6), nil -} - -func procMem(pid int) (uint64, uint64, error) { - handle, err := syscall.OpenProcess(processQueryLimitedInfoAccess|windows.PROCESS_VM_READ, false, uint32(pid)) - if err != nil { - return 0, 0, fmt.Errorf("openProcess failed for pid=%v: %w", pid, err) - } - defer func() { - _ = syscall.CloseHandle(handle) - }() - - counters, err := windows.GetProcessMemoryInfo(handle) - if err != nil { - return 0, 0, fmt.Errorf("getProcessMemoryInfo failed for pid=%v: %w", pid, err) - } - return uint64(counters.WorkingSetSize), uint64(counters.PrivateUsage), nil -} - -// getProcName returns the process name associated with the PID. -func getProcName(pid int) (string, error) { - handle, err := syscall.OpenProcess(processQueryLimitedInfoAccess, false, uint32(pid)) - if err != nil { - return "", fmt.Errorf("openProcess failed for pid=%v: %w", pid, err) - } - defer func() { - _ = syscall.CloseHandle(handle) - }() - - filename, err := windows.GetProcessImageFileName(handle) - if err != nil { - return "", fmt.Errorf("getProcessImageFileName failed for pid=%v: %w", pid, err) - } - - return filepath.Base(filename), nil -} - -// getProcStatus returns the status of a process. -func getPidStatus(pid int) (PidState, error) { - handle, err := syscall.OpenProcess(processQueryLimitedInfoAccess, false, uint32(pid)) - if err != nil { - return Unknown, fmt.Errorf("openProcess failed for pid=%v: %w", pid, err) - } - defer func() { - _ = syscall.CloseHandle(handle) - }() - - var exitCode uint32 - err = syscall.GetExitCodeProcess(handle, &exitCode) - if err != nil { - return Unknown, fmt.Errorf("getExitCodeProcess failed for pid=%v: %w", pid, err) - } - - if exitCode == 259 { //still active - return Running, nil - } - return Sleeping, nil -} - -// getParentPid returns the parent process ID of a process. -func getParentPid(pid int) (int, error) { - handle, err := syscall.OpenProcess(processQueryLimitedInfoAccess, false, uint32(pid)) - if err != nil { - return 0, fmt.Errorf("openProcess failed for pid=%v: %w", pid, err) - } - defer func() { - _ = syscall.CloseHandle(handle) - }() - - procInfo, err := windows.NtQueryProcessBasicInformation(handle) - if err != nil { - return 0, fmt.Errorf("ntQueryProcessBasicInformation failed for pid=%v: %w", pid, err) - } - - return int(procInfo.InheritedFromUniqueProcessID), nil -} - -func getProcCredName(pid int) (string, error) { - handle, err := syscall.OpenProcess(syscall.PROCESS_QUERY_INFORMATION, false, uint32(pid)) - if err != nil { - return "", fmt.Errorf("openProcess failed for pid=%v: %w", pid, err) - } - defer func() { - _ = syscall.CloseHandle(handle) - }() - - // Find process token via win32. - var token syscall.Token - err = syscall.OpenProcessToken(handle, syscall.TOKEN_QUERY, &token) - if err != nil { - return "", fmt.Errorf("openProcessToken failed for pid=%v: %w", pid, err) - } - // Close token to prevent handle leaks. - defer token.Close() - - // Find the token user. - tokenUser, err := token.GetTokenUser() - if err != nil { - return "", fmt.Errorf("getTokenInformation failed for pid=%v: %w", pid, err) - } - - // Look up domain account by SID. - account, domain, _, err := tokenUser.User.Sid.LookupAccount("") - if err != nil { - sid, sidErr := tokenUser.User.Sid.String() - if sidErr != nil { - return "", fmt.Errorf("failed while looking up account name for pid=%v: %w", pid, err) - } - return "", fmt.Errorf("failed while looking up account name for SID=%v of pid=%v: %w", sid, pid, err) - } - - return fmt.Sprintf(`%s\%s`, domain, account), nil -} diff --git a/libbeat/metric/system/resolve/resolve.go b/libbeat/metric/system/resolve/resolve.go deleted file mode 100644 index 66b83b977454..000000000000 --- a/libbeat/metric/system/resolve/resolve.go +++ /dev/null @@ -1,64 +0,0 @@ -// Licensed to Elasticsearch B.V. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Elasticsearch B.V. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package resolve - -import "path/filepath" - -// Resolver is an interface for HostFS resolvers. This is meant to be generic and (hopefully) future-proof way of dealing with a user-supplied root filesystem path. -// A resolver-style function serves two ends: -// 1) if we attempt to stop consumers from merely "saving off" a string, the underlying implementation can update hostfs values and pass the new paths along to consumers -// 2) This stops different bits of code from making different assumptions about what's in hostfs and otherwise treating the concept differently. It's easy to mix up "hostfs" and "procfs" and "sysfs" as concepts. -// A single resolver forces this logic to be a little more centralized. -type Resolver interface { - // ResolveHostFS Resolves a path based on a user-set HostFS flag, in cases where a user wants to monitor an alternate filesystem root - // If no user root has been set, it will return the input string - ResolveHostFS(string) string - // IsSet returns true if the user has set an alternate filesystem root - IsSet() bool - // Join emulates the behavior of filepath.join - Join(...string) string -} - -// TestingResolver is a bare implementation of the resolver, for system tests that need a Resolver object or a test path for input files. -type TestingResolver struct { - path string - isSet bool -} - -// NewTestResolver returns a new resolver for internal testing, or other uses outside metricbeat modules. -func NewTestResolver(path string) TestingResolver { - if path == "" || path == "/" { - return TestingResolver{path: "/", isSet: false} - } - - return TestingResolver{path: path, isSet: true} -} - -func (t TestingResolver) ResolveHostFS(path string) string { - return filepath.Join(t.path, path) -} - -func (t TestingResolver) Join(path ...string) string { - fullpath := append([]string{t.path}, path...) - return filepath.Join(fullpath...) - -} - -func (t TestingResolver) IsSet() bool { - return t.isSet -} diff --git a/libbeat/processors/add_docker_metadata/add_docker_metadata.go b/libbeat/processors/add_docker_metadata/add_docker_metadata.go index 41fa8b13ba3f..d363ba080180 100644 --- a/libbeat/processors/add_docker_metadata/add_docker_metadata.go +++ b/libbeat/processors/add_docker_metadata/add_docker_metadata.go @@ -31,8 +31,6 @@ import ( "github.com/elastic/beats/v7/libbeat/beat" "github.com/elastic/beats/v7/libbeat/common" - "github.com/elastic/beats/v7/libbeat/metric/system/cgroup" - "github.com/elastic/beats/v7/libbeat/metric/system/resolve" "github.com/elastic/beats/v7/libbeat/processors" "github.com/elastic/beats/v7/libbeat/processors/actions" "github.com/elastic/elastic-agent-autodiscover/docker" @@ -40,6 +38,8 @@ import ( "github.com/elastic/elastic-agent-libs/logp" "github.com/elastic/elastic-agent-libs/mapstr" "github.com/elastic/elastic-agent-libs/safemapstr" + "github.com/elastic/elastic-agent-system-metrics/metric/system/cgroup" + "github.com/elastic/elastic-agent-system-metrics/metric/system/resolve" ) const ( diff --git a/libbeat/processors/add_docker_metadata/add_docker_metadata_test.go b/libbeat/processors/add_docker_metadata/add_docker_metadata_test.go index c910744beb82..c634df375679 100644 --- a/libbeat/processors/add_docker_metadata/add_docker_metadata_test.go +++ b/libbeat/processors/add_docker_metadata/add_docker_metadata_test.go @@ -30,13 +30,13 @@ import ( "github.com/stretchr/testify/assert" "github.com/elastic/beats/v7/libbeat/beat" - "github.com/elastic/beats/v7/libbeat/metric/system/cgroup" - "github.com/elastic/beats/v7/libbeat/metric/system/resolve" "github.com/elastic/elastic-agent-autodiscover/bus" "github.com/elastic/elastic-agent-autodiscover/docker" "github.com/elastic/elastic-agent-libs/config" "github.com/elastic/elastic-agent-libs/logp" "github.com/elastic/elastic-agent-libs/mapstr" + "github.com/elastic/elastic-agent-system-metrics/metric/system/cgroup" + "github.com/elastic/elastic-agent-system-metrics/metric/system/resolve" ) func init() { diff --git a/libbeat/processors/add_host_metadata/add_host_metadata.go b/libbeat/processors/add_host_metadata/add_host_metadata.go index dd6a240153bc..5f78c32a84d2 100644 --- a/libbeat/processors/add_host_metadata/add_host_metadata.go +++ b/libbeat/processors/add_host_metadata/add_host_metadata.go @@ -25,13 +25,13 @@ import ( "github.com/pkg/errors" "github.com/elastic/beats/v7/libbeat/beat" - "github.com/elastic/beats/v7/libbeat/metric/system/host" "github.com/elastic/beats/v7/libbeat/processors" jsprocessor "github.com/elastic/beats/v7/libbeat/processors/script/javascript/module/processor" "github.com/elastic/beats/v7/libbeat/processors/util" "github.com/elastic/elastic-agent-libs/config" "github.com/elastic/elastic-agent-libs/logp" "github.com/elastic/elastic-agent-libs/mapstr" + "github.com/elastic/elastic-agent-system-metrics/metric/system/host" "github.com/elastic/go-sysinfo" ) diff --git a/libbeat/processors/add_process_metadata/add_process_metadata.go b/libbeat/processors/add_process_metadata/add_process_metadata.go index 67bbfc41ec1a..7b16b2481924 100644 --- a/libbeat/processors/add_process_metadata/add_process_metadata.go +++ b/libbeat/processors/add_process_metadata/add_process_metadata.go @@ -28,13 +28,13 @@ import ( "github.com/elastic/beats/v7/libbeat/beat" "github.com/elastic/beats/v7/libbeat/common" "github.com/elastic/beats/v7/libbeat/common/atomic" - "github.com/elastic/beats/v7/libbeat/metric/system/cgroup" - "github.com/elastic/beats/v7/libbeat/metric/system/resolve" "github.com/elastic/beats/v7/libbeat/processors" jsprocessor "github.com/elastic/beats/v7/libbeat/processors/script/javascript/module/processor" conf "github.com/elastic/elastic-agent-libs/config" "github.com/elastic/elastic-agent-libs/logp" "github.com/elastic/elastic-agent-libs/mapstr" + "github.com/elastic/elastic-agent-system-metrics/metric/system/cgroup" + "github.com/elastic/elastic-agent-system-metrics/metric/system/resolve" ) const ( diff --git a/libbeat/processors/add_process_metadata/add_process_metadata_test.go b/libbeat/processors/add_process_metadata/add_process_metadata_test.go index 5c5255ed56f5..d833a188fc04 100644 --- a/libbeat/processors/add_process_metadata/add_process_metadata_test.go +++ b/libbeat/processors/add_process_metadata/add_process_metadata_test.go @@ -28,11 +28,11 @@ import ( "github.com/stretchr/testify/assert" "github.com/elastic/beats/v7/libbeat/beat" - "github.com/elastic/beats/v7/libbeat/metric/system/cgroup" - "github.com/elastic/beats/v7/libbeat/metric/system/resolve" conf "github.com/elastic/elastic-agent-libs/config" "github.com/elastic/elastic-agent-libs/logp" "github.com/elastic/elastic-agent-libs/mapstr" + "github.com/elastic/elastic-agent-system-metrics/metric/system/cgroup" + "github.com/elastic/elastic-agent-system-metrics/metric/system/resolve" ) func TestAddProcessMetadata(t *testing.T) { diff --git a/libbeat/processors/add_process_metadata/gosigar_cid_provider.go b/libbeat/processors/add_process_metadata/gosigar_cid_provider.go index 58c199dcd4b1..cc1063635b20 100644 --- a/libbeat/processors/add_process_metadata/gosigar_cid_provider.go +++ b/libbeat/processors/add_process_metadata/gosigar_cid_provider.go @@ -26,9 +26,9 @@ import ( "github.com/pkg/errors" "github.com/elastic/beats/v7/libbeat/common" - "github.com/elastic/beats/v7/libbeat/metric/system/cgroup" - "github.com/elastic/beats/v7/libbeat/metric/system/resolve" "github.com/elastic/elastic-agent-libs/logp" + "github.com/elastic/elastic-agent-system-metrics/metric/system/cgroup" + "github.com/elastic/elastic-agent-system-metrics/metric/system/resolve" ) const ( diff --git a/metricbeat/internal/metrics/cpu/metrics.go b/metricbeat/internal/metrics/cpu/metrics.go index 5f3c623c0bdc..1043d97ab961 100644 --- a/metricbeat/internal/metrics/cpu/metrics.go +++ b/metricbeat/internal/metrics/cpu/metrics.go @@ -21,9 +21,9 @@ import ( "github.com/pkg/errors" "github.com/elastic/beats/v7/libbeat/common" - "github.com/elastic/beats/v7/libbeat/metric/system/resolve" "github.com/elastic/beats/v7/libbeat/opt" "github.com/elastic/elastic-agent-libs/mapstr" + "github.com/elastic/elastic-agent-system-metrics/metric/system/resolve" ) // CPU manages the CPU metrics from /proc/stat diff --git a/metricbeat/internal/metrics/cpu/metrics_aix.go b/metricbeat/internal/metrics/cpu/metrics_aix.go index 022e69ea601f..628691cc4492 100644 --- a/metricbeat/internal/metrics/cpu/metrics_aix.go +++ b/metricbeat/internal/metrics/cpu/metrics_aix.go @@ -38,8 +38,8 @@ import ( "github.com/pkg/errors" - "github.com/elastic/beats/v7/libbeat/metric/system/resolve" "github.com/elastic/beats/v7/libbeat/opt" + "github.com/elastic/elastic-agent-system-metrics/metric/system/resolve" ) func init() { diff --git a/metricbeat/internal/metrics/cpu/metrics_darwin.go b/metricbeat/internal/metrics/cpu/metrics_darwin.go index 6064fbb37006..b09d06b11cf4 100644 --- a/metricbeat/internal/metrics/cpu/metrics_darwin.go +++ b/metricbeat/internal/metrics/cpu/metrics_darwin.go @@ -21,8 +21,8 @@ import ( "github.com/pkg/errors" "github.com/shirou/gopsutil/v3/cpu" - "github.com/elastic/beats/v7/libbeat/metric/system/resolve" "github.com/elastic/beats/v7/libbeat/opt" + "github.com/elastic/elastic-agent-system-metrics/metric/system/resolve" ) // Get is the Darwin implementation of Get diff --git a/metricbeat/internal/metrics/cpu/metrics_openbsd.go b/metricbeat/internal/metrics/cpu/metrics_openbsd.go index 15969d906dad..7111937c9f9c 100644 --- a/metricbeat/internal/metrics/cpu/metrics_openbsd.go +++ b/metricbeat/internal/metrics/cpu/metrics_openbsd.go @@ -36,8 +36,8 @@ import ( "syscall" "unsafe" - "github.com/elastic/beats/v7/libbeat/metric/system/resolve" "github.com/elastic/beats/v7/libbeat/opt" + "github.com/elastic/elastic-agent-system-metrics/metric/system/resolve" ) // Get is the OpenBSD implementation of get diff --git a/metricbeat/internal/metrics/cpu/metrics_procfs_common.go b/metricbeat/internal/metrics/cpu/metrics_procfs_common.go index be86cb1213c2..720c3a4fd180 100644 --- a/metricbeat/internal/metrics/cpu/metrics_procfs_common.go +++ b/metricbeat/internal/metrics/cpu/metrics_procfs_common.go @@ -27,7 +27,7 @@ import ( "github.com/pkg/errors" - "github.com/elastic/beats/v7/libbeat/metric/system/resolve" + "github.com/elastic/elastic-agent-system-metrics/metric/system/resolve" ) // Get returns a metrics object for CPU data diff --git a/metricbeat/internal/metrics/cpu/metrics_test.go b/metricbeat/internal/metrics/cpu/metrics_test.go index 156a87442b02..726b9b69bdda 100644 --- a/metricbeat/internal/metrics/cpu/metrics_test.go +++ b/metricbeat/internal/metrics/cpu/metrics_test.go @@ -22,9 +22,9 @@ import ( "github.com/stretchr/testify/assert" - "github.com/elastic/beats/v7/libbeat/metric/system/resolve" "github.com/elastic/beats/v7/libbeat/opt" "github.com/elastic/elastic-agent-libs/mapstr" + "github.com/elastic/elastic-agent-system-metrics/metric/system/resolve" ) func TestMonitorSample(t *testing.T) { diff --git a/metricbeat/internal/metrics/cpu/metrics_windows.go b/metricbeat/internal/metrics/cpu/metrics_windows.go index 7e0a258aa065..acc90b097fd6 100644 --- a/metricbeat/internal/metrics/cpu/metrics_windows.go +++ b/metricbeat/internal/metrics/cpu/metrics_windows.go @@ -27,8 +27,8 @@ import ( "github.com/pkg/errors" - "github.com/elastic/beats/v7/libbeat/metric/system/resolve" "github.com/elastic/beats/v7/libbeat/opt" + "github.com/elastic/elastic-agent-system-metrics/metric/system/resolve" "github.com/elastic/gosigar/sys/windows" ) diff --git a/metricbeat/internal/metrics/memory/memory.go b/metricbeat/internal/metrics/memory/memory.go index 79efbdd825e3..c3047e913717 100644 --- a/metricbeat/internal/metrics/memory/memory.go +++ b/metricbeat/internal/metrics/memory/memory.go @@ -21,8 +21,8 @@ import ( "github.com/pkg/errors" "github.com/elastic/beats/v7/libbeat/common" - "github.com/elastic/beats/v7/libbeat/metric/system/resolve" "github.com/elastic/beats/v7/libbeat/opt" + "github.com/elastic/elastic-agent-system-metrics/metric/system/resolve" ) // Memory holds os-specifc memory usage data diff --git a/metricbeat/internal/metrics/memory/memory_aix.go b/metricbeat/internal/metrics/memory/memory_aix.go index 326b01e8125e..df19642488ee 100644 --- a/metricbeat/internal/metrics/memory/memory_aix.go +++ b/metricbeat/internal/metrics/memory/memory_aix.go @@ -36,8 +36,8 @@ import ( "fmt" "os" - "github.com/elastic/beats/v7/libbeat/metric/system/resolve" "github.com/elastic/beats/v7/libbeat/opt" + "github.com/elastic/elastic-agent-system-metrics/metric/system/resolve" ) var system struct { diff --git a/metricbeat/internal/metrics/memory/memory_darwin.go b/metricbeat/internal/metrics/memory/memory_darwin.go index dac04d070ea4..1a4689c16219 100644 --- a/metricbeat/internal/metrics/memory/memory_darwin.go +++ b/metricbeat/internal/metrics/memory/memory_darwin.go @@ -39,8 +39,8 @@ import ( "github.com/pkg/errors" - "github.com/elastic/beats/v7/libbeat/metric/system/resolve" "github.com/elastic/beats/v7/libbeat/opt" + "github.com/elastic/elastic-agent-system-metrics/metric/system/resolve" ) type xswUsage struct { diff --git a/metricbeat/internal/metrics/memory/memory_freebsd.go b/metricbeat/internal/metrics/memory/memory_freebsd.go index 007e5ef21b3d..380acd137332 100644 --- a/metricbeat/internal/metrics/memory/memory_freebsd.go +++ b/metricbeat/internal/metrics/memory/memory_freebsd.go @@ -22,8 +22,8 @@ import ( "github.com/pkg/errors" - "github.com/elastic/beats/v7/libbeat/metric/system/resolve" "github.com/elastic/beats/v7/libbeat/opt" + "github.com/elastic/elastic-agent-system-metrics/metric/system/resolve" ) /* diff --git a/metricbeat/internal/metrics/memory/memory_helpers.go b/metricbeat/internal/metrics/memory/memory_helpers.go index c935837d88fe..9e9c7e60bea3 100644 --- a/metricbeat/internal/metrics/memory/memory_helpers.go +++ b/metricbeat/internal/metrics/memory/memory_helpers.go @@ -27,7 +27,7 @@ import ( "github.com/pkg/errors" - "github.com/elastic/beats/v7/libbeat/metric/system/resolve" + "github.com/elastic/elastic-agent-system-metrics/metric/system/resolve" ) // ParseMeminfo parses the contents of /proc/meminfo into a hashmap diff --git a/metricbeat/internal/metrics/memory/memory_linux.go b/metricbeat/internal/metrics/memory/memory_linux.go index 2aad8b367110..0b55a36129e4 100644 --- a/metricbeat/internal/metrics/memory/memory_linux.go +++ b/metricbeat/internal/metrics/memory/memory_linux.go @@ -20,8 +20,8 @@ package memory import ( "github.com/pkg/errors" - "github.com/elastic/beats/v7/libbeat/metric/system/resolve" "github.com/elastic/beats/v7/libbeat/opt" + "github.com/elastic/elastic-agent-system-metrics/metric/system/resolve" ) // get is the linux implementation for fetching Memory data diff --git a/metricbeat/internal/metrics/memory/memory_openbsd.go b/metricbeat/internal/metrics/memory/memory_openbsd.go index addc33e88755..fe713fd3ac4c 100644 --- a/metricbeat/internal/metrics/memory/memory_openbsd.go +++ b/metricbeat/internal/metrics/memory/memory_openbsd.go @@ -35,8 +35,8 @@ import ( "github.com/pkg/errors" - "github.com/elastic/beats/v7/libbeat/metric/system/resolve" "github.com/elastic/beats/v7/libbeat/opt" + "github.com/elastic/elastic-agent-system-metrics/metric/system/resolve" ) // Uvmexp wraps memory data from sysctl diff --git a/metricbeat/internal/metrics/memory/memory_test.go b/metricbeat/internal/metrics/memory/memory_test.go index 4c9c979fdcef..c1ebc8b71460 100644 --- a/metricbeat/internal/metrics/memory/memory_test.go +++ b/metricbeat/internal/metrics/memory/memory_test.go @@ -27,8 +27,8 @@ import ( "github.com/stretchr/testify/assert" - "github.com/elastic/beats/v7/libbeat/metric/system/resolve" "github.com/elastic/beats/v7/libbeat/opt" + "github.com/elastic/elastic-agent-system-metrics/metric/system/resolve" ) func TestGetMemory(t *testing.T) { diff --git a/metricbeat/internal/metrics/memory/memory_windows.go b/metricbeat/internal/metrics/memory/memory_windows.go index be0f003552e0..ae1d8601c193 100644 --- a/metricbeat/internal/metrics/memory/memory_windows.go +++ b/metricbeat/internal/metrics/memory/memory_windows.go @@ -20,8 +20,8 @@ package memory import ( "github.com/pkg/errors" - "github.com/elastic/beats/v7/libbeat/metric/system/resolve" "github.com/elastic/beats/v7/libbeat/opt" + "github.com/elastic/elastic-agent-system-metrics/metric/system/resolve" "github.com/elastic/go-windows" ) diff --git a/metricbeat/module/docker/network_summary/network_summary.go b/metricbeat/module/docker/network_summary/network_summary.go index 9ea83fcf3924..19e7db5f4d19 100644 --- a/metricbeat/module/docker/network_summary/network_summary.go +++ b/metricbeat/module/docker/network_summary/network_summary.go @@ -28,10 +28,10 @@ import ( "github.com/pkg/errors" "github.com/elastic/beats/v7/libbeat/common/cfgwarn" - "github.com/elastic/beats/v7/libbeat/metric/system/network" "github.com/elastic/beats/v7/metricbeat/mb" "github.com/elastic/beats/v7/metricbeat/module/docker" "github.com/elastic/elastic-agent-libs/mapstr" + "github.com/elastic/elastic-agent-system-metrics/metric/system/network" ) // init registers the MetricSet with the central registry as soon as the program diff --git a/metricbeat/module/linux/conntrack/conntrack.go b/metricbeat/module/linux/conntrack/conntrack.go index 713d1585d167..3970ff689c8a 100644 --- a/metricbeat/module/linux/conntrack/conntrack.go +++ b/metricbeat/module/linux/conntrack/conntrack.go @@ -22,9 +22,9 @@ import ( "github.com/prometheus/procfs" "github.com/elastic/beats/v7/libbeat/common/cfgwarn" - "github.com/elastic/beats/v7/libbeat/metric/system/resolve" "github.com/elastic/beats/v7/metricbeat/mb" "github.com/elastic/elastic-agent-libs/mapstr" + "github.com/elastic/elastic-agent-system-metrics/metric/system/resolve" ) // init registers the MetricSet with the central registry as soon as the program diff --git a/metricbeat/module/linux/iostat/data.go b/metricbeat/module/linux/iostat/data.go index 7dbf08df45df..a71c4e654867 100644 --- a/metricbeat/module/linux/iostat/data.go +++ b/metricbeat/module/linux/iostat/data.go @@ -18,8 +18,8 @@ package iostat import ( - "github.com/elastic/beats/v7/libbeat/metric/system/diskio" "github.com/elastic/elastic-agent-libs/mapstr" + "github.com/elastic/elastic-agent-system-metrics/metric/system/diskio" ) // AddLinuxIOStat adds the linux iostat data to the provided map diff --git a/metricbeat/module/linux/iostat/iostat.go b/metricbeat/module/linux/iostat/iostat.go index a8172a8ed3f0..495addddde43 100644 --- a/metricbeat/module/linux/iostat/iostat.go +++ b/metricbeat/module/linux/iostat/iostat.go @@ -24,9 +24,9 @@ import ( "github.com/pkg/errors" "github.com/elastic/beats/v7/libbeat/common/cfgwarn" - "github.com/elastic/beats/v7/libbeat/metric/system/diskio" "github.com/elastic/beats/v7/metricbeat/mb" "github.com/elastic/elastic-agent-libs/mapstr" + "github.com/elastic/elastic-agent-system-metrics/metric/system/diskio" ) // init registers the MetricSet with the central registry as soon as the program diff --git a/metricbeat/module/linux/ksm/ksm.go b/metricbeat/module/linux/ksm/ksm.go index a538168faed1..abbd899cd8a3 100644 --- a/metricbeat/module/linux/ksm/ksm.go +++ b/metricbeat/module/linux/ksm/ksm.go @@ -21,9 +21,9 @@ import ( "github.com/pkg/errors" "github.com/elastic/beats/v7/libbeat/common/cfgwarn" - "github.com/elastic/beats/v7/libbeat/metric/system/resolve" "github.com/elastic/beats/v7/metricbeat/mb" "github.com/elastic/elastic-agent-libs/mapstr" + "github.com/elastic/elastic-agent-system-metrics/metric/system/resolve" ) // init registers the MetricSet with the central registry as soon as the program diff --git a/metricbeat/module/linux/memory/data.go b/metricbeat/module/linux/memory/data.go index c83b355acfa6..7c3b2fc72c5e 100644 --- a/metricbeat/module/linux/memory/data.go +++ b/metricbeat/module/linux/memory/data.go @@ -27,10 +27,10 @@ import ( "github.com/elastic/beats/v7/libbeat/common" "github.com/elastic/beats/v7/libbeat/common/transform/typeconv" - "github.com/elastic/beats/v7/libbeat/metric/system/resolve" "github.com/elastic/beats/v7/metricbeat/internal/metrics/memory" metrics "github.com/elastic/beats/v7/metricbeat/internal/metrics/memory" "github.com/elastic/elastic-agent-libs/mapstr" + "github.com/elastic/elastic-agent-system-metrics/metric/system/resolve" ) // FetchLinuxMemStats gets page_stat and huge pages data for linux diff --git a/metricbeat/module/linux/memory/memory.go b/metricbeat/module/linux/memory/memory.go index b70349b0267a..e74b8b36e608 100644 --- a/metricbeat/module/linux/memory/memory.go +++ b/metricbeat/module/linux/memory/memory.go @@ -21,9 +21,9 @@ import ( "github.com/pkg/errors" "github.com/elastic/beats/v7/libbeat/common/cfgwarn" - "github.com/elastic/beats/v7/libbeat/metric/system/resolve" "github.com/elastic/beats/v7/metricbeat/mb" "github.com/elastic/elastic-agent-libs/mapstr" + "github.com/elastic/elastic-agent-system-metrics/metric/system/resolve" ) // init registers the MetricSet with the central registry as soon as the program diff --git a/metricbeat/module/linux/memory/memory_linux_test.go b/metricbeat/module/linux/memory/memory_linux_test.go index 638e5be20dee..2a779e8d5ba3 100644 --- a/metricbeat/module/linux/memory/memory_linux_test.go +++ b/metricbeat/module/linux/memory/memory_linux_test.go @@ -22,10 +22,10 @@ import ( "github.com/stretchr/testify/assert" - "github.com/elastic/beats/v7/libbeat/metric/system/resolve" mbtest "github.com/elastic/beats/v7/metricbeat/mb/testing" _ "github.com/elastic/beats/v7/metricbeat/module/linux" "github.com/elastic/elastic-agent-libs/mapstr" + "github.com/elastic/elastic-agent-system-metrics/metric/system/resolve" ) func TestPercents(t *testing.T) { diff --git a/metricbeat/module/linux/pageinfo/pageinfo.go b/metricbeat/module/linux/pageinfo/pageinfo.go index 016294cc22ac..d32243812f2c 100644 --- a/metricbeat/module/linux/pageinfo/pageinfo.go +++ b/metricbeat/module/linux/pageinfo/pageinfo.go @@ -24,9 +24,9 @@ import ( "github.com/pkg/errors" "github.com/elastic/beats/v7/libbeat/common/cfgwarn" - "github.com/elastic/beats/v7/libbeat/metric/system/resolve" "github.com/elastic/beats/v7/metricbeat/mb" "github.com/elastic/elastic-agent-libs/mapstr" + "github.com/elastic/elastic-agent-system-metrics/metric/system/resolve" ) // init registers the MetricSet with the central registry as soon as the program diff --git a/metricbeat/module/linux/pressure/pressure.go b/metricbeat/module/linux/pressure/pressure.go index e856673e22ae..529fb69ed33c 100644 --- a/metricbeat/module/linux/pressure/pressure.go +++ b/metricbeat/module/linux/pressure/pressure.go @@ -25,9 +25,9 @@ import ( "github.com/prometheus/procfs" "github.com/elastic/beats/v7/libbeat/common/cfgwarn" - "github.com/elastic/beats/v7/libbeat/metric/system/resolve" "github.com/elastic/beats/v7/metricbeat/mb" "github.com/elastic/elastic-agent-libs/mapstr" + "github.com/elastic/elastic-agent-system-metrics/metric/system/resolve" ) const ( diff --git a/metricbeat/module/linux/rapl/rapl.go b/metricbeat/module/linux/rapl/rapl.go index fc6b4ee67d72..04f0466a134c 100644 --- a/metricbeat/module/linux/rapl/rapl.go +++ b/metricbeat/module/linux/rapl/rapl.go @@ -36,10 +36,10 @@ import ( "github.com/elastic/beats/v7/libbeat/common" "github.com/elastic/beats/v7/libbeat/common/cfgwarn" - "github.com/elastic/beats/v7/libbeat/metric/system/resolve" "github.com/elastic/beats/v7/metricbeat/mb" "github.com/elastic/elastic-agent-libs/logp" "github.com/elastic/elastic-agent-libs/mapstr" + "github.com/elastic/elastic-agent-system-metrics/metric/system/resolve" ) // init registers the MetricSet with the central registry as soon as the program diff --git a/metricbeat/module/linux/rapl/rapl_test.go b/metricbeat/module/linux/rapl/rapl_test.go index 43568a5031a2..958f0098c55a 100644 --- a/metricbeat/module/linux/rapl/rapl_test.go +++ b/metricbeat/module/linux/rapl/rapl_test.go @@ -25,7 +25,7 @@ import ( "github.com/stretchr/testify/assert" - "github.com/elastic/beats/v7/libbeat/metric/system/resolve" + "github.com/elastic/elastic-agent-system-metrics/metric/system/resolve" ) // func TestData(t *testing.T) { diff --git a/metricbeat/module/system/core/core.go b/metricbeat/module/system/core/core.go index 7d46bf95a7f4..0373ced0bd40 100644 --- a/metricbeat/module/system/core/core.go +++ b/metricbeat/module/system/core/core.go @@ -23,10 +23,10 @@ package core import ( "github.com/pkg/errors" - "github.com/elastic/beats/v7/libbeat/metric/system/resolve" metrics "github.com/elastic/beats/v7/metricbeat/internal/metrics/cpu" "github.com/elastic/beats/v7/metricbeat/mb" "github.com/elastic/beats/v7/metricbeat/mb/parse" + "github.com/elastic/elastic-agent-system-metrics/metric/system/resolve" ) func init() { diff --git a/metricbeat/module/system/cpu/cpu.go b/metricbeat/module/system/cpu/cpu.go index ed6028cd69de..a55968de1c62 100644 --- a/metricbeat/module/system/cpu/cpu.go +++ b/metricbeat/module/system/cpu/cpu.go @@ -23,11 +23,11 @@ package cpu import ( "github.com/pkg/errors" - "github.com/elastic/beats/v7/libbeat/metric/system/resolve" metrics "github.com/elastic/beats/v7/metricbeat/internal/metrics/cpu" "github.com/elastic/beats/v7/metricbeat/mb" "github.com/elastic/beats/v7/metricbeat/mb/parse" "github.com/elastic/elastic-agent-libs/mapstr" + "github.com/elastic/elastic-agent-system-metrics/metric/system/resolve" ) func init() { diff --git a/metricbeat/module/system/diskio/diskio.go b/metricbeat/module/system/diskio/diskio.go index b9296f399a9d..06ba8b138320 100644 --- a/metricbeat/module/system/diskio/diskio.go +++ b/metricbeat/module/system/diskio/diskio.go @@ -23,10 +23,10 @@ package diskio import ( "runtime" - "github.com/elastic/beats/v7/libbeat/metric/system/diskio" "github.com/elastic/beats/v7/metricbeat/mb" "github.com/elastic/beats/v7/metricbeat/mb/parse" "github.com/elastic/elastic-agent-libs/mapstr" + "github.com/elastic/elastic-agent-system-metrics/metric/system/diskio" "github.com/pkg/errors" ) diff --git a/metricbeat/module/system/entropy/entropy.go b/metricbeat/module/system/entropy/entropy.go index 207c65dfceeb..182593e6db27 100644 --- a/metricbeat/module/system/entropy/entropy.go +++ b/metricbeat/module/system/entropy/entropy.go @@ -28,9 +28,9 @@ import ( "github.com/pkg/errors" "github.com/elastic/beats/v7/libbeat/common/cfgwarn" - "github.com/elastic/beats/v7/libbeat/metric/system/resolve" "github.com/elastic/beats/v7/metricbeat/mb" "github.com/elastic/elastic-agent-libs/mapstr" + "github.com/elastic/elastic-agent-system-metrics/metric/system/resolve" ) // init registers the MetricSet with the central registry as soon as the program diff --git a/metricbeat/module/system/filesystem/filesystem.go b/metricbeat/module/system/filesystem/filesystem.go index ec828a8ddde0..4b0ca0a50235 100644 --- a/metricbeat/module/system/filesystem/filesystem.go +++ b/metricbeat/module/system/filesystem/filesystem.go @@ -23,10 +23,10 @@ package filesystem import ( "strings" - "github.com/elastic/beats/v7/libbeat/metric/system/resolve" "github.com/elastic/beats/v7/metricbeat/mb" "github.com/elastic/beats/v7/metricbeat/mb/parse" "github.com/elastic/elastic-agent-libs/logp" + "github.com/elastic/elastic-agent-system-metrics/metric/system/resolve" "github.com/pkg/errors" ) diff --git a/metricbeat/module/system/filesystem/filesystem_test.go b/metricbeat/module/system/filesystem/filesystem_test.go index a0ac2cf97ed9..def6d0bf49fc 100644 --- a/metricbeat/module/system/filesystem/filesystem_test.go +++ b/metricbeat/module/system/filesystem/filesystem_test.go @@ -25,9 +25,9 @@ import ( "github.com/stretchr/testify/assert" - "github.com/elastic/beats/v7/libbeat/metric/system/resolve" mbtest "github.com/elastic/beats/v7/metricbeat/mb/testing" _ "github.com/elastic/beats/v7/metricbeat/module/system" + "github.com/elastic/elastic-agent-system-metrics/metric/system/resolve" ) func TestFetch(t *testing.T) { diff --git a/metricbeat/module/system/filesystem/helper.go b/metricbeat/module/system/filesystem/helper.go index da71738bd7f3..a2542789fea3 100644 --- a/metricbeat/module/system/filesystem/helper.go +++ b/metricbeat/module/system/filesystem/helper.go @@ -30,8 +30,8 @@ import ( "runtime" "github.com/elastic/beats/v7/libbeat/common" - "github.com/elastic/beats/v7/libbeat/metric/system/resolve" "github.com/elastic/elastic-agent-libs/mapstr" + "github.com/elastic/elastic-agent-system-metrics/metric/system/resolve" sigar "github.com/elastic/gosigar" ) diff --git a/metricbeat/module/system/fsstat/fsstat.go b/metricbeat/module/system/fsstat/fsstat.go index 03078d8d2afb..3149d22f2de6 100644 --- a/metricbeat/module/system/fsstat/fsstat.go +++ b/metricbeat/module/system/fsstat/fsstat.go @@ -24,11 +24,11 @@ import ( "runtime" "strings" - "github.com/elastic/beats/v7/libbeat/metric/system/resolve" "github.com/elastic/beats/v7/metricbeat/mb" "github.com/elastic/beats/v7/metricbeat/mb/parse" "github.com/elastic/beats/v7/metricbeat/module/system/filesystem" "github.com/elastic/elastic-agent-libs/mapstr" + "github.com/elastic/elastic-agent-system-metrics/metric/system/resolve" "github.com/pkg/errors" ) diff --git a/metricbeat/module/system/load/load.go b/metricbeat/module/system/load/load.go index c1d60ca161ab..954b95645591 100644 --- a/metricbeat/module/system/load/load.go +++ b/metricbeat/module/system/load/load.go @@ -23,11 +23,11 @@ package load import ( "github.com/pkg/errors" - "github.com/elastic/beats/v7/libbeat/metric/system/cpu" - "github.com/elastic/beats/v7/libbeat/metric/system/numcpu" "github.com/elastic/beats/v7/metricbeat/mb" "github.com/elastic/beats/v7/metricbeat/mb/parse" "github.com/elastic/elastic-agent-libs/mapstr" + "github.com/elastic/elastic-agent-system-metrics/metric/system/cpu" + "github.com/elastic/elastic-agent-system-metrics/metric/system/numcpu" ) func init() { diff --git a/metricbeat/module/system/memory/memory.go b/metricbeat/module/system/memory/memory.go index e3504b59be68..cc4ec230b992 100644 --- a/metricbeat/module/system/memory/memory.go +++ b/metricbeat/module/system/memory/memory.go @@ -24,11 +24,11 @@ import ( "github.com/pkg/errors" "github.com/elastic/beats/v7/libbeat/common/transform/typeconv" - "github.com/elastic/beats/v7/libbeat/metric/system/resolve" metrics "github.com/elastic/beats/v7/metricbeat/internal/metrics/memory" "github.com/elastic/beats/v7/metricbeat/mb" "github.com/elastic/beats/v7/metricbeat/mb/parse" "github.com/elastic/elastic-agent-libs/mapstr" + "github.com/elastic/elastic-agent-system-metrics/metric/system/resolve" ) func init() { diff --git a/metricbeat/module/system/network_summary/network_summary.go b/metricbeat/module/system/network_summary/network_summary.go index ff08d6731e0c..92a48d23b617 100644 --- a/metricbeat/module/system/network_summary/network_summary.go +++ b/metricbeat/module/system/network_summary/network_summary.go @@ -21,8 +21,8 @@ import ( "github.com/pkg/errors" "github.com/elastic/beats/v7/libbeat/common/cfgwarn" - "github.com/elastic/beats/v7/libbeat/metric/system/network" "github.com/elastic/beats/v7/metricbeat/mb" + "github.com/elastic/elastic-agent-system-metrics/metric/system/network" sysinfo "github.com/elastic/go-sysinfo" sysinfotypes "github.com/elastic/go-sysinfo/types" ) diff --git a/metricbeat/module/system/network_summary/network_summary_test.go b/metricbeat/module/system/network_summary/network_summary_test.go index 2e50589dc29a..614326a2b808 100644 --- a/metricbeat/module/system/network_summary/network_summary_test.go +++ b/metricbeat/module/system/network_summary/network_summary_test.go @@ -22,10 +22,10 @@ import ( "github.com/stretchr/testify/assert" - "github.com/elastic/beats/v7/libbeat/metric/system/network" mbtest "github.com/elastic/beats/v7/metricbeat/mb/testing" _ "github.com/elastic/beats/v7/metricbeat/module/system" "github.com/elastic/elastic-agent-libs/mapstr" + "github.com/elastic/elastic-agent-system-metrics/metric/system/network" "github.com/elastic/go-sysinfo/types" ) diff --git a/metricbeat/module/system/process/config.go b/metricbeat/module/system/process/config.go index 317515b93f08..12266700538b 100644 --- a/metricbeat/module/system/process/config.go +++ b/metricbeat/module/system/process/config.go @@ -19,7 +19,7 @@ package process import ( "github.com/elastic/beats/v7/libbeat/common/cfgwarn" - "github.com/elastic/beats/v7/libbeat/metric/system/process" + "github.com/elastic/elastic-agent-system-metrics/metric/system/process" ) // Config stores the system/process config options diff --git a/metricbeat/module/system/process/process.go b/metricbeat/module/system/process/process.go index 3336ddc23a20..2f08d19e637d 100644 --- a/metricbeat/module/system/process/process.go +++ b/metricbeat/module/system/process/process.go @@ -26,12 +26,12 @@ import ( "github.com/pkg/errors" - "github.com/elastic/beats/v7/libbeat/metric/system/cgroup" - "github.com/elastic/beats/v7/libbeat/metric/system/process" - "github.com/elastic/beats/v7/libbeat/metric/system/resolve" "github.com/elastic/beats/v7/metricbeat/mb" "github.com/elastic/beats/v7/metricbeat/mb/parse" "github.com/elastic/elastic-agent-libs/logp" + "github.com/elastic/elastic-agent-system-metrics/metric/system/cgroup" + "github.com/elastic/elastic-agent-system-metrics/metric/system/process" + "github.com/elastic/elastic-agent-system-metrics/metric/system/resolve" ) var debugf = logp.MakeDebug("system.process") diff --git a/metricbeat/module/system/process/process_test.go b/metricbeat/module/system/process/process_test.go index fda3dc25b3ba..45f3934e359e 100644 --- a/metricbeat/module/system/process/process_test.go +++ b/metricbeat/module/system/process/process_test.go @@ -26,10 +26,10 @@ import ( "github.com/stretchr/testify/assert" - "github.com/elastic/beats/v7/libbeat/metric/system/process" mbtest "github.com/elastic/beats/v7/metricbeat/mb/testing" _ "github.com/elastic/beats/v7/metricbeat/module/system" "github.com/elastic/elastic-agent-libs/logp" + "github.com/elastic/elastic-agent-system-metrics/metric/system/process" ) func TestFetch(t *testing.T) { diff --git a/metricbeat/module/system/process_summary/process_summary.go b/metricbeat/module/system/process_summary/process_summary.go index 3d056ca31c43..76de5443d9f4 100644 --- a/metricbeat/module/system/process_summary/process_summary.go +++ b/metricbeat/module/system/process_summary/process_summary.go @@ -24,11 +24,11 @@ import ( "github.com/pkg/errors" "github.com/elastic/beats/v7/libbeat/common/transform/typeconv" - "github.com/elastic/beats/v7/libbeat/metric/system/process" - "github.com/elastic/beats/v7/libbeat/metric/system/resolve" "github.com/elastic/beats/v7/metricbeat/mb" "github.com/elastic/beats/v7/metricbeat/mb/parse" "github.com/elastic/elastic-agent-libs/mapstr" + "github.com/elastic/elastic-agent-system-metrics/metric/system/process" + "github.com/elastic/elastic-agent-system-metrics/metric/system/resolve" ) // init registers the MetricSet with the central registry. diff --git a/metricbeat/module/system/process_summary/process_summary_test.go b/metricbeat/module/system/process_summary/process_summary_test.go index f85a1c160fc0..eaf03413d2cb 100644 --- a/metricbeat/module/system/process_summary/process_summary_test.go +++ b/metricbeat/module/system/process_summary/process_summary_test.go @@ -26,11 +26,11 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/elastic/beats/v7/libbeat/metric/system/process" mbtest "github.com/elastic/beats/v7/metricbeat/mb/testing" _ "github.com/elastic/beats/v7/metricbeat/module/system" "github.com/elastic/elastic-agent-libs/logp" "github.com/elastic/elastic-agent-libs/mapstr" + "github.com/elastic/elastic-agent-system-metrics/metric/system/process" ) func TestData(t *testing.T) { diff --git a/metricbeat/module/system/raid/raid.go b/metricbeat/module/system/raid/raid.go index 4bdad8d3af4b..238b067fd6f6 100644 --- a/metricbeat/module/system/raid/raid.go +++ b/metricbeat/module/system/raid/raid.go @@ -20,11 +20,11 @@ package raid import ( "github.com/pkg/errors" - "github.com/elastic/beats/v7/libbeat/metric/system/resolve" "github.com/elastic/beats/v7/metricbeat/mb" "github.com/elastic/beats/v7/metricbeat/mb/parse" "github.com/elastic/beats/v7/metricbeat/module/system/raid/blockinfo" "github.com/elastic/elastic-agent-libs/mapstr" + "github.com/elastic/elastic-agent-system-metrics/metric/system/resolve" ) func init() { diff --git a/metricbeat/module/system/socket/socket.go b/metricbeat/module/system/socket/socket.go index 0436fe6ec91c..87f637ca80ce 100644 --- a/metricbeat/module/system/socket/socket.go +++ b/metricbeat/module/system/socket/socket.go @@ -30,12 +30,12 @@ import ( "github.com/pkg/errors" - "github.com/elastic/beats/v7/libbeat/metric/system/resolve" sock "github.com/elastic/beats/v7/metricbeat/helper/socket" "github.com/elastic/beats/v7/metricbeat/mb" "github.com/elastic/beats/v7/metricbeat/mb/parse" "github.com/elastic/elastic-agent-libs/logp" "github.com/elastic/elastic-agent-libs/mapstr" + "github.com/elastic/elastic-agent-system-metrics/metric/system/resolve" "github.com/elastic/gosigar/sys/linux" ) diff --git a/metricbeat/module/system/socket_summary/socket_summary.go b/metricbeat/module/system/socket_summary/socket_summary.go index 3a7569f3f3b5..57d4312fad91 100644 --- a/metricbeat/module/system/socket_summary/socket_summary.go +++ b/metricbeat/module/system/socket_summary/socket_summary.go @@ -23,9 +23,9 @@ import ( "github.com/pkg/errors" "github.com/shirou/gopsutil/v3/net" - "github.com/elastic/beats/v7/libbeat/metric/system/resolve" "github.com/elastic/beats/v7/metricbeat/mb" "github.com/elastic/elastic-agent-libs/mapstr" + "github.com/elastic/elastic-agent-system-metrics/metric/system/resolve" ) // init registers the MetricSet with the central registry as soon as the program diff --git a/metricbeat/module/system/socket_summary/sockstat_linux.go b/metricbeat/module/system/socket_summary/sockstat_linux.go index 56d1c7ee01c2..22fc4dd26302 100644 --- a/metricbeat/module/system/socket_summary/sockstat_linux.go +++ b/metricbeat/module/system/socket_summary/sockstat_linux.go @@ -28,8 +28,8 @@ import ( "github.com/pkg/errors" "github.com/shirou/gopsutil/v3/net" - "github.com/elastic/beats/v7/libbeat/metric/system/resolve" "github.com/elastic/elastic-agent-libs/mapstr" + "github.com/elastic/elastic-agent-system-metrics/metric/system/resolve" ) // SockStat contains data from /proc/net/sockstat diff --git a/metricbeat/module/system/socket_summary/sockstat_other.go b/metricbeat/module/system/socket_summary/sockstat_other.go index a4c42eaa23da..b3584036c4f8 100644 --- a/metricbeat/module/system/socket_summary/sockstat_other.go +++ b/metricbeat/module/system/socket_summary/sockstat_other.go @@ -23,8 +23,8 @@ package socket_summary import ( "github.com/shirou/gopsutil/v3/net" - "github.com/elastic/beats/v7/libbeat/metric/system/resolve" "github.com/elastic/elastic-agent-libs/mapstr" + "github.com/elastic/elastic-agent-system-metrics/metric/system/resolve" ) //a stub function for non-linux systems