statistics

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2024 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// RequestsTotal is the total number of requests.
	RequestTotal = promauto.NewCounter(prometheus.CounterOpts{
		Name: "konterfai_requests_total",
		Help: "The total number of requests processed.",
	})

	// PromptsGeneratedTotal is the total number of prompts generated.
	PromptsGeneratedTotal = promauto.NewCounter(prometheus.CounterOpts{
		Name: "konterfai_prompts_generated_total",
		Help: "The total number of prompts generated.",
	})

	// DataFedTotal is the total amount of data fed.
	DataFedTotal = promauto.NewCounter(prometheus.CounterOpts{
		Name: "konterfai_data_fed_total_bytes",
		Help: "The total amount of data fed in bytes.",
	})

	// RobotsTxtViolatorsTotal is the total number of violators of robots.txt.
	RobotsTxtViolatorsTotal = promauto.NewGauge(prometheus.GaugeOpts{
		Name: "konterfai_robots_txt_violators_total",
		Help: "The total number of violators of robots.txt.",
	})

	// AgentTraffic is the traffic per user agent.
	AgentTraffic = promauto.NewGaugeVec(prometheus.GaugeOpts{
		Name: "konterfai_agent_traffic_bytes",
		Help: "The traffic per user agent in bytes.",
	}, []string{"user_agent"})

	// AgentRequests is the requests per user agent.
	AgentRequests = promauto.NewGaugeVec(prometheus.GaugeOpts{
		Name: "konterfai_agent_requests_total",
		Help: "The requests per user agent.",
	}, []string{"user_agent"})

	// IpTraffic is the traffic per IP address.
	IpTraffic = promauto.NewGaugeVec(prometheus.GaugeOpts{
		Name: "konterfai_ip_traffic_bytes",
		Help: "The traffic per IP address in bytes.",
	}, []string{"ip_address"})

	// IpRequests is the requests per IP address.
	IpRequests = promauto.NewGaugeVec(prometheus.GaugeOpts{
		Name: "konterfai_ip_requests_total",
		Help: "The requests per IP address.",
	}, []string{"ip_address"})
)

Functions

This section is empty.

Types

type Request

type Request struct {
	Context     context.Context
	UserAgent   string    `yaml:"userAgent"`
	IpAddress   string    `yaml:"ipAddress"`
	Timestamp   time.Time `yaml:"timestamp"`
	IsRobotsTxt bool      `yaml:"isRobotsTxt"`
	Size        int       `yaml:"size"`
}

Request is the structure for the Request.

type Statistics

type Statistics struct {
	Context           context.Context
	Requests          []Request
	StatisticsLock    sync.Mutex
	ConfigurationInfo string
	Prompts           map[string]int
	PromptsLock       sync.Mutex
	PromptsCount      int
}

Statistics is the structure for the Statistics.

func NewStatistics

func NewStatistics(ctx context.Context, configurationInfo string) *Statistics

NewStatistics creates a new Statistics instance.

func (*Statistics) AppendRequest

func (s *Statistics) AppendRequest(ctx context.Context, r Request)

AppendRequest appends a request to the statistics.

func (*Statistics) GetRequests

func (s *Statistics) GetRequests(ctx context.Context) []Request

GetRequests returns the requests.

func (*Statistics) GetRequestsByIpAddress

func (s *Statistics) GetRequestsByIpAddress(ctx context.Context, ipAddress string) []Request

GetRequestsByIpAddress returns the requests by IP address.

func (*Statistics) GetRequestsByTimeRange

func (s *Statistics) GetRequestsByTimeRange(ctx context.Context, start, end time.Time) []Request

GetRequestsByTimeRange returns the requests by time range.

func (*Statistics) GetRequestsByUserAgent

func (s *Statistics) GetRequestsByUserAgent(ctx context.Context, userAgent string) []Request

GetRequestsByUserAgent returns the requests by user agent.

func (*Statistics) GetRequestsGroupedByIpAddress

func (s *Statistics) GetRequestsGroupedByIpAddress(ctx context.Context) map[string][]Request

GetRequestsGroupedByIpAddress returns the requests grouped by IP address.

func (*Statistics) GetRequestsGroupedByUserAgent

func (s *Statistics) GetRequestsGroupedByUserAgent(ctx context.Context) map[string][]Request

GetRequestsGroupedByUserAgent returns the requests grouped by user agent.

func (*Statistics) GetTotalDataSizeServed added in v0.3.0

func (s *Statistics) GetTotalDataSizeServed(ctx context.Context) int

GetTotalDataSizeServed returns the data size served.

func (*Statistics) GetTotalDataSizeServedByTimeRange added in v0.3.0

func (s *Statistics) GetTotalDataSizeServedByTimeRange(ctx context.Context, start, end time.Time) int

GetTotalDataSizeServedByTimeRange returns the data size served by time range.

func (*Statistics) GetTotalRequests added in v0.3.0

func (s *Statistics) GetTotalRequests(ctx context.Context) int

GetTotalRequests returns the total requests.

func (*Statistics) GetTotalRobotsTxtViolators added in v0.3.0

func (s *Statistics) GetTotalRobotsTxtViolators(ctx context.Context) int

GetTotalRobotsTxtViolators returns the total robots.txt violators.

func (*Statistics) UpdatePrompts

func (s *Statistics) UpdatePrompts(ctx context.Context, prompts map[string]int)

UpdatePrompts updates the prompts.

Jump to

Keyboard shortcuts

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