本文整理汇总了Golang中expvar.Do函数的典型用法代码示例。如果您正苦于以下问题:Golang Do函数的具体用法?Golang Do怎么用?Golang Do使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Do函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: Cleanup
func (eb *Winlogbeat) Cleanup(b *beat.Beat) error {
logp.Debug("winlogbeat", "Dumping runtime metrics...")
expvar.Do(func(kv expvar.KeyValue) {
logp.Debug("winlogbeat", "%s=%s", kv.Key, kv.Value.String())
})
return nil
}
开发者ID:ruflin,项目名称:winlogbeat,代码行数:7,代码来源:winlogbeat.go
示例2: TestSchemaInfoQueryCache
func TestSchemaInfoQueryCache(t *testing.T) {
db := fakesqldb.Register()
for query, result := range getSchemaInfoTestSupportedQueries() {
db.AddQuery(query, result)
}
firstQuery := "select * from test_table_01"
secondQuery := "select * from test_table_02"
db.AddQuery("select * from test_table_01 where 1 != 1", &sqltypes.Result{})
db.AddQuery("select * from test_table_02 where 1 != 1", &sqltypes.Result{})
schemaInfo := newTestSchemaInfo(10, 10*time.Second, 10*time.Second, true)
dbaParams := sqldb.ConnParams{Engine: db.Name}
schemaInfo.Open(&dbaParams, true)
defer schemaInfo.Close()
ctx := context.Background()
logStats := newLogStats("GetPlanStats", ctx)
schemaInfo.SetQueryCacheCap(1)
firstPlan := schemaInfo.GetPlan(ctx, logStats, firstQuery)
if firstPlan == nil {
t.Fatalf("plan should not be nil")
}
secondPlan := schemaInfo.GetPlan(ctx, logStats, secondQuery)
if secondPlan == nil {
t.Fatalf("plan should not be nil")
}
expvar.Do(func(kv expvar.KeyValue) {
_ = kv.Value.String()
})
schemaInfo.ClearQueryPlanCache()
}
开发者ID:CowLeo,项目名称:vitess,代码行数:32,代码来源:schema_info_test.go
示例3: ExportVariablesWithTimestamp
// Export expvars to Cube right now. Use the provided timestamp for the
// submitted event. This function sends variables once and returns.
//
// You shouldn't need this function under normal circumstances. Use Run()
// instead.
func ExportVariablesWithTimestamp(collectionType string, putUrl string, timestamp time.Time) error {
variables := make([]string, 0)
expvar.Do(func(entry expvar.KeyValue) {
variables = append(variables, fmt.Sprintf("%q: %s", entry.Key, entry.Value))
})
request := fmt.Sprintf(
`[
{
"type": "%s",
"time": "%s",
"data": { %s }
}
]`,
collectionType,
timestamp.Format(time.ANSIC),
strings.Join(variables, ","))
response, err := http.Post(putUrl, "application/json", bytes.NewBufferString(request))
if err != nil {
log.Printf("Error POSTing events to Cube collector: %v", err)
log.Printf("The request we tried to post: %v", request)
return err
}
defer response.Body.Close()
return nil
}
开发者ID:sburnett,项目名称:cube,代码行数:31,代码来源:emitter.go
示例4: StatsLogInterval
// By using StatsLog, you can print stats on stdout every second, which is sometimes handy to check the state
// of the server. The stats themselves are declared using the "expvar" package
// to use this function, just before starting your listeners, create a goroutine like this
// go logging.StatsLog()
func StatsLogInterval(seconds int) {
// If we are running in debug mode, do not clog the screen
if IsDebug() {
log.Println("disabling logger in debug mode")
return
}
log.Println("starting logger")
info := log.New(os.Stdout, "s:", log.Ldate|log.Ltime)
sleepTime := time.Duration(seconds) * time.Second
for _ = range time.Tick(sleepTime) {
var buffer bytes.Buffer
expvar.Do(func(k expvar.KeyValue) {
if strings.HasPrefix(k.Key, StatsPrefix) {
buffer.WriteString(fmt.Sprintf("[%s %s] ", strings.TrimLeft(k.Key, StatsPrefix), k.Value))
// reset stats every nseconds
if v, ok := (k.Value).(*expvar.Int); ok {
v.Set(0)
}
}
})
info.Println(buffer.String())
}
}
开发者ID:tokopedia,项目名称:logging,代码行数:32,代码来源:stats.go
示例5: RegisterDebug
// RegisterDebug adds handlers for /debug/vars (expvar) and /debug/pprof (net/http/pprof) support
func (this *HttpWeb) RegisterDebug(m *martini.ClassicMartini) {
m.Get("/debug/vars", func(w http.ResponseWriter, r *http.Request) {
// from expvar.go, since the expvarHandler isn't exported :(
w.Header().Set("Content-Type", "application/json; charset=utf-8")
fmt.Fprintf(w, "{\n")
first := true
expvar.Do(func(kv expvar.KeyValue) {
if !first {
fmt.Fprintf(w, ",\n")
}
first = false
fmt.Fprintf(w, "%q: %s", kv.Key, kv.Value)
})
fmt.Fprintf(w, "\n}\n")
})
// list all the /debug/ endpoints we want
m.Get("/debug/pprof", pprof.Index)
m.Get("/debug/pprof/cmdline", pprof.Cmdline)
m.Get("/debug/pprof/profile", pprof.Profile)
m.Get("/debug/pprof/symbol", pprof.Symbol)
m.Post("/debug/pprof/symbol", pprof.Symbol)
m.Get("/debug/pprof/block", pprof.Handler("block").ServeHTTP)
m.Get("/debug/pprof/heap", pprof.Handler("heap").ServeHTTP)
m.Get("/debug/pprof/goroutine", pprof.Handler("goroutine").ServeHTTP)
m.Get("/debug/pprof/threadcreate", pprof.Handler("threadcreate").ServeHTTP)
}
开发者ID:0-T-0,项目名称:orchestrator,代码行数:29,代码来源:web.go
示例6: ExpvarHandler
// ExpvarHandler dumps json representation of expvars to http response.
//
// Expvars may be filtered by regexp provided via 'r' query argument.
//
// See https://golang.org/pkg/expvar/ for details.
func ExpvarHandler(ctx *fasthttp.RequestCtx) {
expvarHandlerCalls.Add(1)
ctx.Response.Reset()
r, err := getExpvarRegexp(ctx)
if err != nil {
expvarRegexpErrors.Add(1)
fmt.Fprintf(ctx, "Error when obtaining expvar regexp: %s", err)
ctx.SetStatusCode(fasthttp.StatusBadRequest)
return
}
fmt.Fprintf(ctx, "{\n")
first := true
expvar.Do(func(kv expvar.KeyValue) {
if r.MatchString(kv.Key) {
if !first {
fmt.Fprintf(ctx, ",\n")
}
first = false
fmt.Fprintf(ctx, "\t%q: %s", kv.Key, kv.Value)
}
})
fmt.Fprintf(ctx, "\n}\n")
ctx.SetContentType("application/json; charset=utf-8")
}
开发者ID:valyala,项目名称:fasthttp,代码行数:33,代码来源:expvar.go
示例7: Status
func (daemon *SSEDaemon) Status(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
fmt.Fprintf(w, "{\"status\":\"OK\"")
expvar.Do(func(kv expvar.KeyValue) {
fmt.Fprintf(w, ",%q:%s", kv.Key, kv.Value)
})
fmt.Fprintf(w, "}")
}
开发者ID:rayyang2000,项目名称:oplog,代码行数:8,代码来源:sse.go
示例8: dumpMetrics
// dumpMetrics is used to log metrics on shutdown.
func dumpMetrics() {
logp.Info("Dumping runtime metrics...")
expvar.Do(func(kv expvar.KeyValue) {
if kv.Key != "memstats" {
logp.Info("%s=%s", kv.Key, kv.Value.String())
}
})
}
开发者ID:ChongFeng,项目名称:beats,代码行数:9,代码来源:metricbeat.go
示例9: LogOnDebugLevel
// LogOnDebugLevel logs all the current metrics, if logging is on Debug level.
func LogOnDebugLevel() {
if log.GetLevel() == log.DebugLevel {
fields := log.Fields{}
expvar.Do(func(kv expvar.KeyValue) {
fields[kv.Key] = kv.Value
})
logger.WithFields(fields).Debug("current values of metrics")
}
}
开发者ID:smancke,项目名称:guble,代码行数:10,代码来源:metrics.go
示例10: Cleanup
// Cleanup performs clean-up after Run completes.
func (bt *Metricbeat) Cleanup(b *beat.Beat) error {
logp.Info("Dumping runtime metrics...")
expvar.Do(func(kv expvar.KeyValue) {
if kv.Key != "memstats" {
logp.Info("%s=%s", kv.Key, kv.Value.String())
}
})
return nil
}
开发者ID:McStork,项目名称:beats,代码行数:10,代码来源:metricbeat.go
示例11: snapshotExpvars
// snapshotExpvars iterates through all the defined expvars, and for the vars
// that are integers it snapshots the name and value in a separate (flat) map.
func snapshotExpvars(varsMap map[string]int64) {
expvar.Do(func(kv expvar.KeyValue) {
switch kv.Value.(type) {
case *expvar.Int:
varsMap[kv.Key], _ = strconv.ParseInt(kv.Value.String(), 10, 64)
case *expvar.Map:
snapshotMap(varsMap, kv.Key, kv.Value.(*expvar.Map))
}
})
}
开发者ID:YaSuenag,项目名称:hsbeat,代码行数:12,代码来源:logp.go
示例12: printVars
func printVars() {
log.Println("expvars:")
expvar.Do(func(kv expvar.KeyValue) {
switch kv.Key {
case "memstats":
// Do nothing, this is a big output.
default:
log.Printf("\t%s -> %s", kv.Key, kv.Value)
}
})
}
开发者ID:rrudduck,项目名称:golang-stuff,代码行数:11,代码来源:expvar.go
示例13: cleanup
// cleanup attempts to remove any files or data it may have created which should
// not be persisted.
func (eb *Winlogbeat) cleanup(b *beat.Beat) {
logp.Info("Dumping runtime metrics...")
expvar.Do(func(kv expvar.KeyValue) {
logf := logp.Info
if kv.Key == "memstats" {
logf = memstatsf
}
logf("%s=%s", kv.Key, kv.Value.String())
})
}
开发者ID:ChongFeng,项目名称:beats,代码行数:13,代码来源:winlogbeat.go
示例14: writeMetrics
func writeMetrics(w io.Writer) {
fmt.Fprintf(w, "{\n")
first := true
expvar.Do(func(kv expvar.KeyValue) {
if !first {
fmt.Fprintf(w, ",\n")
}
first = false
fmt.Fprintf(w, "%q: %s", kv.Key, kv.Value)
})
fmt.Fprintf(w, "\n}\n")
}
开发者ID:cosminrentea,项目名称:guble,代码行数:12,代码来源:metrics.go
示例15: do
func do(f func(expvar.KeyValue)) {
expvar.Do(func(kv expvar.KeyValue) {
switch kv.Key {
case "cmdline",
"memstats":
return
}
if _, ok := kv.Value.(*expvar.Int); !ok {
return
}
f(kv)
})
}
开发者ID:zgo,项目名称:expvar-munin-node,代码行数:13,代码来源:expvar.go
示例16: writeMetrics
func writeMetrics(w io.Writer) {
numGoroutines.Set(int64(runtime.NumGoroutine()))
fmt.Fprint(w, "{\n")
first := true
expvar.Do(func(kv expvar.KeyValue) {
if !first {
fmt.Fprint(w, ",\n")
}
first = false
fmt.Fprintf(w, "%q: %s", kv.Key, kv.Value)
})
fmt.Fprint(w, "\n}\n")
}
开发者ID:smancke,项目名称:guble,代码行数:13,代码来源:metrics.go
示例17: LogOnDebugLevel
// LogOnDebugLevel logs all the current metrics, if logging is on Debug level.
func LogOnDebugLevel() {
if !*config.Metrics.Enabled {
log.Debug("metrics: not enabled")
return
}
if log.GetLevel() == log.DebugLevel {
fields := log.Fields{}
expvar.Do(func(kv expvar.KeyValue) {
fields[kv.Key] = kv.Value
})
log.WithFields(fields).Debug("metrics: current values")
}
}
开发者ID:cosminrentea,项目名称:guble,代码行数:14,代码来源:metrics.go
示例18: serveExpvar
// serveExpvar serves registered expvar information over HTTP.
func serveExpvar(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json; charset=utf-8")
fmt.Fprintf(w, "{\n")
first := true
expvar.Do(func(kv expvar.KeyValue) {
if !first {
fmt.Fprintf(w, ",\n")
}
first = false
fmt.Fprintf(w, "%q: %s", kv.Key, kv.Value)
})
fmt.Fprintf(w, "\n}\n")
}
开发者ID:edwkar,项目名称:influxdb,代码行数:14,代码来源:handler.go
示例19: TestSchemaInfoExportVars
func TestSchemaInfoExportVars(t *testing.T) {
db := fakesqldb.Register()
for query, result := range getSchemaInfoTestSupportedQueries() {
db.AddQuery(query, result)
}
schemaInfo := newTestSchemaInfo(10, 1*time.Second, 1*time.Second, true)
dbaParams := sqldb.ConnParams{Engine: db.Name}
schemaInfo.Open(&dbaParams, true)
defer schemaInfo.Close()
expvar.Do(func(kv expvar.KeyValue) {
_ = kv.Value.String()
})
}
开发者ID:CowLeo,项目名称:vitess,代码行数:13,代码来源:schema_info_test.go
示例20: GetByDo
// GetByDo takes expvar map using Do method from expvar package
func GetByDo() (string, error) {
result := "{"
first := true
expvar.Do(func(kv expvar.KeyValue) {
if !first {
result += ",\n"
}
first = false
result += fmt.Sprintf("%q: %s", kv.Key, kv.Value)
})
result += "}"
return result, nil
}
开发者ID:betacraft,项目名称:deferclient,代码行数:15,代码来源:expvars.go
注:本文中的expvar.Do函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论