Created
April 18, 2024 10:12
-
-
Save bodokaiser/aed1547bedebab0d7987a14c99384f70 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"log" | |
"net" | |
"net/http" | |
"os" | |
"github.com/prometheus/client_golang/prometheus" | |
"github.com/prometheus/client_golang/prometheus/promhttp" | |
"github.com/rydyb/devices/srs" | |
) | |
var ( | |
controllerAddress = os.Getenv("CONTROLLER_ADDRESS") | |
prometheusAddress = os.Getenv("PROMETHEUS_ADDRESS") | |
) | |
const ( | |
prometheusNamespace = "vacuum_apparatus" | |
prometheusSubsystem = "atomic_beam_system" | |
) | |
var ( | |
hw_temp = prometheus.NewGauge(prometheus.GaugeOpts{ | |
Namespace: prometheusNamespace, | |
Subsystem: prometheusSubsystem, | |
Name: "hot_window_temperature_celsius", | |
}) | |
hw_curr = prometheus.NewGauge(prometheus.GaugeOpts{ | |
Namespace: prometheusNamespace, | |
Subsystem: prometheusSubsystem, | |
Name: "hot_window_current_amperes", | |
}) | |
oven_temp = prometheus.NewGauge(prometheus.GaugeOpts{ | |
Namespace: prometheusNamespace, | |
Subsystem: prometheusSubsystem, | |
Name: "oven_temperature_celsius", | |
}) | |
oven_power = prometheus.NewGauge(prometheus.GaugeOpts{ | |
Namespace: prometheusNamespace, | |
Subsystem: prometheusSubsystem, | |
Name: "oven_power_watts", | |
}) | |
) | |
func main() { | |
conn, err := net.Dial("tcp", controllerAddress) | |
if err != nil { | |
log.Fatalf("failed to connect to controller: %s", err) | |
} | |
defer conn.Close() | |
ptc10 := srs.NewPTC10(conn) | |
promhandler := promhttp.Handler() | |
http.Handle("/metrics", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | |
outputs, err := ptc10.Outputs() | |
if err != nil { | |
http.Error(w, err.Error(), http.StatusInternalServerError) | |
log.Fatalf("failed to get outputs: %s", err) | |
return | |
} | |
hw_temp.Set(outputs["HW TC"]) | |
hw_curr.Set(outputs["HW Out"]) | |
oven_temp.Set(outputs["Oven TC"]) | |
oven_power.Set(outputs["Oven Out"]) | |
promhandler.ServeHTTP(w, r) | |
})) | |
if err := http.ListenAndServe(prometheusAddress, nil); err != nil { | |
log.Fatalf("failed to listen and serve to %s: %s", prometheusAddress, err) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment