I created a script on my routers that sends the rx and tx of each interface to a php web server. The server takes care of the necessary calculations and sends everything back to a mysql database server.
Working on the latest version of Grafana, this query:
SELECT sum(total_tx)
FROM bandwidth
WHERE agent_host =~ /^$routerIP$/
AND time BETWEEN
(select MAX(time)
from supervision.bandwidth) - 3000
AND
(select MAX(time)
from supervision.bandwidth)
returns me the error:
db query error: Error 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '/^'10.211.0.2','10.211.0.3','10.211.0.4','10.211.0.5','10.211.0.6','10.211.0....' at line 3
SELECT sum(total_tx)
FROM bandwidth
WHERE agent_host =~ $routerIP
AND time BETWEEN
(select MAX(time)
from supervision.bandwidth) - 3000
AND
(select MAX(time)
from supervision.bandwidth)
Which returns the same erroe (without the " /^ ").
Also tried:
SELECT SUM(total_tx)
FROM supervision.bandwidth
WHERE agent_host =~ '${routerIP:singlequote}'
AND time BETWEEN
(select MAX(time)
from supervision.bandwidth) - 3000
AND
(select MAX(time)
from supervision.bandwidth)
or:
SELECT SUM(total_tx)
FROM supervision.bandwidth
WHERE agent_host =~ '$routerIP'
AND time BETWEEN
(select MAX(time)
from supervision.bandwidth) - 3000
AND
(select MAX(time)
from supervision.bandwidth)
I’ve build a new variable MYSQLrouterIP using the mysql connection instead of the routerIP which was using the influxDB connection (I have two bases).
This solved the error problem, but the panel is returning a no data, as if the use of the variable were empty or other than the values it contains.
SELECT SUM(total_tx)
FROM supervision.bandwidth
WHERE agent_host =~ '{$MSQLrouterIP:singlequote}'
AND time BETWEEN
(select MAX(time)
from supervision.bandwidth) - 3000
AND
(select MAX(time)
from supervision.bandwidth)
SELECT SUM(total_tx)
FROM supervision.bandwidth
WHERE agent_host =~ '{$MSQLrouterIP:singlequote}'
AND time BETWEEN
(select MAX(time)
from supervision.bandwidth) - 3000
AND
(select MAX(time)
from supervision.bandwidth)
So, do you see the problem with your query if you had to copy it from that query inspector and run it directly in mysql using for example mysql workbench?
which is not a solution for my case since grafana is taking as value '{$MSQLrouterIP:singlequote}' instead of the content of this variable for each panel (I’m doing a repeat panel).
Well, it does not exist, but I’ve started to work on influxDB base with Grafana, so I speculated that it might work the same way. At first, I’ve tried with agent_host = but got the same result as well…
I wanted to do the same as with my influxDB queries, which iterate trough each values of my variable using the =~.
No need to create new variable or weird things, just use the correct syntax for MariaDB query:
SELECT SUM(total_tx)
FROM supervision.bandwidth
WHERE agent_host IN ($routerIP )
AND time BETWEEN
(select MAX(time)
from supervision.bandwidth) - 3000
AND
(select MAX(time)
from supervision.bandwidth)