Accessing the database of a remote machine via Grafana locally

Hello,

I installed Grafana on my local PC, I can access it via: http://grafana.staged-by-discourse.com/ I have another machine, let’s call it machine A. on the same network with a mySQL database and an ip address of: 17XXXXXXXX. I was wondering if I can use the database on machine A as a data source to visualize on my local Grafana dashboard? if so, how?

Yes, you can do this. Make sure to type the Host as the IP address:port (172.43.34.65:3306). Here are the detailed instructions.

I installed Grafana on my local PC, I can access it via:
http://grafana.staged-by-discourse.com/

I have another machine, let’s call it machine A. on the same network with a
mySQL database and an ip address of: 17XXXXXXXX.

If that address starts with 172.16.something through to 17.31.something, then
there’s no need to obfuscate it when posting to a public list - it’s a private
address accessible only from your own local network.

I was wondering if I can use the database on machine A as a data source to
visualize on my local Grafana dashboard?

Yes.

if so, how?

Configure MyQSL as your data source and enter the IP address of your database
server (let’s call it machine A).

Antony.

Hi grant, thank you for your answer. I added the IP address:port as the host. However, I get the following error when I try to 'save & test ’ it : db query error: failed to connect to server - please inspect Grafana server log for details.
Any idea on what could be the problem? thank you

Does adding http:// make any difference? Any username and password to enter? Can your ping the machine using Cmd or terminal?

Hello, did you get any solution ? I’m in the same situation.

On the computer that is running Grafana, can your ping the computer that is running MySQL using Cmd or terminal?

Hello grant2.
Thx for reply.
I’m running grafana in docker at a Synology NAS.
All mysql (local) databases at the same NAS are working fine.
I wanted to add a dashboard with a chart with data from another MySQL db located at another machine in the same 192.168.1.1/24 net.

I can ping , ssh and access the second db from my NAS with “mysql ip:port -user -password”.
grafana-docker logfile tells me “connection timed out”.

Now I’m searching grafana community for a solution but only found question regarding the same issue :wink:

BR
Ralf

Hi @daisychain

So it sounds like Grafana can connect fine to the MySQL databases on the same Synology NAS (where Grafana is running), but Grafana cannot establish a working connection to a different MySQL database on the LAN.

Can you share a screenshot from Grafana of the non-working connection?


Hi Grant,

you’re right. Grafana works fine with the local database, but not with others in the same LAN. I have 3 of them I want to connect to Grafana. 192.168.1.172 is one of them, a Raspberry Pi collecting data into his local MySQL db.

There Is not much to be seen at the screenshot, I think ?

Daisy.

you will need something like this (modify per specific need of yours)

GRANT ALL PRIVILEGES ON *.* TO 'USERNAME'@'grafana.ip.address' IDENTIFIED BY 'PASSWORD' WITH GRANT OPTION;

This is not a grafana issue but mysql permissions issue so you might get more mileage from a mysql forum

Hi yosiasz,

unfortunately, your proposal didn’t work:-(
BR
Daisy.

Can you please post what you ran?

Can you please check if port 3306 is allowed in the firewall (if you are using one)?

Another way to verify is to use the ss (or netstat) command e.g.

ss -tupln | grep 3306

“netstat -tupln | grep 3306” doesn’t show the port 3306.

I run this from the cml of my NAS :

root@INIGMANAS1:~/tmp>mysql --host="192.168.1.172"  --user=grafanaReader --password=xyz --port=3306
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 970631
Server version: 10.1.48-MariaDB-0+deb9u2 Raspbian 9.11

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> use AQ;
Database changed
MariaDB [AQ]> SELECT * from temp limit 10;
+---------+------------+-----------+-------------+------------+---------+---------------------+
| id      | tempfilter | tempboden | tempschrank | tempdeckel | tempcpu | datumzeit           |
+---------+------------+-----------+-------------+------------+---------+---------------------+
|       1 |         23 |        24 |          20 |         20 |      55 | 2018-04-12 07:06:42 |
|       2 |         26 |      26.5 |          30 |         33 |      55 | 2018-04-12 07:06:53 |
|       3 |        0.2 |       0.2 |         0.2 |        0.2 |    53.7 | 2020-02-21 11:37:01 |
| 1177473 |       23.5 |      25.2 |        22.4 |         23 |    45.6 | 2023-06-05 22:56:04 |
| 1177474 |       23.5 |      25.2 |        22.5 |         23 |    45.1 | 2023-06-05 22:57:04 |
| 1177475 |       23.5 |      25.2 |        22.5 |         23 |    45.6 | 2023-06-05 22:58:04 |
| 1177476 |       23.5 |      25.2 |        22.5 |         23 |    45.1 | 2023-06-05 22:59:04 |
| 1177477 |       23.5 |      25.2 |        22.4 |         23 |    45.1 | 2023-06-05 23:00:04 |
| 1177478 |       23.5 |      25.2 |        22.4 |         23 |    44.5 | 2023-06-05 23:01:04 |
| 1177479 |       23.5 |      25.2 |        22.5 |       22.8 |    45.1 | 2023-06-05 23:02:04 |
+---------+------------+-----------+-------------+------------+---------+---------------------+
10 rows in set (0.01 sec)

MariaDB [AQ]>

So SQL query from NAS @ ip .200 to PI @ ip .172 is working well.
Grafana should do the same, but it fails to connect.

1 Like

@yosiasz :
In Raspberry Pi MySQL db, I did :

GRANT SELECT ON AQ.* TO grafanaReader@192.168.1.200 IDENTIFIED BY 'xyz';

.200 is the ip of my NAS running the grafana in docker.

1 Like

what does

SHOW GRANTS FOR

for that user show?

Is the mariadb server also listening to all ip addresses? or at least to a range

netstat -ant | grep 3306

@yosiasz :

I don’t think that an ‘user@ip’ is needed. ‘user@%’ is enough.
This is how a run all my sql stuff in my network for years.

If I can run

root@INIGMANAS1:~>echo "use AQ; select * from temp limit 2; " | mysql --host="192.168.1.172"  --user=grafanaReader --password=xyz
id      tempfilter      tempboden       tempschrank     tempdeckel      tempcpu datumzeit
1       23      24      20      20      55      2018-04-12 07:06:42
2       26      26.5    30      33      55      2018-04-12 07:06:53

from my NAS, all regarding ip, firewall, ports, user, grants … is configured well on both sides.

Grafana is doing something special in addition to the cml.

yes that is doable but that opens it up for user@% from anywhere, might be a security hole?

Going to try your setup in my home network.

1 Like

My whole podman containerization environment went down with an upgrade. Will see about this maybe this weekend