Some issues on grafana docker container

Hi Grafana Support Team!

I run a grafana docker container, mySQL container and web server container on Raspberry Pi4 using docker-compose. Everything is going well. I just two minor issues with the Grafana container.

  1. I can’t connect to the MySQL db using localhost:3306
    My initial db connection setting on grafana was as follows.


As you can see, I got an error when I use localhost:3306. I also tried 127.0.0.1:3306, but the result is the same. If I use the IP address of the Pi, then I can connect to the database, but I really need to connect to DB using localhost:3306. I think it’s possible because grafana container and db container are on the same device(raspberry pi). How can I implement it?

  1. Data is displayed with a delay of 1 hour in grafana

I also changed the raspberry pi timezone to GMT and local timezone and another timezone, but the result is the same.
How can I solve this problem?
This is my first post to Grafana Community. I need to quickly release this project now. I hope that you, the community team, provide me with the best solution as soon as possible.

Thanks in advance!!!

Christian

For what i know, you have to try the name of your database container instead of ‘localhost:3306’. For instant, in my case I have ‘mariadb’ to indicate Host.

Hi @ricardoati
Your suggestion is a very good solution for me. I used the name of db container as host name instead of IP address. It works well. Thanks!
Is there any good solution for the second issue?
Thanks in advance.

Christian

I’m glad to know. Regarding the second problem, i think is more usual but sorry, I am far from mastering that topic.
Ricardo

Welcome @ricardoati
You already helped me. I’m grateful for that.
I hope someone can help me soon.

Regarding “Data is displayed with a delay of 1 hour in grafana”.

This is almost certainly due to timestamps in your database not being in GMT.

Since you are using MySQL, be sure to define the timestamp field as DATETIME and
not as TIMESTAMP.

See https://dev.mysql.com/doc/refman/8.0/en/datetime.html specifically “MySQL
converts TIMESTAMP values from the current time zone to UTC for storage, and
back from UTC to the current time zone for retrieval. (This does not occur for
other types such as DATETIME.)”

Thus a TMESTAMP value can be modified by MySQL, whereas a DATETIME is not.

Antony.

Hi @pooh
Thanks for your reply. Nice to meet you here.
Yes, I’ll try your suggestion. However, I want to know how to set it in docker-compose.yml file.
When building the image, I want to set the timestamp field in the DB to datatime initially. So there is no need to do any manual work in the db container. Is it possible?
If it’s possible, let me know how to set db timestamp as datetime in docker-compose.yml

Thanks in advance.
Christian

Hi @pooh
Thanks for your reply. Nice to meet you here.

I know a few Christians - are you one of them?

Yes, I’ll try your suggestion. However, I want to know how to set it in
docker-compose.yml file.

I’m not a docker expert, but someone else may be able to help you with that
part.

Antony.

Hi Christian, from what pooh explained and from what I know about MySQL, the change he proposes is to use DATETIME instead of TIMESTAMP, and that concerns MySQL, having nothing to do with Docker.
You have to work in MySQL, which will be in a container within Docker, and there change the time column of your table from TIMESTAMP -> DATETIME.
Ricardo.

Thanks @ricardoati @pooh
I already solved the timestamp issue. I added an environment related db timezone. It works for me.
Thanks.

Christian