-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
metric for deleted and unclosed file descriptors
- Loading branch information
1 parent
953aa11
commit 4408aa0
Showing
3 changed files
with
54 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package fd | ||
|
||
import ( | ||
"os" | ||
"strings" | ||
|
||
"github.com/ozontech/file.d/logger" | ||
"github.com/prometheus/client_golang/prometheus" | ||
"github.com/prometheus/procfs" | ||
) | ||
|
||
func newFdsCollector() prometheus.Collector { | ||
c := &fdsCollector{ | ||
processDeletedFds: prometheus.NewDesc( | ||
"process_deleted_fds", | ||
"Number of deleted and unclosed file descriptors.", | ||
nil, nil, | ||
), | ||
} | ||
return c | ||
} | ||
|
||
type fdsCollector struct { | ||
processDeletedFds *prometheus.Desc | ||
} | ||
|
||
func (f *fdsCollector) Collect(ch chan<- prometheus.Metric) { | ||
p, err := procfs.NewProc(os.Getpid()) | ||
if err != nil { | ||
logger.Errorf("failed to get procfs: %s", err.Error()) | ||
return | ||
} | ||
|
||
targets, err := p.FileDescriptorTargets() | ||
if err != nil { | ||
logger.Errorf("failed to read file descriptor targets: %s", err.Error()) | ||
return | ||
} | ||
|
||
processDeletedFds := 0 | ||
for _, target := range targets { | ||
if strings.HasSuffix(target, " (deleted)") { | ||
processDeletedFds++ | ||
} | ||
} | ||
|
||
ch <- prometheus.MustNewConstMetric(f.processDeletedFds, prometheus.GaugeValue, float64(processDeletedFds)) | ||
} | ||
|
||
func (f *fdsCollector) Describe(ch chan<- *prometheus.Desc) { | ||
ch <- f.processDeletedFds | ||
} |
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