Skip to content

Commit c665fb1

Browse files
committed
StatsD: Index page and tutorial
1 parent 26db150 commit c665fb1

File tree

4 files changed

+243
-0
lines changed

4 files changed

+243
-0
lines changed

docs/ingest/telemetry/index.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ for collecting metrics data from applications and infrastructures.
6565
Send logs with rsyslog, a rocket‑fast system for log processing.
6666
::::
6767

68+
::::{grid-item-card} StatsD
69+
:link: statsd
70+
:link-type: ref
71+
Store metrics and statistics from StatsD, a daemon for stats aggregation.
72+
::::
73+
6874
::::{grid-item-card} Telegraf
6975
:link: telegraf
7076
:link-type: ref

docs/integrate/statsd/index.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
(statsd)=
2+
# StatsD
3+
4+
```{div} .float-right
5+
[![StatsD logo](https://avatars.githubusercontent.com/u/8270030?s=200&v=4){height=100px loading=lazy}][StatsD]
6+
```
7+
```{div} .clearfix
8+
```
9+
10+
:::{rubric} About
11+
:::
12+
13+
[StatsD] is a daemon for easy but powerful system and application
14+
metrics and stats aggregation.
15+
16+
It is a network daemon that runs on the Node.js platform and listens for
17+
statistics, like counters and timers, sent over UDP or TCP and sends
18+
aggregates to one or more pluggable backend services.
19+
20+
StatsD traditionally uses the Graphite backend and its successors, but it
21+
can also use CrateDB as a backend, by relaying data through Telegraf and
22+
using its built-in [CrateDB Output Plugin for Telegraf].
23+
24+
:::{rubric} Synopsis
25+
:::
26+
27+
Configure Telegraf using the StatsD input plugin and the CrateDB output plugin.
28+
29+
:::{literalinclude} telegraf.conf
30+
:::
31+
32+
33+
:::{rubric} Learn
34+
:::
35+
36+
::::{grid}
37+
38+
:::{grid-item-card} Tutorial: Use StatsD with CrateDB
39+
:link: statsd-tutorial
40+
:link-type: ref
41+
How to configure StatsD and Telegraf to submit statistics to CrateDB.
42+
:::
43+
44+
::::
45+
46+
47+
:::{toctree}
48+
:maxdepth: 1
49+
:hidden:
50+
Tutorial <tutorial>
51+
:::
52+
53+
54+
[CrateDB Output Plugin for Telegraf]: https://github.com/influxdata/telegraf/tree/master/plugins/outputs/cratedb
55+
[StatsD]: https://github.com/statsd/statsd
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# StatsD Input Plugin
2+
# https://github.com/influxdata/telegraf/tree/master/plugins/inputs/statsd
3+
[[inputs.statsd]]
4+
## Protocol, must be "tcp", "udp4", "udp6" or "udp" (default=udp)
5+
protocol = "udp"
6+
7+
## Address and port to host UDP listener on
8+
service_address = ":8125"
9+
10+
interval = "5s"
11+
12+
# CrateDB Output Plugin
13+
# https://github.com/influxdata/telegraf/tree/master/plugins/outputs/cratedb
14+
[[outputs.cratedb]]
15+
## Connection parameters for accessing the database see
16+
## https://pkg.go.dev/github.com/jackc/pgx/v4#ParseConfig
17+
## for available options
18+
url = "postgres://crate:crate@cratedb/doc?sslmode=disable"
19+
20+
## Timeout for all CrateDB queries.
21+
# timeout = "5s"
22+
23+
## Name of the table to store metrics in.
24+
# table = "metrics"
25+
26+
## If true, and the metrics table does not exist, create it automatically.
27+
table_create = true
28+
29+
## The character(s) to replace any '.' in an object key with
30+
# key_separator = "_"

docs/integrate/statsd/tutorial.md

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
(statsd-tutorial)=
2+
# Load data into CrateDB using StatsD and Telegraf
3+
4+
This tutorial walks you through configuring [Telegraf] to receive [StatsD]
5+
metrics and store them into CrateDB.
6+
7+
## Prerequisites
8+
9+
Docker is used for running all components. This approach works consistently
10+
across Linux, macOS, and Windows. Alternatively, you can use Podman.
11+
12+
### CLI
13+
14+
Prepare shortcut for the psql command.
15+
16+
::::{tab-set}
17+
:sync-group: os
18+
19+
:::{tab-item} Linux and macOS
20+
:sync: unix
21+
To make the settings persistent, add them to your shell profile (`~/.profile`).
22+
```shell
23+
alias nc="docker run --rm -i --network=cratedb-demo docker.io/toolbelt/netcat"
24+
alias psql="docker run --rm -i --network=cratedb-demo docker.io/postgres psql"
25+
```
26+
:::
27+
:::{tab-item} Windows PowerShell
28+
:sync: powershell
29+
To make the settings persistent, add them to your PowerShell profile (`$PROFILE`).
30+
```powershell
31+
function psql { docker run --rm -i --network=cratedb-demo docker.io/postgres psql @args }
32+
```
33+
:::
34+
:::{tab-item} Windows Command
35+
:sync: dos
36+
```shell
37+
doskey psql=docker run --rm -i --network=cratedb-demo docker.io/postgres psql $*
38+
```
39+
:::
40+
41+
::::
42+
43+
### CrateDB
44+
45+
Create a shared network.
46+
```shell
47+
docker network create cratedb-demo
48+
```
49+
50+
Start CrateDB.
51+
```shell
52+
docker run --name=cratedb --rm -it --network=cratedb-demo \
53+
--publish=4200:4200 --publish=5432:5432 \
54+
--env=CRATE_HEAP_SIZE=2g docker.io/crate -Cdiscovery.type=single-node
55+
```
56+
57+
58+
## Configure Telegraf
59+
60+
Configure Telegraf to receive StatsD and to store them
61+
in CrateDB, by using the configuration blueprint outlined below, possibly
62+
adjusting it to match your environment. Store this file under the name
63+
`telegraf.conf`.
64+
65+
:::{literalinclude} telegraf.conf
66+
:::
67+
68+
69+
## Start Telegraf
70+
71+
::::{tab-set}
72+
:sync-group: os
73+
74+
:::{tab-item} Linux and macOS
75+
:sync: unix
76+
```shell
77+
docker run --name=telegraf --rm -it --network=cratedb-demo \
78+
--volume "$(pwd)"/telegraf.conf:/etc/telegraf/telegraf.conf \
79+
--publish 8125:8125/udp \
80+
docker.io/telegraf
81+
```
82+
:::
83+
:::{tab-item} Windows PowerShell
84+
:sync: powershell
85+
```powershell
86+
docker run --name=telegraf --rm -it --network=cratedb-demo `
87+
--volume "${PWD}\telegraf.conf:/etc/telegraf/telegraf.conf" `
88+
--publish 8125:8125/udp `
89+
docker.io/telegraf
90+
```
91+
:::
92+
:::{tab-item} Windows Command
93+
:sync: dos
94+
```shell
95+
docker run --name=telegraf --rm -it --network=cratedb-demo ^
96+
--volume "%cd%\telegraf.conf:/etc/telegraf/telegraf.conf" ^
97+
--publish 8125:8125/udp ^
98+
docker.io/telegraf
99+
```
100+
:::
101+
::::
102+
103+
## Submit data
104+
105+
### netcat
106+
Use [netcat] for submitting data.
107+
```shell
108+
echo "temperature:42|g\nhumidity:84|g" | nc -C -w 1 -u telegraf 8125
109+
```
110+
111+
### Python
112+
Use the [statsd package] to submit data from your Python application.
113+
```shell
114+
uv pip install statsd
115+
```
116+
```python
117+
from statsd import StatsClient
118+
119+
statsd = StatsClient("localhost", 8125)
120+
statsd.gauge("temperature", 42)
121+
statsd.gauge("humidity", 84)
122+
statsd.close()
123+
```
124+
125+
### Any
126+
127+
Use any of the available [StatsD client libraries] for Node.js, Java, Python,
128+
Ruby, Perl, PHP, Clojure, Io, C, C++, .NET, Go, Apache, Varnish, PowerShell,
129+
Browser, Objective-C, ActionScript, WordPress, Drupal, Haskell, R, Lua, or
130+
Nim.
131+
132+
## Explore data
133+
134+
After receiving data, the first metrics will appear in the designated table in
135+
CrateDB, ready to be inspected.
136+
```shell
137+
psql "postgresql://crate:crate@cratedb:5432/" -c "SELECT * FROM doc.metrics ORDER BY timestamp LIMIT 5;"
138+
```
139+
```psql
140+
hash_id | timestamp | name | tags | fields | day
141+
----------------------+----------------------------+-------------+-----------------------------------------------+--------------+----------------------------
142+
-8005856065082590291 | 2025-09-20 19:30:45.000+00 | temperature | {"host":"2748411a9651","metric_type":"gauge"} | {"value":42} | 2025-09-20 00:00:00.000+00
143+
7068016256787696496 | 2025-09-20 19:30:45.000+00 | humidity | {"host":"2748411a9651","metric_type":"gauge"} | {"value":84} | 2025-09-20 00:00:00.000+00
144+
(2 rows)
145+
```
146+
147+
148+
[netcat]: https://en.wikipedia.org/wiki/Netcat
149+
[StatsD]: https://github.com/statsd/statsd
150+
[statsd package]: https://pypi.org/project/statsd/
151+
[StatsD client libraries]: https://github.com/statsd/statsd/wiki#client-implementations
152+
[Telegraf]: https://www.influxdata.com/time-series-platform/telegraf/

0 commit comments

Comments
 (0)