本文整理汇总了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

最后编辑: kuteng  文档更新时间: 2021-08-23 19:14   作者:kuteng