succd: Add metrics for RP and RP operating time
Add counter metrics that count the total operating time for the roughing pump and the diffusion pump.
This commit is contained in:
		
							parent
							
								
									918a020e68
								
							
						
					
					
						commit
						2cfea46852
					
				
					 2 changed files with 27 additions and 4 deletions
				
			
		| 
						 | 
					@ -217,6 +217,14 @@ func (s *webServer) viewMetrics(w http.ResponseWriter, r *http.Request) {
 | 
				
			||||||
	fmt.Fprintf(w, "# HELP sem_vacuum_high_reached Whether the high vacuum threshold has been passed (boolean)\n")
 | 
						fmt.Fprintf(w, "# HELP sem_vacuum_high_reached Whether the high vacuum threshold has been passed (boolean)\n")
 | 
				
			||||||
	fmt.Fprintf(w, "# TYPE sem_vacuum_high_reached gauge\n")
 | 
						fmt.Fprintf(w, "# TYPE sem_vacuum_high_reached gauge\n")
 | 
				
			||||||
	fmt.Fprintf(w, "sem_vacuum_high_reached %f\n", boolToFloat(high))
 | 
						fmt.Fprintf(w, "sem_vacuum_high_reached %f\n", boolToFloat(high))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						fmt.Fprintf(w, "# HELP sem_rp_operating_seconds_total Operating time of the roughing pump, in seconds\n")
 | 
				
			||||||
 | 
						fmt.Fprintf(w, "# TYPE sem_rp_operating_seconds_total counter\n")
 | 
				
			||||||
 | 
						fmt.Fprintf(w, "sem_rp_operating_seconds_total %f\n", state.rpOperatingTime.Seconds())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						fmt.Fprintf(w, "# HELP sem_dp_operating_seconds_total Operating time of the diffusion pump, in seconds\n")
 | 
				
			||||||
 | 
						fmt.Fprintf(w, "# TYPE sem_dp_operating_seconds_total counter\n")
 | 
				
			||||||
 | 
						fmt.Fprintf(w, "sem_dp_operating_seconds_total %f\n", state.dpOperatingTime.Seconds())
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (s *webServer) viewRoughingPumpEnable(w http.ResponseWriter, r *http.Request) {
 | 
					func (s *webServer) viewRoughingPumpEnable(w http.ResponseWriter, r *http.Request) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -51,6 +51,9 @@ type daemonState struct {
 | 
				
			||||||
	rpOn bool
 | 
						rpOn bool
 | 
				
			||||||
	dpOn bool
 | 
						dpOn bool
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						rpOperatingTime time.Duration
 | 
				
			||||||
 | 
						dpOperatingTime time.Duration
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	vent       momentaryOutput
 | 
						vent       momentaryOutput
 | 
				
			||||||
	pumpdown   momentaryOutput
 | 
						pumpdown   momentaryOutput
 | 
				
			||||||
	aboveRough thresholdOutput
 | 
						aboveRough thresholdOutput
 | 
				
			||||||
| 
						 | 
					@ -77,11 +80,15 @@ func (d *daemon) process(ctx context.Context) {
 | 
				
			||||||
		select {
 | 
							select {
 | 
				
			||||||
		case <-ticker.C:
 | 
							case <-ticker.C:
 | 
				
			||||||
			now := time.Now()
 | 
								now := time.Now()
 | 
				
			||||||
			if elapsed := now.Sub(lastRun); !lastRun.IsZero() && elapsed > periodGrace {
 | 
								var elapsed time.Duration = 0
 | 
				
			||||||
				klog.Warningf("Processing loop lag: took %s, want %s", elapsed, period)
 | 
								if !lastRun.IsZero(){
 | 
				
			||||||
 | 
									elapsed = now.Sub(lastRun)
 | 
				
			||||||
 | 
									if elapsed > periodGrace {
 | 
				
			||||||
 | 
										klog.Warningf("Processing loop lag: took %s, want %s", elapsed, period)
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			lastRun = now
 | 
								lastRun = now
 | 
				
			||||||
			if err := d.processOnce(ctx); err != nil {
 | 
								if err := d.processOnce(ctx, elapsed); err != nil {
 | 
				
			||||||
				if errors.Is(err, ctx.Err()) {
 | 
									if errors.Is(err, ctx.Err()) {
 | 
				
			||||||
					return
 | 
										return
 | 
				
			||||||
				} else {
 | 
									} else {
 | 
				
			||||||
| 
						 | 
					@ -99,7 +106,7 @@ func (d *daemon) process(ctx context.Context) {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// processOnce runs the main loop step of succd.
 | 
					// processOnce runs the main loop step of succd.
 | 
				
			||||||
func (d *daemon) processOnce(_ context.Context) error {
 | 
					func (d *daemon) processOnce(_ context.Context, elapsed time.Duration) error {
 | 
				
			||||||
	v, err := d.adcPirani.Read()
 | 
						v, err := d.adcPirani.Read()
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return fmt.Errorf("when reading ADC: %w", err)
 | 
							return fmt.Errorf("when reading ADC: %w", err)
 | 
				
			||||||
| 
						 | 
					@ -190,5 +197,13 @@ func (d *daemon) processOnce(_ context.Context) error {
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Update operating time counters
 | 
				
			||||||
 | 
						if d.rpOn && elapsed > 0 {
 | 
				
			||||||
 | 
							d.rpOperatingTime += elapsed
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if d.dpOn && elapsed > 0 {
 | 
				
			||||||
 | 
							d.dpOperatingTime += elapsed
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return nil
 | 
						return nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue