cowboy 2
Cowboy2 Plugin
Section titled “Cowboy2 Plugin”Description
Section titled “Description”The Cowboy2 plugin collects metrics related to requests served by the application.
Applications it depends on
Section titled “Applications it depends on”cowboy version 2.4 and over
Modules
Section titled “Modules”wombat_plugin_cowboy2
Reports
Section titled “Reports”The Cowboy 2 plugin reports hit counts and average response time for pathsth, it also reports hit counts for different HTTP statuses grouped by their type.
For the plugin to work the application has to be prepared with the following changes:
The handler configuration needs to be extended to include the cowboy metrics handler and a metrics callback has to be added:
{ok, _} = cowboy:start_clear(my_http_listener, [{port, 8081}], #{env => #{dispatch => Dispatch}, metrics_callback => fun do_metrics_callback/1, stream_handlers => [cowboy_metrics_h, cowboy_stream_h]}),The cowboy_metrics_h module in the stream handlers will prepare Cowboy to call
the metrics_callback function with the metrics related to a request.
The implementation of the do_metrics_callback is as follows:
do_metrics_callback(Metric) -> try wombat_plugin_cowboy2 ! {cowboy_metric, Metric} of _ -> ok catch _:_ -> ok end.If the cowboy_metrics_h is missing or there is no metrics callback, you will
see this warning in Wombat:
cowboy_metrics_h is not installed for handler HANDLER, metrics will not be reported.Please check the Wombat docs for setting up Cowboy2 for metrics collecting.The metrics will appear on the GUI soon after the plugin has been started and the application started serving requests.

Elixir Configuration
Section titled “Elixir Configuration”Add metrics_callback and stream_handlers to the cowboy2 application start function, and define the do_metric_callback function as below:
def start(_type, _args) do dispatch_config = build_dispatch_config { :ok, _ } = :cowboy.start_clear(:http,[{:port, 8081}], {:env => %{:dispatch => dispatch_config}, :metrics_callback => &do_metrics_callback/1, :stream_handlers => [:cowboy_metrics_h, :cowboy_stream_h], :middlewares => [:cowboy_router, :directory_lister, :cowboy_handler]})enddef do_metrics_callback(metric) do try do send :wombat_plugin_cowboy2, {:cowboy_metric, metric} :ok rescue _ -> :ok endend