Let Grafana Alloy agent run local Bash script and use the output

Hi,
I’m new to Alloy and I have a question. Is it possible to let Alloy run a Bash or Oython script and grab thoe output or even better exit code and send it to Mimir instead of letting another function (cron) run the script and then let Alloy scrape the output file from the script?

I am not a prometheus/node-exporter expert, but my understanding is that this pattern is generally not preferred by prometheus. There is a community exporter that allows you to trigger a script, there is also textfile-collector, but neither is available in alloy.

Options I would recommend:

  1. Turn your fire-and-forget script into a long-running little app (you can run in a container or bare metal), use prometheus_flask_exporter to expose metrics from your script app, and scrape from http://<YOUR_APP_IP>/metrics using Alloy.
  2. Write your metrics into an output file in a format that’s easily parsable (perhaps JSON), configure Alloy to tail the log file using loki.source.file, then in loki.process use stage.metrics to turn your parsed logs into metrics and forward to your metrics storage. This would be similar to how textfile-collector works. And yes you would have to schedule your script on your own.
1 Like

What does the bash or python do? What app or system does it interact with?

Thanks.
@yosiasz The Python scripts run several checks in running Podman containers to check if the are running and if the services in them are accessible.

@tonyswumac
I think solution 2 is the most simple one (even I can underständ it :grinning:)
I will try, I may have some more questions soon.

Where are you running podman containers, what host? Running root or rootless?
Then use alloy to read the container log directory?
Check this though for docker

Do the services have a health check endpoint?

Doesn’t podman also provide a means of tailing logs podman-logs

Note that the Unix exporter in Alloy supports reading text files: prometheus.exporter.unix | Grafana Alloy documentation

But yeah, you’d still have to schedule the script via cron or a systemd timer.

1 Like

Yes, I realized that after some time when I re-read the documentation. Thanks for point that out.