nginx

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CalculateDockerRequestRate

func CalculateDockerRequestRate(containerID string) (float64, int64, error)

CalculateDockerRequestRate calculates request rate from Docker container logs

func DetectDockerNginx

func DetectDockerNginx() (string, error)

DetectDockerNginx checks if NGINX is running in Docker and returns container ID

func DockerDisableSite

func DockerDisableSite(containerID, siteName string) error

DockerDisableSite - Not applicable for Docker (sites are in config)

func DockerEnableSite

func DockerEnableSite(containerID, siteName string) error

DockerEnableSite - Not applicable for Docker (sites are in config)

func DockerReload

func DockerReload(containerID string) error

DockerReload reloads NGINX in Docker container

func DockerTestConfig

func DockerTestConfig(containerID string) error

DockerTestConfig tests NGINX config in Docker container

func FormatLogEntry

func FormatLogEntry(entry LogEntry) string

FormatLogEntry formats a log entry for display with colors and detailed information

func GetDockerNginxPorts

func GetDockerNginxPorts(containerID string) ([]string, error)

GetDockerNginxPorts gets ports from Docker container

func GetDockerNginxSites

func GetDockerNginxSites(containerID string) ([]model.Site, error)

GetDockerNginxSites gets sites from Docker NGINX container

func IsDockerAvailable

func IsDockerAvailable() bool

IsDockerAvailable checks if docker command is available

func ParseLogLine

func ParseLogLine(line string) string

ParseLogLine parses an NGINX access log line and returns a styled version

Types

type LogEntry

type LogEntry struct {
	IP          string
	Timestamp   time.Time
	Method      string
	Path        string
	StatusCode  int
	BytesSent   int
	UserAgent   string
	Referer     string
	StatusClass string // "2xx", "3xx", "4xx", "5xx"
}

LogEntry represents a parsed NGINX log entry

func GetDockerAccessLogs

func GetDockerAccessLogs(containerID string, lines int) ([]LogEntry, error)

GetDockerAccessLogs reads access logs from Docker container

type LogStats

type LogStats struct {
	TotalRequests      int
	UniqueIPs          int
	StatusCounts       map[string]int // "2xx", "3xx", "4xx", "5xx"
	MethodCounts       map[string]int // "GET", "POST", etc.
	TopPaths           map[string]int
	TotalBytes         int64
	AvgBytesPerRequest int64
}

LogStats represents aggregated log statistics

type Metrics

type Metrics struct {
	CPU            float64
	Memory         float64
	NetworkIn      float64 // Total bytes in (cumulative)
	NetworkOut     float64 // Total bytes out (cumulative)
	NetworkInRate  float64 // MB/s
	NetworkOutRate float64 // MB/s
	RequestRate    float64
	ActiveConns    int
	TotalConns     int64
	Timestamp      time.Time
}

Metrics represents real-time NGINX metrics

type MetricsHistory

type MetricsHistory struct {
	CPU        []float64
	Memory     []float64
	Network    []float64
	Requests   []float64
	Timestamps []time.Time
	MaxPoints  int
}

MetricsHistory stores historical metrics

func NewMetricsHistory

func NewMetricsHistory(maxPoints int) *MetricsHistory

NewMetricsHistory creates a new metrics history tracker

func (*MetricsHistory) AddMetrics

func (h *MetricsHistory) AddMetrics(m *Metrics)

AddMetrics adds a metrics snapshot to history

type Service

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

Service handles NGINX operations using crossplane for real config parsing

func New

func New() *Service

New creates a new NGINX service

func (*Service) CreateSiteConfig

func (s *Service) CreateSiteConfig(filename, content string) error

CreateSiteConfig creates a new NGINX site configuration file

func (*Service) DisableSite

func (s *Service) DisableSite(siteName string) error

DisableSite disables an NGINX site

func (*Service) EnableSite

func (s *Service) EnableSite(siteName string) error

EnableSite enables an NGINX site

func (*Service) GetAccessLogs

func (s *Service) GetAccessLogs(maxLines int) ([]LogEntry, error)

GetAccessLogs returns the last N lines of the access log

func (*Service) GetConfigErrors

func (s *Service) GetConfigErrors() ([]string, error)

GetConfigErrors validates nginx configuration and returns errors

func (*Service) GetErrorLogs

func (s *Service) GetErrorLogs(maxLines int) ([]string, error)

GetErrorLogs returns recent error log entries

func (*Service) GetListeningPorts

func (s *Service) GetListeningPorts() ([]string, error)

GetListeningPorts returns all ports that NGINX is configured to listen on

func (*Service) GetLogStats

func (s *Service) GetLogStats() (*LogStats, error)

GetLogStats returns statistics from access logs

func (*Service) GetMetrics

func (s *Service) GetMetrics() (*Metrics, error)

GetMetrics collects current NGINX metrics

func (*Service) GetServerNames

func (s *Service) GetServerNames() (map[string][]string, error)

GetServerNames extracts all server names from configurations

func (*Service) GetSiteConfigPath

func (s *Service) GetSiteConfigPath() (string, error)

GetSiteConfigPath returns the path where site configs are stored

func (*Service) GetStats

func (s *Service) GetStats() (*Stats, error)

GetStats retrieves real NGINX statistics

func (*Service) GetSystemMetrics

func (s *Service) GetSystemMetrics() (*SystemMetrics, error)

GetSystemMetrics gets overall system metrics

func (*Service) ListSites

func (s *Service) ListSites() ([]model.Site, error)

ListSites returns a list of all NGINX sites with real config parsing

func (*Service) Reload

func (s *Service) Reload() error

Reload reloads the NGINX configuration

func (*Service) TestConfig

func (s *Service) TestConfig() error

TestConfig tests the NGINX configuration

type Stats

type Stats struct {
	ActiveConnections int
	RequestRate       float64
	TotalRequests     int64
	Uptime            time.Duration
	WorkerProcesses   int
}

Stats represents NGINX statistics

type SystemMetrics

type SystemMetrics struct {
	LoadAvg1          float64
	LoadAvg5          float64
	LoadAvg15         float64
	MemoryTotal       int64
	MemoryUsed        int64
	MemoryUsedPercent float64
	DiskUsage         string
}

SystemMetrics represents system-wide metrics

Jump to

Keyboard shortcuts

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