aboutsummaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorXe Iaso <me@xeiaso.net>2025-03-03 07:17:47 -0500
committerGitHub <noreply@github.com>2025-03-03 12:17:47 +0000
commit19f0d3d0c1b171ebc25176f777d034ffaa98a4be (patch)
treedfb2f65eb35a232449796934e170cb1bafe15668 /cmd
parent6ccc79e1abb29e91e654ba0cc55858b6ffa76d14 (diff)
downloadx-19f0d3d0c1b171ebc25176f777d034ffaa98a4be.tar.xz
x-19f0d3d0c1b171ebc25176f777d034ffaa98a4be.zip
cmd/anubis: implement health check (#685)
Closes #681 Signed-off-by: Xe Iaso <me@xeiaso.net>
Diffstat (limited to 'cmd')
-rw-r--r--cmd/anubis/main.go22
1 files changed, 22 insertions, 0 deletions
diff --git a/cmd/anubis/main.go b/cmd/anubis/main.go
index 9b39aab..69be826 100644
--- a/cmd/anubis/main.go
+++ b/cmd/anubis/main.go
@@ -42,6 +42,7 @@ var (
robotsTxt = flag.Bool("serve-robots-txt", false, "serve a robots.txt file that disallows all robots")
policyFname = flag.String("policy-fname", "", "full path to anubis policy document (defaults to a sensible built-in policy)")
target = flag.String("target", "http://localhost:3923", "target to reverse proxy to")
+ healthcheck = flag.Bool("healthcheck", false, "run a health check against Anubis")
//go:embed static botPolicies.json
static embed.FS
@@ -84,9 +85,30 @@ const (
//go:generate zstd -f -k --ultra -22 static/js/main.mjs
//go:generate brotli -fZk static/js/main.mjs
+func doHealthCheck() error {
+ resp, err := http.Get("http://localhost" + *metricsBind + "/metrics")
+ if err != nil {
+ return fmt.Errorf("failed to fetch metrics: %w", err)
+ }
+ defer resp.Body.Close()
+
+ if resp.StatusCode != http.StatusOK {
+ return fmt.Errorf("unexpected status code: %d", resp.StatusCode)
+ }
+
+ return nil
+}
+
func main() {
internal.HandleStartup()
+ if *healthcheck {
+ if err := doHealthCheck(); err != nil {
+ log.Fatal(err)
+ }
+ return
+ }
+
s, err := New(*target, *policyFname)
if err != nil {
log.Fatal(err)