[erlang-questions] How to do counters?

Thomas Lindgren thomasl_erlang@REDACTED
Wed Jun 10 19:57:10 CEST 2009

----- Original Message ----
> From: Jarrod Roberson <jarrod@REDACTED>
> To: Erlang <erlang-questions@REDACTED>
> Sent: Wednesday, June 10, 2009 7:21:20 PM
> Subject: [erlang-questions] How to do counters?
> I want to add counters to my gen_tcp implementation to track total
> number of connections made, total number of requests serviced, total
> number of bytes transfered, etc.
> I need to have numbers like this for production monitoring. In python
> or java I would just have a singleton class that had these counters
> with thread safe increment/decrement methods. How would I get this
> same behavior using Erlang?

Two ways:

1. Your singleton is a registered process, e.g. a gen_server. Write an API that sends messages which update the internal state of this process.
2. Your singleton is a named ets-table. Write a wrapper module that uses ets:update_counter/3 to update well-known counters.

Extra credit: use snmp.



More information about the erlang-questions mailing list