This page covers configuration for tcollector deployments.
| File | Purpose |
|---|---|
etc/tcollector.conf |
Main configuration file |
collectors/ |
Collector scripts directory |
Edit etc/tcollector.conf:
[default]
# OpenTSDB host
opentsdb_host = opentsdb.example.com
# OpenTSDB port
opentsdb_port = 4242
# Collectors directory
collectors = /opt/tcollector/collectors
# Dry run (don't send to OpenTSDB)
dry_run = False
# Verbose logging
verbose = True
Enable/disable system collectors in the config:
[collectors]
# CPU metrics
cpu = True
# Memory metrics
memory = True
# Disk metrics
disk = True
# Network metrics
network = True
# Load average
loadavg = True
# Uptime
uptime = True
Create custom Python collector scripts in the collectors/ directory:
#!/usr/bin/env python3
"""
Custom collector for application metrics
"""
import sys
import time
COLLECTION_INTERVAL = 30
def main():
last_time = int(time.time())
last_value = 0
while True:
now = int(time.time())
# Get your metric value
value = get_metric_value()
# Calculate rate if needed
rate = (value - last_value) / (now - last_time)
# Output in tcollector format
print(f"app.requests {now} {rate} source=web01")
sys.stdout.flush()
last_time = now
last_value = value
time.sleep(COLLECTION_INTERVAL)
def get_metric_value():
# Your metric collection logic
return 42
if __name__ == "__main__":
main()
tcollector uses a tag-based model. Add tags to your metrics:
metric_name tag1=value1 tag2=value2 value
Example:
cpu.usage host=web01 cpu=0 type=user 45.2
memory.used host=web01 type=physical 8192
disk.io host=db01 device=sda read 1024
# Start tcollector
./startstop start
# Run in foreground
./startstop foreground
# Stop tcollector
./startstop stop
# Check status
./startstop status
# Check logs
tail -f /var/log/tcollector.log
# Query OpenTSDB for metrics
curl "http://opentsdb:4242/api/suggest?type=metrics&q=cpu"
# Check tcollector process
ps aux | grep tcollector
| Collector | Purpose | Metrics |
|---|---|---|
cpu.py |
CPU usage | cpu.usage, cpu.interrupt |
memory.py |
Memory usage | memory.used, memory.free |
disk.py |
Disk I/O | disk.io, disk.space |
network.py |
Network stats | net.bytes, net.packets |
loadavg.py |
Load average | loadavg.1m, loadavg.5m |
uptime.py |
System uptime | uptime.seconds |
Check collector permissions:
chmod +x collectors/*.py
Verify OpenTSDB connectivity:
telnet opentsdb.example.com 4242
Review tag usage to avoid excessive metric combinations: