-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Report number of open file handles on Windows (#8329)
Now file handles/descriptors are reported by the same name on all platforms which support either one of them. New "unified" name is beat.handles.open. I other FD related metrics to beat.handles.limit.hard and beat.handles.limit.soft. I also moved registration of callbacks after initialization of variables used inside the callbacks. Failures of metrics which caused by environment problems (e.g. Beat cannot query something) are reported once for the first time. Then it's not attempted anymore. Errors which are due to programming errors, for example initializing beatProcessStats, does not let the Beat start. It helps us noticing errors before others and can be easily corrected.
- Loading branch information
Showing
15 changed files
with
289 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
// 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. | ||
|
||
// +build linux freebsd,cgo | ||
|
||
package instance | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/elastic/beats/libbeat/logp" | ||
"github.com/elastic/beats/libbeat/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 := getBeatProcessState() | ||
if err != nil { | ||
return 0, 0, 0, err | ||
} | ||
|
||
iOpen, err := state.GetValue("fd.open") | ||
if err != nil { | ||
return 0, 0, 0, fmt.Errorf("error getting number of open FD: %v", err) | ||
} | ||
|
||
open, ok := iOpen.(uint64) | ||
if !ok { | ||
return 0, 0, 0, fmt.Errorf("error converting value of open FDs to uint64: %v", iOpen) | ||
} | ||
|
||
iHardLimit, err := state.GetValue("fd.limit.hard") | ||
if err != nil { | ||
return 0, 0, 0, fmt.Errorf("error getting FD hard limit: %v", err) | ||
} | ||
|
||
hardLimit, ok = iHardLimit.(uint64) | ||
if !ok { | ||
return 0, 0, 0, fmt.Errorf("error converting values of FD hard limit: %v", iHardLimit) | ||
} | ||
|
||
iSoftLimit, err := state.GetValue("fd.limit.soft") | ||
if err != nil { | ||
return 0, 0, 0, fmt.Errorf("error getting FD hard limit: %v", err) | ||
} | ||
|
||
softLimit, ok = iSoftLimit.(uint64) | ||
if !ok { | ||
return 0, 0, 0, fmt.Errorf("error converting values of FD hard limit: %v", iSoftLimit) | ||
} | ||
|
||
return open, hardLimit, softLimit, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// 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. | ||
|
||
// +build !linux | ||
// +build !freebsd !cgo | ||
|
||
package instance | ||
|
||
// FDUsage is only supported on Linux and FreeBSD. | ||
func setupLinuxBSDFDMetrics() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// 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. | ||
|
||
// +build windows | ||
|
||
package instance | ||
|
||
import ( | ||
"github.com/elastic/beats/libbeat/logp" | ||
"github.com/elastic/beats/libbeat/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)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// 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. | ||
|
||
// +build !windows | ||
|
||
package instance | ||
|
||
// Counting number of open handles is only supported on Windows. | ||
func setupWindowsHandlesMetrics() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 4 additions & 2 deletions
6
vendor/github.com/elastic/go-sysinfo/providers/linux/process_linux.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
12 changes: 12 additions & 0 deletions
12
vendor/github.com/elastic/go-sysinfo/providers/windows/process_windows.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.