In long running cowboy application, sometimes log files are not enough to monitor the behaviour of the application. SNMP is a good starting point to introduce intstrumentation in cowboy. Hence this application.
Cowboy onrequest
and onresponse
hooks are used for this
instrumentation. See
Cowboy Hooks
for details on the hooks.
This application implements the following tables from WWW-MIB defined in RFC-2594:
- Service Information Table
- Protocol Summary Table
- Request In Table
- Response Out Table
To use this application, you will need to configure and start erlang
snmp agent. Some help
here. After
that configure your cowboy application to use
cowboy_metrics:on_requeqst/1
&
cowboy_metrics:on_response/4
. Alternatively, you could use
cowboy_metrics:start_http/5
instead of cowboy:start_http/4
.
Starting a cowboy http server with index of 4.
%% Snippet
Dispatch = cowboy_router:compile([{'_', [
{"/", test_handler, []}
]}
]),
{ok, _} = cowboy_metrics:start_http(4, http_handler, 100, [{port, 80}],
[{env, [{dispatch, Dispatch}]}]),
%% End snippet