common

package
v0.0.0-...-5b448de Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2017 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// StoppedState service stopped
	StoppedState = iota + 1
	// RunningState service running
	RunningState
	// StoppingState service stopping
	StoppingState
)

Variables

View Source
var (
	// ErrInvalidPortRange invalid port range
	ErrInvalidPortRange = errors.New("Invalid port range")
	// ErrNoPortLeft no port left in the range
	ErrNoPortLeft = errors.New("No free port left")
)
View Source
var (
	// ErrCantCompareInterface error can't compare inteface
	ErrCantCompareInterface = errors.New("Can't compare interface")
	// ErrFieldNotFound error field not found
	ErrFieldNotFound = errors.New("Field not found")
	// ErrFieldWrongType error field has wrong type
	ErrFieldWrongType = errors.New("Field has wrong type")
)
View Source
var (
	// CaptureTypes contain all registred capture type and associated probes
	CaptureTypes = map[string]CaptureType{}
)

Functions

func CrossTypeCompare

func CrossTypeCompare(a interface{}, b interface{}) (int, error)

CrossTypeCompare compare 2 differents number types like Float64 vs Float32

func CrossTypeEqual

func CrossTypeEqual(a interface{}, b interface{}) bool

CrossTypeEqual compare 2 differents number types

func GetField

func GetField(obj map[string]interface{}, k string) (interface{}, error)

GetField retrieve a value from a tree from the dot key like "a.b.c.d"

func IPToString

func IPToString(ip net.IP) string

IPToString convert IPv4 or IPv6 to a string

func IPv6Supported

func IPv6Supported() bool

IPv6Supported returns true if the platform support IPv6

func IsCaptureAllowed

func IsCaptureAllowed(nodeType string) bool

IsCaptureAllowed returns true if the node capture type exist

func JSONDecode

func JSONDecode(r io.Reader, i interface{}) error

JSONDecode wrapper to UseNumber during JSON decoding

func MaxInt64

func MaxInt64(a, b int64) int64

MaxInt64 returns the biggest value

func MinInt64

func MinInt64(a, b int64) int64

MinInt64 returns the lowest value

func Retry

func Retry(fnc func() error, try int, delay time.Duration) error

Retry tries to execute the given function until a success applying a delay between each try

func SetField

func SetField(obj map[string]interface{}, k string, v interface{}) bool

SetField set a value in a tree based on dot key ("a.b.c.d" = "ok")

func SetupTLSClientConfig

func SetupTLSClientConfig(certPEM string, keyPEM string) *tls.Config

SetupTLSClientConfig creates a client X509 certificate from public and private key

func SetupTLSLoadCertificate

func SetupTLSLoadCertificate(certPEM string) *x509.CertPool

SetupTLSLoadCertificate creates a X509 certificate from file

func SetupTLSServerConfig

func SetupTLSServerConfig(certPEM string, keyPEM string) *tls.Config

SetupTLSServerConfig creates a server X509 certificate from public and private key

func ToFloat64

func ToFloat64(f interface{}) (float64, error)

ToFloat64 Convert all number like type to float64

func ToInt64

func ToInt64(i interface{}) (int64, error)

ToInt64 Convert all number like type to int64

func UnixMillis

func UnixMillis(t time.Time) int64

UnixMillis returns the current time in miliseconds

Types

type CaptureType

type CaptureType struct {
	Allowed []string
	Default string
}

CaptureType describes a list of allowed and default captures probes

type Iterator

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

Iterator describes a int64 iterator

func NewIterator

func NewIterator(values ...int64) (it *Iterator)

NewIterator creates a new iterator based on (at, from, to) parameters

func (*Iterator) Done

func (it *Iterator) Done() bool

Done returns true when the Iterator is at the end or uninitialized properly

func (*Iterator) Next

func (it *Iterator) Next() bool

Next returns true if we can continue to iterate

type Metric

type Metric interface {
	GetFieldInt64(field string) (int64, error)
	Add(m Metric) Metric
}

Metric defines accessors

type NetNSContext

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

NetNSContext describes a NameSpace Context switch API

func NewNetNsContext

func NewNetNsContext(path string) (*NetNSContext, error)

NewNetNsContext creates a new NameSpace context base on path

func (*NetNSContext) Close

func (n *NetNSContext) Close()

Close the NameSpace

func (*NetNSContext) Quit

func (n *NetNSContext) Quit() error

Quit the NameSpace and go back to the original one

type PortAllocator

type PortAllocator struct {
	sync.RWMutex
	MinPort int
	MaxPort int
	PortMap map[int]interface{}
}

PortAllocator describes a threads safe port list that can be allocated

func NewPortAllocator

func NewPortAllocator(min, max int) (*PortAllocator, error)

NewPortAllocator creates a new port allocator range

func (*PortAllocator) Allocate

func (p *PortAllocator) Allocate() (int, error)

Allocate returns a new unused port between min and max ports

func (*PortAllocator) Release

func (p *PortAllocator) Release(i int) error

Release a port

func (*PortAllocator) ReleaseAll

func (p *PortAllocator) ReleaseAll()

ReleaseAll ports

func (*PortAllocator) Set

func (p *PortAllocator) Set(i int, obj interface{}) error

Set associate an object to the port map

type RawSocket

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

RawSocket describes a raw socket C implemenation

func NewRawSocket

func NewRawSocket(ifName string) (*RawSocket, error)

NewRawSocket creates a raw socket for the network interface ifName

func NewRawSocketInNs

func NewRawSocketInNs(nsPath string, ifName string) (*RawSocket, error)

NewRawSocketInNs create/open a socket in the namespace nsPath for the network interface ifName

func (*RawSocket) Close

func (s *RawSocket) Close() error

Close the file descriptor

func (*RawSocket) GetFd

func (s *RawSocket) GetFd() int

GetFd returns the file descriptor

type ServiceAddress

type ServiceAddress struct {
	Addr string
	Port int
}

ServiceAddress describes the service listening address and port

func ServiceAddressFromString

func ServiceAddressFromString(addressPort string) (ServiceAddress, error)

ServiceAddressFromString returns a service address from a string, could be IPv4 or IPv6

type ServiceType

type ServiceType string

ServiceType describes the service type (analyzer or agent)

const (
	// AnalyzerService analyzer
	AnalyzerService ServiceType = "analyzer"
	// AgentService agent
	AgentService ServiceType = "agent"
)

func (ServiceType) String

func (st ServiceType) String() string

type SortOrder

type SortOrder string

SortOrder describes ascending or descending order

const (
	// SortAscending sorting order
	SortAscending SortOrder = "ASC"
	// SortDescending sorting order
	SortDescending SortOrder = "DESC"
)

type TimeSlice

type TimeSlice struct {
	Start int64 `json:"Start"`
	Last  int64 `json:"Last"`
}

TimeSlice defines a time boudary values

func NewTimeSlice

func NewTimeSlice(s, l int64) *TimeSlice

NewTimeSlice creates a new TimeSlice based on Start and Last

type TimedMetric

type TimedMetric struct {
	TimeSlice
	Metric Metric
}

TimedMetric defines Metric during a time slice

func (*TimedMetric) GetFieldInt64

func (tm *TimedMetric) GetFieldInt64(field string) (int64, error)

GetFieldInt64 returns the field value

func (*TimedMetric) MarshalJSON

func (tm *TimedMetric) MarshalJSON() ([]byte, error)

MarshalJSON serialized a TimedMetric in JSON

Jump to

Keyboard shortcuts

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