allow disabling prometheus entirely
[akkoma] / lib / pleroma / web / akkoma_api / controllers / metrics_controller.ex
index c8d3d8948b7f55af3c6b0dcfe45c298ffced6fc9..cc7a616ee6f30fcd598acd65ba61087965d80a9c 100644 (file)
@@ -2,15 +2,23 @@ defmodule Pleroma.Web.AkkomaAPI.MetricsController do
   use Pleroma.Web, :controller
 
   alias Pleroma.Web.Plugs.OAuthScopesPlug
+  alias Pleroma.Config
 
-  @unauthenticated_access %{fallback: :proceed_unauthenticated, scopes: []}
-  plug(:skip_auth)
-
+  plug(
+    OAuthScopesPlug,
+    %{scopes: ["admin:metrics"]}
+    when action in [
+           :show
+         ]
+  )
 
   def show(conn, _params) do
-    stats = TelemetryMetricsPrometheus.Core.scrape()
-
-    conn
-    |> text(stats)
+    if Config.get([:instance, :export_prometheus_metrics], true) do
+      conn
+      |> text(TelemetryMetricsPrometheus.Core.scrape())
+    else
+      conn
+      |> send_resp(404, "Not Found")
+    end
   end
 end