Skip to content

Commit

Permalink
Update Alloy tutorials (#1257)
Browse files Browse the repository at this point in the history
Co-authored-by: Mischa Thompson <[email protected]>
Co-authored-by: Paulin Todev <[email protected]>
  • Loading branch information
3 people authored Jul 17, 2024
1 parent 287775c commit 05d5b1e
Show file tree
Hide file tree
Showing 6 changed files with 201 additions and 186 deletions.
5 changes: 3 additions & 2 deletions docs/sources/tutorials/_index.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
---
canonical: https://grafana.com/docs/alloy/latest/tutorials/
description: Learn how to use Grafana Alloy
title: Tutorials
menuTitle: Tutorials
title: Grafana Alloy tutorials
weight: 200
---

# Tutorials
# {{% param "FULL_PRODUCT_NAME" %}} tutorials

This section provides a set of step-by-step tutorials that show how to use {{< param "PRODUCT_NAME" >}}.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
---
canonical: https://grafana.com/docs/alloy/latest/tutorials/first-components-and-stdlib/
description: Learn about the basics of the Alloy configuration syntax
title: First components and the standard library
weight: 20
description: Learn the basics of the Grafana Alloy configuration syntax
menuTitle: First components and the standard library
title: First components and the standard library in Grafana Alloy
weight: 200
---

# First components and the standard library
# First components and the standard library in {{% param "FULL_PRODUCT_NAME" %}}

This tutorial covers the basics of the {{< param "PRODUCT_NAME" >}} configuration syntax and the standard library.
It introduces a basic pipeline that collects metrics from the host and sends them to Prometheus.

## Prerequisites
## Before you begin

Set up a local Grafana instance as described in [Get started with {{< param "FULL_PRODUCT_NAME" >}}][get started]
To complete this tutorial:

* You must set up a [local Grafana instance][previous tutorial].

### Recommended reading

- [{{< param "PRODUCT_NAME" >}} configuration syntax][Configuration syntax]
- [{{< param "PRODUCT_NAME" >}} configuration syntax][configuration syntax]

## {{< param "PRODUCT_NAME" >}} configuration syntax basics
## {{% param "PRODUCT_NAME" %}} configuration syntax basics

An {{< param "PRODUCT_NAME" >}} configuration file is comprised of three things:
An {{< param "PRODUCT_NAME" >}} configuration file contains three elements:

1. **Attributes**

Expand Down Expand Up @@ -50,7 +53,7 @@ An {{< param "PRODUCT_NAME" >}} configuration file is comprised of three things:
```

{{< admonition type="note" >}}
The default log level is `info` and the default log format is `logfmt`.
The default log level is `info` and the default log format is `logfmt`.
{{< /admonition >}}

Try pasting this into `config.alloy` and running `<BINARY_FILE_PATH> run config.alloy` to see what happens. Replace _`<BINARY_FILE_PATH>`_ with the path to the {{< param "PRODUCT_NAME" >}} binary.
Expand All @@ -59,7 +62,7 @@ The default log level is `info` and the default log format is `logfmt`.
This configuration won't do anything, so let's add some components to it.

{{< admonition type="note" >}}
Comments in {{< param "PRODUCT_NAME" >}} syntax are prefixed with `//` and are single-line only. For example: `// This is a comment`.
Comments in {{< param "PRODUCT_NAME" >}} syntax are prefixed with `//` and are single-line only. For example: `// This is a comment`.
{{< /admonition >}}

## Components
Expand Down Expand Up @@ -291,16 +294,15 @@ Generally, you can use a persistent directory for this, as some components may u
In the next tutorial, you learn how to configure {{< param "PRODUCT_NAME" >}} to collect logs from a file and send them to Loki.
You also learn how to use different components to process metrics and logs.

[get started]: ../get-started/#set-up-a-local-grafana-instance
[Configuration syntax]: ../../concepts/configuration-syntax/
[previous tutorial]: ../send-logs-to-loki/#set-up-a-local-grafana-instance
[configuration syntax]: ../../get-started/configuration-syntax/
[Standard library documentation]: ../../reference/stdlib/
[node_exporter]: https://github.com/prometheus/node_exporter
[prometheus.exporter.redis]: ../../reference/components/prometheus.exporter.redis/
[http://localhost:3000/explore]: http://localhost:3000/explore
[prometheus.exporter.unix]: ../../reference/components/prometheus.exporter.unix/
[prometheus.scrape]: ../../reference/components/prometheus.scrape/
[prometheus.remote_write]: ../../reference/components/prometheus.remote_write/
[Components]: ../../concepts/components/
[Component controller]: ../../concepts/component_controller/
[Components configuration language]: ../../concepts/configuration-syntax/components/
[prometheus.exporter.redis]: ../../reference/components/prometheus/prometheus.exporter.redis/
[prometheus.exporter.unix]: ../../reference/components/prometheus/prometheus.exporter.unix/
[prometheus.scrape]: ../../reference/components/prometheus/prometheus.scrape/
[prometheus.remote_write]: ../../reference/components/prometheus/prometheus.remote_write/
[Components]: ../../get-started/components/
[Component controller]: ../../get-started/component_controller/
[Components configuration language]: ../../get-started/configuration-syntax/components/
[env]: ../../reference/stdlib/env/
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
---
canonical: https://grafana.com/docs/alloy/latest/tutorials/logs-and-relabeling-basics/
description: Learn how to relabel metrics and collect logs
title: Logs and relabeling basics
weight: 30
menuTitle: Logs and relabeling basics
title: Logs and relabeling basics in Grafana Alloy
weight: 250
---

# Logs and relabeling basics
# Logs and relabeling basics in {{% param "FULL_PRODUCT_NAME" %}}

This tutorial covers some basic metric relabeling, and shows you how to send logs to Loki.

## Prerequisites
## Before you begin

Complete the [First components and the standard library][first] tutorial.
To complete this tutorial:

* You must complete the [First components and the standard library][first] tutorial.

## Relabel metrics

Expand Down Expand Up @@ -83,7 +86,7 @@ There is an issue commonly faced when relabeling and using labels that start wit
These labels are considered internal and are dropped before relabeling rules from a `prometheus.relabel` component are applied.
If you would like to keep or act on these kinds of labels, use a [discovery.relabel][] component.

[discovery.relabel]: ../../reference/components/discovery.relabel/
[discovery.relabel]: ../../reference/components/discovery/discovery.relabel/
{{< /admonition >}}

## Send logs to Loki
Expand Down Expand Up @@ -181,8 +184,8 @@ loki.write "local_loki" {
{{< admonition type="tip" >}}
You can use the [loki.relabel][] component to relabel and add labels, just like you can with the [prometheus.relabel][] component.

[loki.relabel]: ../../reference/components/loki.relabel
[prometheus.relabel]: ../../reference/components/prometheus.relabel
[loki.relabel]: ../../reference/components/loki/loki.relabel
[prometheus.relabel]: ../../reference/components/prometheus/prometheus.relabel
{{< /admonition >}}

Run {{< param "PRODUCT_NAME" >}} and execute the following:
Expand Down Expand Up @@ -259,7 +262,7 @@ echo 'level=warn msg="WARN: This is a warn level log!"' >> /tmp/alloy-logs/log.l
echo 'level=debug msg="DEBUG: This is a debug level log!"' >> /tmp/alloy-logs/log.log
```

Navigate to [localhost:3000/explore][] and switch the Datasource to `Loki`.
Navigate to [http://localhost:3000/explore](http://localhost:3000/explore) and switch the Datasource to `Loki`.
Try querying for `{level!=""}` to see the new labels in action.

{{< figure src="/media/docs/alloy/screenshot-log-line-levels.png" alt="Grafana Explore view of example log lines, now with the extracted 'level' label" >}}
Expand Down Expand Up @@ -325,12 +328,11 @@ You have also seen how to use some standard library components to collect metric
In the next tutorial, you learn more about how to use the `loki.process` component to extract values from logs and use them.

[first]: ../first-components-and-stdlib/
[prometheus.relabel]: ../../reference/components/prometheus.relabel/
[prometheus.relabel]: ../../reference/components/prometheus/prometheus.relabel/
[constants]: ../../reference/stdlib/constants/
[localhost:3000/explore]: http://localhost:3000/explore
[prometheus.relabel rule-block]: ../../reference/components/prometheus.relabel/#rule-block
[local.file_match]: ../../reference/components/local.file_match/
[loki.source.file]: ../../reference/components/loki.source.file/
[loki.write]: ../../reference/components/loki.write/
[loki.relabel]: ../../reference/components/loki.relabel/
[loki.process]: ../../reference/components/loki.process/
[prometheus.relabel rule-block]: ../../reference/components/prometheus/prometheus.relabel/#rule-block
[local.file_match]: ../../reference/components/local/local.file_match/
[loki.source.file]: ../../reference/components/loki/loki.source.file/
[loki.write]: ../../reference/components/loki/loki.write/
[loki.relabel]: ../../reference/components/loki/loki.relabel/
[loki.process]: ../../reference/components/loki/loki.process/
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
---
canonical: https://grafana.com/docs/alloy/latest/tutorials/processing-logs/
description: Learn how to process logs
title: Processing Logs
weight: 40
menuTitle: Processing Logs
title: Processing logs with Grafana Alloy
weight: 300
---

# Processing Logs
# Processing logs with {{% param "FULL_PRODUCT_NAME" %}}

This tutorial assumes you are familiar with setting up and connecting components.
It covers using `loki.source.api` to receive logs over HTTP, processing and filtering them, and sending them to Loki.

## Prerequisites
## Before you begin

Complete the [Logs and relabeling basics][logs] tutorial.
To complete this tutorial:

* You must complete the [Logs and relabeling basics][logs] tutorial.

## Receive logs over HTTP and Process

Expand Down Expand Up @@ -349,7 +352,7 @@ curl localhost:9999/loki/api/v1/raw -XPOST -H "Content-Type: application/json" -
```

Now that you have sent some logs, its time to see how they look in Grafana.
Navigate to [localhost:3000/explore][] and switch the Datasource to `Loki`.
Navigate to [http://localhost:3000/explore](http://localhost:3000/explore) and switch the Datasource to `Loki`.
Try querying for `{source="demo-api"}` and see if you can find the logs you sent.

Try playing around with the values of `"level"`, `"message"`, `"timestamp"`, and `"is_secret"` and see how the logs change.
Expand Down Expand Up @@ -412,11 +415,10 @@ loki.write "local_loki" {
{{< /collapse >}}

[logs]: ../logs-and-relabeling-basics/
[loki.source.api]: ../../reference/components/loki.source.api/
[loki.process#stage.drop]: ../../reference/components/loki.process/#stagedrop-block
[loki.process#stage.json]: ../../reference/components/loki.process/#stagejson-block
[loki.process#stage.labels]: ../../reference/components/loki.process/#stagelabels-block
[localhost:3000/explore]: http://localhost:3000/explore
[discovery.docker]: ../../reference/components/discovery.docker/
[loki.source.docker]: ../../reference/components/loki.source.docker/
[discovery.relabel]: ../../reference/components/discovery.relabel/
[loki.source.api]: ../../reference/components/loki/loki.source.api/
[loki.process#stage.drop]: ../../reference/components/loki/loki.process/#stagedrop-block
[loki.process#stage.json]: ../../reference/components/loki/loki.process/#stagejson-block
[loki.process#stage.labels]: ../../reference/components/loki/loki.process/#stagelabels-block
[discovery.docker]: ../../reference/components/discovery/discovery.docker/
[loki.source.docker]: ../../reference/components/loki/loki.source.docker/
[discovery.relabel]: ../../reference/components/discovery/discovery.relabel/
Loading

0 comments on commit 05d5b1e

Please sign in to comment.