Skip to content

Collect and report key metrics for a typical web application based on Phoenix and Ecto.

License

Notifications You must be signed in to change notification settings

globocom/alchemetrics_web

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

55 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Alchemetrics Web

Alchemetrics Web

Metrics for phoenix and ecto.

Travis Hex

Installation

If available in Hex, the package can be installed by adding alchemetrics_web to your list of dependencies in mix.exs:

def deps do
  [
    {:alchemetrics_web, "~> 0.5.4"}
  ]
end

Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/alchemetrics_web.

Usage

  1. Add alchemetris_web to your application list in mix.exs file:
def application do
  ...
  applications: [:phoenix, ..., :alchemetrics_web]
  ...
end
  1. Plug AlchemetricsWeb to your endpoint:
defmodule MyApp.Endpoint do
  use Phoenix.Endpoint, otp_app: ...
  use AlchemetricsWeb
end
%{datapoint: :last_interval, request_count: %{action: :index, controller: "page_controller", type: "controller"}, value: 1}
%{datapoint: :total,         request_count: %{action: :index, controller: "page_controller", type: "controller"}, value: 1}

%{datapoint: :avg, request_time: %{action: :index, controller: "page_controller", type: "controller"}, value: 192090}
%{datapoint: :max, request_time: %{action: :index, controller: "page_controller", type: "controller"}, value: 192090}
%{datapoint: :min, request_time: %{action: :index, controller: "page_controller", type: "controller"}, value: 192090}
%{datapoint: :p95, request_time: %{action: :index, controller: "page_controller", type: "controller"}, value: 192090}
%{datapoint: :p99, request_time: %{action: :index, controller: "page_controller", type: "controller"}, value: 192090}
%{datapoint: :total, request_time: %{action: :index, controller: "page_controller", type: "controller"}, value: 192090}
%{datapoint: :last_interval, request_time: %{action: :index, controller: "page_controller",type: "controller"}, value: 192090}
  1. To collect and report ecto query metrics, config ecto logger in config.exs:
config :my_app, MyApp.Repo, ..., 
  loggers: [..., {AlchemetricsWeb.Collectors.Ecto, :collect, []}]

Ecto collector will report the follow data:

%{datapoint: :total, options: [], query_count: %{type: "database.ecto"}, value: 1}
%{datapoint: :total, name: "queue_time", options: [], type: "database.ecto", value: 46}

Custom reporter

Alchemetrics automatically schedule collected request and query metrics, but its possible to customize the way how the metrics is reported. In order to do that you must implement modules to receive the collected metrics and set this up in your config file. The follow example shows how can you do that:

  defmodule MyApp.CustomPhoenixReporter do
    def report(value, metadata) do
      # value is the reported metric value.
      # metadata is a keyword list.
    end

    def increment(metadata) do
      # metadata is a keywork list.
    end
  end

In config.exs

  config :alchemetrics_web, :custom_request_reporter, MyApp.CustomPhoenixReporter

To create a custom reporter for ecto queries just replace :custom_request_reporter config key by :custom_ecto_reporter

About

Collect and report key metrics for a typical web application based on Phoenix and Ecto.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages