Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to use Loki to query logs from MySQL database?

Ok. We have Promtail to gather text log files and send them to loki.
Also I can create MySQL data source to query data from database for visialization purposes.

I am curious. Is it possible to configure Loki/Promtail or there is some logging driver which allows Loki to access them.

Why I am asking about this. Because our legacy system stores logs of our application into database into (ID, time, text) fields. So I am trying to find a way to import these logs into Loki or to configure Promtail to fetch logs not from text files but from this database table.

Is that possible?

like image 541
Eugen Konkov Avatar asked Jan 24 '26 16:01

Eugen Konkov


1 Answers

This is possible.

Found how to post log to Loki directly:

/loki/api/v1/push is the endpoint used to send log entries to Loki. The default behavior is for the POST body to be a snappy-compressed protobuf message. Alternatively, if the Content-Type header is set to application/json, a JSON post body can be sent in the following format:

{
  "streams": [
    {
      "stream": {
        "label": "value"
      },
      "values": [
          [ "<unix epoch in nanoseconds>", "<log line>" ],
          [ "<unix epoch in nanoseconds>", "<log line>" ]
      ]
    }
  ]
}

Here is blog post how to do that with python: https://medium.com/geekculture/pushing-logs-to-loki-without-using-promtail-fc31dfdde3c6#8290

like image 184
Eugen Konkov Avatar answered Jan 27 '26 01:01

Eugen Konkov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!