How can I retrieve the hostname from the browser URL

  • What Grafana version and what operating system are you using?
    8.3.1 on Linux

  • What are you trying to achieve?
    I’m trying to use a button plugin to make an HTTP request to a web server running on the same computer as the Grafana server. Users can view the dashboard locally or remotely, so I can’t just POST to “https://localhost/…” since that won’t resolve properly when viewing the dashboard remotely.

I’m trying to figure out how to get the hostname portion of the browser URL into a dashboard variable. Then I can put that variable into the URL for the button, and the button will work wherever the user accesses the dashboard from.

Getting the hostname from Grafana isn’t a solution since it will always be the same. I want to get the hostname from the browser, in the same way that window.location.hostname would in JavaScript.

Is there any way to do this in Grafana, either natively or using a third-party plugin?


I didn’t end up finding a way to do this, however I was able to do what I needed using the HTML Graphics plugin. That plugin allowed me to write arbitrary JavaScript, HTML, and CSS, so I was able to create a button and generate fetch() requests, retrieving the hostname using JS.