watcher

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: May 16, 2023 License: Apache-2.0 Imports: 11 Imported by: 12

Documentation

Overview

Package Watcher is responsible for watching latest metrics from metrics provider via a fetcher client. It exposes an HTTP REST endpoint to get these metrics, in addition to application API via clients This also uses a fast json parser

Index

Constants

View Source
const (
	K8sClientName      = "KubernetesMetricsServer"
	PromClientName     = "Prometheus"
	SignalFxClientName = "SignalFx"

	MetricsProviderNameKey    = "METRICS_PROVIDER_NAME"
	MetricsProviderAddressKey = "METRICS_PROVIDER_ADDRESS"
	MetricsProviderTokenKey   = "METRICS_PROVIDER_TOKEN"
	InsecureSkipVerify        = "INSECURE_SKIP_VERIFY"
)
View Source
const (
	FirstNode            = "worker-1"
	SecondNode           = "worker-2"
	TestServerClientName = "TestServerClient"
)
View Source
const (
	BaseUrl         = "/watcher"
	HealthCheckUrl  = "/watcher/health"
	FifteenMinutes  = "15m"
	TenMinutes      = "10m"
	FiveMinutes     = "5m"
	CPU             = "CPU"
	Memory          = "Memory"
	Bandwidth       = "Bandwidth"
	Storage         = "Storage"
	Average         = "AVG"
	Std             = "STD"
	Latest          = "Latest"
	UnknownOperator = "Unknown"
)

Variables

View Source
var FifteenMinutesMetricsMap = map[string][]Metric{
	FirstNode: {
		{
			Name:  "test-cpu",
			Type:  CPU,
			Value: 26,
		},
	},
	SecondNode: {
		{
			Name:  "test-cpu",
			Type:  CPU,
			Value: 60,
		},
	},
}
View Source
var FiveMinutesMetricsMap = map[string][]Metric{
	FirstNode: {
		{
			Name:  "test-cpu",
			Type:  CPU,
			Value: 21,
		},
	},
	SecondNode: {
		{
			Name:  "test-cpu",
			Type:  CPU,
			Value: 50,
		},
	},
}
View Source
var TenMinutesMetricsMap = map[string][]Metric{
	FirstNode: {
		{
			Name:  "test-cpu",
			Type:  CPU,
			Value: 22,
		},
	},
	SecondNode: {
		{
			Name:  "test-cpu",
			Type:  CPU,
			Value: 65,
		},
	},
}

Functions

This section is empty.

Types

type Data

type Data struct {
	NodeMetricsMap NodeMetricsMap
}

func (*Data) IsNil

func (d *Data) IsNil() bool

IsNil checks if instance is nil

func (*Data) MarshalJSONObject

func (d *Data) MarshalJSONObject(enc *gojay.Encoder)

MarshalJSONObject implements MarshalerJSONObject

func (*Data) NKeys

func (d *Data) NKeys() int

NKeys returns the number of keys to unmarshal

func (*Data) UnmarshalJSONObject

func (d *Data) UnmarshalJSONObject(dec *gojay.Decoder, k string) error

UnmarshalJSONObject implements gojay's UnmarshalerJSONObject

type Metadata

type Metadata struct {
	DataCenter string `json:"dataCenter,omitempty"`
}

func (*Metadata) IsNil

func (m *Metadata) IsNil() bool

IsNil checks if instance is nil

func (*Metadata) MarshalJSONObject

func (m *Metadata) MarshalJSONObject(enc *gojay.Encoder)

MarshalJSONObject implements MarshalerJSONObject

func (*Metadata) NKeys

func (m *Metadata) NKeys() int

NKeys returns the number of keys to unmarshal

func (*Metadata) UnmarshalJSONObject

func (m *Metadata) UnmarshalJSONObject(dec *gojay.Decoder, k string) error

UnmarshalJSONObject implements gojay's UnmarshalerJSONObject

type Metric

type Metric struct {
	Name     string  `json:"name"`             // Name of metric at the provider
	Type     string  `json:"type"`             // CPU or Memory
	Operator string  `json:"operator"`         // STD or AVE or SUM, etc.
	Rollup   string  `json:"rollup,omitempty"` // Rollup used for metric calculation
	Value    float64 `json:"value"`            // Value is expected to be in %
}

func (*Metric) IsNil

func (m *Metric) IsNil() bool

IsNil checks if instance is nil

func (*Metric) MarshalJSONObject

func (m *Metric) MarshalJSONObject(enc *gojay.Encoder)

MarshalJSONObject implements MarshalerJSONObject

func (*Metric) NKeys

func (m *Metric) NKeys() int

NKeys returns the number of keys to unmarshal

func (*Metric) UnmarshalJSONObject

func (m *Metric) UnmarshalJSONObject(dec *gojay.Decoder, k string) error

UnmarshalJSONObject implements gojay's UnmarshalerJSONObject

type Metrices

type Metrices []Metric

func (Metrices) IsNil

func (s Metrices) IsNil() bool

func (Metrices) MarshalJSONArray

func (s Metrices) MarshalJSONArray(enc *gojay.Encoder)

func (*Metrices) UnmarshalJSONArray

func (s *Metrices) UnmarshalJSONArray(dec *gojay.Decoder) error

type MetricsProviderClient

type MetricsProviderClient interface {
	// Return the client name
	Name() string
	// Fetch metrics for given host
	FetchHostMetrics(host string, window *Window) ([]Metric, error)
	// Fetch metrics for all hosts
	FetchAllHostsMetrics(window *Window) (map[string][]Metric, error)
	// Get metric provider server health status
	// Returns 0 if healthy, -1 if unhealthy along with error if any
	Health() (int, error)
}

Interface to be implemented by any metrics provider client to interact with Watcher

func NewTestMetricsServerClient

func NewTestMetricsServerClient() MetricsProviderClient

type MetricsProviderOpts

type MetricsProviderOpts struct {
	Name               string
	Address            string
	AuthToken          string
	InsecureSkipVerify bool
}

Generic metrics provider options

var (
	EnvMetricProviderOpts MetricsProviderOpts
)

type NodeMetrics

type NodeMetrics struct {
	Metrics  []Metric `json:"metrics,omitempty"`
	Tags     Tags     `json:"tags,omitempty"`
	Metadata Metadata `json:"metadata,omitempty"`
}

func (*NodeMetrics) IsNil

func (m *NodeMetrics) IsNil() bool

IsNil checks if instance is nil

func (*NodeMetrics) MarshalJSONObject

func (m *NodeMetrics) MarshalJSONObject(enc *gojay.Encoder)

MarshalJSONObject implements MarshalerJSONObject

func (*NodeMetrics) NKeys

func (m *NodeMetrics) NKeys() int

NKeys returns the number of keys to unmarshal

func (*NodeMetrics) UnmarshalJSONObject

func (m *NodeMetrics) UnmarshalJSONObject(dec *gojay.Decoder, k string) error

UnmarshalJSONObject implements gojay's UnmarshalerJSONObject

type NodeMetricsMap

type NodeMetricsMap map[string]NodeMetrics

func (*NodeMetricsMap) IsNil

func (m *NodeMetricsMap) IsNil() bool

IsNil checks if instance is nil

func (*NodeMetricsMap) MarshalJSONObject

func (m *NodeMetricsMap) MarshalJSONObject(enc *gojay.Encoder)

MarshalJSONObject implements MarshalerJSONObject

func (*NodeMetricsMap) NKeys

func (m *NodeMetricsMap) NKeys() int

NKeys returns the number of keys to unmarshal

func (*NodeMetricsMap) UnmarshalJSONObject

func (m *NodeMetricsMap) UnmarshalJSONObject(dec *gojay.Decoder, k string) error

UnmarshalJSONObject implements gojay's UnmarshalerJSONObject

type Tags

type Tags struct {
}

func (*Tags) IsNil

func (t *Tags) IsNil() bool

IsNil checks if instance is nil

func (*Tags) MarshalJSONObject

func (t *Tags) MarshalJSONObject(enc *gojay.Encoder)

MarshalJSONObject implements MarshalerJSONObject

func (*Tags) NKeys

func (t *Tags) NKeys() int

NKeys returns the number of keys to unmarshal

func (*Tags) UnmarshalJSONObject

func (t *Tags) UnmarshalJSONObject(dec *gojay.Decoder, k string) error

UnmarshalJSONObject implements gojay's UnmarshalerJSONObject

type Watcher

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

func NewWatcher

func NewWatcher(client MetricsProviderClient) *Watcher

NewWatcher Returns a new initialised Watcher

func (*Watcher) GetLatestWatcherMetrics

func (w *Watcher) GetLatestWatcherMetrics(duration string) (*WatcherMetrics, error)

GetLatestWatcherMetrics It starts from 15 minute window, and falls back to 10 min, 5 min windows subsequently if metrics are not present. StartWatching() should be called before calling this.

func (*Watcher) StartWatching

func (w *Watcher) StartWatching()

StartWatching This function needs to be called to begin actual watching

type WatcherMetrics

type WatcherMetrics struct {
	Timestamp int64  `json:"timestamp"`
	Window    Window `json:"window"`
	Source    string `json:"source"`
	Data      Data   `json:"data"`
}

func (*WatcherMetrics) IsNil

func (m *WatcherMetrics) IsNil() bool

IsNil checks if instance is nil

func (*WatcherMetrics) MarshalJSONObject

func (m *WatcherMetrics) MarshalJSONObject(enc *gojay.Encoder)

MarshalJSONObject implements MarshalerJSONObject

func (*WatcherMetrics) NKeys

func (m *WatcherMetrics) NKeys() int

NKeys returns the number of keys to unmarshal

func (*WatcherMetrics) UnmarshalJSONObject

func (m *WatcherMetrics) UnmarshalJSONObject(dec *gojay.Decoder, k string) error

UnmarshalJSONObject implements gojay's UnmarshalerJSONObject

type Window

type Window struct {
	Duration string `json:"duration"`
	Start    int64  `json:"start"`
	End      int64  `json:"end"`
}

func CurrentFifteenMinuteWindow

func CurrentFifteenMinuteWindow() *Window

func CurrentFiveMinuteWindow

func CurrentFiveMinuteWindow() *Window

func CurrentTenMinuteWindow

func CurrentTenMinuteWindow() *Window

func (*Window) IsNil

func (w *Window) IsNil() bool

IsNil checks if instance is nil

func (*Window) MarshalJSONObject

func (w *Window) MarshalJSONObject(enc *gojay.Encoder)

MarshalJSONObject implements MarshalerJSONObject

func (*Window) NKeys

func (w *Window) NKeys() int

NKeys returns the number of keys to unmarshal

func (*Window) UnmarshalJSONObject

func (w *Window) UnmarshalJSONObject(dec *gojay.Decoder, k string) error

UnmarshalJSONObject implements gojay's UnmarshalerJSONObject

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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