better performance for process_* metrics on linux
Current process_* metrics implementation for linux has a huge overhead by re-opening/closing files on each pull. Instead it should keep the process related files open (they do not change over lifetime) and let the OS auto-close them on exit. This way performance can be improved by factor 2..6.
Attaching 2 files as proof of concept/for comparison/micro benchmarking:
The process_* metrics are usually read once per scrape interval. The usual scrape interval is in the range 10s - 30s. There is no practical sense in optimizing the code, which reads process_* metric values from various files at the operating system, since this won't reduce CPU usage of the process, which exposes these metrics, by any measurable value. On the other hand, this optimization may complicate further maintenance of the code and may lead to subtle bugs.