Skip to content

Commit

Permalink
Add AIX diskstats
Browse files Browse the repository at this point in the history
  • Loading branch information
discordianfish committed Jul 30, 2024
1 parent 442eaa2 commit 43f1a54
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 2 deletions.
70 changes: 70 additions & 0 deletions collector/diskstats_aix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Copyright 2024 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 !nodiskstats
// +build !nodiskstats

package collector

import (
"fmt"

"github.com/go-kit/log"
"github.com/prometheus/client_golang/prometheus"
perfstat "github.com/thorhs/aix_libperfstat/generated"
)

const diskstatsDefaultIgnoredDevices = ""

type diskstatsCollector struct {
rbytes typedDesc
wbytes typedDesc
time typedDesc

deviceFilter deviceFilter
logger log.Logger
}

func init() {
registerCollector("diskstats", defaultEnabled, NewDiskstatsCollector)
}

// NewDiskstatsCollector returns a new Collector exposing disk device stats.
func NewDiskstatsCollector(logger log.Logger) (Collector, error) {
deviceFilter, err := newDiskstatsDeviceFilter(logger)
if err != nil {
return nil, fmt.Errorf("failed to parse device filter flags: %w", err)
}

return &diskstatsCollector{
rbytes: typedDesc{readBytesDesc, prometheus.CounterValue},
wbytes: typedDesc{writtenBytesDesc, prometheus.CounterValue},
time: typedDesc{ioTimeSecondsDesc, prometheus.CounterValue},

deviceFilter: deviceFilter,
logger: logger,
}, nil
}

func (c *diskstatsCollector) Update(ch chan<- prometheus.Metric) error {
diskStats := perfstat.CollectDisks()
for disk, stat := range diskStats {
if c.deviceFilter.ignored(disk) {
continue
}
ch <- c.rbytes.mustNewConstMetric(stat.Rblks/512, disk)
ch <- c.wbytes.mustNewConstMetric(stat.Wblks/512, disk)
ch <- c.time.mustNewConstMetric(stat.Time, disk)
}
return nil
}
4 changes: 2 additions & 2 deletions collector/diskstats_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build !nodiskstats && (openbsd || linux || darwin)
//go:build !nodiskstats && (openbsd || linux || darwin || aix)
// +build !nodiskstats
// +build openbsd linux darwin
// +build openbsd linux darwin aix

package collector

Expand Down

0 comments on commit 43f1a54

Please sign in to comment.