|
|
|
|
@ -28,6 +28,29 @@ defmodule PlausibleWeb.Api.ExternalController do
|
|
|
|
|
send_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) do
|
|
|
|
|
uri = params["url"] && URI.parse(params["url"])
|
|
|
|
|
user_agent = Plug.Conn.get_req_header(conn, "user-agent") |> List.first()
|
|
|
|
|
|