Skip to content
This repository was archived by the owner on Jun 30, 2021. It is now read-only.

Commit 835eb3f

Browse files
committed
Added exporter for memory and increased clock collection
1 parent c9a4ef1 commit 835eb3f

File tree

3 files changed

+59
-7
lines changed

3 files changed

+59
-7
lines changed

collector/clock.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
)
99

1010
const (
11-
CoreClock string = "core"
11+
GpuClock string = "core"
1212
EmmcClock string = "emmc"
1313
ArmClock string = "arm"
1414
)

collector/memory.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package collector
2+
3+
import (
4+
"../utils"
5+
"github.com/prometheus/client_golang/prometheus"
6+
"regexp"
7+
"strconv"
8+
)
9+
10+
const (
11+
CpuMemory string = "arm"
12+
GpuMemory string = "gpu"
13+
)
14+
15+
func getMemory(desc *prometheus.Desc, device string) prometheus.Metric {
16+
memory, err := utils.ExecuteVcGen("get_mem", device)
17+
18+
if err != nil {
19+
return prometheus.NewInvalidMetric(desc, err)
20+
}
21+
22+
memory = regexp.MustCompile(`(gpu=)|(arm=)|(M)|(\n)|(\r)`).ReplaceAllString(memory, "")
23+
memoryFloat, err := strconv.ParseFloat(memory, 64)
24+
25+
if err != nil {
26+
return prometheus.NewInvalidMetric(desc, err)
27+
}
28+
29+
return prometheus.MustNewConstMetric(
30+
desc,
31+
prometheus.GaugeValue,
32+
memoryFloat,
33+
)
34+
}

collector/vcgencmcollector.go

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ type VcGenCmdCollector struct {
1313
CoreClock *prometheus.Desc
1414
ArmClock *prometheus.Desc
1515
EmmcClock *prometheus.Desc
16+
CpuMemory *prometheus.Desc
17+
GpuMemory *prometheus.Desc
1618
}
1719

1820
func (VcGenCmdCollector) Describe(channel chan<- *prometheus.Desc) {
@@ -26,6 +28,8 @@ func (VcGenCmdCollector) Describe(channel chan<- *prometheus.Desc) {
2628
channel <- collector.CoreClock
2729
channel <- collector.ArmClock
2830
channel <- collector.EmmcClock
31+
channel <- collector.CpuMemory
32+
channel <- collector.GpuMemory
2933
}
3034

3135
func (VcGenCmdCollector) Collect(channel chan<- prometheus.Metric) {
@@ -36,9 +40,11 @@ func (VcGenCmdCollector) Collect(channel chan<- prometheus.Metric) {
3640
channel <- getVoltage(collector.SdramPhysicalVoltage, SdramPhysicalVoltage)
3741
channel <- getVoltage(collector.SdramInputOutputVoltage, SdramInputOutputVoltage)
3842
channel <- getVoltage(collector.SdramControllerVoltage, SdramControllerVoltage)
39-
channel <- getClock(collector.CoreClock, CoreClock)
43+
channel <- getClock(collector.CoreClock, GpuClock)
4044
channel <- getClock(collector.ArmClock, ArmClock)
4145
channel <- getClock(collector.EmmcClock, EmmcClock)
46+
channel <- getMemory(collector.CpuMemory, CpuMemory)
47+
channel <- getMemory(collector.GpuMemory, GpuMemory)
4248
}
4349

4450
var _ prometheus.Collector = &VcGenCmdCollector{}
@@ -81,20 +87,32 @@ func NewVcGenCmdCollector() *VcGenCmdCollector {
8187
nil,
8288
),
8389
CoreClock: prometheus.NewDesc(
84-
prometheus.BuildFQName(namespace, subsystem, "core_clock"),
85-
"Clock of the core in Hz",
90+
prometheus.BuildFQName(namespace, subsystem, "gpu_clock"),
91+
"Clock speed of the GPU in Hz",
8692
nil,
8793
nil,
8894
),
8995
ArmClock: prometheus.NewDesc(
90-
prometheus.BuildFQName(namespace, subsystem, "arm_clock"),
91-
"Clock of the ARM CPU in Hz",
96+
prometheus.BuildFQName(namespace, subsystem, "cpu_clock"),
97+
"Clock speed of the ARM CPU in Hz",
9298
nil,
9399
nil,
94100
),
95101
EmmcClock: prometheus.NewDesc(
96102
prometheus.BuildFQName(namespace, subsystem, "emmc_clock"),
97-
"Clock of the external MMC in Hz",
103+
"Clock speed of the SD card in Hz",
104+
nil,
105+
nil,
106+
),
107+
CpuMemory: prometheus.NewDesc(
108+
prometheus.BuildFQName(namespace, subsystem, "cpu_memory"),
109+
"Memory for the CPU in Megabytes",
110+
nil,
111+
nil,
112+
),
113+
GpuMemory: prometheus.NewDesc(
114+
prometheus.BuildFQName(namespace, subsystem, "gpu_memory"),
115+
"Memory for the GPU in Megabytes",
98116
nil,
99117
nil,
100118
),

0 commit comments

Comments
 (0)