Open source, privacy-first web analytics. Lightweight, cookie-free Google Analytics alternative. Self-hosted or cloud.
TypeScript analyticsanalytics-dashboardclickhouseelixirgoogle-analyticsmarketingopen-source-analyticsphoenixplausible-analyticspostgresqlprivacyprivacy-friendlyself-hostedsimple-analyticsstatisticstailwindcssweb-analyticswebsite-analyticswebsite-statswebsite-tracking
Add healthcheck endpoint
Uku Taht15f6594ddb77
diff --git a/lib/plausible_web/controllers/api/external_controller.ex b/lib/plausible_web/controllers/api/external_controller.exindex c9dcc5c009..3924a83dac 100644--- a/lib/plausible_web/controllers/api/external_controller.ex+++ b/lib/plausible_web/controllers/api/external_controller.ex@@ -28,6 +28,29 @@ defmodule PlausibleWeb.Api.ExternalController dosend_resp(conn, 200, "")end+ def health(conn, _params) do+ postgres_health = case Ecto.Adapters.SQL.query(Plausible.Repo, "SELECT 1", []) do+ {:ok, _} -> "ok"+ e -> "error: #{inspect e}"+ end++ clickhouse_health = case Clickhousex.query(:clickhouse, "SELECT 1", []) do+ {:ok, _} -> "ok"+ e -> "error: #{inspect e}"+ end++ status = case {postgres_health, clickhouse_health} do+ {"ok", "ok"} ->200+ _ -> 500+ end++ put_status(conn, status)+ |> json(%{+ postgres: postgres_health,+ clickhouse: clickhouse_health,+ })+ end+defp create_event(conn, params) douri = params["url"] && URI.parse(params["url"])user_agent = Plug.Conn.get_req_header(conn, "user-agent") |> List.first()diff --git a/lib/plausible_web/router.ex b/lib/plausible_web/router.exindex 529af527e1..a48eb00a36 100644--- a/lib/plausible_web/router.ex+++ b/lib/plausible_web/router.ex@@ -59,6 +59,7 @@ defmodule PlausibleWeb.Router dopost "/event", Api.ExternalController, :eventget "/error", Api.ExternalController, :error+ get "/health", Api.ExternalController, :healthpost "/paddle/webhook", Api.PaddleController, :webhookdiff --git a/test/plausible_web/controllers/api/external_controller_test.exs b/test/plausible_web/controllers/api/external_controller_test.exsindex 8f7a705ed9..a9c71bea51 100644--- a/test/plausible_web/controllers/api/external_controller_test.exs+++ b/test/plausible_web/controllers/api/external_controller_test.exs@@ -410,4 +410,12 @@ defmodule PlausibleWeb.Api.ExternalControllerTest doassert response(conn, 400) == ""end++ describe "GET /api/health" do+ test "returns 200 OK", %{conn: conn} do+ conn = get(conn, "/api/health")++ assert conn.status == 200+ end+ endend