How to read prometheus metric from a custom plugin

I am trying to retrieve Prometheus metrics from a custom plugin. Seems achievable by overwritting the write_fn() Anyone did this before? Any suggestions?