Browse Source

Set up telemetry and prometheus

tags/v1.1.4
href Mark Felder 5 years ago
parent
commit
bc3618a38d
4 changed files with 37 additions and 0 deletions
  1. +5
    -0
      config/config.exs
  2. +8
    -0
      lib/pleroma/application.ex
  3. +4
    -0
      lib/pleroma/repo.ex
  4. +20
    -0
      lib/pleroma/web/endpoint.ex

+ 5
- 0
config/config.exs View File

@@ -8,6 +8,10 @@ use Mix.Config
# General application configuration
config :pleroma, ecto_repos: [Pleroma.Repo]

config :pleroma, Pleroma.Repo,
types: Pleroma.PostgresTypes,
loggers: [Pleroma.Repo.Instrumenter, Ecto.LogEntry]

config :pleroma, Pleroma.Captcha,
enabled: false,
seconds_valid: 60,
@@ -87,6 +91,7 @@ websocket_config = [

# Configures the endpoint
config :pleroma, Pleroma.Web.Endpoint,
instrumenters: [Pleroma.Web.Endpoint.Instrumenter],
url: [host: "localhost"],
http: [
dispatch: [


+ 8
- 0
lib/pleroma/application.ex View File

@@ -25,6 +25,7 @@ defmodule Pleroma.Application do
import Cachex.Spec

Pleroma.Config.DeprecationWarnings.warn()
setup_instrumenters()

# Define workers and child supervisors to be supervised
children =
@@ -140,6 +141,13 @@ defmodule Pleroma.Application do
end
end

defp setup_instrumenters() do
Pleroma.Web.Endpoint.MetricsExporter.setup()
Pleroma.Web.Endpoint.PipelineInstrumenter.setup()
Pleroma.Web.Endpoint.Instrumenter.setup()
Pleroma.Repo.Instrumenter.setup()
end

if Mix.env() == :test do
defp streamer_child, do: []
defp chat_child, do: []


+ 4
- 0
lib/pleroma/repo.ex View File

@@ -8,6 +8,10 @@ defmodule Pleroma.Repo do
adapter: Ecto.Adapters.Postgres,
migration_timestamps: [type: :naive_datetime_usec]

defmodule Instrumenter do
use Prometheus.EctoInstrumenter
end

@doc """
Dynamically loads the repository url from the
DATABASE_URL environment variable.


+ 20
- 0
lib/pleroma/web/endpoint.ex View File

@@ -70,6 +70,26 @@ defmodule Pleroma.Web.Endpoint do
extra: "SameSite=Strict"
)

# Note: the plug and its configuration is compile-time this can't be upstreamed yet
if proxies = Pleroma.Config.get([__MODULE__, :reverse_proxies]) do
plug(RemoteIp, proxies: proxies)
end

defmodule Instrumenter do
use Prometheus.PhoenixInstrumenter
end

defmodule PipelineInstrumenter do
use Prometheus.PlugPipelineInstrumenter
end

defmodule MetricsExporter do
use Prometheus.PlugExporter
end

plug(PipelineInstrumenter)
plug(MetricsExporter)

plug(Pleroma.Web.Router)

@doc """


Loading…
Cancel
Save