From 381559a4446b3a8c4d4f1005f4ddf92f29c2aa1e Mon Sep 17 00:00:00 2001 From: Alec Pinson <30310787+alec-pinson@users.noreply.github.com> Date: Fri, 5 May 2023 14:19:59 +0100 Subject: [PATCH 1/3] Added prom metrics + changed sensor values to 2 decimal places --- .gitignore | 1 + README.md | 22 ++++++++++-- cmd/terrarium-bot/apiserver.go | 9 +++++ cmd/terrarium-bot/config.go | 10 +++--- cmd/terrarium-bot/config_test.go | 8 ++--- cmd/terrarium-bot/http.go | 17 ++++++++- cmd/terrarium-bot/http_test.go | 60 ++++++++++++++++++++++++++++++++ cmd/terrarium-bot/main.go | 2 ++ cmd/terrarium-bot/metrics.go | 19 ++++++++++ cmd/terrarium-bot/sensor.go | 27 ++++++++++---- cmd/terrarium-bot/sensor_test.go | 4 +-- cmd/terrarium-bot/trigger.go | 8 ++--- go.mod | 12 +++++++ go.sum | 37 +++++++++++++++++++- 14 files changed, 211 insertions(+), 25 deletions(-) create mode 100644 cmd/terrarium-bot/metrics.go diff --git a/.gitignore b/.gitignore index 56a1ca2..48ca762 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,4 @@ # Go workspace file go.work cmd/terrarium-bot/test.yaml +cmd/terrarium-bot/fly-pi-config.yaml diff --git a/README.md b/README.md index b013385..831f82d 100644 --- a/README.md +++ b/README.md @@ -3,8 +3,6 @@ [![Latest release](https://img.shields.io/github/v/release/alec-pinson/terrarium-bot?label=Latest%20release)](https://github.com/alec-pinson/terrarium-bot/releases/latest) [![GitHub Release Date](https://img.shields.io/github/release-date/alec-pinson/terrarium-bot)](https://github.com/alec-pinson/terrarium-bot/releases/latest) -**CURRENTLY IN TESTING** - I have been running this for a week or so now and I am still fixing minor issues. - Manage a Terrarium. Temperature, humidity, heating, misting, lighting, all fully configurable and customisable via YAML. I currently run this in a Kubernetes cluster (3 Raspberry Pis using [K3S](https://k3s.io/)). I run it along side my other apps: @@ -244,5 +242,25 @@ Example response:- } ``` +## Prometheus Metrics +Prometheus metrics can be accessed via `:8081/metrics` and currently includes standard go metrics and the following custom metrics:- +``` +# HELP terrarium_bot_http_client_pools_total The total number of http client pools +# TYPE terrarium_bot_http_client_pools_total counter +terrarium_bot_http_client_pools_total 3 +# HELP terrarium_bot_http_requests_received_total The total number of http requests received by terrarium bot +# TYPE terrarium_bot_http_requests_received_total counter +terrarium_bot_http_requests_received_total 2 +# HELP terrarium_bot_http_requests_sent_total The total number of http requests sent from terrarium bot +# TYPE terrarium_bot_http_requests_sent_total counter +terrarium_bot_http_requests_sent_total 33 +# HELP terrarium_bot_sensor_humidity The current value of the humidity sensor +# TYPE terrarium_bot_sensor_humidity gauge +terrarium_bot_sensor_humidity 65 +# HELP terrarium_bot_sensor_temperature The current value of the temperature sensor +# TYPE terrarium_bot_sensor_temperature gauge +terrarium_bot_sensor_temperature 27 +``` + ## The End Hopefully the configuration should be pretty self explanitory, if you get stuck or there are any features you think might be missing then feel free to create an issue :slightly_smiling_face:. diff --git a/cmd/terrarium-bot/apiserver.go b/cmd/terrarium-bot/apiserver.go index 253c401..1d28597 100644 --- a/cmd/terrarium-bot/apiserver.go +++ b/cmd/terrarium-bot/apiserver.go @@ -6,10 +6,18 @@ import ( "net/http" "strings" "time" + + "github.com/prometheus/client_golang/prometheus" + "github.com/prometheus/client_golang/prometheus/promauto" ) type APIServer struct{} +var metricHttpRequestsReceived = promauto.NewCounter(prometheus.CounterOpts{ + Name: "terrarium_bot_http_requests_received_total", + Help: "The total number of http requests received by terrarium bot", +}) + func (apiServer APIServer) Start() { log.Println("Starting API server...") http.HandleFunc("/", apiServer.Endpoint) @@ -19,6 +27,7 @@ func (apiServer APIServer) Start() { } func (apiServer APIServer) Endpoint(w http.ResponseWriter, r *http.Request) { + metricHttpRequestsReceived.Inc() switch path := r.URL.Path[1:]; { case path == "health/live" || path == "health/ready": fmt.Fprintf(w, "ok") diff --git a/cmd/terrarium-bot/config.go b/cmd/terrarium-bot/config.go index 7febe14..28e8495 100644 --- a/cmd/terrarium-bot/config.go +++ b/cmd/terrarium-bot/config.go @@ -62,7 +62,7 @@ type Sensor struct { Insecure bool `yaml:"insecure"` JsonPath string `yaml:"jsonPath"` Unit string `yaml:"unit"` - Value int + Value float64 } type Notification struct { @@ -90,13 +90,13 @@ type Alert struct { type When struct { Day struct { - Below int `yaml:"below"` - Above int `yaml:"above"` + Below float64 `yaml:"below"` + Above float64 `yaml:"above"` Every time.Duration `yaml:"every"` } `yaml:"day"` Night struct { - Below int `yaml:"below"` - Above int `yaml:"above"` + Below float64 `yaml:"below"` + Above float64 `yaml:"above"` Every time.Duration `yaml:"every"` } `yaml:"night"` } diff --git a/cmd/terrarium-bot/config_test.go b/cmd/terrarium-bot/config_test.go index 3725ff4..bc63039 100644 --- a/cmd/terrarium-bot/config_test.go +++ b/cmd/terrarium-bot/config_test.go @@ -129,8 +129,8 @@ alert: assert.Equal(t, "trigger1", loadedConfig.Trigger[0].Id) assert.Equal(t, "sensor1", loadedConfig.Trigger[0].Sensor) assert.Equal(t, "http://localhost:8080", loadedConfig.Trigger[0].Endpoint) - assert.Equal(t, 5, loadedConfig.Trigger[0].When.Day.Below) - assert.Equal(t, 5, loadedConfig.Trigger[0].When.Night.Below) + assert.Equal(t, float64(5), loadedConfig.Trigger[0].When.Day.Below) + assert.Equal(t, float64(5), loadedConfig.Trigger[0].When.Night.Below) assert.Equal(t, []string{"doSomething"}, loadedConfig.Trigger[0].Action) assert.Equal(t, []string{"doSomethingElse"}, loadedConfig.Trigger[0].Else) @@ -162,8 +162,8 @@ alert: assert.Len(t, loadedConfig.Alert, 1) assert.Equal(t, "alert1", loadedConfig.Alert[0].Id) assert.Equal(t, "sensor1", loadedConfig.Alert[0].Sensor) - assert.Equal(t, 10, loadedConfig.Alert[0].When.Day.Below) - assert.Equal(t, 5, loadedConfig.Alert[0].When.Night.Below) + assert.Equal(t, float64(10), loadedConfig.Alert[0].When.Day.Below) + assert.Equal(t, float64(5), loadedConfig.Alert[0].When.Night.Below) assert.Equal(t, 20*time.Minute, loadedConfig.Alert[0].After) assert.Equal(t, []string{"notification1"}, loadedConfig.Alert[0].Notification) diff --git a/cmd/terrarium-bot/http.go b/cmd/terrarium-bot/http.go index cd26946..5d375ef 100644 --- a/cmd/terrarium-bot/http.go +++ b/cmd/terrarium-bot/http.go @@ -14,9 +14,22 @@ import ( "net/url" "strings" "time" + + "github.com/prometheus/client_golang/prometheus" + "github.com/prometheus/client_golang/prometheus/promauto" ) -var httpClientPool []*HttpClientPool +var ( + httpClientPool []*HttpClientPool + metricHttpClientPool = promauto.NewCounter(prometheus.CounterOpts{ + Name: "terrarium_bot_http_client_pools_total", + Help: "The total number of http client pools", + }) + metricHttpRequestsSent = promauto.NewCounter(prometheus.CounterOpts{ + Name: "terrarium_bot_http_requests_sent_total", + Help: "The total number of http requests sent from terrarium bot", + }) +) type HttpClientPool struct { Hostname string @@ -45,6 +58,7 @@ func getClient(address string, insecure bool) *http.Client { Hostname: hostname, Client: client, }) + metricHttpClientPool.Inc() return &client } @@ -71,6 +85,7 @@ func SendRequest(url string, insecure bool, retries int, decodeJson bool) (map[s // retry x times if an error occurs, sleep 1 second each time for i := 0; i < retries; i++ { Debug("Request attempt %v/%v", i+1, retries) + metricHttpRequestsSent.Inc() resp, err = client.Do(req) if err == nil && resp.StatusCode == 200 { break diff --git a/cmd/terrarium-bot/http_test.go b/cmd/terrarium-bot/http_test.go index 9a10548..3b4ccd0 100644 --- a/cmd/terrarium-bot/http_test.go +++ b/cmd/terrarium-bot/http_test.go @@ -77,3 +77,63 @@ func TestSendRequest(t *testing.T) { log.SetOutput(os.Stderr) }) } + +func TestSendRequestConnectionPooling(t *testing.T) { + isTesting = true + config.Debug = true + httpClientPool = nil + var buf bytes.Buffer + log.SetOutput(&buf) + + // Mock http request response + mockResponse := `{"key1": "value1", "key2": 2, "key3": ["element1", "element2"]}` + mux := http.NewServeMux() + mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + fmt.Fprint(w, mockResponse) + }) + server := httptest.NewServer(mux) + defer server.Close() + + // first request should create a new http pool + SendRequest(server.URL, false, 1, true) + if got := buf.String(); !strings.Contains(got, "Creating http pool") { + t.Errorf("Expected new connection to be created: %q", got) + } + + buf.Reset() + SendRequest(server.URL, false, 1, true) + if got := buf.String(); !strings.Contains(got, "conn was reused: true") { + t.Errorf("Expected connection to be reused: %q", got) + } + + buf.Reset() + SendRequest(server.URL, false, 1, true) + if got := buf.String(); !strings.Contains(got, "conn was reused: true") { + t.Errorf("Expected connection to be reused: %q", got) + } + + buf.Reset() + SendRequest(server.URL+"/123", false, 1, true) + if got := buf.String(); !strings.Contains(got, "conn was reused: true") { + t.Errorf("Expected connection to be reused: %q", got) + } + + buf.Reset() + SendRequest(server.URL+"/abcdef", false, 1, true) + if got := buf.String(); !strings.Contains(got, "conn was reused: true") { + t.Errorf("Expected connection to be reused: %q", got) + } + + buf.Reset() + SendRequest(server.URL, false, 1, true) + if got := buf.String(); !strings.Contains(got, "conn was reused: true") { + t.Errorf("Expected connection to be reused: %q", got) + } + + // reset + isTesting = false + config.Debug = false + log.SetOutput(os.Stderr) +} diff --git a/cmd/terrarium-bot/main.go b/cmd/terrarium-bot/main.go index c17f48b..7ffb30a 100644 --- a/cmd/terrarium-bot/main.go +++ b/cmd/terrarium-bot/main.go @@ -7,6 +7,7 @@ import ( var ( config Config apiServer APIServer + metrics Metrics isTesting bool = false // flag used when testing ) @@ -33,6 +34,7 @@ func main() { InitTime() InitAlerting() apiServer.Start() + metrics.Start() InitTriggers() InitNotifications() diff --git a/cmd/terrarium-bot/metrics.go b/cmd/terrarium-bot/metrics.go new file mode 100644 index 0000000..7f00405 --- /dev/null +++ b/cmd/terrarium-bot/metrics.go @@ -0,0 +1,19 @@ +package main + +import ( + "log" + "net/http" + "time" + + "github.com/prometheus/client_golang/prometheus/promhttp" +) + +type Metrics struct{} + +func (metrics Metrics) Start() { + log.Println("Starting Metrics server...") + http.Handle("/metrics", promhttp.Handler()) + http.ListenAndServe(":8081", nil) + time.Sleep(1 * time.Second) // give some time for metrics server to start before moving on + log.Println("Metrics Server started...") +} diff --git a/cmd/terrarium-bot/sensor.go b/cmd/terrarium-bot/sensor.go index 5fa3575..7ea930a 100644 --- a/cmd/terrarium-bot/sensor.go +++ b/cmd/terrarium-bot/sensor.go @@ -4,9 +4,13 @@ import ( "encoding/json" "fmt" "log" + "math" "strconv" "strings" "time" + + "github.com/prometheus/client_golang/prometheus" + "github.com/prometheus/client_golang/prometheus/promauto" ) func GetSensor(id string) *Sensor { @@ -26,15 +30,15 @@ func InitSensors() { time.Sleep(5 * time.Second) // give abit of time for any sensors to collect data } -func (s *Sensor) SetValue(value int) { +func (s *Sensor) SetValue(value float64) { s.Value = value } -func (s *Sensor) GetValue() int { +func (s *Sensor) GetValue() float64 { return s.Value } -func (s *Sensor) getSensorValue() int { +func (s *Sensor) getSensorValue() float64 { r, respCode, err := SendRequest(s.Url, s.Insecure, 3, s.JsonPath != "") if err != nil { log.Println(err) @@ -50,10 +54,15 @@ func (s *Sensor) getSensorValue() int { return 0 } value := getJsonValue(string(b), s.JsonPath) - intValue, err := strconv.Atoi(fmt.Sprintf("%.0f", value)) - s.SetValue(intValue) + floatVal, err := strconv.ParseFloat(fmt.Sprint(value), 64) + if err != nil { + log.Println(err) + return 0 + } + roundedValue := math.Round(floatVal*100) / 100 + s.SetValue(roundedValue) s.checkValue() - return intValue + return roundedValue } func (s *Sensor) checkValue() { @@ -66,10 +75,16 @@ func (s *Sensor) checkValue() { } func (s *Sensor) monitor() { + var sensorMetrics = promauto.NewGauge(prometheus.GaugeOpts{ + Name: "terrarium_bot_sensor_" + s.Id, + Help: "The current value of the " + s.Id + " sensor", + }) + val := s.getSensorValue() log.Printf("Monitoring sensor '%s' (%v%s)", s.Id, val, s.Unit) for { val = s.getSensorValue() + sensorMetrics.Set(float64(val)) Debug("%s: %v%s", strings.Title(s.Id), val, s.Unit) time.Sleep(1 * time.Minute) } diff --git a/cmd/terrarium-bot/sensor_test.go b/cmd/terrarium-bot/sensor_test.go index 28fec70..eddc265 100644 --- a/cmd/terrarium-bot/sensor_test.go +++ b/cmd/terrarium-bot/sensor_test.go @@ -21,7 +21,7 @@ func TestSensorSetValue(t *testing.T) { s := &Sensor{} s.SetValue(42) if s.Value != 42 { - t.Errorf("Expected sensor value to be 42, but got %d", s.Value) + t.Errorf("Expected sensor value to be 42, but got %v", s.Value) } } @@ -29,6 +29,6 @@ func TestSensorGetValue(t *testing.T) { s := &Sensor{Value: 42} v := s.GetValue() if v != 42 { - t.Errorf("Expected sensor value to be 42, but got %d", v) + t.Errorf("Expected sensor value to be 42, but got %v", v) } } diff --git a/cmd/terrarium-bot/trigger.go b/cmd/terrarium-bot/trigger.go index 71c2117..3cbfdf9 100644 --- a/cmd/terrarium-bot/trigger.go +++ b/cmd/terrarium-bot/trigger.go @@ -1,8 +1,8 @@ package main import ( + "fmt" "log" - "strconv" "time" ) @@ -23,8 +23,8 @@ func InitTriggers() { } } -func GenerateReason(value int, unit string, maxValue int) string { - return strconv.Itoa(value) + unit + "/" + strconv.Itoa(maxValue) + unit +func GenerateReason(value float64, unit string, maxValue float64) string { + return fmt.Sprintf("%.2f", value) + unit + "/" + fmt.Sprintf("%.2f", maxValue) + unit } func (t *Trigger) monitor() { @@ -32,7 +32,7 @@ func (t *Trigger) monitor() { s *Sensor runAction bool reason string - value int + value float64 ) // get trigger sensor if one is set diff --git a/go.mod b/go.mod index 494bdd1..5d1c1ce 100644 --- a/go.mod +++ b/go.mod @@ -8,11 +8,23 @@ require github.com/thedevsaddam/gojsonq v2.3.0+incompatible require ( github.com/gregdel/pushover v1.1.0 + github.com/prometheus/client_golang v1.15.1 github.com/stretchr/testify v1.8.2 ) require ( + github.com/beorn7/perks v1.0.1 // indirect + github.com/cespare/xxhash/v2 v2.2.0 // indirect github.com/davecgh/go-spew v1.1.1 // indirect + github.com/golang/protobuf v1.5.3 // indirect + github.com/kr/text v0.2.0 // indirect + github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/prometheus/client_model v0.3.0 // indirect + github.com/prometheus/common v0.42.0 // indirect + github.com/prometheus/procfs v0.9.0 // indirect + github.com/rogpeppe/go-internal v1.10.0 // indirect + golang.org/x/sys v0.6.0 // indirect + google.golang.org/protobuf v1.30.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 28be763..293f8eb 100644 --- a/go.sum +++ b/go.sum @@ -1,10 +1,37 @@ +github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= +github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= +github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= +github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.5/go.mod h1:6O5/vntMXwX2lRkT1hjjk0nAC1IDOTvTlVgjlRvqsdk= +github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= +github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= +github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= +github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= github.com/gregdel/pushover v1.1.0 h1:dwHyvrcpZCOS9V1fAnKPaGRRI5OC55cVaKhMybqNsKQ= github.com/gregdel/pushover v1.1.0/go.mod h1:EcaO66Nn1StkpEm1iKtBTV3d2A16SoMsVER1PthX7to= +github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zkfA9PSy5pEvNWRP0ET0TIVo= +github.com/matttproud/golang_protobuf_extensions v1.0.4/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/prometheus/client_golang v1.15.1 h1:8tXpTmJbyH5lydzFPoxSIJ0J46jdh3tylbvM1xCv0LI= +github.com/prometheus/client_golang v1.15.1/go.mod h1:e9yaBhRPU2pPNsZwE+JdQl0KEt1N9XgF6zxWmaC0xOk= +github.com/prometheus/client_model v0.3.0 h1:UBgGFHqYdG/TPFD1B1ogZywDqEkwp3fBMvqdiQ7Xew4= +github.com/prometheus/client_model v0.3.0/go.mod h1:LDGWKZIo7rky3hgvBe+caln+Dr3dPggB5dvjtD7w9+w= +github.com/prometheus/common v0.42.0 h1:EKsfXEYo4JpWMHH5cg+KOUWeuJSov1Id8zGR8eeI1YM= +github.com/prometheus/common v0.42.0/go.mod h1:xBwqVerjNdUDjgODMpudtOMwlOwf2SaTr1yjz4b7Zbc= +github.com/prometheus/procfs v0.9.0 h1:wzCHvIvM5SxWqYvwgVL7yJY8Lz3PKn49KQtpgMYJfhI= +github.com/prometheus/procfs v0.9.0/go.mod h1:+pB4zwohETzFnmlpe6yd2lSc+0/46IYZRB/chUwxUZY= +github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= +github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= @@ -14,8 +41,16 @@ github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/thedevsaddam/gojsonq v2.3.0+incompatible h1:i2lFTvGY4LvoZ2VUzedsFlRiyaWcJm3Uh6cQ9+HyQA8= github.com/thedevsaddam/gojsonq v2.3.0+incompatible/go.mod h1:RBcQaITThgJAAYKH7FNp2onYodRz8URfsuEGpAch0NA= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= +google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng= +google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= From 71a40107905c838b1bcb16d7a9cbe067c4c8720c Mon Sep 17 00:00:00 2001 From: Alec Pinson <30310787+alec-pinson@users.noreply.github.com> Date: Fri, 5 May 2023 14:33:56 +0100 Subject: [PATCH 2/3] forgot this --- cmd/terrarium-bot/metrics.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/terrarium-bot/metrics.go b/cmd/terrarium-bot/metrics.go index 7f00405..09ecb03 100644 --- a/cmd/terrarium-bot/metrics.go +++ b/cmd/terrarium-bot/metrics.go @@ -13,7 +13,7 @@ type Metrics struct{} func (metrics Metrics) Start() { log.Println("Starting Metrics server...") http.Handle("/metrics", promhttp.Handler()) - http.ListenAndServe(":8081", nil) + go http.ListenAndServe(":8081", nil) time.Sleep(1 * time.Second) // give some time for metrics server to start before moving on log.Println("Metrics Server started...") } From 53e91cd2fe23adf41e29493e3979d02fef2f6e23 Mon Sep 17 00:00:00 2001 From: Alec Pinson <30310787+alec-pinson@users.noreply.github.com> Date: Tue, 9 May 2023 14:21:59 +0100 Subject: [PATCH 3/3] [ci-skip] update git ignore --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 48ca762..47d489a 100644 --- a/.gitignore +++ b/.gitignore @@ -20,4 +20,4 @@ # Go workspace file go.work cmd/terrarium-bot/test.yaml -cmd/terrarium-bot/fly-pi-config.yaml +cmd/terrarium-bot/terrarium-bot