Hello, I am new to Grafana, just done my first dashboards. My case is to show a Production Performance board in our factories.
I basically need to understand how to define parameters in the URL, and not least how to connect them to variables in my SQL scripts. I use onprem Grafana and a local MS SQL.
I have seen topics here, but it unfortunately didnt give me the overview.
Any help appreciated
The linking overview docs page is here: Manage dashboard links | Grafana documentation
It sounds like you are looking for dashboard links: Manage dashboard links | Grafana documentation
The format for specifying template variables in a url is:
https://${you-domain}/path/to/your/dashboard?var-${template-variable1}=value1&var-${template-variable2}=value2
A real life example with three variables named datacenter, host and summarize: https://play.grafana.org/d/000000002/influxdb-templated?orgId=1&var-datacenter=Africa&var-host=All&var-summarize=1m
Visiting this link will set the three variables that you can see at the top of the page:
Those variables then have to be used in a query to actually have any effect. Here is an example of an sql query using variables (host and summarize) by putting a dollar sign in front of the variable name:
SELECT
$__timeGroup(createdAt,'$summarize') as time,
avg(value) as value,
hostname as metric
FROM
grafana_metric
WHERE
$__timeFilter(createdAt) AND
measurement = 'logins.count' AND
hostname IN($host)
GROUP BY $__timeGroup(createdAt,'$summarize'), hostname
ORDER BY 1
When a variable value is changed either by changing the URL or by choosing a value in a dropdown then a query to MSSQL is triggered and the visualization in Grafana is updated with the new data.
Thank you Daniel,
I run Grafana local towards MS SQL, using this URL e.g.:
community.grafana.com/d/W2cZyXdnk/silo-history-dashboard-ver-24-okt-2021?orgId=1&var-unit=3021
My variable “unit” should be transferred to $unit
My SQL look like:
SELECT
$__timeEpoch(time),
state_NUM as ‘3011’
FROM
REPORT_CACHE
WHERE
$__timeFilter(time) AND UNIT_ID IN ($unit) – I have also tried UNIT_IS = $unit
ORDER BY
time ASC
It simply does not work, nothing happens, and the native MS SQL is not generated ?
I am not anywhere in the dashboard “defining” the variable “unit”, right ?
I have also tried to cast the incoming “unit” variable to INT, as I assume it may come in as string ?
Things works quite different, pointing at Influx as opposed to pointing at MS SQL, by the way, part of my problem, I cant find MS SQL examples …
Hope you have another idea …
You have to create a variable in the dashboard named “unit” otherwise it won’t get passed from the url to the query. There are different types of variables - you are probably looking for one of these 3:
- query variables where you specify a query to provide the values in a dropdown
- custom variables where you hardcode the values
- textbox - just a textbox where the user can type in any free text
Templating docs: Microsoft SQL Server data source | Grafana documentation
There are some examples in docs here: Microsoft SQL Server data source | Grafana documentation
These are the test dashboards we using for testing MSSQL with Grafana: https://github.com/grafana/grafana/tree/main/devenv/dev-dashboards/datasource-mssql
If the access to the particular dashboard is access controlled, how do you prevent users from changing the query string parameters and viewing the dashboards for which they are not supposed to have access