Avoid recreating all metrics on reload

This commit fixes a bug in the comparison of the loaded metrics
and all application metrics. Because the Props for each metric
differ in the output of couch_stats:list/0 and
load_metrics_for_application/0 the set subtraction operations
in reload_metrics/0 would always leave a full set, so all metrics
would be deleted and created on every reload.

This is fixed by ensuring the sets for existing and current
metrics consist of {Name, Type} only.
1 file changed
tree: 354a422d6350df933ba45e1376721cb824776946
  1. priv/
  2. src/
  3. .gitignore
  4. LICENSE
  5. README.md
  6. rebar.config
README.md

couch_stats

couch_stats is a simple statistics collection app for Erlang applications. Its core API is a thin wrapper around a stat storage library (currently Folsom,) but abstracting over that library provides several benefits:

  • All references to stat storage are in one place, so it's easy to swap the module out.

  • Some common patterns, such as tying a process's lifetime to a counter value, are straightforward to support.

  • Configuration can be managed in a single place - for example, it's much easier to ensure that all histogram metrics use a 10-second sliding window if those metrics are instantiated/configured centrally.

Adding a metric

  1. Write a stat description file. See `priv/descriptions.cfg for an example.
  • The metric name should be of type [atom()].
  • The type should be one of counter, gauge, or histogram.

If you don‘t add your metric to a description file, your metric will be accessible via couch_stats:sample/1, but it won’t be read by the stats collector and therefore won't be available to HTTP _stats requests, etc.

  1. Tell couch_stats to use your description file via application configuration.

  2. Instrument your code with the helper functions in couch_stats.erl.