Skip to content

awsutils/sniff2cw

sniff2cw

A Go application that sniffs ingress/egress HTTP traffic for a target application, maps request/response pairs, and ships logs to AWS CloudWatch Logs. Also emits CloudWatch Metrics for health, latency, request counts, payload size, and HTTP status codes.

Requirements

  • Linux, any kernel (capture method is auto-selected from best available)
  • Minimum capabilities: CAP_NET_RAW (for AF_PACKET / pcap fallback paths)
  • For eBPF paths: additionally CAP_BPF, CAP_NET_ADMIN, CAP_PERFMON; kernel ≥ 4.18 with /sys/kernel/btf/vmlinux

sniff2cw tries capture methods in priority order — eBPF TCX → eBPF cls_bpf → AF_PACKET TPACKET_V3 → pcap — and uses the first that succeeds. See SPEC.md for the full priority table.

Quick Start

APP_NAME=my-service \
APP_PORT=8080 \
DIRECTION=BOTH \
LOG_GROUP_NAME=/app/log/my-service \
./sniff2cw

Environment Variables

Variable Default Description
APP_NAME hostname Identifier used in CloudWatch Logs and Metrics
APP_PORT 8080 Port of the target application
DIRECTION BOTH Traffic direction: BOTH, INGRESS, or EGRESS
HEALTH_URLS 127.0.0.1:{APP_PORT}/health Comma-separated health check endpoints
LOG_GROUP_NAME /app/log/{APP_NAME} CloudWatch Logs group name
LOG_STREAM_NAME hostname CloudWatch Logs stream name
MAX_BODY_BYTES 4096 Max bytes captured per body (0 = disabled, max 65536)
EKS_CLUSTER_NAME (empty) Kubernetes cluster name for platform metadata
K8S_POD_NAME (empty) Pod name (inject via Kubernetes downward API)
K8S_POD_NAMESPACE (empty) Namespace (inject via Kubernetes downward API)
K8S_NODE_NAME (empty) Node name (inject via Kubernetes downward API)

See SPEC.md for full details including HEALTH_URLS shorthand syntax, log/metric formats, and fail-safe behavior. See TESTING.md for the WSL2 test setup guide.

Log Format

Each matched request/response pair is logged as minified JSON to stdout and CloudWatch Logs:

{
  "_q": "my-service INGRESS /api/foo 200 42ms",
  "app_name": "my-service",
  "direction": "INGRESS",
  "delay": 42,
  "platform": { "ec2_instance_id": "i-0abc123", "ec2_region": "us-east-1", "..." : "..." },
  "request": { "time": 1700000000000, "method": "POST", "path": "/api/foo", "..." : "..." },
  "response": { "time": 1700000000042, "status": 200, "..." : "..." }
}

The platform key is omitted when no EC2/ECS/EKS metadata is detected. See SPEC.md for the full field list.

Metrics

Published under sniff2cw/{APP_NAME} in CloudWatch Metrics:

  • HealthStatus — health check up/down per endpoint
  • HealthLatency — health check response time
  • RequestCount / ErrorCount — total and error requests
  • Latency — request-to-response delay
  • RequestBodySize / ResponseBodySize — payload sizes
  • StatusCode — request count by HTTP status code

Security

See CONTRIBUTING for more information.

License

This library is licensed under the MIT-0 License. See the LICENSE file.

About

sniff2cw is the HTTP packet sniffer with report to CloudWatch Logs

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors