Giter Club home page Giter Club logo

loki-k6-handson's Introduction

Loki logs producer hands-on

Create a Grafana Cloud stack

Create a Grafana Cloud Free account. No credit card required.

Save credentials for k6

We will save all informations needed to write to Loki in k6

Log into your Grafana.com account to find and create relevant informations In another tab, open your Grafana.

  • Click on Details next to Loki to see all details.
  • Create an API Token by clicking on Generate now
  • In Grafana, copy-paste it into your k6 > Settings > Environnement variables as LOKITOKEN
  • Copy paste the domain name of your Loki cluster
  • In Grafana, save it without the https:// into a new k6 variables as LOKIURL (ex: logs-prod-012.grafana.net)
  • Find the user for your Loki cluster just under the URL. It should be a number (ex: 123456)
  • In Grafana, save it into a new k6 variables as LOKIUSER

Create the k6 scripts

Create a new project in Grafana Cloud k6, and start editing the script Copy paste the provided script: load-test.js and save

Run the test

Let the test run for few minutes

Find your data in Loki

Be careful of the time interval you are querying, otherwise you could be looking at a time where you have no data to show

Go to Explore in Grafana, and select the Loki datasource called grafanacloud-mystack-logs. Select the label foo and value bar, then run the query. You should see some logs now.

Play with Explore mode

Open a log line from the previous query. You can see the content, but in the structured result, you only have the labels (app and foo). You can't use the content as key/value pairs

The LogQL builder is giving you a hint: "Add a logfmt parser". Click on it and run the query. Open one of the log line. You should now see the content as a key/value pair. logfmt is key=value otherkey=othervalue format. The builder caught it from the results and told you he can give you actionable results. Now it gives you another hint: "Add label filter" click on it and set Label as VirtualUserID and value as 5, then run the query.

Looking at the result, you can only see log lines with this VirtualUserID.

You successfully queried, parsed and filtered logs that were not fully indexed. Now let's look at more advanced use case and Logs to Metrics cases.

loki-k6-handson's People

Contributors

clementduveau avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.