Skip to content

Commit 3083446

Browse files
Add AIX diskstats
Signed-off-by: Johannes Ziemke <[email protected]>
1 parent 88ed2ce commit 3083446

File tree

2 files changed

+84
-2
lines changed

2 files changed

+84
-2
lines changed

collector/diskstats_aix.go

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
// Copyright 2024 The Prometheus Authors
2+
// Licensed under the Apache License, Version 2.0 (the "License");
3+
// you may not use this file except in compliance with the License.
4+
// You may obtain a copy of the License at
5+
//
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
//
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
14+
//go:build !nodiskstats
15+
// +build !nodiskstats
16+
17+
package collector
18+
19+
import (
20+
"fmt"
21+
"log/slog"
22+
23+
"github.com/power-devops/perfstat"
24+
"github.com/prometheus/client_golang/prometheus"
25+
)
26+
27+
const diskstatsDefaultIgnoredDevices = ""
28+
29+
type diskstatsCollector struct {
30+
rbytes typedDesc
31+
wbytes typedDesc
32+
time typedDesc
33+
34+
deviceFilter deviceFilter
35+
logger *slog.Logger
36+
37+
tickPerSecond int64
38+
}
39+
40+
func init() {
41+
registerCollector("diskstats", defaultEnabled, NewDiskstatsCollector)
42+
}
43+
44+
// NewDiskstatsCollector returns a new Collector exposing disk device stats.
45+
func NewDiskstatsCollector(logger *slog.Logger) (Collector, error) {
46+
ticks, err := tickPerSecond()
47+
if err != nil {
48+
return nil, err
49+
}
50+
deviceFilter, err := newDiskstatsDeviceFilter(logger)
51+
if err != nil {
52+
return nil, fmt.Errorf("failed to parse device filter flags: %w", err)
53+
}
54+
55+
return &diskstatsCollector{
56+
rbytes: typedDesc{readBytesDesc, prometheus.CounterValue},
57+
wbytes: typedDesc{writtenBytesDesc, prometheus.CounterValue},
58+
time: typedDesc{ioTimeSecondsDesc, prometheus.CounterValue},
59+
60+
deviceFilter: deviceFilter,
61+
logger: logger,
62+
63+
tickPerSecond: ticks,
64+
}, nil
65+
}
66+
67+
func (c *diskstatsCollector) Update(ch chan<- prometheus.Metric) error {
68+
stats, err := perfstat.DiskStat()
69+
if err != nil {
70+
return err
71+
}
72+
73+
for _, stat := range stats {
74+
if c.deviceFilter.ignored(stat.Name) {
75+
continue
76+
}
77+
ch <- c.rbytes.mustNewConstMetric(float64(stat.Rblks*512), stat.Name)
78+
ch <- c.wbytes.mustNewConstMetric(float64(stat.Wblks*512), stat.Name)
79+
ch <- c.time.mustNewConstMetric(float64(stat.Time/c.tickPerSecond), stat.Name)
80+
}
81+
return nil
82+
}

collector/diskstats_common.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
// See the License for the specific language governing permissions and
1212
// limitations under the License.
1313

14-
//go:build !nodiskstats && (openbsd || linux || darwin)
14+
//go:build !nodiskstats && (openbsd || linux || darwin || aix)
1515
// +build !nodiskstats
16-
// +build openbsd linux darwin
16+
// +build openbsd linux darwin aix
1717

1818
package collector
1919

0 commit comments

Comments
 (0)