[Enhancement] Add Prometheus support (#556)

* Added prometheus to deps list

* WIP - screwing around with Prometheus and grafana

* Added basic prometheus config

* Updated docs in prom_ex module

* Updated README
This commit is contained in:
Kieran 2025-01-09 12:38:17 -08:00 committed by GitHub
parent 8a40d296c4
commit fb27988963
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 83 additions and 23 deletions

View file

@ -11,6 +11,7 @@ defmodule Pinchflat.Application do
check_and_update_timezone()
children = [
Pinchflat.PromEx,
PinchflatWeb.Telemetry,
Pinchflat.Repo,
# Must be before startup tasks

40
lib/pinchflat/prom_ex.ex Normal file
View file

@ -0,0 +1,40 @@
defmodule Pinchflat.PromEx do
@moduledoc """
Configuration for the PromEx library which provides Prometheus metrics
"""
use PromEx, otp_app: :pinchflat
alias PromEx.Plugins
@impl true
def plugins do
[
Plugins.Application,
Plugins.Beam,
{Plugins.Phoenix, router: PinchflatWeb.Router, endpoint: PinchflatWeb.Endpoint},
Plugins.Ecto,
Plugins.Oban,
Plugins.PhoenixLiveView
]
end
@impl true
def dashboard_assigns do
[
default_selected_interval: "30s"
]
end
@impl true
def dashboards do
[
{:prom_ex, "application.json"},
{:prom_ex, "beam.json"},
{:prom_ex, "phoenix.json"},
{:prom_ex, "ecto.json"},
{:prom_ex, "oban.json"},
{:prom_ex, "phoenix_live_view.json"}
]
end
end

View file

@ -32,6 +32,8 @@ defmodule PinchflatWeb.Endpoint do
plug Phoenix.Ecto.CheckRepoStatus, otp_app: :pinchflat
end
plug PromEx.Plug, prom_ex_module: Pinchflat.PromEx
plug Phoenix.LiveDashboard.RequestLogger,
param_key: "request_logger",
cookie_key: "request_logger"