MCPcopy Create free account
hub / github.com/CovenantSQL/CovenantSQL / Update

Method Update

metric/cpu_openbsd.go:43–76  ·  view source on GitHub ↗
(ch chan<- prometheus.Metric)

Source from the content-addressed store, hash-verified

41}
42
43func (c *cpuCollector) Update(ch chan<- prometheus.Metric) (err error) {
44 clockb, err := unix.SysctlRaw("kern.clockrate")
45 if err != nil {
46 return err
47 }
48 clock := *(*C.struct_clockinfo)(unsafe.Pointer(&clockb[0]))
49 hz := float64(clock.stathz)
50
51 ncpus, err := unix.SysctlUint32("hw.ncpu")
52 if err != nil {
53 return err
54 }
55
56 var cp_time [][C.CPUSTATES]C.int64_t
57 for i := 0; i < int(ncpus); i++ {
58 cp_timeb, err := unix.SysctlRaw("kern.cp_time2", i)
59 if err != nil {
60 return err
61 }
62 cp_time = append(cp_time, *(*[C.CPUSTATES]C.int64_t)(unsafe.Pointer(&cp_timeb[0])))
63 }
64
65 for cpu, time := range cp_time {
66 lcpu := strconv.Itoa(cpu)
67 ch <- c.cpu.mustNewConstMetric(float64(time[C.CP_USER])/hz, lcpu, "user")
68 ch <- c.cpu.mustNewConstMetric(float64(time[C.CP_NICE])/hz, lcpu, "nice")
69 ch <- c.cpu.mustNewConstMetric(float64(time[C.CP_SYS])/hz, lcpu, "system")
70 ch <- c.cpu.mustNewConstMetric(float64(time[C.CP_INTR])/hz, lcpu, "interrupt")
71 ch <- c.cpu.mustNewConstMetric(float64(time[C.CP_IDLE])/hz, lcpu, "idle")
72 }
73 ch <- prometheus.MustNewConstMetric(nodeCPUCountDesc, prometheus.GaugeValue, float64(runtime.NumCPU()))
74
75 return err
76}

Callers

nothing calls this directly

Calls 1

mustNewConstMetricMethod · 0.45

Tested by

no test coverage detected