document prometheus
authorFloatingGhost <hannah@coffee-and-dreams.uk>
Fri, 16 Dec 2022 10:24:36 +0000 (10:24 +0000)
committerFloatingGhost <hannah@coffee-and-dreams.uk>
Fri, 16 Dec 2022 10:24:36 +0000 (10:24 +0000)
docs/docs/administration/monitoring.md [new file with mode: 0644]
lib/pleroma/web/plugs/rate_limiter.ex
scripts/create_metrics_app.sh

diff --git a/docs/docs/administration/monitoring.md b/docs/docs/administration/monitoring.md
new file mode 100644 (file)
index 0000000..65fbbb2
--- /dev/null
@@ -0,0 +1,31 @@
+# Monitoring Akkoma
+
+If you run akkoma, you may be inclined to collect metrics to ensure your instance is running smoothly,
+and that there's nothing quietly failing in the background.
+
+To facilitate this, akkoma exposes prometheus metrics to be scraped.
+
+## Prometheus
+
+To scrape prometheus metrics, we need an oauth2 token with the `admin:metrics` scope.
+
+consider using [constanze](https://akkoma.dev/AkkomaGang/constanze) to make this easier -
+
+```bash
+constanze token --client-app --scopes "admin:metrics" --client-name "Prometheus"
+```
+
+or see `scripts/create_metrics_app.sh` in the source tree for the process to get this token.
+
+Once you have your token of the form `Bearer $ACCESS_TOKEN`, you can use that in your prometheus config:
+
+```yaml
+- job_name: akkoma
+  scheme: https
+  authorization:
+    credentials: $ACCESS_TOKEN # this should have the bearer prefix removed
+  metrics_path: /api/v1/akkoma/metrics
+  static_configs:
+  - targets:
+    - example.com
+```
\ No newline at end of file
index f5ca27f0c0f1e73f67a2173d639eb3ce885b21a3..3c82654b4eb264859c5675d20007a8426a6c9330 100644 (file)
@@ -207,6 +207,8 @@ defmodule Pleroma.Web.Plugs.RateLimiter do
     |> Enum.join(".")
   end
 
+  defp ip(_), do: nil
+
   defp render_throttled_error(conn) do
     conn
     |> render_error(:too_many_requests, "Throttled")
index c2f32e50f139c6d4f5ada15eca5a7740ad56ac5e..c42f5dde8c37dd059efe1633ecd712a497a2ec7f 100755 (executable)
@@ -17,7 +17,7 @@ RESP=$(curl \
 client_id=$(echo $RESP | jq -r .client_id)
 client_secret=$(echo $RESP | jq -r .client_secret)
 
-if [ -z "$client_id"]; then
+if [ -z "$client_id" ]; then
   echo "Could not create an app"
   echo "$RESP"
   exit 1
@@ -47,7 +47,7 @@ RESP=$(curl \
     --data-urlencode 'redirect_uri=urn:ietf:wg:oauth:2.0:oob' \
     --data-urlencode "scope=admin:metrics"
 )
-
+echo $RESP
 ACCESS_TOKEN="$(echo $RESP | jq -r .access_token)"
 
 echo "Token is $ACCESS_TOKEN"