The Ops Community ⚙️

Alex
Alex

Posted on

loki && curl && logcli

With https://community.ops.io/la3mmchen/grafana-loki-28b9 I've shared some words on Loki as an introduction.

Lets follow up with some practical stuff: How can we run Loki an our local notebook with docker-compose?

Loki

As Grafana provides a good enough container images we just use the one from docker hub to get a local instance running.

---
version: "3.9"

services:
  loki:
    image: "grafana/loki:2.5.0"
    ports:
      - "3100:3100"
Enter fullscreen mode Exit fullscreen mode

As Loki follows the unix philosophy "Do One Thing and Do It Well" it's just a backend to send logs to and to query logs from.
Plain speaking: there is no graphical user interface in the Loki server.

We interact with the Loki instance with curl using the http api:

$  curl http://localhost:3100/ready  
ready
$ curl http://localhost:3100/loki/api/v1/labels
{"status":"success","data":["__name__"]}
Enter fullscreen mode Exit fullscreen mode

As the second request shows there are not many labels in the system yet.

Lets change this.

interact with curl

Loki offers a http api to send metrics. The data format is described at http push api, we use the following curl to create a new event stream:

$ curl -S -H "Content-Type: application/json" -XPOST -s http://localhost:3100/loki/api/v1/push --data-raw '{"streams": [{ "stream": { "app": "app1" }, "values": [ [ "1653855518000000000", "random log line" ] ] }]}'
$ curl http://localhost:3100/loki/api/v1/labels
{"status":"success","data":["__name__","app"]}
Enter fullscreen mode Exit fullscreen mode

As you can see in the second curl there is now a new label named "app". We can explore possible values for this label with the following curl.

$ curl http://localhost:3100/loki/api/v1/label/app/values
{"status":"success","data":["app1"]}
Enter fullscreen mode Exit fullscreen mode

And finaly see the stream with this label:

$ curl -G -Ss  http://localhost:3100/loki/api/v1/query_range --data-urlencode 'query={app="app1"}' | jq .
{
  "status": "success",
(...)
        "values": [
          [
            "1653855518000000000",
            "random log line"
          ]
        ]
      }
(...)
Enter fullscreen mode Exit fullscreen mode

(output shorted)

logcli

A more covenient way to interact with Loki from the command line is using logcli

$ LOKI_ADDR=http://localhost:3100 logcli labels
http://localhost:3100/loki/api/v1/labels?end=1653856566774536000&start=1653852966774536000
__name__
app
$ LOKI_ADDR=http://localhost:3100 logcli query '{app=~".+"}'
http://localhost:3100/loki/api/v1/query_range?direction=BACKWARD&end=1653856568404563000&limit=30&query=%7Bapp%3D~%22.%2B%22%7D&start=1653852968404563000
Common labels: {app="app1"}
2022-05-29T22:18:38+02:00 {} random log line
http://localhost:3100/loki/api/v1/query_range?direction=BACKWARD&end=1653855518000000001&limit=30&query=%7Bapp%3D~%22.%2B%22%7D&start=1653852968404563000
Common labels: {app="app1"}
Enter fullscreen mode Exit fullscreen mode

in case you do not want to install logcli locally just add another container to our docker-compose setup from the beginning of this article:

(..)
  logcli:
    image: "grafana/logcli:2.5.0-amd64"
    environment:
      - "LOKI_ADDR=http://loki:3100"
Enter fullscreen mode Exit fullscreen mode

with this container you can just do:

$ docker-compose run logcli labels
Creating loki_logcli_run ... done
(..)
__name__
app
Enter fullscreen mode Exit fullscreen mode

following up

in the next post we will add a grafana instance to our docker-compose that will enable us to click something ;-)

references

links

code reference

---
version: "3.9"

services:
  loki:
    image: "grafana/loki:2.5.0"
    ports:
      - "3100:3100"
  logcli:
    image: "grafana/logcli:2.5.0-amd64"
    environment:
      - "LOKI_ADDR=http://loki:3100"
Enter fullscreen mode Exit fullscreen mode

Top comments (16)

Collapse
 
nntech_ce34765219fe9625b6 profile image
nntech

Kick off your morning with the 2025 breakfast menu’s savory tacos, warm kolaches, and fresh pastries. Perfect for a quick and delicious start. Explore the full menu and prices at the breakfast essentials spot today.

Collapse
 
emily_watson_cc5430265406 profile image
Emily Watson

That’s a solid setup for getting Loki running locally — thanks for sharing such a clear walkthrough! I’ve been working on some local deployments myself and totally get the satisfaction of seeing it run smoothly. After coding sessions like these, I often grab something from the Texas Roadhouse catering menu for the team — their hearty meals make debugging marathons way more enjoyable! You can visit thetexasroadhousemenu.com to explore more about catering menu!

Collapse
 
shoaib_akhtar_6b13bbe6f7d profile image
Mr Kaja

Apaar ID is a smart and secure platform designed to manage personal and account information efficiently. 🔑💻 It makes accessing services easier while ensuring your data stays safe and well-organized.

Collapse
 
india_sewa_bf756f501fe2bc profile image
India sewa

Here are a few short comment options for Loki, cURL, and LogCLI:
Powerful combo for log management and analysis! 🔥
Loki + cURL + LogCLI = efficient logging workflow. 💻
Great tools for developers and DevOps teams! ⚙️
Loving how seamless log queries are with this setup! 🚀Visit Parivahan

Collapse
 
shoaib_akhtar_7b7fbf63239 profile image
Shoaib Akhtar

Loki, Curl, and Logcli are powerful tools for managing and querying logs efficiently. ⚙️🔥 Together, they make log analysis faster and more flexible — perfect for developers and system admins who need reliable observability and real-time monitoring. Parivahan sewa

Collapse
 
us_menu_0eb41e2a7f180fe4e profile image
Us Menu

The Sonic menu is amazing! It offers a great mix of classic fast-food favorites, refreshing drinks, and sweet treats — perfect for anyone who loves variety and great taste.

Collapse
 
wendys_menu_1f6cd4c61b68 profile image
Wendy's Menu

Wendy’s menu croissants are such a delicious breakfast pick — soft, buttery, and filled with savory goodness. Whether it’s sausage, bacon, or egg, each croissant sandwich feels like a cozy morning treat. Perfect for a quick yet satisfying start to the day!

Collapse
 
burger_kingmenu_d4ae2673 profile image
Burger King Menu

Thanks for sharing! I found this really helpful. By the way, if anyone’s looking for an updated list, check out the full Burger King Menue with prices—it’s super easy to navigate and really detailed!

Collapse
 
panada_expressmenu_3450d profile image
Panada Express Menu

Great tips here! Also, for anyone looking for the latest Panda Express offerings, check out the full Panda Menu—it’s super easy to browse and see all the options available!

Collapse
 
wendys_menu_9d16407a981c profile image
Wendy's Menu

Nice write-up! If you're looking for a quick, delicious option while working, check out our Wendys Menu—complete, easy to browse, and perfect when you need something tasty on the go!