Documentation ¶
Index ¶
- func GetCdHierJson(cd *CounterDiff) ([]byte, error)
- func GetSdHierJson(sd *StateData) ([]byte, error)
- func KeyGen(key string, keyPrefix string, programName string, withProgramName bool) string
- func NextInterval(now time.Time, interval int) int
- type CounterDiff
- type CounterSlice
- func (cs *CounterSlice) Get() CounterDiff
- func (cs *CounterSlice) GetJson() ([]byte, error)
- func (cs *CounterSlice) GetKeyPrefix() string
- func (cs *CounterSlice) Init(s *State, interval int)
- func (cs *CounterSlice) Set(counters Counters)
- func (cs *CounterSlice) SetKeyPrefix(prefix string)
- func (cs *CounterSlice) SetProgramName(programName string)
- type Counters
- type FloatCounters
- type State
- func (s *State) CountersInit(keys []string)
- func (s *State) Dec(key string, value int)
- func (s *State) Delete(key string)
- func (s *State) GetAll() *StateData
- func (s *State) GetCounter(key string) int64
- func (s *State) GetCounters() Counters
- func (s *State) GetFloatState(key string) float64
- func (s *State) GetKeyPrefix() string
- func (s *State) GetNumState(key string) int64
- func (s *State) GetState(key string) string
- func (s *State) Inc(key string, value int)
- func (s *State) Init()
- func (s *State) Set(key string, value string)
- func (s *State) SetFloat(key string, value float64)
- func (s *State) SetKeyPrefix(prefix string)
- func (s *State) SetNum(key string, value int64)
- func (s *State) SetProgramName(programName string)
- type StateData
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 ¶
GetSdHierJson gets hierarchical StataData of json format Params:
- sd: flat state data
Returns:
- []byte: json formated byte
- error: error msg
func KeyGen ¶
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)
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) 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 FloatCounters ¶
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 ¶
CountersInit Initializes counters for given keys to zero
func (*State) GetCounter ¶
GetCounter gets counter value of given key
func (*State) GetFloatState ¶
GetFloatState gets float state value of given key
func (*State) GetNumState ¶
GetNumState gets num state value of given key
func (*State) SetKeyPrefix ¶
SetKeyPrefix sets key prefix
func (*State) SetProgramName ¶
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 ¶
FormatOutput formats output according format value in params
func (*StateData) KVWithProgramName ¶
KVWithProgramName outputs key-value string (lines of key:value) for StateData, with program name