-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Receive + Prometheus Agent tutorial. (#4817)
* Added Receive + Prometheus Agent tutorial. Also updated tutorial 3. Signed-off-by: Bartlomiej Plotka <bwplotka@gmail.com> * Apply suggestions from code review Co-authored-by: Matej Gera <38492574+matej-g@users.noreply.github.com> * Added minor nits. Signed-off-by: Bartlomiej Plotka <bwplotka@gmail.com> * Apply suggestions from code review Co-authored-by: Ian Billett <ibillett@redhat.com> * Moved to Prometheus main. Signed-off-by: Bartlomiej Plotka <bwplotka@gmail.com> * Reverted due to broken main. Signed-off-by: Bartlomiej Plotka <bwplotka@gmail.com> * nits. Signed-off-by: Bartlomiej Plotka <bwplotka@gmail.com> Co-authored-by: Matej Gera <38492574+matej-g@users.noreply.github.com> Co-authored-by: Ian Billett <ibillett@redhat.com>
- Loading branch information
1 parent
1c3b984
commit 885b3bb
Showing
18 changed files
with
350 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/usr/bin/env bash | ||
|
||
docker pull quay.io/bwplotka/prometheus:agent1 | ||
docker pull quay.io/thanos/thanos:v0.21.0 | ||
|
||
mkdir /root/editor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Summary | ||
|
||
Congratulations! 🎉🎉🎉 | ||
You completed this Prometheus Agent tutorial. Let's summarize what we learned: | ||
|
||
* Thanos Receive is a component that implements the `Prometheus Remote Write` protocol. | ||
* Prometheus Agent can be deployed to remote write its metric data in real-time to another server that implements the Remote Write protocol. | ||
* Prometheus Agent uses a _fraction_ of the resources as normal Prometheus, by not enabling features like: local metrics storage and local query APIs. | ||
|
||
See next courses for other tutorials about different deployment models and more advanced features of Thanos! | ||
|
||
## Further Reading | ||
|
||
TBD | ||
|
||
### Feedback | ||
|
||
Do you see any bug, typo in the tutorial or you have some feedback for us? | ||
|
||
let us know on https://github.com/thanos-io/thanos or #thanos slack channel linked on https://thanos.io |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
{ | ||
"title": "Bonus: Using Prometheus Agent for streaming metrics to Thanos Receive", | ||
"description": "Learn how to use Prometheus in agent mode to efficiently stream metrics out of cluster.", | ||
"difficulty": "Moderate", | ||
"details": { | ||
"steps": [ | ||
{ | ||
"title": "Problem Statement & Setup", | ||
"text": "step1.md", | ||
"verify": "step1-verify.sh" | ||
}, | ||
{ | ||
"title": "Setup Prometheus Agents", | ||
"text": "step2.md", | ||
"verify": "step2-verify.sh" | ||
}, | ||
{ | ||
"title": "Verify Setup", | ||
"text": "step3.md", | ||
"verify": "step3-verify.sh" | ||
} | ||
], | ||
"intro": { | ||
"text": "intro.md", | ||
"courseData": "courseBase.sh", | ||
"credits": "https://thanos.io" | ||
}, | ||
"finish": { | ||
"text": "finish.md", | ||
"credits": "test" | ||
} | ||
}, | ||
"files": [ | ||
"prom-agent-batmobile.yaml", | ||
"prom-agent-batcopter.yaml" | ||
], | ||
"environment": { | ||
"uilayout": "editor-terminal", | ||
"uisettings": "yaml", | ||
"uieditorpath": "/root/editor", | ||
"showdashboard": true, | ||
"dashboards": [ | ||
{"name": "Prometheus Agent Batmobile", "port": 9090}, | ||
{"name": "Prometheus Agent Batcopter", "port": 9091}, | ||
{"name": "Thanos Query", "port": 39090} | ||
] | ||
}, | ||
"backend": { | ||
"imageid": "docker-direct" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Intermediate: (Bonus) Using Prometheus Agent for pure forward-only metric streaming with Thanos Receive | ||
|
||
The [Thanos](thanos.io) project defines a set of components that can be composed together into a highly available metric system with **unlimited storage capacity** that **seamlessly** integrates into your existing Prometheus deployments. | ||
|
||
But [Prometheus](https://prometheus.io/) project is far from slowing down the development. Together with the community, it constantly evolves to bring value to different network and cluster topologies that we see. Thanos brings distributed and cloud storage and querying to the table, built on the core Prometheus code and design. It allowed Prometheus to focus on critical collection and single cluster monitoring functionalities. | ||
|
||
As we learned in the previous tutorial, certain situations require us to collect (pull) data from applications and stream them out of the cluster as soon as possible. `Thanos Receive` allows doing that by ingesting metrics using the Remote Write protocol that the sender can implement. Typically we recommended using Prometheus with short retention and blocked read and query API as a "lightweight" sender. | ||
|
||
In November 2021, however, we, the Prometheus community, introduced a brand new Prometheus mode called "Agent mode". The implementation itself was already battle tested on https://github.com/grafana/agent, where it was available and authored by [Robert Fratto](https://github.com/rfratto) since 2020. | ||
|
||
The agent mode is optimized for efficient metric scraping and forwarding (i.e. immediate metric removal once it's securely delivered to a remote location). Since this is incredibly helpful for the Thanos community, we wanted to give you first-hand experience deploying Prometheus Agent together with Thanos Receive in this course. | ||
|
||
In this tutorial, you will learn: | ||
|
||
* How to reduce Prometheus based client-side metric collection to a minimum, using the new Prometheus "Agent mode" with `Thanos Receiver`, explained in the previous tutorial. | ||
|
||
> NOTE: This course uses docker containers with pre-built Thanos, Prometheus, and Minio Docker images available publicly. | ||
### Prerequisites | ||
|
||
Please complete tutorial #3 first: [Intermediate: Streaming metrics from remote source with Thanos Receive](https://www.katacoda.com/thanos/courses/thanos/3-receiver) 🤗 | ||
|
||
### Feedback | ||
|
||
Do you see any bug, typo in the tutorial, or do you have some feedback for us? | ||
Let us know on https://github.com/thanos-io/thanos or #thanos slack channel linked on https://thanos.io | ||
|
||
### Contributed by: | ||
|
||
* Bartek Plotka [@bwplotka](http://bwplotka.dev) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/usr/bin/env bash | ||
|
||
# receive | ||
curl -s 127.0.0.1:10909/metrics >/dev/null || exit 1 | ||
# query | ||
curl -s 127.0.0.1:39090/metrics >/dev/null || exit 1 | ||
|
||
echo '"done"' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
## Problem Statement | ||
|
||
Let's get back to our example from [Tutorial 3](https://www.katacoda.com/thanos/courses/thanos/3-receiver). Imagine you run a company called `Wayne Enterprises`. In tutorial 3, we established monitoring of two special clusters: `Batcave` & `Batcomputer`. These are special because they do not expose public endpoints to the Prometheus instances running there for security reasons, so we used the Remote Write protocol to stream all metrics to Thanos Receive in our centralized space. | ||
|
||
Let's imagine we want to expand our `Wayne Enterprises` by adding metrics collection to applications running on smaller devices inside more mobile Batman tools: `Batmobile` and `Batcopter`. | ||
|
||
Each of these vehicles has a smaller computer that runs applications from which we want to scrape Prometheus-like metrics using OpenMetrics format. | ||
|
||
As the person responsible for implementing monitoring in these environments, you have three requirements to meet: | ||
|
||
1. Implement a global view of this data. `Wayne Enterprises` needs to know what is happening in all company parts - including secret ones! | ||
2. `Batmobile` and `Batcopter` can be out of network for some duration of time. You don't want to lose precious data. | ||
3. `Batmobile` and `Batcopter` environments are very **resource constrained**, so you want an efficient solution that avoids extra computations and storage. | ||
|
||
Firstly, let us set up Thanos as we explained in the previous tutorial. | ||
|
||
## Setup Central Platform | ||
|
||
As you might remember from the previous tutorial, in the simplest form for streaming use cases, we need to deploy Thanos Receive and Thanos Querier. | ||
|
||
Let's run `Thanos Receive`: | ||
|
||
``` | ||
docker run -d --rm \ | ||
-v $(pwd)/receive-data:/receive/data \ | ||
--net=host \ | ||
--name receive \ | ||
quay.io/thanos/thanos:v0.21.0 \ | ||
receive \ | ||
--tsdb.path "/receive/data" \ | ||
--grpc-address 127.0.0.1:10907 \ | ||
--http-address 127.0.0.1:10909 \ | ||
--label "receive_replica=\"0\"" \ | ||
--label "receive_cluster=\"wayne-enterprises\"" \ | ||
--remote-write.address 127.0.0.1:10908 | ||
```{{execute}} | ||
This starts Thanos Receive that listens on `http://127.0.0.1:10908/api/v1/receive` endpoint for Remote Write and on `127.0.0.1:10907` for Thanos StoreAPI. | ||
Next, let us run a `Thanos Query` instance connected to Thanos Receive: | ||
``` | ||
docker run -d --rm \ | ||
--net=host \ | ||
--name query \ | ||
quay.io/thanos/thanos:v0.21.0 \ | ||
query \ | ||
--http-address "0.0.0.0:39090" \ | ||
--store "127.0.0.1:10907" | ||
```{{execute}} | ||
Verify that `Thanos Query` is working and configured correctly by looking at the 'stores' tab [here](https://[[HOST_SUBDOMAIN]]-39090-[[KATACODA_HOST]].environments.katacoda.com/stores) (try refreshing the Thanos UI if it does not show up straight away). | ||
We should see Receive store on this page and, as expected, no metric data since we did not connect any Remote Write sender yet. | ||
With our "central" platform that is ready to ingest metrics, we can now start to architect our collection pipeline that will stream all metrics to our `Wayne Enterprises`. |
12 changes: 12 additions & 0 deletions
12
tutorials/katacoda/thanos/4-receiver-agent/step2-verify.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/usr/bin/env bash | ||
|
||
# prometheus-batcave | ||
curl -s 127.0.0.1:9090/metrics >/dev/null || exit 1 | ||
# prometheus-batcomputer | ||
curl -s 127.0.0.1:9091/metrics >/dev/null || exit 1 | ||
# receive | ||
curl -s 127.0.0.1:10909/metrics >/dev/null || exit 1 | ||
# query | ||
curl -s 127.0.0.1:39090/metrics >/dev/null || exit 1 | ||
|
||
echo '"done"' |
Oops, something went wrong.