dmetric

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetSideEffectPublishMessageToPrometheus

func GetSideEffectPublishMessageToPrometheus(reg *Registerer) func(context.Context, interface{}) (interface{}, error)

Types

type Counter

type Counter struct {
	SourceId peer.ID
	Name     string
	Desc     string

	LabelPairs       []LabelPair
	LastPublishedVal uint64
	LastPublishedAt  time.Time
	// contains filtered or unexported fields
}

Counter dMetric uint counter struct

func NewCounter

func NewCounter(sourceId peer.ID, name string, desc string, val uint64, labelPairs []LabelPair) *Counter

NewCounter create a new counter

func (*Counter) GetVal

func (c *Counter) GetVal() uint64

GetVal return the value of the counter

func (*Counter) Inc

func (c *Counter) Inc()

Inc increase the counter value by 1

func (*Counter) OnPublished

func (c *Counter) OnPublished()

OnPublished for Publishable interface update LastPublishedVal upon published

func (*Counter) ShouldBePublished

func (c *Counter) ShouldBePublished() bool

ShouldBePublished for Publishable interface return true if LastPublishedVal is not the same as uintVal

func (*Counter) ToJsonBytes

func (c *Counter) ToJsonBytes() ([]byte, error)

ToJsonBytes for Marshalable interface return json.Marshal of Message

type CounterVec

type CounterVec struct {
	SourceId   peer.ID
	Name       string
	Desc       string
	CounterMap map[string]*Counter
}

CounterVec collection of counters

func NewCounterVec

func NewCounterVec(sourceId peer.ID, name string, desc string) *CounterVec

NewCounterVec create a new CounterVec

func (*CounterVec) GetValueOf

func (cv *CounterVec) GetValueOf(labelPairs []LabelPair) uint64

GetValueOf return the value of the target counter

func (*CounterVec) Inc

func (cv *CounterVec) Inc(labelPairs []LabelPair)

Inc increase the value of the target counter, or create a new one if needed

type LabelPair

type LabelPair struct {
	Name   string `json:"name"`
	StrVal string `json:"strVal"`
}

func GetLabelPairsFromLabelMap

func GetLabelPairsFromLabelMap(m map[string]string) []LabelPair

GetLabelPairsFromLabelMap return []LabelPair with a sorted map

type LabelPairs

type LabelPairs []LabelPair

func (LabelPairs) String

func (lps LabelPairs) String() string

func (LabelPairs) ToMap

func (lps LabelPairs) ToMap() map[string]string

type Message

type Message struct {
	SourceId   peer.ID     `json:"sourceId"`
	Type       MetricType  `json:"type"`
	Name       string      `json:"name"`
	LabelPairs []LabelPair `json:"labelPairs"`
	UIntVal    uint64      `json:"uintVal"`
}

func (Message) GetLabelPairsMap

func (m Message) GetLabelPairsMap() map[string]string

func (Message) GetLabelPairsStr

func (m Message) GetLabelPairsStr() string

type MetricType

type MetricType uint64
const (
	MetricTypeUndefined MetricType = iota
	MetricTypeCounter
)

type Registerer

type Registerer struct {
	CounterMsgMap map[string]*Message
}

func NewRegisterer

func NewRegisterer() *Registerer

Jump to

Keyboard shortcuts

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