grafana / loki

Like Prometheus, but for logs.
https://grafana.com/loki
GNU Affero General Public License v3.0
23.94k stars 3.45k forks source link

How to configure Loki as Prometheus datasource? #1222

Closed vukor closed 5 years ago

vukor commented 5 years ago

Hello, New v0.4.0 release version is support PromQL as I understand. Here proof link - https://grafana.com/blog/2019/10/28/whats-new-in-loki-v0.4.0/

I would like to add Loki as Prometheus datasource in Grafana (6.4.3 version) but can't find what is correct address? I already use Loki datasource (address is http://loki:3100) and it works.

I need to use PromQL to configure alert trigger for some log message regexp. Thanks.

vukor commented 5 years ago

More details:

Inside grafana/loki:v0.4.0 container:

/ $ netstat -ltnup
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 :::3100                 :::*                    LISTEN      1/loki
tcp        0      0 :::9095                 :::*                    LISTEN      1/loki

9095 - is some binary data 3100 - Loki datasource, http://loki:3100/loki return 404

negbie commented 5 years ago

Hi, did you try it with curl like in the examples here? Just to make sure that you can reach the query endpoint. https://github.com/grafana/loki/blob/master/docs/api.md#examples

slim-bean commented 5 years ago

Append loki to the end of your URL, like this: http://loki:3100/loki and be sure to select the Prometheus data source type.

vukor commented 5 years ago

Thanks guys, http://loki:3100/loki looks working.

lobatt commented 5 years ago

Append loki to the end of your URL, like this: http://loki:3100/loki and be sure to select the Prometheus data source type.

I know this issue has been closed, but I am having some issue setting this up. I am thrilled to learn the support for metrics for Loki.

However, when I configure my Prometheus data source to use http://loki:3100/loki as server URL, with latest docker images.

My grafana UI got stucked "Loading metrics", hence not being able to perform any query.

image

Am I missing anything?

cyriltovena commented 5 years ago

No you’re not missing anything. This box doesn’t yet work (soon) but you can still make queries.

lobatt commented 5 years ago

No you’re not missing anything. This box doesn’t yet work (soon) but you can still make queries.

Thanks @cyriltovena .

So for keep an eye on the progress, should I watch releases of Loki or Grafana itself?

cyriltovena commented 4 years ago

Grafana, there is already a version supporting this but not tagged I think

guobei2028 commented 3 years ago

https://[my-loki-url]/loki in my 2.0 version seems to have no effect. Has anyone encountered the same situation? I already use Loki datasource (address is http://loki:3100) and it works.

frankyaorenjie commented 3 years ago

Yes, this solution doesn't work in new version. Grafana 7.4.0-pre. I found a video from Grafana officials to introduce Alert on your Loki logs with Grafana in Feb/2020. Can I say this feature is supported but somehow, doesn't work right now?

In 7.4.0-pre, Grafana will request two APIs:

  1. query_range
  2. query_exemplar

The request of query_exemplar will get a 404 return, and cancel then query_range is cancelled.

We also tested 7.0.4 and everything is working fine. There are no query_exemplar when Grafana requests backend data source.

The exemplar is used to correlate metrics and tracing, from TNS Observability Demo of Grafana/Loki/Prometheus/Tempo. And I guess it is a quite new feature and Loki didn't support it yet.

saibug commented 2 years ago

Having same issue in production ! My loki version is : 2.4.2 From read instance, this is log output : read_1 | level=error ts=2022-05-09T12:41:32.850473694Z caller=retry.go:73 org_id=fake msg="error processing request" try=4 err="rpc error: code = Code(500) desc = unsupported response type, got (scalar)" read_1 | level=info ts=2022-05-09T12:41:32.850559168Z caller=metrics.go:92 org_id=fake latency=fast query=1+1 query_type=metric range_type=instant length=0s step=0s duration=0s status=500 limit=100 returned_lines=0 throughput=0B total_bytes=0B

Thank you

KVInventoR commented 2 years ago

Hey same for me, I also got an issue:

loki-linux-amd64 --version
loki, version 2.5.0 (branch: HEAD, revision: 2d9d0ee23)
  build user:       root@4779f4b48f3a
  build date:       2022-04-07T21:50:00Z
  go version:       go1.17.6
  platform:         linux/amd64

grafana 7.0.0