From a943586b7e3c8e58db579ae88a1cfdee9ad442f0 Mon Sep 17 00:00:00 2001 From: hmelder Date: Sat, 26 Oct 2024 19:42:35 +0200 Subject: [PATCH] Add more metrics --- succbone/succd/gpio.go | 13 ++++++++++++ succbone/succd/http.go | 19 ++++++++++++++++++ succbone/succd/process_controller.go | 30 ++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+) diff --git a/succbone/succd/gpio.go b/succbone/succd/gpio.go index 9bdfbf5..b5c9f78 100644 --- a/succbone/succd/gpio.go +++ b/succbone/succd/gpio.go @@ -13,6 +13,7 @@ type gpio interface { // set returns the GPIO value. The meaning of the logic level is // implementation-dependent. set(state bool) error + get() bool } // bbGPIO implements gpio using BeagleBone's built-in GPIO pins. @@ -72,6 +73,12 @@ func (b *bbGPIO) set(state bool) error { return nil } +func (b *bbGPIO) get() bool { + b.mu.Lock() + defer b.mu.Unlock() + return b.state +} + // fakeGPIO implements a GPIO that logs state changes. type fakeGPIO struct { desc string @@ -90,3 +97,9 @@ func (b *fakeGPIO) set(state bool) error { b.state = state return nil } + +func (b *fakeGPIO) get() bool { + b.mu.Lock() + defer b.mu.Unlock() + return b.state +} diff --git a/succbone/succd/http.go b/succbone/succd/http.go index 4365428..123983c 100644 --- a/succbone/succd/http.go +++ b/succbone/succd/http.go @@ -170,9 +170,28 @@ func (s *webServer) viewMetrics(w http.ResponseWriter, r *http.Request) { // TODO(q3k): serve the rest of the data model state := s.d.snapshot() mbar := state.piraniMbar100.mbar + rpOn := state.rpOn + dpOn := state.dpOn + pumpDownStatus := s.d.gpioPumpDownStatus() + ventStatus := s.d.gpioVentStatus() + belowRoughStatus := s.d.gpioBelowRoughStatus() + belowHighStatus := s.d.gpioBelowHighStatus() + fmt.Fprintf(w, "# HELP sem_pressure_mbar Pressure in the SEM chamber, in millibar\n") fmt.Fprintf(w, "# TYPE sem_pressure_mbar gauge\n") fmt.Fprintf(w, "sem_pressure_mbar %f\n", mbar) + fmt.Fprintf(w, "# TYPE sem_rp_on gauge\n") + fmt.Fprintf(w, "sem_rp_on %t\n", rpOn) + fmt.Fprintf(w, "# TYPE sem_dp_on gauge\n") + fmt.Fprintf(w, "sem_dp_on %t\n", dpOn) + fmt.Fprintf(w, "# TYPE sem_gpio_pump_down_status gauge\n") + fmt.Fprintf(w, "sem_gpio_pump_down_status %t\n", pumpDownStatus) + fmt.Fprintf(w, "# TYPE sem_gpio_vent_status gauge\n") + fmt.Fprintf(w, "sem_gpio_vent_status %t\n", ventStatus) + fmt.Fprintf(w, "# TYPE sem_gpio_below_rough_status gauge\n") + fmt.Fprintf(w, "sem_gpio_below_rough_status %t\n", belowRoughStatus) + fmt.Fprintf(w, "# TYPE sem_gpio_below_high_status gauge\n") + fmt.Fprintf(w, "sem_gpio_below_high_status %t\n", belowHighStatus) } func (s *webServer) viewRoughingPumpEnable(w http.ResponseWriter, r *http.Request) { diff --git a/succbone/succd/process_controller.go b/succbone/succd/process_controller.go index b7f689c..129c740 100644 --- a/succbone/succd/process_controller.go +++ b/succbone/succd/process_controller.go @@ -18,6 +18,12 @@ type daemonController interface { pumpDownPress() // ventPRess simulates a vent button press. ventPress() + // returns the current gpio state of the pump down button + gpioPumpDownStatus() bool + // returns the current gpio state of the vent button + gpioVentStatus() bool + gpioBelowRoughStatus() bool + gpioBelowHighStatus() bool } func (d *daemon) loopLoad() int64 { @@ -62,3 +68,27 @@ func (d *daemon) ventPress() { defer d.mu.Unlock() d.vent.trigger() } + +func (d *daemon) gpioPumpDownStatus() bool { + d.mu.Lock() + defer d.mu.Unlock() + return d.gpioBtnPumpDown.get() +} + +func (d *daemon) gpioVentStatus() bool { + d.mu.Lock() + defer d.mu.Unlock() + return d.gpioBtnVent.get() +} + +func (d *daemon) gpioBelowRoughStatus() bool { + d.mu.Lock() + defer d.mu.Unlock() + return d.gpioBelowRough.get() +} + +func (d *daemon) gpioBelowHighStatus() bool { + d.mu.Lock() + defer d.mu.Unlock() + return d.gpioBelowHigh.get() +}