traffic

package
v0.4.0-beta.1 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2026 License: MIT Imports: 9 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)

func (*DB) REDSeries

func (db *DB) REDSeries(deploymentName string, since time.Time, bucket time.Duration) ([]REDPoint, error)

REDSeries returns a deployment's request rate, error rate and latency over time, bucketed.

Every deployment's traffic crosses FlatRun's proxy, and the proxy already reports each request here, so this is instrumentation of an application that was never asked to cooperate: no agent in the container, no change to the app.

An empty deployment name covers every deployment at once.

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) GetREDSeries

func (m *Manager) GetREDSeries(deploymentName string, since time.Duration) ([]REDPoint, error)

GetREDSeries returns a deployment's request rate, error rate and latency over time. The bucket is chosen from the window so a chart gets a useful number of points rather than one per second over a day.

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 REDPoint

type REDPoint struct {
	Time      time.Time `json:"time"`
	Requests  int64     `json:"requests"`
	Errors    int64     `json:"errors"`
	AvgTimeMs float64   `json:"avg_time_ms"`
	P95TimeMs float64   `json:"p95_time_ms"`
}

REDPoint is one time bucket of a deployment's request behaviour: how many requests, how many failed, and how long they took.

func (REDPoint) ErrorRate

func (p REDPoint) ErrorRate() float64

ErrorRate is the share of requests that failed, as a percentage.

func (REDPoint) RequestsPerSecond

func (p REDPoint) RequestsPerSecond(bucket time.Duration) float64

RequestsPerSecond is the rate over the bucket it was measured in.

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