nipwaayoni / elastic-apm-php-agent

PHP Agent for Elastic APM
Other
28 stars 15 forks source link

Make it easier to send system metrics (cpu/mem) with apm #41

Closed science695 closed 1 year ago

science695 commented 4 years ago

APM's requests that all agents send metrics on cpu and memory.

I had been looking around and having difficulty finding these options. I finally managed to piece some details together:

And then I finally found the example page in the docs for this agent: https://github.com/nipwaayoni/elastic-apm-php-agent/blob/7162481bd9f8164e4396f8438cfecc010d6a6a1c/docs/examples/metricset.php#L21

For the mean time, I will be using these resources to manually send metrics in my applications.

Does anyone else think that automatically sending those metrics would make sense? (the official agents all send them, but not sure about the interval)

Or in the least, a helper to trigger the metrics being sent rather then the application having to gather and send them.

science695 commented 4 years ago

I think I have found the full reason why this isn't mainstream in php: No standardized way to collect system cpu/mem information in php.

dstepe commented 4 years ago

The metric event is unchanged the previous version of this module. I intend to put together a roadmap for some releases that improve alignment with the APM agent guidelines, including metrics as described here:

https://github.com/elastic/apm/blob/master/docs/agents/agent-development.md#metrics

I expect sending metrics by default makes sense, but allowing it to be disabled.

While there may be no 'standardized' way to collect CPU and memory data in PHP, it is possible and we can provide an extensible framework to do it in the package.

dstepe commented 4 years ago

I've been looking into this more and I am concerned with the trade-offs required to implement metric collection in PHP. Not only is there no standardized way to get this data, but the common suggestions involve very costly methods which don't fit with the single request processing typically done with PHP.

I can think of ways to solve this but none are simple nor something I'd just bake into this package. For example, if I really wanted to get metrics, I could run a separate metric service which constantly collects the system metrics. Then the Agent would query that service for current system metrics to send to APM. That may not be something people are able or willing to do, though.

Or, I could spawn a background process which could somehow acquire a configured Agent, calculate the metrics and send them to APM without impacting the current request. That doesn't quite feel right, though.

I'd like to have some more discussion on this issue to get a sense for how important metrics are to users of this package and what may acceptable to acquire them.

science695 commented 4 years ago

I've also been looking, but not having much success on trying to get metrics from metricbeat, but I have yet to find anything discussing how you would combine metricbeat records with apm.

I suppose you could have metricbeat log the last few records to a file (with a very small rotate size), and then pull the last couple lines from that file.

dstepe commented 1 year ago

Closing due to inactivity