# Configuration

This guide covers all configuration options for socktop client and agent.

## Client Configuration

### Configuration File Location

By default, socktop looks for configuration in:

- **Linux**: `~/.config/socktop/`
- **Custom**: Set `XDG_CONFIG_HOME` environment variable

### Command-Line Options

```bash
socktop_agent --help

OPTIONS:
    --port <PORT>              Port to listen on [default: 3000]
    --host <HOST>              Host/IP to bind to [default: 0.0.0.0]
    --token <TOKEN>            Authentication token (optional)
    --tls-cert <FILE>          TLS certificate path (optional)
    --tls-key <FILE>           TLS private key path (optional)
    --log-level <LEVEL>        Log level: error, warn, info, debug, trace
    --cache-duration <MS>      Metrics cache duration in milliseconds [default: 1000]
    --max-processes <NUM>      Maximum processes to report [default: 100]
    --enable-journald          Enable journald log collection
    --journald-lines <NUM>     Number of journal lines to keep [default: 1000]
```

### Configuration File (APT Installation)

Edit `/etc/default/socktop-agent`:

```bash
# Port configuration
PORT=3000

# Bind address (0.0.0.0 for all interfaces, 127.0.0.1 for local only)
HOST=0.0.0.0

# Authentication token
# Uncomment and set for token-based auth
# TOKEN=your-secret-token-here

# TLS configuration
# Uncomment to enable TLS
# TLS_CERT=/etc/socktop/cert.pem
# TLS_KEY=/etc/socktop/key.pem

# Log level (error, warn, info, debug, trace)
LOG_LEVEL=info

# Cache duration (milliseconds)
CACHE_DURATION=1000

# Maximum processes to report
MAX_PROCESSES=100

# Enable journald collection
ENABLE_JOURNALD=false

# Additional options
# OPTIONS="--some-option --another-option"
```

After editing, restart the service:

```bash
sudo systemctl restart socktop-agent
```

### Environment Variables (debugging)

Override settings with environment variables:

```bash
# Refresh rate
export SOCKTOP_REFRESH_RATE=2000

# Default profile
export SOCKTOP_DEFAULT_PROFILE=production

# Config directory
export SOCKTOP_CONFIG_DIR=~/.config/socktop

# Disable TLS verification (not recommended)
export SOCKTOP_NO_VERIFY_TLS=1

# Authentication token
export SOCKTOP_TOKEN=your-secret-token
```

### Agent Environment Variables (debugging)

```bash
# Port
export SOCKTOP_AGENT_PORT=3000

# Host
export SOCKTOP_AGENT_HOST=0.0.0.0

# Token
export SOCKTOP_AGENT_TOKEN=secret

# TLS cert path
export SOCKTOP_AGENT_TLS_CERT=/path/to/cert.pem

# TLS key path
export SOCKTOP_AGENT_TLS_KEY=/path/to/key.pem

# Log level
export SOCKTOP_AGENT_LOG_LEVEL=info
```
