Add more metrics #15
					 3 changed files with 62 additions and 0 deletions
				
			
		| 
						 | 
				
			
			@ -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
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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()
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue