本文整理汇总了Golang中github.com/youtube/vitess/go/stats.StringFunc函数的典型用法代码示例。如果您正苦于以下问题:Golang StringFunc函数的具体用法?Golang StringFunc怎么用?Golang StringFunc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了StringFunc函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: NewRowcacheInvalidator
// NewRowcacheInvalidator creates a new RowcacheInvalidator.
// Just like QueryEngine, this is a singleton class.
// You must call this only once.
func NewRowcacheInvalidator(qe *QueryEngine) *RowcacheInvalidator {
rci := &RowcacheInvalidator{qe: qe}
stats.Publish("RowcacheInvalidatorState", stats.StringFunc(rci.svm.StateName))
stats.Publish("RowcacheInvalidatorPosition", stats.StringFunc(rci.PositionString))
stats.Publish("RowcacheInvalidatorLagSeconds", stats.IntFunc(rci.lagSeconds.Get))
return rci
}
示例2: NewRowcacheInvalidator
// NewRowcacheInvalidator creates a new RowcacheInvalidator.
// Just like QueryEngine, this is a singleton class.
// You must call this only once.
func NewRowcacheInvalidator(statsPrefix string, checker MySQLChecker, qe *QueryEngine, enablePublishStats bool) *RowcacheInvalidator {
rci := &RowcacheInvalidator{checker: checker, qe: qe}
if enablePublishStats {
stats.Publish(statsPrefix+"RowcacheInvalidatorState", stats.StringFunc(rci.svm.StateName))
stats.Publish(statsPrefix+"RowcacheInvalidatorPosition", stats.StringFunc(rci.PositionString))
stats.Publish(statsPrefix+"RowcacheInvalidatorLagSeconds", stats.IntFunc(rci.lagSeconds.Get))
}
return rci
}
示例3: NewTabletServer
// NewTabletServer creates an instance of TabletServer. Only one instance
// of TabletServer can be created per process.
func NewTabletServer(config Config) *TabletServer {
tsv := &TabletServer{
config: config,
QueryTimeout: sync2.NewAtomicDuration(time.Duration(config.QueryTimeout * 1e9)),
BeginTimeout: sync2.NewAtomicDuration(time.Duration(config.TxPoolTimeout * 1e9)),
checkMySQLThrottler: sync2.NewSemaphore(1, 0),
streamHealthMap: make(map[int]chan<- *querypb.StreamHealthResponse),
sessionID: Rand(),
history: history.New(10),
}
tsv.qe = NewQueryEngine(tsv, config)
tsv.invalidator = NewRowcacheInvalidator(config.StatsPrefix, tsv, tsv.qe, config.EnablePublishStats)
if config.EnablePublishStats {
stats.Publish(config.StatsPrefix+"TabletState", stats.IntFunc(func() int64 {
tsv.mu.Lock()
state := tsv.state
tsv.mu.Unlock()
return state
}))
stats.Publish(config.StatsPrefix+"QueryTimeout", stats.DurationFunc(tsv.QueryTimeout.Get))
stats.Publish(config.StatsPrefix+"BeginTimeout", stats.DurationFunc(tsv.BeginTimeout.Get))
stats.Publish(config.StatsPrefix+"TabletStateName", stats.StringFunc(tsv.GetState))
}
return tsv
}
示例4: NewSchemaInfo
func NewSchemaInfo(queryCacheSize int, reloadTime time.Duration, idleTimeout time.Duration) *SchemaInfo {
si := &SchemaInfo{
queries: cache.NewLRUCache(int64(queryCacheSize)),
rules: NewQueryRules(),
connPool: dbconnpool.NewConnectionPool("", 2, idleTimeout),
ticks: timer.NewTimer(reloadTime),
}
stats.Publish("QueryCacheLength", stats.IntFunc(si.queries.Length))
stats.Publish("QueryCacheSize", stats.IntFunc(si.queries.Size))
stats.Publish("QueryCacheCapacity", stats.IntFunc(si.queries.Capacity))
stats.Publish("QueryCacheOldest", stats.StringFunc(func() string {
return fmt.Sprintf("%v", si.queries.Oldest())
}))
stats.Publish("SchemaReloadTime", stats.DurationFunc(si.ticks.Interval))
_ = stats.NewMultiCountersFunc("TableStats", []string{"Table", "Stats"}, si.getTableStats)
_ = stats.NewMultiCountersFunc("TableInvalidations", []string{"Table"}, si.getTableInvalidations)
_ = stats.NewMultiCountersFunc("QueryCounts", []string{"Table", "Plan"}, si.getQueryCount)
_ = stats.NewMultiCountersFunc("QueryTimesNs", []string{"Table", "Plan"}, si.getQueryTime)
_ = stats.NewMultiCountersFunc("QueryRowCounts", []string{"Table", "Plan"}, si.getQueryRowCount)
_ = stats.NewMultiCountersFunc("QueryErrorCounts", []string{"Table", "Plan"}, si.getQueryErrorCount)
http.Handle("/debug/query_plans", si)
http.Handle("/debug/query_stats", si)
http.Handle("/debug/table_stats", si)
http.Handle("/debug/schema", si)
return si
}
示例5: publishMainStats
func (memstats *MemcacheStats) publishMainStats() {
memstats.mu.Lock()
defer memstats.mu.Unlock()
for k, isstr := range mainStringMetrics {
key := k
if isstr {
memstats.main[key] = ""
stats.Publish(memstats.statsPrefix+"Memcache"+formatKey(key), stats.StringFunc(func() string {
memstats.mu.Lock()
defer memstats.mu.Unlock()
return memstats.main[key]
}))
} else {
memstats.main[key] = "0"
stats.Publish(memstats.statsPrefix+"Memcache"+formatKey(key), stats.IntFunc(func() int64 {
memstats.mu.Lock()
defer memstats.mu.Unlock()
ival, err := strconv.ParseInt(memstats.main[key], 10, 64)
if err != nil {
log.Errorf("value '%v' for key %v is not an int", memstats.main[key], key)
memstats.queryServiceStats.InternalErrors.Add("MemcacheStats", 1)
return -1
}
return ival
}))
}
}
}
示例6: NewSchemaInfo
// NewSchemaInfo creates a new SchemaInfo.
func NewSchemaInfo(
queryCacheSize int,
statsPrefix string,
endpoints map[string]string,
reloadTime time.Duration,
idleTimeout time.Duration,
enablePublishStats bool,
queryServiceStats *QueryServiceStats) *SchemaInfo {
si := &SchemaInfo{
queries: cache.NewLRUCache(int64(queryCacheSize)),
connPool: NewConnPool("", 2, idleTimeout, enablePublishStats, queryServiceStats),
ticks: timer.NewTimer(reloadTime),
endpoints: endpoints,
reloadTime: reloadTime,
}
if enablePublishStats {
stats.Publish(statsPrefix+"QueryCacheLength", stats.IntFunc(si.queries.Length))
stats.Publish(statsPrefix+"QueryCacheSize", stats.IntFunc(si.queries.Size))
stats.Publish(statsPrefix+"QueryCacheCapacity", stats.IntFunc(si.queries.Capacity))
stats.Publish(statsPrefix+"QueryCacheOldest", stats.StringFunc(func() string {
return fmt.Sprintf("%v", si.queries.Oldest())
}))
stats.Publish(statsPrefix+"SchemaReloadTime", stats.DurationFunc(si.ticks.Interval))
_ = stats.NewMultiCountersFunc(statsPrefix+"RowcacheStats", []string{"Table", "Stats"}, si.getRowcacheStats)
_ = stats.NewMultiCountersFunc(statsPrefix+"RowcacheInvalidations", []string{"Table"}, si.getRowcacheInvalidations)
_ = stats.NewMultiCountersFunc(statsPrefix+"QueryCounts", []string{"Table", "Plan"}, si.getQueryCount)
_ = stats.NewMultiCountersFunc(statsPrefix+"QueryTimesNs", []string{"Table", "Plan"}, si.getQueryTime)
_ = stats.NewMultiCountersFunc(statsPrefix+"QueryRowCounts", []string{"Table", "Plan"}, si.getQueryRowCount)
_ = stats.NewMultiCountersFunc(statsPrefix+"QueryErrorCounts", []string{"Table", "Plan"}, si.getQueryErrorCount)
}
for _, ep := range endpoints {
http.Handle(ep, si)
}
return si
}
示例7: NewSchemaInfo
func NewSchemaInfo(queryCacheSize int, reloadTime time.Duration, idleTimeout time.Duration, sensitiveMode bool) *SchemaInfo {
si := &SchemaInfo{
queryCacheSize: queryCacheSize,
queries: cache.NewLRUCache(int64(queryCacheSize)),
rules: NewQueryRules(),
connPool: NewConnectionPool("", 2, idleTimeout),
reloadTime: reloadTime,
ticks: timer.NewTimer(reloadTime),
sensitiveMode: sensitiveMode,
}
stats.Publish("QueryCacheLength", stats.IntFunc(si.queries.Length))
stats.Publish("QueryCacheSize", stats.IntFunc(si.queries.Size))
stats.Publish("QueryCacheCapacity", stats.IntFunc(si.queries.Capacity))
stats.Publish("QueryCacheOldest", stats.StringFunc(func() string {
return fmt.Sprintf("%v", si.queries.Oldest())
}))
stats.Publish("SchemaReloadTime", stats.DurationFunc(func() time.Duration {
return si.reloadTime
}))
stats.Publish("TableStats", stats.NewMatrixFunc("Table", "Stats", si.getTableStats))
stats.Publish("TableInvalidations", stats.CountersFunc(si.getTableInvalidations))
stats.Publish("QueryCounts", stats.NewMatrixFunc("Table", "Plan", si.getQueryCount))
stats.Publish("QueryTimesNs", stats.NewMatrixFunc("Table", "Plan", si.getQueryTime))
stats.Publish("QueryRowCounts", stats.NewMatrixFunc("Table", "Plan", si.getQueryRowCount))
stats.Publish("QueryErrorCounts", stats.NewMatrixFunc("Table", "Plan", si.getQueryErrorCount))
// query_plans cannot be shown in sensitive mode
if !si.sensitiveMode {
http.Handle("/debug/query_plans", si)
}
http.Handle("/debug/query_stats", si)
http.Handle("/debug/table_stats", si)
http.Handle("/debug/schema", si)
return si
}
示例8: publishMainStats
func (s *MemcacheStats) publishMainStats() {
s.main.mu.Lock()
defer s.main.mu.Unlock()
for key, isstr := range mainStringMetrics {
key := key
if isstr {
s.main.stats[key] = ""
f := func() string {
s.main.mu.Lock()
defer s.main.mu.Unlock()
s.updateMainStats()
return s.main.stats[key]
}
stats.Publish(s.cachePool.name+"Memcache"+formatKey(key), stats.StringFunc(f))
continue
}
s.main.stats[key] = "0"
f := func() int64 {
s.main.mu.Lock()
defer s.main.mu.Unlock()
s.updateMainStats()
ival, err := strconv.ParseInt(s.main.stats[key], 10, 64)
if err != nil {
log.Errorf("value '%v' for key %v is not an int", s.main.stats[key], key)
return -1
}
return ival
}
stats.Publish(s.cachePool.name+"Memcache"+formatKey(key), stats.IntFunc(f))
}
}
示例9: NewSqlQuery
// NewSqlQuery creates an instance of SqlQuery. Only one instance
// of SqlQuery can be created per process.
func NewSqlQuery(config Config) *SqlQuery {
sq := &SqlQuery{}
sq.qe = NewQueryEngine(config)
stats.Publish("TabletState", stats.IntFunc(sq.state.Get))
stats.Publish("TabletStateName", stats.StringFunc(sq.GetState))
return sq
}
示例10: publishMainStats
func (s *MemcacheStats) publishMainStats() {
s.mu.Lock()
defer s.mu.Unlock()
s.main = make(map[string]string)
for key, isstr := range mainStringMetrics {
key := key
if isstr {
s.main[key] = ""
stats.Publish(s.cachePool.name+"Memcache"+formatKey(key), stats.StringFunc(func() string {
s.mu.Lock()
defer s.mu.Unlock()
return s.main[key]
}))
} else {
s.main[key] = "0"
stats.Publish(s.cachePool.name+"Memcache"+formatKey(key), stats.IntFunc(func() int64 {
s.mu.Lock()
defer s.mu.Unlock()
ival, err := strconv.ParseInt(s.main[key], 10, 64)
if err != nil {
log.Errorf("value '%v' for key %v is not an int", s.main[key], key)
internalErrors.Add("MemcacheStats", 1)
return -1
}
return ival
}))
}
}
}
示例11: init
func init() {
CacheInvalidationProcessor = new(InvalidationProcessor)
stats.Publish("RowcacheInvalidationState", stats.StringFunc(func() string {
return rcinvStateNames[CacheInvalidationProcessor.state.Get()]
}))
stats.Publish("RowcacheInvalidationCheckPoint", stats.IntFunc(func() int64 {
return CacheInvalidationProcessor.GroupId.Get()
}))
}
示例12: NewSqlQuery
func NewSqlQuery(config Config) *SqlQuery {
sq := &SqlQuery{}
sq.qe = NewQueryEngine(config)
sq.rci = NewRowcacheInvalidator(sq.qe)
stats.PublishJSONFunc("Voltron", sq.statsJSON)
stats.Publish("TabletState", stats.IntFunc(sq.state.Get))
stats.Publish("TabletStateName", stats.StringFunc(sq.GetState))
return sq
}
示例13: RegisterUpdateStreamService
func RegisterUpdateStreamService(mycnf *Mycnf) {
if UpdateStreamRpcService != nil {
panic("Update Stream service already initialized")
}
UpdateStreamRpcService = &UpdateStream{mycnf: mycnf}
stats.Publish("UpdateStreamState", stats.StringFunc(func() string {
return usStateNames[UpdateStreamRpcService.state.Get()]
}))
proto.RegisterAuthenticated(UpdateStreamRpcService)
}
示例14: RegisterService
// RegisterService needs to be called to publish stats, and to start listening
// to clients. Only once instance can call this in a process.
func (updateStream *UpdateStreamImpl) RegisterService() {
// publish the stats
stats.Publish("UpdateStreamState", stats.StringFunc(func() string {
return usStateNames[updateStream.state.Get()]
}))
// and register all the RPC protocols
for _, f := range RegisterUpdateStreamServices {
f(updateStream)
}
}
示例15: newZkCell
func newZkCell(name, zkaddr string, zkrstats *zkrStats) *zkCell {
result := &zkCell{cellName: name, zkAddr: zkaddr, zcache: newZkCache(), zkrStats: zkrstats}
result.ready = sync.NewCond(&result.mutex)
stats.Publish("Zcell"+name, stats.StringFunc(func() string {
result.mutex.Lock()
defer result.mutex.Unlock()
return stateNames[result.state]
}))
go result.backgroundRefresher()
return result
}