當前位置: 首頁>>代碼示例>>Golang>>正文


Golang expvar.Do函數代碼示例

本文整理匯總了Golang中expvar.Do函數的典型用法代碼示例。如果您正苦於以下問題:Golang Do函數的具體用法?Golang Do怎麽用?Golang Do使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了Do函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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


注:本文中的expvar.Do函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。