libpressio 0.93.0
|
libpressio supports adding custom metrics plugins.
To create a metrics plugin, simply create a subclass of libpressio_metrics_plugin
that implements the check that you are interested in, and register the plugin with libpressio.
For example, let's create a plugin that counts the number of compressions of each data type that the user preforms.
First we will include a number of required headers:
Next, we need to write our class. Since we want to count the number of data buffers of each type that we compress, we will hook the begin_compress_impl
method. Alternatively we could also hook the end_compress_impl
method. Once we have the counts, we report them out using the get_metrics_results
function. We do this like so:
Finally, we will register the plugin in the under the names "counts" in the metrics plugging registry
Then a user of the library can then ask libpressio to construct their new plugin as normal. But what if our metrics modules takes arguments? Instead of registering it directly, the user can instantiate it manually and combine it with others from the library using the make_m_composite
method.
If your metric is suitably general and well implemented, you can contribute it back to libpressio. Metrics should be added to the src/plugins/metrics/
directory and to the main CMakeLists.txt
. If the metric requires additional dependencies beyond the standard library, it should be hidden behind a configuration flag that enables its use and disabled by default.
This full example can be found in the test/test_regsiter_metrics.cc
file, and the full documentation of the allowed hooks and their arguments can be found in the documentation for libpressio_metrics_plugin
.