Best way to scrape metric from a custom service

I have grafana-agent on a Linux node and I am getting the metric into the dashboard. So far, so good.

I have a custom script (say foo.py) that computes some matrices. Currently, I am writing these metrics onto console. I am thinking of appending these metrics to a file let the node_exporter's textfile collector collects the metric. Is this a decent approach?

If I take this route, I have a question:

Can foo.py appending metrics to a prom file and file textfile will keep track of what is new in the metrics file? Or should I delete the old file and create a new one every time there is a new metric?

Is there any other solution to this problem?

I really like using the textfile collector. But, I’ve also used the python prometheus client to record the output from a periodic script, and it works even better.

This is mostly boilerplate code and maybe a useful place to start re the exporter:

Otherwise I often refer to this article for more details on using the textfile collector:
https://www.robustperception.io/tag/textfile-collector