traffic

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 25, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DB

type DB struct {
	// contains filtered or unexported fields
}

func NewDB

func NewDB(deploymentsPath string) (*DB, error)

func (*DB) Cleanup

func (db *DB) Cleanup(olderThan time.Duration) (int64, error)

func (*DB) Close

func (db *DB) Close() error

func (*DB) GetLogs

func (db *DB) GetLogs(filter *TrafficFilter) ([]TrafficLog, int, error)

func (*DB) GetStats

func (db *DB) GetStats(deploymentName string, since time.Duration) (*TrafficStats, error)

func (*DB) GetUnknownDomainStats

func (db *DB) GetUnknownDomainStats(knownDeployments []string, since time.Duration) (*UnknownDomainStats, error)

func (*DB) InsertLog

func (db *DB) InsertLog(log *TrafficLog) (int64, error)

type DeploymentTrafficStats

type DeploymentTrafficStats struct {
	Name            string  `json:"name"`
	TotalRequests   int64   `json:"total_requests"`
	AvgResponseTime float64 `json:"avg_response_time_ms"`
	ErrorRate       float64 `json:"error_rate"`
	Status2xx       int64   `json:"status_2xx"`
	Status3xx       int64   `json:"status_3xx"`
	Status4xx       int64   `json:"status_4xx"`
	Status5xx       int64   `json:"status_5xx"`
}

type HourlyStats

type HourlyStats struct {
	Hour         string `json:"hour"`
	RequestCount int64  `json:"request_count"`
}

type IPTrafficStats

type IPTrafficStats struct {
	IP           string    `json:"ip"`
	RequestCount int64     `json:"request_count"`
	BytesSent    int64     `json:"bytes_sent"`
	LastSeen     time.Time `json:"last_seen"`
}

type IngestTrafficLog

type IngestTrafficLog struct {
	DeploymentName string `json:"deployment_name"`
	RequestPath    string `json:"request_path"`
	RequestMethod  string `json:"request_method"`
	StatusCode     int    `json:"status_code"`
	SourceIP       string `json:"source_ip"`
	ResponseTimeMs int    `json:"response_time_ms"`
	BytesSent      int    `json:"bytes_sent"`
	RequestLength  int    `json:"request_length"`
	UpstreamTimeMs *int   `json:"upstream_time_ms,omitempty"`
	Timestamp      int64  `json:"timestamp"`
}

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

func NewManager

func NewManager(deploymentsPath string, retentionDays int) (*Manager, error)

func (*Manager) Cleanup

func (m *Manager) Cleanup(days int) (int64, error)

func (*Manager) Close

func (m *Manager) Close() error

func (*Manager) GetLogs

func (m *Manager) GetLogs(filter *TrafficFilter) ([]TrafficLog, int, error)

func (*Manager) GetStats

func (m *Manager) GetStats(deploymentName string, since time.Duration) (*TrafficStats, error)

func (*Manager) GetUnknownDomainStats

func (m *Manager) GetUnknownDomainStats(knownDeployments []string, since time.Duration) (*UnknownDomainStats, error)

func (*Manager) IngestLog

func (m *Manager) IngestLog(ingest *IngestTrafficLog) (*TrafficLog, error)

type PathStats

type PathStats struct {
	Path         string  `json:"path"`
	Deployment   string  `json:"deployment"`
	RequestCount int64   `json:"request_count"`
	AvgTimeMs    float64 `json:"avg_time_ms"`
	ErrorCount   int64   `json:"error_count"`
}

type TrafficFilter

type TrafficFilter struct {
	DeploymentName string
	RequestMethod  string
	StatusCode     *int
	StatusGroup    string // "2xx", "3xx", "4xx", "5xx"
	SourceIP       string
	RequestPath    string
	StartTime      time.Time
	EndTime        time.Time
	Limit          int
	Offset         int
}

type TrafficLog

type TrafficLog struct {
	ID             int64     `json:"id"`
	DeploymentName string    `json:"deployment_name"`
	RequestPath    string    `json:"request_path"`
	RequestMethod  string    `json:"request_method"`
	StatusCode     int       `json:"status_code"`
	SourceIP       string    `json:"source_ip"`
	ResponseTimeMs int       `json:"response_time_ms"`
	BytesSent      int       `json:"bytes_sent"`
	RequestLength  int       `json:"request_length"`
	UpstreamTimeMs *int      `json:"upstream_time_ms,omitempty"`
	CreatedAt      time.Time `json:"created_at"`
}

type TrafficStats

type TrafficStats struct {
	TotalRequests     int64                    `json:"total_requests"`
	TotalBytes        int64                    `json:"total_bytes"`
	AvgResponseTimeMs float64                  `json:"avg_response_time_ms"`
	ByStatusGroup     map[string]int64         `json:"by_status_group"`
	ByDeployment      map[string]int64         `json:"by_deployment"`
	ByMethod          map[string]int64         `json:"by_method"`
	TopPaths          []PathStats              `json:"top_paths"`
	TopIPs            []IPTrafficStats         `json:"top_ips"`
	RequestsPerHour   []HourlyStats            `json:"requests_per_hour"`
	DeploymentStats   []DeploymentTrafficStats `json:"deployment_stats"`
}

type UnknownDomainEntry

type UnknownDomainEntry struct {
	Domain       string    `json:"domain"`
	RequestCount int64     `json:"request_count"`
	LastSeen     time.Time `json:"last_seen"`
}

type UnknownDomainIPEntry

type UnknownDomainIPEntry struct {
	IP           string    `json:"ip"`
	RequestCount int64     `json:"request_count"`
	Domains      []string  `json:"domains"`
	LastSeen     time.Time `json:"last_seen"`
}

type UnknownDomainStats

type UnknownDomainStats struct {
	TotalRequests int64                  `json:"total_requests"`
	TopDomains    []UnknownDomainEntry   `json:"top_domains"`
	TopIPs        []UnknownDomainIPEntry `json:"top_ips"`
	RecentLogs    []TrafficLog           `json:"recent_logs"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL