Measure stats-data
authorTim Buchwaldt <tim@buchwaldt.ws>
Sat, 12 Nov 2022 16:13:39 +0000 (17:13 +0100)
committerFloatingGhost <hannah@coffee-and-dreams.uk>
Thu, 15 Dec 2022 01:04:56 +0000 (01:04 +0000)
lib/pleroma/application.ex
lib/pleroma/web/telemetry.ex

index ad768b0e021bb0e9657a66a24699ec5e19f6eb99..02336d6d1f26acb957c8393c3e8e3e96f461ea24 100644 (file)
@@ -64,7 +64,6 @@ defmodule Pleroma.Application do
         Config.TransferTask,
         Pleroma.Emoji,
         Pleroma.Web.Plugs.RateLimiter.Supervisor,
-        Pleroma.Web.Telemetry,
         {Task.Supervisor, name: Pleroma.TaskSupervisor}
       ] ++
         cachex_children() ++
@@ -74,7 +73,8 @@ defmodule Pleroma.Application do
           Pleroma.JobQueueMonitor,
           {Majic.Pool, [name: Pleroma.MajicPool, pool_size: Config.get([:majic_pool, :size], 2)]},
           {Oban, Config.get(Oban)},
-          Pleroma.Web.Endpoint
+          Pleroma.Web.Endpoint,
+          Pleroma.Web.Telemetry
         ] ++
         elasticsearch_children() ++
         task_children(@mix_env) ++
index 46b5865f73d58b48d2df06a90ca0866bcaefece7..73ce6a85cdda2ce425994afc4f536d0602cae80d 100644 (file)
@@ -1,6 +1,7 @@
 defmodule Pleroma.Web.Telemetry do
   use Supervisor
   import Telemetry.Metrics
+  alias Pleroma.Stats
 
   def start_link(arg) do
     Supervisor.start_link(__MODULE__, arg, name: __MODULE__)
@@ -103,11 +104,23 @@ defmodule Pleroma.Web.Telemetry do
         reporter_options: [
           buckets: [0.01, 0.025, 0.05, 0.1, 0.2, 0.5, 1, 2.5, 5, 10]
         ]
-      )
+      ),
+      last_value("pleroma.local_users.total"),
+      last_value("pleroma.domains.total"),
+      last_value("pleroma.local_statuses.total")
     ]
   end
 
   defp periodic_measurements do
-    []
+    [
+      {__MODULE__, :instance_stats, []}
+    ]
+  end
+
+  def instance_stats do
+    stats = Stats.get_stats()
+    :telemetry.execute([:pleroma, :local_users], %{total: stats.user_count}, %{})
+    :telemetry.execute([:pleroma, :domains], %{total: stats.domain_count}, %{})
+    :telemetry.execute([:pleroma, :local_statuses], %{total: stats.status_count}, %{})
   end
 end