Skip to content

Commit fdc4a65

Browse files
committed
Merge #133: New article: Visualize Stats with Prometheus and Grafana
41b835f feat: new artivle: Visualize Stats with Prometheous and Grafana (Jose Celano) Pull request description: New article: Visualize Stats with Prometheus and Grafana ACKs for top commit: josecelano: ACK 41b835f Tree-SHA512: 54d9428885caafd307887fe21f74b2b1e409f4693f16aa3103bcf79aadc1c3fb24d09626bbc045c9dd17005c56cc146f4338f28e23038c3c8e52393752d4fa4d
2 parents d5b55a4 + 41b835f commit fdc4a65

File tree

3 files changed

+242
-0
lines changed

3 files changed

+242
-0
lines changed
Lines changed: 242 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,242 @@
1+
---
2+
title: 'Visualize Tracker Metrics with Prometheus and Grafana'
3+
slug: 'visualize-tracker-metrics-prometheus-grafana'
4+
coverImage: '/images/posts/visualize-tracker-metrics-prometheus-grafana/tracker-stats-visualized-with-grafana.webp'
5+
date: 2024-12-13T11:43:34.921Z
6+
updated: 2024-12-13T11:43:34.921Z
7+
excerpt: "Learn how to set up Prometheus and Grafana to monitor the Torrust Tracker's performance metrics and contribute to shaping future enhancements."
8+
contributor: Jose Celano
9+
contributorSlug: jose-celano
10+
tags:
11+
- Torrust Tracker
12+
- Prometheus
13+
- Grafana
14+
- Statistics
15+
- Community
16+
hidden: false
17+
---
18+
19+
<script>
20+
import Callout from "$lib/components/molecules/Callout.svelte";
21+
import CodeBlock from "$lib/components/molecules/CodeBlock.svelte";
22+
import Image from "$lib/components/atoms/Image.svelte";
23+
import PostBody from "$lib/components/molecules/PostBody.svelte";
24+
import PostContainer from "$lib/components/molecules/PostContainer.svelte";
25+
import PostTable from "$lib/components/molecules/PostTable.svelte";
26+
import TableOfContents from '$lib/components/atoms/TableOfContents.svelte';
27+
28+
let sections = [
29+
{ name: "Introduction", id: "introduction" },
30+
{ name: "Setting Up Prometheus and Grafana", id: "setting-up-prometheus-and-grafana" },
31+
{ name: "Visualizing Metrics", id: "visualizing-metrics" },
32+
{ name: "Future Plans and Challenges", id: "future-plans-and-challenges" },
33+
{ name: "Call for Community Input", id: "call-for-community-input" },
34+
];
35+
36+
let activeSection = '';
37+
</script>
38+
39+
<PostContainer>
40+
<PostTable>
41+
42+
## Table of contents
43+
44+
<TableOfContents {sections} {activeSection} />
45+
46+
</PostTable>
47+
48+
<PostBody>
49+
50+
## Introduction
51+
52+
The Torrust Tracker has taken a significant leap forward with a newly added feature: the ability to export its statistics in the **Prometheus** format. This update enables admins to visualize tracker metrics seamlessly using **Grafana**. As this has been a highly requested feature, we’re excited to share its details and how you can set it up in your own environment.
53+
54+
With this addition, the Torrust Tracker provides better insights into its performance and behavior, paving the way for more informed decision-making and robust tracker management.
55+
56+
## Setting Up Prometheus and Grafana
57+
58+
To make the integration process as smooth as possible, we’ve updated the [Torrust Demo repository](https://github.com/torrust/torrust-demo) with the necessary **Docker Compose** configuration. By following the provided documentation, you can quickly set up a monitoring stack that includes Prometheus and Grafana.
59+
60+
We will not include instructions about how to install Prometheus and Grafana. Please follow the official documentation. We will only highlight some things to consider.
61+
62+
This is the new services added to the docker compose configuration we are using in the live demo:
63+
64+
<CodeBlock lang="yml">
65+
66+
```yml
67+
grafana:
68+
image: grafana/grafana:11.4.0
69+
container_name: grafana
70+
restart: unless-stopped
71+
environment:
72+
- GF_SECURITY_ADMIN_USER=${GF_SECURITY_ADMIN_USER:-admin}
73+
- GF_SECURITY_ADMIN_PASSWORD=${GF_SECURITY_ADMIN_PASSWORD:-admin}
74+
networks:
75+
- backend_network
76+
ports:
77+
- '3100:3000'
78+
volumes:
79+
- grafana_data:/var/lib/grafana
80+
depends_on:
81+
- prometheus
82+
83+
prometheus:
84+
image: prom/prometheus:v3.0.1
85+
container_name: prometheus
86+
tty: true
87+
restart: unless-stopped
88+
networks:
89+
- backend_network
90+
ports:
91+
- '9090:9090' # This port should not be exposed to the internet
92+
volumes:
93+
- ./storage/prometheus/etc:/etc/prometheus:Z
94+
logging:
95+
options:
96+
max-size: '10m'
97+
max-file: '10'
98+
depends_on:
99+
- tracker
100+
101+
volumes:
102+
grafana_data: {}
103+
```
104+
105+
</CodeBlock>
106+
107+
<Callout type="warning">
108+
109+
You have to provide a docker compose environment variable `GF_SECURITY_ADMIN_PASSWORD` with the password for the Grafana `admin` user.
110+
111+
</Callout>
112+
113+
The `Nginx` service was also changed a little bit to make sure it's started after the Grafana container. We need that to server Grafana via Nginx (to use HTTPs).
114+
115+
<CodeBlock lang="yml">
116+
117+
```yml
118+
proxy:
119+
# The rest of the configuration is the same ...
120+
depends_on:
121+
- index-gui
122+
- index
123+
- tracker
124+
- grafana
125+
```
126+
127+
</CodeBlock>
128+
129+
THe Prometheus configuration is very simple. We only need to set the Tracker URL.
130+
131+
<CodeBlock lang="yml">
132+
133+
```yml
134+
global:
135+
scrape_interval: 15s # How often to scrape metrics
136+
137+
scrape_configs:
138+
- job_name: 'tracker_metrics'
139+
metrics_path: '/api/v1/stats'
140+
params:
141+
token: ['MyAccessToken']
142+
format: ['prometheus']
143+
static_configs:
144+
- targets: ['tracker:1212']
145+
```
146+
147+
</CodeBlock>
148+
149+
<Callout type="warning">
150+
151+
Be aware Prometheus does not have authentication and the configuration includes the Tracker API token. To avoid exposing the token you need to close the Prometheus port (`9090`) in the server firewall.
152+
153+
</Callout>
154+
155+
If you want to setup [Grafana behind the Nginx proxy](https://grafana.com/tutorials/run-grafana-behind-a-proxy/) as we do you will also need to change the [Nginx configuration](https://github.com/torrust/torrust-demo/blob/main/share/container/default/config/nginx.conf).
156+
157+
Please, follow the latest [Grafana documentation for configuration using a reverse proxy](https://grafana.com/tutorials/run-grafana-behind-a-proxy/).
158+
159+
<Callout type="info">
160+
161+
To generate the Let's Encrypt certificate you will need to enable Grafana on port 80 temporarily. The process is the same as the one described in the [Deploying Torrust to Production](https://torrust.com/blog/deploying-torrust-to-production) blog post.
162+
163+
</Callout>
164+
165+
## Visualizing Metrics
166+
167+
Once the setup is complete, you’ll have access to essential tracker statistics. The stats are imported into Prometheus from the Tracker via the REST API.
168+
169+
Endpoint with the new format: <https://127.0.0.1/api/v1/stats?token=MyAccessToken&format=prometheus>
170+
171+
<CodeBlock lang="text">
172+
173+
```text
174+
torrents 250966
175+
seeders 71116
176+
completed 3395
177+
leechers 201896
178+
tcp4_connections_handled 0
179+
tcp4_announces_handled 0
180+
tcp4_scrapes_handled 0
181+
tcp6_connections_handled 0
182+
tcp6_announces_handled 0
183+
tcp6_scrapes_handled 0
184+
udp4_connections_handled 2692635
185+
udp4_announces_handled 7015031
186+
udp4_scrapes_handled 129299
187+
udp4_errors_handled 2418729
188+
udp6_connections_handled 0
189+
udp6_announces_handled 0
190+
udp6_scrapes_handled 0
191+
udp6_errors_handled 0
192+
```
193+
194+
</CodeBlock>
195+
196+
[We are considering adding new metrics](https://github.com/torrust/torrust-tracker/issues/1128).
197+
198+
<Callout type="warning">
199+
200+
The new format for the endpoint is not yet stable. We could change the data returned by the endpoint in the Prometheus format
201+
202+
</Callout>
203+
204+
Some changes that might be introduced in the future are:
205+
206+
- Changing the names. See [recommendations](https://prometheus.io/docs/practices/naming/).
207+
- Adding labels. See: [data model](https://prometheus.io/docs/concepts/data_model/).
208+
209+
Once Prometheus and Grafana are configured you can create new dashboards. These dashboards provide actionable insights to optimize tracker performance and identify potential issues.
210+
211+
Sample dashboard after running the demo tracker for 3 hours:
212+
213+
<Image src="/images/posts/visualize-tracker-metrics-prometheus-grafana/tracker-stats-visualized-with-grafana-dashboard.webp" alt="Sample dashboard in Grafana" />
214+
215+
## Future Plans and Challenges
216+
217+
While the current implementation is a step forward, we recognize the need for further enhancements:
218+
219+
1. **Adding More Metrics**: We’re actively working on expanding the range of metrics to provide even deeper insights into tracker operations.
220+
2. **User-Specific Statistics**: Private trackers often require detailed user statistics, but integrating this with Prometheus and Grafana poses scalability challenges. Handling thousands of users with numerous stats per user could impact tracker performance and slow down data imports via the API.
221+
222+
### **Exploring Alternatives**
223+
224+
We’re exploring potential solutions to overcome these limitations, such as:
225+
226+
- Dedicated database systems for user statistics.
227+
- Event-driven architectures to handle metrics in real-time.
228+
229+
We invite the community to share ideas and propose alternative approaches to ensure the tracker remains efficient and scalable.
230+
231+
## Call for Community Input
232+
233+
Your feedback is crucial in shaping the future of the Torrust Tracker. Here’s how you can get involved:
234+
235+
- **Join the Discussion**: Participate in our [GitHub discussions](https://github.com/torrust/torrust-tracker/discussions) to share your thoughts on improving [tracker statistics](https://github.com/torrust/torrust-tracker/discussions/820).
236+
- **Propose Metrics**: Let us know what additional metrics would benefit you as a tracker admin.
237+
- **Suggest Alternatives**: If you’re familiar with tools that could better handle large-scale user statistics, we want to hear about them.
238+
239+
Together, we can continue to enhance the Torrust Tracker and meet the evolving needs of our community. Let’s build a more robust and insightful tracker experience!
240+
241+
</PostBody>
242+
</PostContainer>
98.7 KB
Loading
52.3 KB
Loading

0 commit comments

Comments
 (0)