web100

package
v2.4.3+incompatible Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2020 License: Apache-2.0 Imports: 13 Imported by: 1

README

Preparing web100 source

Install go-bindata:

go get -u github.com/jteeuwen/go-bindata/...

Convert tcp-kis.txt into embedded go file:

go-bindata -prefix embed/ -pkg web100 -o tcpkis.go embed

TODOs

  • Upstream the web100.c changes to support 64-bit environments.
  • Upstream the tcp-kis.txt changes to eliminate conflicts for StartTimeSec and StartTimeUsec (and other inconsistencies across published versions).
  • Optimize web100.go implementation, e.g. to read snaplog from byte buffer instead of from file.

Documentation

Overview

web100 provides tools for reading web100 snapshot logs, and parsing snapshots.

Index

Constants

View Source
const (
	BEGIN_SNAP_DATA   = "----Begin-Snap-Data----\n"
	END_OF_HEADER     = "\x00----End-Of-Header---- -1 -1\n"
	GROUPNAME_LEN_MAX = 32
	VARNAME_LEN_MAX   = 32
)

=================================================================================

View Source
const (
	// The ordering here is important, as it reflects the type values
	// defined by the web100 libraries.  Do not change ordering.
	WEB100_TYPE_INTEGER varType = iota
	WEB100_TYPE_INTEGER32
	WEB100_TYPE_INET_ADDRESS_IPV4
	WEB100_TYPE_COUNTER32
	WEB100_TYPE_GAUGE32
	WEB100_TYPE_UNSIGNED32
	WEB100_TYPE_TIME_TICKS
	WEB100_TYPE_COUNTER64
	WEB100_TYPE_INET_PORT_NUMBER
	WEB100_TYPE_INET_ADDRESS
	WEB100_TYPE_INET_ADDRESS_IPV6
	WEB100_TYPE_STR32
	WEB100_TYPE_OCTET
	WEB100_NUM_TYPES
)
View Source
const (
	// The ordering here is important, as it reflects the type values
	// defined by the web100 libraries.  Do not change ordering.
	WEB100_ADDRTYPE_UNKNOWN addrType = iota
	WEB100_ADDRTYPE_IPV4
	WEB100_ADDRTYPE_IPV6
	WEB100_ADDRTYPE_DNS = 16
)

Variables

View Source
var (
	ErrIPIsUnparseable   = errors.New("IP not parsable")
	ErrIPIsUnconvertible = errors.New("IP not convertible to ipv4 or ipv6")
	ErrIPIsZero          = errors.New("IP is zero/unspecified")
	ErrIPIsUnroutable    = errors.New("IP is nonroutable")

	ErrIPv4IsPrivate    = errors.New("private IPv4")
	ErrIPv6IsPrivate    = errors.New("private IPv6")
	ErrIPv4IsUnroutable = errors.New("unroutable IPv4")
	ErrIPv6IsUnroutable = errors.New("unroutable IPv6")

	ErrIPv6MultipleTripleColon = errors.New("more than one ::: in an ip address")
	ErrIPv6QuadColon           = errors.New("IP address contains :::: ")
)

IP validation errors.

View Source
var CanonicalNames map[string]string

CanonicalNames provides the mapping from old names (in snaplog files) to new canonical names. This is exported so that SideStream parser can use it easily.

Functions

func Asset

func Asset(name string) ([]byte, error)

Asset loads and returns the asset for the given name. It returns an error if the asset could not be found or could not be loaded.

func AssetDir

func AssetDir(name string) ([]string, error)

AssetDir returns the file names below a certain directory embedded in the file by go-bindata. For example if you run go-bindata on data/... and data contains the following hierarchy:

data/
  foo.txt
  img/
    a.png
    b.png

then AssetDir("data") would return []string{"foo.txt", "img"} AssetDir("data/img") would return []string{"a.png", "b.png"} AssetDir("foo.txt") and AssetDir("notexist") would return an error AssetDir("") will return []string{"data"}.

func AssetInfo

func AssetInfo(name string) (os.FileInfo, error)

AssetInfo loads and returns the asset info for the given name. It returns an error if the asset could not be found or could not be loaded.

func AssetNames

func AssetNames() []string

AssetNames returns the names of the assets.

func IPFromBytes

func IPFromBytes(data []byte) (net.IP, error)

IPFromBytes handles the 17 byte web100 IP address fields.

func MustAsset

func MustAsset(name string) []byte

MustAsset is like Asset but panics when Asset would return an error. It simplifies safe initialization of global variables.

func NormalizeIPv6

func NormalizeIPv6(ipStr string) (string, error)

NormalizeIPv6 fixes triple colon ::: which is produced by sidestream. This error is produced by older versions of the c-web100 library, which is still used by sidestream.

func ParseIPFamily

func ParseIPFamily(ipStr string) int64

ParseIPFamily determines whether an IP string is v4 or v6

func ParseWeb100Definitions

func ParseWeb100Definitions(tcpKis io.Reader) (map[string]string, error)

ParseWeb100Definitions reads all web100 variable definitions from tcpKis and returns a mapping from legacy names to canonical names. This mapping is necessary for translating variable names in archived web100 snapshots to canonical variable names.

func RestoreAsset

func RestoreAsset(dir, name string) error

RestoreAsset restores an asset under the given directory

func RestoreAssets

func RestoreAssets(dir, name string) error

RestoreAssets restores an asset under the given directory recursively

func ValidateIP

func ValidateIP(ipStr string) error

ValidateIP validates (and possibly repairs) IP addresses. Return nil if it is a valid IPv4 or IPv6 address (or can be repaired), non-nil otherwise.

Types

type IntArraySaver

type IntArraySaver struct {
	Integers []int64
}

func NewIntArraySaver

func NewIntArraySaver(n int) IntArraySaver

func (*IntArraySaver) SetBool

func (s *IntArraySaver) SetBool(name string, val bool)

func (*IntArraySaver) SetInt64

func (s *IntArraySaver) SetInt64(name string, val int64)

func (*IntArraySaver) SetString

func (s *IntArraySaver) SetString(name string, val string)

type Saver

type Saver interface {
	SetInt64(name string, value int64)
	SetString(name string, value string)
	SetBool(name string, value bool)
}

The Saver interface decouples reading data from the web100 log files and saving those values.

type SnapLog

type SnapLog struct {
	Version   string
	LogTime   uint32
	GroupName string
	// contains filtered or unexported fields
}

SnapLog encapsulates the raw data and all elements of the header.

func NewSnapLog

func NewSnapLog(raw []byte) (*SnapLog, error)

NewSnapLog creates a SnapLog from a byte array. Returns error if there are problems.

func (*SnapLog) ChangeIndices

func (sl *SnapLog) ChangeIndices(fieldName string) ([]int, error)

ChangeIndices finds all snapshot indices where the specified field changes value.

func (*SnapLog) ConnectionSpecValues

func (sl *SnapLog) ConnectionSpecValues(saver Saver)

func (*SnapLog) SliceIntField

func (sl *SnapLog) SliceIntField(fieldName string, indices []int) []int64

about 40 nsec per field.

func (*SnapLog) SnapCount

func (sl *SnapLog) SnapCount() int

SnapCount returns the number of valid snapshots.

func (*SnapLog) Snapshot

func (sl *SnapLog) Snapshot(n int) (Snapshot, error)

Snapshot returns the snapshot at index n, or error if n is not a valid index, or data is corrupted.

func (*SnapLog) SnapshotNumBytes

func (sl *SnapLog) SnapshotNumBytes() int

SnapshotNumBytes returns the length of snapshot records, including preamble. Used only for testing.

func (*SnapLog) SnapshotNumFields

func (sl *SnapLog) SnapshotNumFields() int

SnapshotNumFields returns the total number of snapshot fields. Used only for testing.

func (*SnapLog) ValidateSnapshots

func (sl *SnapLog) ValidateSnapshots() error

ValidateSnapshots checks whether the first and last snapshots are valid and complete.

type Snapshot

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

Snapshot represents a complete snapshot from a snapshot log.

func (*Snapshot) SnapshotDeltas

func (snap *Snapshot) SnapshotDeltas(other *Snapshot, snapValues Saver) error

SnapshotDeltas writes changed values into the provided Saver.

func (*Snapshot) SnapshotValues

func (snap *Snapshot) SnapshotValues(snapValues Saver) error

SnapshotValues writes all values into the provided Saver.

type Variable

type Variable struct {
	Name   string  // Encoded field name (before conversion to canonicalName)
	Offset int     // Offset, beyond the BEGIN_SNAP_HEADER
	Type   varType // Web100 type of the field
	Size   int     // Size, in bytes, of the raw data field.
}

Variable is a representation of a Web100 field specifications, as they appear in snaplog headers.

func NewVariable

func NewVariable(s string) (*Variable, error)

NewVariable creates a new variable based on web100 definition string

func (*Variable) Save

func (v *Variable) Save(data []byte, snapValues Saver) error

Save interprets data according to the receiver type, and saves the result to snapValues. Most of the types are unused, but included here for completeness. This does a single alloc per int64 save??? TODO URGENT - unit tests for this!!

Jump to

Keyboard shortcuts

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