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 (29)

Collapse
 
officialibommaapp_55aabcc profile image
officialibommaapp

I’ve seen a lot of people mention the ibomma app download telugu movies​‍​‌‍​‍‌ when discussing platforms focused mainly on Telugu cinema. Users usually bring it up for its clean layout and the way it organizes movies by language and release type. For anyone who regularly watches Telugu films and wants a straightforward app experience, it often comes up in community discussions.

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
 
khurum_khan_083254db824f8 profile image
Khurum Khan

Waho App is a social interaction app designed to make communication simple, expressive, and engaging. It allows users to join conversations, reply to comments, share thoughts, and connect with others in a clean and friendly environment. Built for fast communication and smooth engagement, Waho focuses on real-time social interaction without distractions.

Collapse
 
carlo_james_8e1e5704340c7 profile image
Carlo james

Thanks for sharing! If you’re exploring food options or just planning your next meal, checking out restaurant menus online can save time and help you decide faster. Sites that organise menus clearly are super helpful, especially when you're in a rush or ordering for a group.

Collapse
 
today_biggboss_92b6281a84 profile image
today biggboss

al karama dubai is renowned for its bustling markets, affordable shopping, authentic dining experiences, and vibrant multicultural community. Unlike the glitzy

Collapse
 
mark_aidel_da9006c52b40ad profile image
Mr Iamhag

The combination of Loki, curl, and logcli offers an efficient way to query, test, and analyze logs directly from the command line, making troubleshooting faster and more effective. Visit Parivahan

Collapse
 
today_biggboss_92b6281a84 profile image
today biggboss

al karama dubai is renowned for its bustling markets, affordable shopping, authentic dining experiences, and vibrant multicultural community. Unlike the glitzy

Collapse
 
officialibommaapp_55aabcc profile image
officialibommaapp

Nice follow-up after the Loki introduction. Using curl and logcli makes it much easier to understand how Loki works in real use cases, especially for quick log querying and debugging.

This approach is also useful for tracking application logs, for example monitoring requests or errors from an app like ibomma app telugu movies‍‌‍‍‌. Overall, a helpful and practical continuation for Loki beginners.

Collapse
 
jackbox profile image
Jack in the Box Menu

Great guide on getting Loki up and running locally with Docker! For anyone diving into monitoring and logs, setting this up is a great first step. If you're looking for a quick bite while working through this setup, why not check out Jack in the Box? Their menu has a wide variety of options that can keep you fueled. You can easily find a Jack in the Box menu near me for some delicious burgers, tacos, or breakfast items. Perfect for a snack between tasks!

Collapse
 
aiman_fareed_af7c8b6dcb72 profile image
Aiman fareed

Enjoy Whataburger’s cozy Cinnamon Roll, crispy Hot Apple Pie, and tasty Chocolate Chunk Cookie for a perfect sweet treat anytime. These desserts deliver comforting flavors that satisfy cravings on the go. Explore all available options and prices at the Whataburger irresistible dessert menu today!

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!

Some comments may only be visible to logged-in visitors. Sign in to view all comments.