Documentation
¶
Overview ¶
Copyright (C) NHR@FAU, University Erlangen-Nuremberg. All rights reserved. This file is part of cc-lib. Use of this source code is governed by a MIT-style license that can be found in the LICENSE file.
Copyright (C) NHR@FAU, University Erlangen-Nuremberg. All rights reserved. This file is part of cc-lib. Use of this source code is governed by a MIT-style license that can be found in the LICENSE file.
Unit system for cluster monitoring metrics like bytes, flops and events
Index ¶
- Constants
- Variables
- func GetPrefixPrefixFactor(in Prefix, out Prefix) func(value interface{}) interface{}
- func GetPrefixStringPrefixStringFactor(in string, out string) func(value interface{}) interface{}
- func GetUnitUnitFactor(in Unit, out Unit) (func(value interface{}) interface{}, error)
- type Measure
- type MeasureData
- type Prefix
- type PrefixData
- type Unit
- func GetUnitPrefixFactor(in Unit, out Prefix) (func(value interface{}) interface{}, Unit)
- func GetUnitPrefixStringFactor(in Unit, out string) (func(value interface{}) interface{}, Unit)
- func GetUnitStringPrefixStringFactor(in string, out string) (func(value interface{}) interface{}, Unit)
- func NewUnit(unitStr string) Unit
Constants ¶
const ( InvalidPrefix Prefix = iota Base = 1 Yotta = 1e24 Zetta = 1e21 Exa = 1e18 Peta = 1e15 Tera = 1e12 Giga = 1e9 Mega = 1e6 Kilo = 1e3 Milli = 1e-3 Micro = 1e-6 Nano = 1e-9 Kibi = 1024 Mebi = 1024 * 1024 Gibi = 1024 * 1024 * 1024 Tebi = 1024 * 1024 * 1024 * 1024 Pebi = 1024 * 1024 * 1024 * 1024 * 1024 Exbi = 1024 * 1024 * 1024 * 1024 * 1024 * 1024 Zebi = 1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024 Yobi = 1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024 )
const PrefixUnitSplitRegexStr = `^([kKmMgGtTpPeEzZyY]?[i]?)(.*)`
Variables ¶
var ( InvalidMeasureLong string = "Invalid" InvalidMeasureShort string = "inval" MeasuresMap map[Measure]MeasureData = map[Measure]MeasureData{ Bytes: { Long: "byte", Short: "B", Regex: "^([bB][yY]?[tT]?[eE]?[sS]?)", }, Flops: { Long: "Flops", Short: "Flops", Regex: "^([fF][lL]?[oO]?[pP]?[sS]?)", }, Percentage: { Long: "Percent", Short: "%", Regex: "^(%|[pP]ercent)", }, TemperatureC: { Long: "DegreeC", Short: "degC", Regex: "^(deg[Cc]|°[cC])", }, TemperatureF: { Long: "DegreeF", Short: "degF", Regex: "^(deg[fF]|°[fF])", }, Rotation: { Long: "RPM", Short: "RPM", Regex: "^([rR][pP][mM])", }, Frequency: { Long: "Hertz", Short: "Hz", Regex: "^([hH][eE]?[rR]?[tT]?[zZ])", }, Time: { Long: "Seconds", Short: "s", Regex: "^([sS][eE]?[cC]?[oO]?[nN]?[dD]?[sS]?)", }, Cycles: { Long: "Cycles", Short: "cyc", Regex: "^([cC][yY][cC]?[lL]?[eE]?[sS]?)", }, Watt: { Long: "Watts", Short: "W", Regex: "^([wW][aA]?[tT]?[tT]?[sS]?)", }, Joule: { Long: "Joules", Short: "J", Regex: "^([jJ][oO]?[uU]?[lL]?[eE]?[sS]?)", }, Requests: { Long: "Requests", Short: "requests", Regex: "^([rR][eE][qQ][uU]?[eE]?[sS]?[tT]?[sS]?)", }, Packets: { Long: "Packets", Short: "packets", Regex: "^([pP][aA]?[cC]?[kK][eE]?[tT][sS]?)", }, Events: { Long: "Events", Short: "events", Regex: "^([eE][vV]?[eE]?[nN][tT][sS]?)", }, } )
Different names and regex used for input and output
var ( InvalidPrefixLong string = "Invalid" InvalidPrefixShort string = "inval" PrefixDataMap map[Prefix]PrefixData = map[Prefix]PrefixData{ Base: { Long: "", Short: "", Regex: "^$", }, Kilo: { Long: "Kilo", Short: "K", Regex: "^[kK]$", }, Mega: { Long: "Mega", Short: "M", Regex: "^[M]$", }, Giga: { Long: "Giga", Short: "G", Regex: "^[gG]$", }, Tera: { Long: "Tera", Short: "T", Regex: "^[tT]$", }, Peta: { Long: "Peta", Short: "P", Regex: "^[pP]$", }, Exa: { Long: "Exa", Short: "E", Regex: "^[eE]$", }, Zetta: { Long: "Zetta", Short: "Z", Regex: "^[zZ]$", }, Yotta: { Long: "Yotta", Short: "Y", Regex: "^[yY]$", }, Milli: { Long: "Milli", Short: "m", Regex: "^[m]$", }, Micro: { Long: "Micro", Short: "u", Regex: "^[u]$", }, Nano: { Long: "Nano", Short: "n", Regex: "^[n]$", }, Kibi: { Long: "Kibi", Short: "Ki", Regex: "^[kK][i]$", }, Mebi: { Long: "Mebi", Short: "Mi", Regex: "^[M][i]$", }, Gibi: { Long: "Gibi", Short: "Gi", Regex: "^[gG][i]$", }, Tebi: { Long: "Tebi", Short: "Ti", Regex: "^[tT][i]$", }, Pebi: { Long: "Pebi", Short: "Pi", Regex: "^[pP][i]$", }, Exbi: { Long: "Exbi", Short: "Ei", Regex: "^[eE][i]$", }, Zebi: { Long: "Zebi", Short: "Zi", Regex: "^[zZ][i]$", }, Yobi: { Long: "Yobi", Short: "Yi", Regex: "^[yY][i]$", }, } )
Different names and regex used for input and output
var INVALID_UNIT = NewUnit("foobar")
Functions ¶
func GetPrefixPrefixFactor ¶
GetPrefixPrefixFactor creates the default conversion function between two prefixes. It returns a conversation function for the value.
func GetPrefixStringPrefixStringFactor ¶
GetPrefixStringPrefixStringFactor is a wrapper for GetPrefixPrefixFactor with string inputs instead of prefixes. It also returns a conversation function for the value.
func GetUnitUnitFactor ¶
GetUnitUnitFactor gets the conversion function and (maybe) error for unit to unit conversion. It is basically a wrapper for GetPrefixPrefixFactor with some special cases for temperature conversion between Fahrenheit and Celsius.
Types ¶
type Measure ¶
type Measure int
func NewMeasure ¶
NewMeasure creates a new measure out of a string representing a measure like 'Bytes', 'Flops' and 'precent'. It uses regular expressions for matching.
type MeasureData ¶
type Prefix ¶
type Prefix float64
func NewPrefix ¶
NewPrefix creates a new prefix out of a string representing a unit like 'k', 'K', 'M' or 'G'.
type PrefixData ¶
type Unit ¶
type Unit interface {
Valid() bool
String() string
Short() string
AddUnitDenominator(div Measure)
GetPrefix() Prefix
GetMeasure() Measure
GetUnitDenominator() Measure
SetPrefix(p Prefix)
}
func GetUnitPrefixFactor ¶
GetUnitPrefixFactor gets the conversion function and resulting unit for a unit and a prefix. This is the most common case where you have some input unit and want to convert it to the same unit but with a different prefix. The returned unit represents the value after conversation.
func GetUnitPrefixStringFactor ¶
GetUnitPrefixStringFactor gets the conversion function and resulting unit for a unit and a prefix as string. It is a wrapper for GetUnitPrefixFactor
func GetUnitStringPrefixStringFactor ¶
func GetUnitStringPrefixStringFactor(in string, out string) (func(value interface{}) interface{}, Unit)
GetUnitStringPrefixStringFactor gets the conversion function and resulting unit for a unit and a prefix when both are only string representations. This is just a wrapper for GetUnitPrefixFactor with the given input unit and the desired output prefix.