Lotty is a Go program that sends command output to Grafana Loki via HTTP API. It supports PTY capabilities, in-memory buffering, and batch sending.
git clone https://github.com/yourname/lotty.git
cd lotty
make build
docker build -t lotty:latest . docker run -e LOKI_ENDPOINT=http://loki:3100 \ -e LOKI_USERNAME=admin \ -e LOKI_PASSWORD=password \ lotty:latest -- your-command
All configuration items support environment variables. Priority: command-line arguments > environment variables > default values
| Variable Name | Description | Default Value |
|---|---|---|
LOKI_ENDPOINT | Loki service address | None (required) |
LOKI_USERNAME | Basic Auth username | None |
LOKI_PASSWORD | Basic Auth password | None |
LOKI_LABELS | Loki labels, format key=value | None |
BUFFER_SIZE | Buffer size | 10000 |
BATCH_INTERVAL | Batch sending interval | 900ms |
BATCH_SIZE | Batch size | 1000 |
RETRY_COUNT | Retry count | 3 |
INPUT_MODE | Input mode (pty/pipe) | pty |
LOG_LEVEL | Log level | info |
lotty [flags] -- command [args...]
Flags:
--config string Configuration file (default is $HOME/.lotty.yaml)
--input-mode string Input mode (pty, pipe) (default "pty")
--log-level string Log level (debug, info, warn, error) (default "info")
-h, --help Show help information
# Configure using environment variables
export LOKI_ENDPOINT="http://localhost:3100/loki/api/v1/push"
export LOKI_USERNAME="admin"
export LOKI_PASSWORD="password"
export LOKI_LABELS="service=myapp,env=prod"
# Send ping output to Loki
lotty -- ping google.com
# Monitor log files
lotty --input-mode pipe -- tail -f /var/log/app.log
# Monitor application output (supports colored output and interactive programs)
lotty -- my-app --arg1 --arg2
Command Output → PTY/Pipe Capture → Line Parsing → Memory Buffer → Batch Processor → HTTP Client → Loki
# Run all tests
make test
# Generate test coverage report
make test-coverage
# Run linter
make lint
# Format code
make fmt
# Build binary
make build
# Cross-compile
make build-all
lotty/ ├── cmd/lotty/main.go # Main entry point ├── internal/ │ ├── config/ # Configuration management │ ├── input/ # Input processing (pty + reader) │ ├── buffer/ # Ring buffer │ ├── loki/ # HTTP client + Auth │ ├── batcher/ # Batch processor │ └── retry/ # Retry mechanism ├── pkg/ │ └── types/ # Common types ├── go.mod ├── go.sum ├── Makefile ├── Dockerfile └── README.md
MIT License
Pull Requests and Issues are welcome.