-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Ben Kochie <superq@gmail.com> Signed-off-by: Nobuhiro MIKI <nmiki@yahoo-corp.jp>
- Loading branch information
1 parent
69a3f73
commit 22cbebd
Showing
7 changed files
with
192 additions
and
0 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
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,6 @@ | ||
slabinfo - version: 2.1 | ||
# name <active_objs> <num_objs> <objsize> <objperslab> <pagesperslab> : tunables <limit> <batchcount> <sharedfactor> : slabdata <active_slabs> <num_slabs> <sharedavail> | ||
tw_sock_TCP 704 864 256 32 2 : tunables 0 0 0 : slabdata 27 27 0 | ||
dmaengine-unmap-128 1206 1320 1088 30 8 : tunables 0 0 0 : slabdata 44 44 0 | ||
kmalloc-8192 132 148 8192 4 8 : tunables 0 0 0 : slabdata 37 37 0 | ||
kmem_cache 320 320 256 32 2 : tunables 0 0 0 : slabdata 10 10 0 |
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,121 @@ | ||
// Copyright 2022 The Prometheus Authors | ||
// 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. | ||
|
||
//go:build linux && !noslabinfo | ||
// +build linux,!noslabinfo | ||
|
||
package collector | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/go-kit/log" | ||
"github.com/prometheus/client_golang/prometheus" | ||
"github.com/prometheus/procfs" | ||
) | ||
|
||
type slabinfoCollector struct { | ||
fs procfs.FS | ||
logger log.Logger | ||
subsystem string | ||
labels []string | ||
} | ||
|
||
func init() { | ||
registerCollector("slabinfo", defaultDisabled, NewSlabinfoCollector) | ||
} | ||
|
||
func NewSlabinfoCollector(logger log.Logger) (Collector, error) { | ||
fs, err := procfs.NewFS(*procPath) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to open procfs: %w", err) | ||
} | ||
|
||
return &slabinfoCollector{logger: logger, | ||
fs: fs, | ||
subsystem: "slabinfo", | ||
labels: []string{"slab"}, | ||
}, nil | ||
} | ||
|
||
func (c *slabinfoCollector) Update(ch chan<- prometheus.Metric) error { | ||
slabinfo, err := c.fs.SlabInfo() | ||
if err != nil { | ||
return fmt.Errorf("couldn't get %s: %w", c.subsystem, err) | ||
} | ||
|
||
for _, slab := range slabinfo.Slabs { | ||
ch <- c.activeObjects(slab.Name, slab.ObjActive) | ||
ch <- c.objects(slab.Name, slab.ObjNum) | ||
ch <- c.objectSizeBytes(slab.Name, slab.ObjSize) | ||
ch <- c.objectsPerSlab(slab.Name, slab.ObjPerSlab) | ||
ch <- c.pagesPerSlab(slab.Name, slab.PagesPerSlab) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (c *slabinfoCollector) activeObjects(label string, val int64) prometheus.Metric { | ||
desc := prometheus.NewDesc( | ||
prometheus.BuildFQName(namespace, c.subsystem, "active_objects"), | ||
"The number of objects that are currently active (i.e., in use).", | ||
c.labels, nil) | ||
|
||
return prometheus.MustNewConstMetric( | ||
desc, prometheus.GaugeValue, float64(val), label, | ||
) | ||
} | ||
|
||
func (c *slabinfoCollector) objects(label string, val int64) prometheus.Metric { | ||
desc := prometheus.NewDesc( | ||
prometheus.BuildFQName(namespace, c.subsystem, "objects"), | ||
"The total number of allocated objects (i.e., objects that are both in use and not in use).", | ||
c.labels, nil) | ||
|
||
return prometheus.MustNewConstMetric( | ||
desc, prometheus.GaugeValue, float64(val), label, | ||
) | ||
} | ||
|
||
func (c *slabinfoCollector) objectSizeBytes(label string, val int64) prometheus.Metric { | ||
desc := prometheus.NewDesc( | ||
prometheus.BuildFQName(namespace, c.subsystem, "object_size_bytes"), | ||
"The size of objects in this slab, in bytes.", | ||
c.labels, nil) | ||
|
||
return prometheus.MustNewConstMetric( | ||
desc, prometheus.GaugeValue, float64(val), label, | ||
) | ||
} | ||
|
||
func (c *slabinfoCollector) objectsPerSlab(label string, val int64) prometheus.Metric { | ||
desc := prometheus.NewDesc( | ||
prometheus.BuildFQName(namespace, c.subsystem, "objects_per_slab"), | ||
"The number of objects stored in each slab.", | ||
c.labels, nil) | ||
|
||
return prometheus.MustNewConstMetric( | ||
desc, prometheus.GaugeValue, float64(val), label, | ||
) | ||
} | ||
|
||
func (c *slabinfoCollector) pagesPerSlab(label string, val int64) prometheus.Metric { | ||
desc := prometheus.NewDesc( | ||
prometheus.BuildFQName(namespace, c.subsystem, "pages_per_slab"), | ||
"The number of pages allocated for each slab.", | ||
c.labels, nil) | ||
|
||
return prometheus.MustNewConstMetric( | ||
desc, prometheus.GaugeValue, float64(val), label, | ||
) | ||
} |
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 |
---|---|---|
|
@@ -38,6 +38,7 @@ enabled_collectors=$(cat << COLLECTORS | |
rapl | ||
schedstat | ||
selinux | ||
slabinfo | ||
sockstat | ||
stat | ||
thermal_zone | ||
|