stats

package
v0.0.0-...-52973e1 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2019 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package stats collects statistics of HTTP requests.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetSection

func GetSection(url *url.URL) string

GetSection returns the "section", which is defined as the host and up to the first part of the path before the second /.

Example
package main

import (
	"fmt"
	"net/url"

	"github.com/raypereda/wiredog/pkg/stats"
)

func main() {
	urls := []string{
		"http://datadog.com",
		"http://datadog.com/",
		"http://datadog.com/section/",
		"http://datadog.com/section/misc",
	}
	for _, u := range urls {
		url, _ := url.Parse(u)
		section := stats.GetSection(url)
		fmt.Println(u, "==>", section)
	}
}
Output:

http://datadog.com ==> datadog.com
http://datadog.com/ ==> datadog.com
http://datadog.com/section/ ==> datadog.com/section
http://datadog.com/section/misc ==> datadog.com/section

Types

type Metrics

type Metrics struct {
	sync.Mutex
	SectionCounts map[string]int
}

Metrics stores HTTP metrics for a stream of requests.

func New

func New() *Metrics

New creates a new set of metrics.

func (*Metrics) GetTopSections

func (m *Metrics) GetTopSections() []string

GetTopSections returns the top 10 sections

func (*Metrics) Tally

func (m *Metrics) Tally(req *http.Request)

Tally adds a request to the stats

Jump to

Keyboard shortcuts

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