Monitor Latency of APIs using loki

Is it possible to monitor latencies of APIs or functions using grafana loki?
Also, is it possible to create a histogram?

You can enable tracing in Loki to give you latency between components. But if you are talking from client perspective, the easiest way probably would be to use Loki Canary (see Loki Canary | Grafana Loki documentation). Once you set it up, it’ll periodically send logs to Loki and query for the log to see if it exists in Loki. It also has other checks like metrics query test and spot check, quite useful. It exposes quite a lot of metrics, such as loki_canary_missing_entries_total. loki_canary_metric_test_request_duration_seconds_bucket, loki_canary_spot_check_request_duration_seconds_bucket, and more, that are quite useful.

Hi @tonyswumac ,

Thanks for your response. Sorry, my question was not detailed. I actually want to monitor my backend application’s APIs & response time of functions. Will that be possible using Loki Canary?

If not, can you suggest any other solution?

Oh, then your question isn’t Loki specific. I’d recommend you to google a bit and see what others are doing, but that is a very big question and everyone does it a bit differently.

Personal opinions:

  1. First you need to decide what you are trying to monitor. Are you trying to get your app’s response time from a client perspective? If so you might be looking at some sort of poke agent like node-exporter.blackbox. If you are looking to map elapsed time for each of your microservice components, you are probably looking for tracing.
  2. Or, you can generate logs from your applications with information you are looking for, such as component A spend x ms on function B. Then you can forward this to Loki and aggregate there.
  3. Or, you can expose metrics from your app directly using standard prometheus format. Then scrape from it and forward to a metrics backend such as prometheus. This is similar to #2, but different approach.

Unfortunately your question is rather broad, and I don’t really know how to answer with more details.