-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement Prometheus Counter type #27
base: main
Are you sure you want to change the base?
Conversation
Nice! Could you also document this? |
Absolutely, I'll be happy to document it. I'm realizing, however, that the benefits of counters are limited when using the in-memory storage. To take advantage of counters with PHP applications I think some caching is needed and it usually works great with the APC or APCng storage collector registries. Is it a config option you're planning to implement some day? It could be part of this PR if that seems interesting to you, I guess it could be an additional option in the config file |
The idea of using APCu/APCng sounds great. I suggest writing a laravel adapter, that implements the Prometheus/Storage/Adapter Interface from PromPHP/prometheus_client_php. This adapter receives a selectable Illuminate\Contracts\Cache\Store (configured via config/cache.php; referenced via config/prometheus.php). This way we would have ootb access to database, redis, memcache, dynamodb, apc, apcu, array and null storages and benefit from third party libraries that add custom storages. It would also bring in all of the test functions that are provided by the laravel caching facades. Separating common storages between nodes could happen through individual host tagging. |
491b63c
to
58f9fae
Compare
@pselge-5anker Did you manage to make the counter metrics work with your cache adapter implementation? I think your PR looks great, however, in practice I'm still struggling to make a successful test. When retrieving the metrics to render, the values are empty as if the counter was just initialized. I'll keep looking into it, but I'm curious to know if you managed to make it work |
@thdebay Yes, it worked fine. I tried it with the database, file, redis and array adapter. the latter of course lost its state after each call while the others kept increasing with each request i sent. have you configured the adapter in both config/queue.php and config/prometheus.php? |
I guess I still don't figure out how the |
I will have a look tomorrow morning. I'm not sure if I conducted any tests outside of the ServiceProvider so far. I was trying to bring the CacheAdapter into the php_prometheus repo, to have it managed further up the chain, as I believe it to be beneficial to other libraries as well. |
This PR adds the ability to create metrics of type
counter
(see https://prometheus.io/docs/concepts/metric_types/#counter)To use it, create the counter with
optionally define an initial value like so:
and increment it with
optionally pass a value to increment the counter by more than one: