The problem
I've heard this question come up many times over the years, and I've been involved in quite a few discussions about it myself: how do you collect metrics from an application running in a container if the application doesn't expose an HTTP /metrics endpoint?
Maybe it was never designed to do that. Or maybe adding an HTTP server just for monitoring feels like unnecessary overhead.
The question becomes particularly interesting when the application runs a short-lived task: a CLI command, a cron job, or a batch job.
One example I dealt with involved CLI commands in a PHP 7.4 monolith that we were gradually moving into a containerized environment.
The application already existed, did its job, and had years of development behind it. We needed both business metrics, such as counters and histograms, and technical metrics, such as database query execution times.
On physical or virtual servers, this was relatively straightforward.β¦