+18
railway-resources/telegraf/Dockerfile
+18
railway-resources/telegraf/Dockerfile
···
1
+
# Telegraf Dockerfile for Railway Deployment
2
+
FROM telegraf:1.33-alpine
3
+
4
+
# Install additional packages for health checks
5
+
RUN apk add --no-cache curl postgresql-client
6
+
7
+
# Create directories for custom configs
8
+
RUN mkdir -p /etc/telegraf/telegraf.d
9
+
10
+
# Copy main configuration
11
+
COPY railway-resources/telegraf/telegraf.conf /etc/telegraf/telegraf.conf
12
+
13
+
# Health check - test configuration validity
14
+
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
15
+
CMD telegraf --config /etc/telegraf/telegraf.conf --test || exit 1
16
+
17
+
# Run telegraf with custom config
18
+
CMD ["telegraf", "--config", "/etc/telegraf/telegraf.conf", "--config-directory", "/etc/telegraf/telegraf.d"]
+48
railway-resources/telegraf/railway.toml
+48
railway-resources/telegraf/railway.toml
···
1
+
# Railway configuration for Telegraf service
2
+
# This file configures how Railway builds and deploys the Telegraf metrics collector
3
+
4
+
[build]
5
+
# Use Dockerfile for building
6
+
builder = "DOCKERFILE"
7
+
dockerfilePath = "railway-resources/telegraf/Dockerfile"
8
+
9
+
[deploy]
10
+
# Start command (handled by Dockerfile CMD)
11
+
startCommand = "telegraf --config /etc/telegraf/telegraf.conf"
12
+
13
+
# No health check path for Telegraf (uses container health check)
14
+
# healthcheckPath = ""
15
+
16
+
# Restart policy
17
+
restartPolicyType = "ALWAYS"
18
+
restartPolicyMaxRetries = 10
19
+
20
+
# Resource limits
21
+
memoryLimitMB = 1024
22
+
cpuLimitCores = 1
23
+
24
+
# Scaling (Telegraf should be singleton)
25
+
minReplicas = 1
26
+
maxReplicas = 1
27
+
28
+
# Graceful shutdown
29
+
stopTimeout = 10
30
+
31
+
# Service configuration for StatsD UDP endpoint
32
+
[[services]]
33
+
name = "telegraf-statsd"
34
+
port = 8125
35
+
protocol = "UDP"
36
+
internalPort = 8125
37
+
38
+
# Service configuration for Telegraf HTTP API (optional)
39
+
[[services]]
40
+
name = "telegraf-http"
41
+
port = 8086
42
+
protocol = "HTTP"
43
+
internalPort = 8086
44
+
45
+
# Environment-specific settings
46
+
[environments.production]
47
+
memoryLimitMB = 512
48
+
cpuLimitCores = 1
+77
railway-resources/telegraf/telegraf.conf
+77
railway-resources/telegraf/telegraf.conf
···
1
+
# Telegraf Configuration for QuickDID Metrics Collection
2
+
# Optimized for Railway deployment with TimescaleDB
3
+
4
+
# Global tags applied to all metrics
5
+
[global_tags]
6
+
environment = "${ENVIRONMENT:-production}"
7
+
service = "quickdid"
8
+
region = "${RAILWAY_REGION:-us-west1}"
9
+
deployment_id = "${RAILWAY_DEPLOYMENT_ID:-unknown}"
10
+
11
+
# Agent configuration
12
+
[agent]
13
+
## Default data collection interval
14
+
interval = "10s"
15
+
16
+
## Rounds collection interval to interval
17
+
round_interval = true
18
+
19
+
## Telegraf will send metrics to outputs in batches of at most metric_batch_size metrics.
20
+
metric_batch_size = 1000
21
+
22
+
## Maximum number of unwritten metrics per output
23
+
metric_buffer_limit = 10000
24
+
25
+
## Collection jitter is used to jitter the collection by a random amount
26
+
collection_jitter = "0s"
27
+
28
+
## Default flushing interval for all outputs
29
+
flush_interval = "10s"
30
+
31
+
## Jitter the flush interval by a random amount
32
+
flush_jitter = "0s"
33
+
34
+
## Precision of timestamps
35
+
precision = "1ms"
36
+
37
+
## Log level
38
+
debug = ${TELEGRAF_DEBUG:-false}
39
+
quiet = ${TELEGRAF_QUIET:-false}
40
+
41
+
## Override default hostname
42
+
hostname = "${HOSTNAME:-telegraf}"
43
+
44
+
## If true, do not set the "host" tag in the telegraf agent
45
+
omit_hostname = false
46
+
47
+
###############################################################################
48
+
# INPUT PLUGINS #
49
+
###############################################################################
50
+
51
+
# StatsD Server - receives metrics from QuickDID
52
+
[[inputs.statsd]]
53
+
service_address = ":8125" # Listen on UDP port 8125 for StatsD metrics
54
+
protocol = "udp"
55
+
delete_gauges = true
56
+
delete_counters = true
57
+
delete_sets = true
58
+
delete_timings = true
59
+
percentiles = [50, 90, 95, 99]
60
+
metric_separator = "."
61
+
allowed_pending_messages = 100
62
+
datadog_extensions = true
63
+
datadog_distributions = true
64
+
65
+
[[outputs.postgresql]]
66
+
connection = "${DATABASE_URL}"
67
+
68
+
schema = "public"
69
+
70
+
create_templates = [
71
+
'''CREATE TABLE IF NOT EXISTS {{.table}} ({{.columns}})''',
72
+
'''SELECT create_hypertable({{.table|quoteLiteral}}, 'time', if_not_exists => TRUE)''',
73
+
]
74
+
75
+
tags_as_jsonb = true
76
+
77
+
fields_as_jsonb = false
+2
-1
src/metrics.rs
+2
-1
src/metrics.rs
···
100
100
) -> Result<Self, Box<dyn std::error::Error>> {
101
101
tracing::info!("Creating StatsdMetricsPublisher: host={}, prefix={}, tags={:?}", host, prefix, default_tags);
102
102
103
-
let socket = UdpSocket::bind("0.0.0.0:0")?;
103
+
// let socket = UdpSocket::bind("0.0.0.0:0")?;
104
+
let socket = UdpSocket::bind("[::0]:0")?;
104
105
socket.set_nonblocking(true)?;
105
106
106
107
let buffered_sink = BufferedUdpMetricSink::from(host, socket)?;