connectors

package
v0.0.0-...-83a4208 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Kb                 = "GW:KB"
	Mb                 = "GW:MB"
	Gb                 = "GW:GB"
	Tb                 = "GW:TB"
	Kb2                = "GW:KB2"
	Mb2                = "GW:MB2"
	Gb2                = "GW:GB2"
	Tb2                = "GW:TB2"
	IntMax             = "GW:maxInt"
	IntMin             = "GW:minInt"
	DoubleMax          = "GW:maxDouble"
	DoubleMin          = "GW:minDouble"
	IntDouble          = "GW:toDouble"
	DoubleInt          = "GW:toInt"
	ToPercent          = "GW:toPercentage"
	PercentUsed        = "GW:percentageUsed"
	PercentUnused      = "GW:percentageUnused"
	ToPercentLimit     = "GW:toPercentageLimit"
	DivideToPercent    = "GW:divideToPercentage"
	ScalePercentUsed   = "GW:scalePercentageUsed"
	ScalePercentUnused = "GW:scalePercentageUnused"
)
View Source
const DefaultCheckInterval = time.Minute * 2

DefaultCheckInterval defines interval

View Source
const ExtKeyCheckInterval = "checkIntervalMinutes"

ExtKeyCheckInterval defines field name

Variables

View Source
var CheckInterval = DefaultCheckInterval

CheckInterval comes from extensions field

View Source
var ErrUnsupportedType = errors.New("unsupported value type")
View Source
var Hashsum = config.Hashsum

Hashsum calculates FNV non-cryptographic hash suitable for checking the equality

View Source
var ProcessesCache = cache.New(5*time.Minute, 5*time.Minute)

ProcessesCache | TODO: move into Server Connector

Functions

func BuildMetric

func BuildMetric(metricBuilder MetricBuilder) (*transit.TimeSeries, error)

BuildMetric creates metric based on data provided with metricBuilder

func BuildServiceForMetric

func BuildServiceForMetric(hostName string, metricBuilder MetricBuilder) (*transit.MonitoredService, error)

BuildServiceForMetric creates metric based on data provided in metric builder and if metric successfully created creates service with same name as metric which contains only this one metric returns the result of service creation

func BuildServiceForMetricWithStatusText

func BuildServiceForMetricWithStatusText(hostName string, metricBuilder MetricBuilder,
	statusMessages map[transit.MonitorStatus]string) (*transit.MonitoredService, error)

func BuildServiceForMetrics

func BuildServiceForMetrics(serviceName string, hostName string, metricBuilders []MetricBuilder) (*transit.MonitoredService, error)

func BuildServiceForMultiMetric

func BuildServiceForMultiMetric(hostName string, serviceName string, customName string, metricBuilders []MetricBuilder) (*transit.MonitoredService, error)

func CreateCriticalThreshold

func CreateCriticalThreshold(label string, value interface{}) (*transit.ThresholdValue, error)

func CreateInventoryResource

func CreateInventoryResource(name string, services []transit.InventoryService) transit.InventoryResource

makes and modifies a copy, doesn't modify services

func CreateInventoryService

func CreateInventoryService(name string, owner string) transit.InventoryService

Inventory Constructors

func CreateMetric

func CreateMetric(name string, value interface{}, args ...interface{}) (*transit.TimeSeries, error)

CreateMetric

required parameters: name, value
optional parameters: interval, UnitType

CreateMetric("cpu", 30) // integer value CreateMetric("percentFree", 30.59) // double value CreateMetric("cpu", 30.59, transit.PercentCPU) // with optional Unit CreateMetric("cpu", 30.59, interval) // with optional interval CreateMetric("cpu", 30.59, transit.PercentCPU, interval) // with optional Unit and optional interval with optional Unit and optional Interval and optional UnitType CreateMetric("cpu", 30.59, interval, transit.PercentCPU) Thresholds must be set separately

func CreateResource

func CreateResource(name string, args ...interface{}) (*transit.MonitoredResource, error)

CreateResource makes node required params: name optional params: services

func CreateResourceGroup

func CreateResourceGroup(name string, description string, groupType transit.GroupType, resources []transit.ResourceRef) transit.ResourceGroup

func CreateResourceRef

func CreateResourceRef(name string, owner string, resourceType transit.ResourceType) transit.ResourceRef

func CreateService

func CreateService(name string, owner string, args ...interface{}) (*transit.MonitoredService, error)

CreateService makes node required params: name, owner(resource) optional params: metrics

func CreateThreshold

func CreateThreshold(thresholdType transit.MetricSampleType, label string, value interface{}) (*transit.ThresholdValue, error)

func CreateWarningThreshold

func CreateWarningThreshold(label string, value interface{}) (*transit.ThresholdValue, error)

func DivideToPercentage

func DivideToPercentage(values ...float64) float64

Given two metrics, <code>dividend</code> and <code>divisor</code> divides them and returns a percentage ratio

Example:

GW:divideToPercentage(summary.quickStats.overallMemoryUsage,summary.hardware.memorySize)

@param - dividend typically a usage or free type metric @param - divisor typically a totality type metric, such as total disk space @return The percentage ratio as an integer

func DoubleToInt

func DoubleToInt(values ...float64) float64

func EvaluateExpression

func EvaluateExpression(expression ExpressionToEvaluate, override bool) (float64, error)

func EvaluateExpressionHandler

func EvaluateExpressionHandler(c *gin.Context)

func EvaluateExpressions

func EvaluateExpressions(services []transit.MonitoredService) []transit.MonitoredService

EvaluateExpressions calculates synthetic metrics

func EvaluateGroundworkExpression

func EvaluateGroundworkExpression(expression string, vars map[string]interface{}, argumentCounter int) (float64, []float64, error)

func FillGroupWithResources

func FillGroupWithResources(group transit.ResourceGroup, resources []transit.InventoryResource) transit.ResourceGroup

func FormatTimeForStatusMessage

func FormatTimeForStatusMessage(value time.Duration, minRound time.Duration) string

Returns duration provided as a "human-readable" string, like: "N second(s)/minute(s)/hour(s)/day(s)"

Following formatting rules are being applied by default (not considering minRound):
	if the value is less than 3 minutes it will be formatted to seconds
	if the value is between 3 minutes and 3 hours it will be formatted to minutes
	if the value is between 3 hours and 3 days (<73 hours) it will be formatted to hours
	values higher than 72 hours (3 days) will be formatted to days
minRound arg determines time unit "limit" lower than that formatting is not allowed
i.e. if the value is for example 120 seconds which is gonna be returned as "120 second(s)" by default rules
	will be returned as "2 minute(s)" if minRound="minute" (i.e. formatting to lower than minute is not allowed)
	or "0 hour(s)" if minRound="hour" (i.e. formatting to lower than hour is not allowed)

func GB

func GB(values ...float64) float64

Converts byte value to Gigabyte value

@param bytes - value in bytes @return value in Gigabytes

func GB2

func GB2(values ...float64) float64

func IntToDouble

func IntToDouble(values ...float64) float64

func KB

func KB(values ...float64) float64

Converts byte value to Kilobyte value

@param bytes - value in bytes @return value in Kilobytes

func KB2

func KB2(values ...float64) float64

func MB

func MB(values ...float64) float64

Converts byte value to Megabyte value

@param bytes - value in bytes @return value in Megabytes

func MB2

func MB2(values ...float64) float64

func MaxDuration

func MaxDuration(x time.Duration, rest ...time.Duration) time.Duration

MaxDuration returns maximum value

func MaxFloat

func MaxFloat(values ...float64) float64

func MaxInt

func MaxInt(values ...float64) float64

func MinFloat

func MinFloat(values ...float64) float64

func MinInt

func MinInt(values ...float64) float64

func Name

func Name(defaultName string, customName string) string

Name defines metric name

func PercentageUnused

func PercentageUnused(values ...float64) float64

This Function provides percentage unused/free synthetic values. Calculates the unused(free) percentage for a given <code>unused</code> metric and a corresponding <code>available</code> metric. Both the unused metric and available metric can be scaled by corresponding scale factor parameters.

Example:

PercentageUnused(summary.freeSpace, summary.capacity)

@param unused - Represents a metric reference value of how much of this resource has not be used (free) @param available - Represents the totality of a resource, such as all disk space available @return The percentage not used (free) as an integer

func PercentageUsed

func PercentageUsed(values ...float64) float64

This Function provides percentage usage synthetic values. Calculates the usage percentage for a given <code>used</code> metric and a corresponding <code>available</code> metric.

Example:

PercentageUsed(summary.quickStats.overallMemoryUsage, summary.hardware.memorySize)

@param - used Represents a 'used' metric value of how much of this resource has been used such as 'overallMemoryUsage' @param - available Represents the totality of a resource, such as all memory available @return The percentage usage as an integer

func SanitizeString

func SanitizeString(str string) string

SanitizeString replaces all special characters with '_'

func ScalePercentageUnused

func ScalePercentageUnused(values ...float64) float64

This Function provides percentage unused/free synthetic values. Calculates the unused(free) percentage for a given <code>unused</code> metric and a corresponding <code>available</code> metric. Both the unused metric and available metric can be scaled by corresponding scale factor parameters.

Example:

scalePercentageUnused(summary.freeSpace,summary.capacity, 1.0, null, true)

@param unused Represents a metric reference value of how much of this resource has not be used (free) @param available Represents the totality of a resource, such as all disk space available @param usageScaleFactor multiply usage parameter by this value, or pass in null to not scale. Passing in 1.0 will also not scale @param availableScaleFactor multiply available parameter by this value, or pass in null to not scale. Passing in 1.0 will also not scale @return The percentage not used (free) as an integer

func ScalePercentageUsed

func ScalePercentageUsed(values ...float64) float64

This Function provides percentage usage synthetic values. Calculates the usage percentage for a given <code>used</code> metric and a corresponding <code>available</code> metric. Both the used metric and available metric can be scaled by corresponding scale factor parameters.

Example:

scalePercentageUsed(summary.quickStats.overallMemoryUsage,summary.hardware.memorySize, 1.0, 1.0)

@param used Represents a 'used' metric value of how much of this resource has been used such as 'overallMemoryUsage' @param available Represents the totality of a resource, such as all memory available @param usedScaleFactor multiply usage parameter by this value, or pass in null to not scale. Passing in 1.0 will also not scale @param availableScaleFactor multiply available parameter by this value, or pass in null to not scale. Passing in 1.0 will also not scale @return The percentage usage as an integer

func SendInventory

func SendInventory(ctx context.Context, resources []transit.InventoryResource, resourceGroups []transit.ResourceGroup, ownershipType transit.HostOwnershipType) error

SendInventory processes inventory payload

func SendMetrics

func SendMetrics(ctx context.Context, resources []transit.MonitoredResource, groups *[]transit.ResourceGroup) error

SendMetrics processes metrics payload

func Start

func Start() error

Start starts services

func StartPeriodic

func StartPeriodic(ctx context.Context, t time.Duration, fn func())

StartPeriodic starts periodic event loop context can provide ctx.Done channel and "notOften" guard with 1 minute defaults

func TB

func TB(values ...float64) float64

Converts byte value to Terabyte value

@param bytes - value in bytes @return value in Terabytes

func TB2

func TB2(values ...float64) float64

func ToPercentage

func ToPercentage(values ...float64) float64

Turns a number such as .87 into an integer percentage (87). Also handles rounding of percentages

@param value - the value to be rounded to a full integer percentage @return the percentage value as an integer

func ToPercentageLimit

func ToPercentageLimit(values ...float64) float64

func UnmarshalConfig

func UnmarshalConfig(data []byte, metricsProfile *transit.MetricsProfile, monitorConnection *transit.MonitorConnection) error

UnmarshalConfig updates args with data

Types

type ExpressionParameter

type ExpressionParameter struct {
	Name  string  `json:"name"`
	Value float64 `json:"value"`
}

type ExpressionToEvaluate

type ExpressionToEvaluate struct {
	Expression string                `json:"expression"`
	Params     []ExpressionParameter `json:"params"`
}

type ExpressionToSuggest

type ExpressionToSuggest struct {
	Name      string `json:"name"`
	ArgsCount int    `json:"argsCount"`
}

func ListExpressions

func ListExpressions(name string) []ExpressionToSuggest

type MetricBuilder

type MetricBuilder struct {
	Name           string
	CustomName     string
	ComputeType    transit.ComputeType
	Expression     string
	Value          interface{}
	UnitType       interface{}
	Warning        interface{}
	Critical       interface{}
	StartTimestamp *transit.Timestamp
	EndTimestamp   *transit.Timestamp
	Graphed        bool
	Tags           map[string]string
}

Jump to

Keyboard shortcuts

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