Changing default port for grafana agent

This was much more difficult than it should have been. Grafana agent runs on port 9090 and 9091, so when I installed it on a server where nginx was using those ports, I got an error, not unreasonably.

error creating the agent server entrypoint" err="creating HTTP listener: listen tcp 127.0.0.1:9090: bind: address already in use

Fair enough. But how to change it? I looked through the /etc/grafana-agent.yaml file but there was nothing in there. I searched the grafana docs and forums. Nothing. I searched google and asked phind for suggestions, which irritatingly told me to make several changes for files and variables that didn't exist.

I looked for the systemd service file, which wasn't in the normal places /etc/systemd/system or /lib/systemd/system/ but in a further subdir of /etc/systemd/system/multi-user.target.wants/ and /usr/lib/systemd/system/multi-user.target.wants/

OK, so now a clue. That contained a line EnvironmentFile=/etc/default/grafana-agent, and that's where you need to edit the ports.

# Any user defined arguments
CUSTOM_ARGS="-server.http.address=127.0.0.1:9090 -server.grpc.address=127.0.0.1:9091"

So hopefully that will save someone some time, as I wasted an hour on it.

Leave a Comment