Skip to content

Commit 0cb7b61

Browse files
AIX: Add partition stats
Signed-off-by: Johannes Ziemke <[email protected]>
1 parent 430023e commit 0cb7b61

File tree

1 file changed

+118
-0
lines changed

1 file changed

+118
-0
lines changed

collector/partition_aix.go

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
// Copyright 2025 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 !nopartition
15+
// +build !nopartition
16+
17+
package collector
18+
19+
import (
20+
"log/slog"
21+
22+
"github.com/power-devops/perfstat"
23+
"github.com/prometheus/client_golang/prometheus"
24+
)
25+
26+
type partitionCollector struct {
27+
logger *slog.Logger
28+
entitledCapacity *prometheus.Desc
29+
memoryMax *prometheus.Desc
30+
memoryOnline *prometheus.Desc
31+
cpuOnline *prometheus.Desc
32+
cpuSys *prometheus.Desc
33+
cpuPool *prometheus.Desc
34+
powerSaveMode *prometheus.Desc
35+
smtThreads *prometheus.Desc
36+
}
37+
38+
const (
39+
partitionCollectorSubsystem = "partition"
40+
)
41+
42+
func init() {
43+
registerCollector("partition", defaultEnabled, NewPartitionCollector)
44+
}
45+
46+
func NewPartitionCollector(logger *slog.Logger) (Collector, error) {
47+
return &partitionCollector{
48+
logger: logger,
49+
entitledCapacity: prometheus.NewDesc(
50+
prometheus.BuildFQName(namespace, partitionCollectorSubsystem, "entitled_capacity"),
51+
"Entitled processor capacity of the partition in CPU units (e.g. 1.0 = one core).",
52+
nil, nil,
53+
),
54+
memoryMax: prometheus.NewDesc(
55+
prometheus.BuildFQName(namespace, partitionCollectorSubsystem, "memory_max"),
56+
"Maximum memory of the partition in bytes.",
57+
nil, nil,
58+
),
59+
memoryOnline: prometheus.NewDesc(
60+
prometheus.BuildFQName(namespace, partitionCollectorSubsystem, "memory_online"),
61+
"Online memory of the partition in bytes.",
62+
nil, nil,
63+
),
64+
cpuOnline: prometheus.NewDesc(
65+
prometheus.BuildFQName(namespace, partitionCollectorSubsystem, "cpus_online"),
66+
"Number of online CPUs in the partition.",
67+
nil, nil,
68+
),
69+
cpuSys: prometheus.NewDesc(
70+
prometheus.BuildFQName(namespace, partitionCollectorSubsystem, "cpus_sys"),
71+
"Number of physical CPUs in the system.",
72+
nil, nil,
73+
),
74+
cpuPool: prometheus.NewDesc(
75+
prometheus.BuildFQName(namespace, partitionCollectorSubsystem, "cpus_pool"),
76+
"Number of physical CPUs in the pool.",
77+
nil, nil,
78+
),
79+
powerSaveMode: prometheus.NewDesc(
80+
prometheus.BuildFQName(namespace, partitionCollectorSubsystem, "power_save_mode"),
81+
"Power save mode of the partition (1 for enabled, 0 for disabled).",
82+
nil, nil,
83+
),
84+
smtThreads: prometheus.NewDesc(
85+
prometheus.BuildFQName(namespace, partitionCollectorSubsystem, "smt_threads"),
86+
"Number of SMT threads per core.",
87+
nil, nil,
88+
),
89+
}, nil
90+
}
91+
92+
func (c *partitionCollector) Update(ch chan<- prometheus.Metric) error {
93+
stats, err := perfstat.PartitionStat()
94+
if err != nil {
95+
return err
96+
}
97+
98+
powerSaveMode := 0.0
99+
if stats.Conf.PowerSave {
100+
powerSaveMode = 1.0
101+
}
102+
103+
ch <- prometheus.MustNewConstMetric(c.entitledCapacity, prometheus.GaugeValue, float64(stats.EntCapacity)/100.0)
104+
105+
ch <- prometheus.MustNewConstMetric(c.memoryMax, prometheus.GaugeValue, float64(stats.Mem.Max)*1024*1024)
106+
ch <- prometheus.MustNewConstMetric(c.memoryOnline, prometheus.GaugeValue, float64(stats.Mem.Online)*1024*1024)
107+
108+
ch <- prometheus.MustNewConstMetric(c.cpuOnline, prometheus.GaugeValue, float64(stats.VCpus.Online))
109+
110+
ch <- prometheus.MustNewConstMetric(c.cpuSys, prometheus.GaugeValue, float64(stats.NumProcessors.Online))
111+
112+
ch <- prometheus.MustNewConstMetric(c.cpuPool, prometheus.GaugeValue, float64(stats.ActiveCpusInPool))
113+
114+
ch <- prometheus.MustNewConstMetric(c.powerSaveMode, prometheus.GaugeValue, powerSaveMode)
115+
ch <- prometheus.MustNewConstMetric(c.smtThreads, prometheus.GaugeValue, float64(stats.SmtThreads))
116+
117+
return nil
118+
}

0 commit comments

Comments
 (0)