I have a producer class which sends messages to a message broker, RabbitMQ. I am using开发者_如何学C Quartz scheduler to send the messages at regular intervals.
I want to measure the time taken for a single job to get executed/completed. How do I go about it?
I want to find the average time it takes for a job to be completed over a period of time. So I want to measure each individual time and then find the mean.
The approach I've taken to this in the past is to create a job logging queue that takes a simple data structure of job name, start time, end time and after the completion of each job, send a message with that information to a the job logging queue.
Then, just write a listener that pulls data out of the job logging queue and either writes it to a database, updates an internal memory structure for reporting, sends an email, etc. This all assumes that you have access to change the code that is performing the jobs.
If you don't have access to the jobs, it will be harder. RabbitMQ has a plug-in API, so you could build a plug-in that calculates how long each particular job takes. The rabbitmq management plugin will give you coarse grain metrics, such as number of messages delivered / sec or acknowledged / sec. An acknowledgement ususally indicates completion of a task, but depending on how you the code is built a job could be acknowledged before completion in which case your only option is to change the code performing the job.
精彩评论