It would be great if these metrics follow the best naming convention.
I looked at the prometheus docs on naming convention for for pushgateway it's a little different because Idk if I should have the metric name include the job or only differentiate the jobs by label and keep the metric name the same (for ex. timing a function).
Considering a celery job, would this be a good example?:celery_job_duration_seconds{job="job_name1"}celery_job_duration_seconds{job="job_name2"}
etc.
On Tue, Jul 17, 2018 at 12:39 AM, Brian Brazil <brian.brazil@robustperception.io> wrote:On 17 July 2018 at 00:33, <mhernand...@gmail.com> wrote:Can someone post pushgateway metric name examples?
It would be great if these metrics follow the best naming convention.
I looked at the prometheus docs on naming convention for for pushgateway it's a little different because Idk if I should have the metric name include the job or only differentiate the jobs by label and keep the metric name the same (for ex. timing a function).The usual naming rules apply, the start of a metric should be the name of the library it is coming from. In the case of batch jobs that's often also the name of the batch job as the library for most metrics will be the main function of the batch job, the same as you'd have in the main function of any other application. In all cases the jobs will also be differentiated by label.--Brian Brazil
The metric is coming from client instrumented code within a celery task (python function), then pushed to the gateway with a job name as a label identifier. Since the job duration is handled by client code instrumentation, would this mean that the metric is NOT coming from celery itself?
If so, would the aforementioned metric name example still be okay?
On Tue, Jul 17, 2018 at 9:55 AM, Brian Brazil <brian.brazil@robustperception.io> wrote:On 17 July 2018 at 17:38, Miguel Hernandez <mhernand...@gmail.com> wrote:Considering a celery job, would this be a good example?:celery_job_duration_seconds{job="job_name1"}celery_job_duration_seconds{job="job_name2"}That's okay if the metric is coming from celery itself.Brianetc.On Tue, Jul 17, 2018 at 12:39 AM, Brian Brazil <brian.brazil@robustperception.io> wrote:On 17 July 2018 at 00:33, <mhernand...@gmail.com> wrote:Can someone post pushgateway metric name examples?
It would be great if these metrics follow the best naming convention.
I looked at the prometheus docs on naming convention for for pushgateway it's a little different because Idk if I should have the metric name include the job or only differentiate the jobs by label and keep the metric name the same (for ex. timing a function).The usual naming rules apply, the start of a metric should be the name of the library it is coming from. In the case of batch jobs that's often also the name of the batch job as the library for most metrics will be the main function of the batch job, the same as you'd have in the main function of any other application. In all cases the jobs will also be differentiated by label.--Brian Brazil--Brian Brazil
Here's a concrete example following from our discussion.
# prom_metrics.py fileCELERY_REGISTRY = CollectorRegistry()
g = Gauge(
'celery_job_duration_seconds', 'Time it takes to complete a celery job.', registry=CELERY_REGISTRY
)
# still in prom_metrics.py file def push_stats(job_name):As you can see above, the push_stats function is called from within an arbitrary celery task, passing in a job name to help identify that celery task.
"""
Call this function at the end of each Celery task;
if you have batch tasks, have another function to push those to the batch registry
"""
push_to_gateway('localhost:9091', job=job_name, registry=CELERY_REGISTRY)
return
from prom_metrics import g, push_stats
# Different file containing celery task@shared_task def do_something():
job_name = 'some_module.do_something'
with g.time(): do_something_else() push_stats(job_name)
push_stab_naIn this case, what would you recommend the metric name be when pushing to the pushgateway?
UPDATE TO PREVIOUS EMAIL, ADDED the prometheus_client imports
Here's a concrete example following from our discussion.
# prom_metrics.py file
from prometheus_client import Gauge, CollectorRegistry, push_to_gatewayCELERY_REGISTRY = CollectorRegistry()
I feel that changing the metric name to include the celery task name (i.e. do_something_duration_seconds) would be redundant since the job label would contain that information either way.
Let me know what you think.Btw, thank you for all your help so far.
So how about this: path_to_file_name_job_duration_seconds{job="do_something"}
Well, there's a folder called "celery" in our project which contains the celery tasks that we want to get metrics from. For instance, let's assume that the project I'm working on is called "omedeus." What do you think about this: omedeus_celery_file_name_job_duration_seconds{job="do_something"} where file_name is the name of the file that contains the celery task python function.
Yes, it is a part of our structure. I see what you mean about celery feeling weird. However, we want to be able to identify that the metric is from within a celery task/job so that it will be easier to find when setting up a 'Celery task/job stats' graph on Grafana.What would you say is best?