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 ¶
const ( K8sClientName = "KubernetesMetricsServer" PromClientName = "Prometheus" SignalFxClientName = "SignalFx" MetricsProviderNameKey = "METRICS_PROVIDER_NAME" MetricsProviderAddressKey = "METRICS_PROVIDER_ADDRESS" MetricsProviderTokenKey = "METRICS_PROVIDER_TOKEN" InsecureSkipVerify = "INSECURE_SKIP_VERIFY" )
const ( FirstNode = "worker-1" SecondNode = "worker-2" TestServerClientName = "TestServerClient" )
const ( BaseUrl = "/watcher" HealthCheckUrl = "/watcher/health" FifteenMinutes = "15m" TenMinutes = "10m" FiveMinutes = "5m" CPU = "CPU" Memory = "Memory" Bandwidth = "Bandwidth" Storage = "Storage" Energy = "Energy" Unknown = "Unknown" Average = "AVG" Std = "STD" Latest = "Latest" UnknownOperator = "Unknown" )
Variables ¶
var FifteenMinutesMetricsMap = map[string][]Metric{ FirstNode: { { Name: "test-cpu", Type: CPU, Value: 26, }, }, SecondNode: { { Name: "test-cpu", Type: CPU, Value: 60, }, }, }
var FiveMinutesMetricsMap = map[string][]Metric{ FirstNode: { { Name: "test-cpu", Type: CPU, Value: 21, }, }, SecondNode: { { Name: "test-cpu", Type: CPU, Value: 50, }, }, }
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) MarshalJSONObject ¶
MarshalJSONObject implements MarshalerJSONObject
type Metadata ¶
type Metadata struct {
DataCenter string `json:"dataCenter,omitempty"`
}
func (*Metadata) MarshalJSONObject ¶
MarshalJSONObject implements MarshalerJSONObject
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) MarshalJSONObject ¶
MarshalJSONObject implements MarshalerJSONObject
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) 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) MarshalJSONObject ¶
MarshalJSONObject implements MarshalerJSONObject
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) MarshalJSONObject ¶
MarshalJSONObject implements MarshalerJSONObject