module_state2

package
v0.0.0-...-42829d4 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2021 License: Apache-2.0 Imports: 8 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetCdHierJson

func GetCdHierJson(cd *CounterDiff) ([]byte, error)

GetCdHierJson gets hierarchical counter diff of json format Params:

  • cd: flat counter diff

Returns:

  • []byte: json formated byte
  • error: error msg

func GetSdHierJson

func GetSdHierJson(sd *StateData) ([]byte, error)

GetSdHierJson gets hierarchical StataData of json format Params:

  • sd: flat state data

Returns:

  • []byte: json formated byte
  • error: error msg

func KeyGen

func KeyGen(key string, keyPrefix string, programName string, withProgramName bool) string

KeyGen generate and escape key for key-value output

Params:

  • key: the original key
  • keyPrefix: e.g., "mod_header"
  • programName: e.g., "bfe"
  • withProgramName: whether program name should be included in the result

Returns:

final key, e.g., "mod_header_ERR_PB_SEEK", "bfe.mod_header_ERR_PB_SEEK"(with programName)

func NextInterval

func NextInterval(now time.Time, interval int) int

NextInterval calculates seconds left for next interval

Params:

  • now: current time
  • interval: in seconds

Returns:

seconds left for next interval

Types

type CounterDiff

type CounterDiff struct {
	LastTime string // time till
	Duration int    // in second

	Diff Counters

	KeyPrefix   string // for key-value string
	ProgramName string // for program name
}

func (*CounterDiff) FormatOutput

func (cd *CounterDiff) FormatOutput(params map[string][]string) ([]byte, error)

FormatOutput formats output according format value in params

func (CounterDiff) KV

func (cd CounterDiff) KV() []byte

KV outputs key-value string (lines of key:value) for CounterDiff

func (CounterDiff) KVWithProgramName

func (cd CounterDiff) KVWithProgramName() []byte

KVWithProgramName outputs key-value string (lines of key:value) for CounterDiff, with program name

type CounterSlice

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

diff of two counters

func (*CounterSlice) Get

func (cs *CounterSlice) Get() CounterDiff

Get gets diff from counter slice

func (*CounterSlice) GetJson

func (cs *CounterSlice) GetJson() ([]byte, error)

GetJson gets json format of counter diff

func (*CounterSlice) GetKeyPrefix

func (cs *CounterSlice) GetKeyPrefix() string

GetKeyPrefix gets key prefix

func (*CounterSlice) Init

func (cs *CounterSlice) Init(s *State, interval int)

Init initializes the counter diff Params:

  • s: module State
  • interval: interval to compute between two counters

Notice: use this method only when you need to get diff between two counters periodically

func (*CounterSlice) Set

func (cs *CounterSlice) Set(counters Counters)

Set sets to counter slice

func (*CounterSlice) SetKeyPrefix

func (cs *CounterSlice) SetKeyPrefix(prefix string)

SetKeyPrefix sets key prefix

func (*CounterSlice) SetProgramName

func (cs *CounterSlice) SetProgramName(programName string)

SetProgramName sets program name

type Counters

type Counters map[string]int64

Counters holds counters for given key

func NewCounters

func NewCounters() Counters

NewCounters creates new Counters

func (*Counters) Sum

func (c *Counters) Sum(c2 Counters)

Sum calculates sum of two Counters

type FloatCounters

type FloatCounters map[string]float64

FloatCounters is flat counters for float64

func NewFloatCounters

func NewFloatCounters() FloatCounters

NewFloatCounters creates new Counters for float64

type State

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

State is state with mutex protect

func (*State) CountersInit

func (s *State) CountersInit(keys []string)

CountersInit Initializes counters for given keys to zero

func (*State) Dec

func (s *State) Dec(key string, value int)

Dec decreases value for given key

func (*State) Delete

func (s *State) Delete(key string)

Delete deletes state for given key

func (*State) GetAll

func (s *State) GetAll() *StateData

GetAll gets all states

func (*State) GetCounter

func (s *State) GetCounter(key string) int64

GetCounter gets counter value of given key

func (*State) GetCounters

func (s *State) GetCounters() Counters

GetCounters gets all counters

func (*State) GetFloatState

func (s *State) GetFloatState(key string) float64

GetFloatState gets float state value of given key

func (*State) GetKeyPrefix

func (s *State) GetKeyPrefix() string

GetKeyPrefix gets key prefix

func (*State) GetNumState

func (s *State) GetNumState(key string) int64

GetNumState gets num state value of given key

func (*State) GetState

func (s *State) GetState(key string) string

GetState get state value of given key

func (*State) Inc

func (s *State) Inc(key string, value int)

Inc increases value for given key

func (*State) Init

func (s *State) Init()

Init initializes the state

func (*State) Set

func (s *State) Set(key string, value string)

Set sets value to given key

func (*State) SetFloat

func (s *State) SetFloat(key string, value float64)

SetFloat sets float state to given key

func (*State) SetKeyPrefix

func (s *State) SetKeyPrefix(prefix string)

SetKeyPrefix sets key prefix

func (*State) SetNum

func (s *State) SetNum(key string, value int64)

SetNum sets num state to given key

func (*State) SetProgramName

func (s *State) SetProgramName(programName string)

SetProgramName sets program name

type StateData

type StateData struct {
	SCounters   Counters          // for count up
	States      map[string]string // for store states
	NumStates   Counters          // for store num states
	FloatStates FloatCounters     // for store float states
	KeyPrefix   string            // for key-value output
	ProgramName string            // for program name
}

StateData holds state data

func NewStateData

func NewStateData() *StateData

func (*StateData) FormatOutput

func (sd *StateData) FormatOutput(params map[string][]string) ([]byte, error)

FormatOutput formats output according format value in params

func (*StateData) KV

func (sd *StateData) KV() []byte

KV output key-value string (lines of key:value) for StateData

func (*StateData) KVWithProgramName

func (sd *StateData) KVWithProgramName() []byte

KVWithProgramName outputs key-value string (lines of key:value) for StateData, with program name

Jump to

Keyboard shortcuts

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