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


Golang expvar.NewString函數代碼示例

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


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

示例1: New

func New(inst string) {
	instance = inst

	exp.Exp(metrics.DefaultRegistry)

	expvar.NewString("instance").Set(instance)
	expvar.NewString("service").Set(service)
}
開發者ID:graphite-ng,項目名稱:carbon-relay-ng,代碼行數:8,代碼來源:metrics_wrapper.go

示例2: init

func init() {
	expvar.NewString("goVersion").Set(runtime.Version())
	expvar.NewString("iconVersion").Set(besticon.VersionString)

	expvar.NewString("timeLastDeploy").Set(parseUnixTimeStamp(os.Getenv("DEPLOYED_AT")).String())
	expvar.NewString("timeStartup").Set(time.Now().String())
	expvar.Publish("timeCurrent", expvar.Func(func() interface{} { return time.Now() }))
}
開發者ID:undernewmanagement,項目名稱:besticon,代碼行數:8,代碼來源:expvar.go

示例3: main

func main() {

	port := flag.Int("p", 8080, "port to listen on")
	input := flag.String("f", "", "file with signatures to load")
	useVPTree := flag.Bool("vptree", true, "load vptree")
	useStore := flag.Bool("store", true, "load simstore")
	storeSize := flag.Int("size", 6, "simstore size (3/6)")
	cpus := flag.Int("cpus", runtime.NumCPU(), "value of GOMAXPROCS")
	myNumber := flag.Int("no", 0, "id of this machine")
	totalMachines := flag.Int("of", 1, "number of machines to distribute the table among")
	small := flag.Bool("small", false, "use small memory for size 3")

	flag.Parse()

	expvar.NewString("BuildVersion").Set(BuildVersion)

	log.Println("starting simd", BuildVersion)

	log.Println("setting GOMAXPROCS=", *cpus)
	runtime.GOMAXPROCS(*cpus)

	if *input == "" {
		log.Fatalln("no import hash list provided (-f)")
	}

	err := loadConfig(*input, *useStore, *storeSize, *small, *useVPTree, *myNumber, *totalMachines)
	if err != nil {
		log.Fatalln("unable to load config:", err)
	}

	if *useStore {
		http.HandleFunc("/search", func(w http.ResponseWriter, r *http.Request) { searchHandler(w, r) })
	}

	if *useVPTree {
		http.HandleFunc("/topk", func(w http.ResponseWriter, r *http.Request) { topkHandler(w, r) })
	}

	go func() {
		sigs := make(chan os.Signal)
		signal.Notify(sigs, syscall.SIGHUP)

		for {
			select {
			case <-sigs:
				log.Println("caught SIGHUP, reloading")

				err := loadConfig(*input, *useStore, *storeSize, *small, *useVPTree, *myNumber, *totalMachines)
				if err != nil {
					log.Println("reload failed: ignoring:", err)
					break
				}
			}
		}

	}()

	log.Println("listening on port", *port)
	log.Fatal(http.ListenAndServe(":"+strconv.Itoa(*port), nil))
}
開發者ID:xukai504087493,項目名稱:go-simstore,代碼行數:60,代碼來源:main.go

示例4: main

func main() {
	flag.Parse()
	expvar.NewString("listen_port").Set(*listenPort)

	stdout := log.New(os.Stdout, "", log.Ldate|log.Ltime)
	stderr := log.New(os.Stderr, "", log.Ldate|log.Ltime)

	http.Handle("/msg", idHandler(stdout, stderr))

	logMessage(stdout,
		&Message{
			Source: &PROG,
			Key:    &STATUS,
			Content: map[string]interface{}{
				"status": "listening",
				"port":   *listenPort,
			},
		})

	err := http.ListenAndServe(fmt.Sprintf(":%s", *listenPort), nil)
	if err != nil {
		logMessage(stderr,
			&Message{
				Source: &PROG,
				Key:    &ERR,
				Content: map[string]interface{}{
					"error": fmt.Sprintf("error starting to listen: %s", err),
				},
			})
		os.Exit(1)
	}
}
開發者ID:JoelPM,項目名稱:httpjsonlogger,代碼行數:32,代碼來源:httpjsonlogger.go

示例5: init

func init() {
	expvar.NewString("service.startTime").Set(time.Now().String())

	// Suppress usage output. Any errors will be complained about when the user
	// parses flags anyway.
	fs.Usage = func() {}
	fs.SetOutput(nullWriter{})
}
開發者ID:postfix,項目名稱:service,代碼行數:8,代碼來源:service.go

示例6: init

func init() {
	currentTar = expvar.NewString("CurrentTar")
	tarBytesRead = expvar.NewInt("TarBytesRead")
	tarsFailed = expvar.NewInt("TarsFailed")
	tarsIndexed = expvar.NewInt("TarsIndexed")
	tarsSkipped = expvar.NewInt("TarsSkipped")
	tracesFailed = expvar.NewInt("TracesFailed")
	tracesIndexed = expvar.NewInt("TracesIndexed")
}
開發者ID:sburnett,項目名稱:bismark-passive-server-go,代碼行數:9,代碼來源:index.go

示例7: NewMetrics

//NewMetrics creates
//Metrics object
func NewMetrics() *Metrics {
	metrics = &Metrics{
		true,
		expvar.NewInt("comparisons"),
		expvar.NewInt("errors"),
		expvar.NewString("database"),
	}
	return metrics
}
開發者ID:sohlich,項目名稱:go-plag,代碼行數:11,代碼來源:metrics.go

示例8: init

func init() {
	expvar.NewInt("NumCPUs").Set(int64(runtime.NumCPU()))

	revision, err := exec.Command("git", "log", "-1", "--pretty=oneline", "HEAD").Output()
	if err != nil {
		expvar.NewString("revision").Set(fmt.Sprintf("Could not determine git version: %s", err))
	} else {
		expvar.NewString("revision").Set(strings.TrimSpace(string(revision)))
	}

	env := expvar.NewMap("env")
	for _, val := range os.Environ() {
		parts := strings.SplitN(val, "=", 2)
		if len(parts) >= 2 {
			env.Set(parts[0], exposedString{parts[1]})
		}
	}
}
開發者ID:vinays,項目名稱:goodies,代碼行數:18,代碼來源:expvar.go

示例9: main

func main() {

	Whispers = whispers{metrics: make(map[string]*carbonmem.Whisper)}

	flag.IntVar(&Whispers.windowSize, "w", 600, "window size")
	flag.IntVar(&Whispers.epochSize, "e", 60, "epoch window size")
	flag.IntVar(&Whispers.epoch0, "epoch0", 0, "epoch0")
	flag.IntVar(&Whispers.prefix, "prefix", 0, "prefix nodes to shard on")

	port := flag.Int("p", 8001, "port to listen on (http)")
	gport := flag.Int("gp", 2003, "port to listen on (graphite)")
	verbose := flag.Bool("v", false, "verbose logging")
	logdir := flag.String("logdir", "/var/log/carbonmem/", "logging directory")
	logtostdout := flag.Bool("stdout", false, "log also to stdout")

	flag.Parse()

	rl := rotatelogs.NewRotateLogs(
		*logdir + "/carbonmem.%Y%m%d%H%M.log",
	)

	// Optional fields must be set afterwards
	rl.LinkName = *logdir + "/carbonmem.log"

	if *logtostdout {
		log.SetOutput(io.MultiWriter(os.Stdout, rl))
	} else {
		log.SetOutput(rl)
	}

	expvar.NewString("BuildVersion").Set(BuildVersion)
	log.Println("starting carbonmem", BuildVersion)

	expvar.Publish("Whispers", expvar.Func(func() interface{} {
		m := make(map[string]int)
		Whispers.RLock()
		for k, v := range Whispers.metrics {
			m[k] = v.Len()
		}
		Whispers.RUnlock()
		return m
	}))

	if Whispers.epoch0 == 0 {
		Whispers.epoch0 = int(time.Now().Unix())
	}

	go graphiteServer(*gport)

	http.HandleFunc("/metrics/find/", accessHandler(*verbose, findHandler))
	http.HandleFunc("/render/", accessHandler(*verbose, renderHandler))

	log.Println("http server starting on port", *port)
	log.Fatal(http.ListenAndServe(":"+strconv.Itoa(*port), nil))
}
開發者ID:tsheasha,項目名稱:carbonmem,代碼行數:55,代碼來源:main.go

示例10: exportBinaryVersion

func exportBinaryVersion() {
	hasher := md5.New()
	exeFile, err := os.Open("/proc/self/exe")
	if err != nil {
		panic(err)
	}
	if _, err = io.Copy(hasher, exeFile); err != nil {
		panic(err)
	}
	md5sum := hex.EncodeToString(hasher.Sum(nil))
	fileInfo, err := exeFile.Stat()
	if err != nil {
		panic(err)
	}
	mtime := fileInfo.ModTime().Format(time.RFC3339)
	version := mtime + " " + md5sum
	expvar.NewString("binary-version").Set(version)
	// rexport this value for varz scraper
	expvar.NewString("Version").Set(version)
}
開發者ID:seacoastboy,項目名稱:vitess,代碼行數:20,代碼來源:vtocc.go

示例11: NewRuntimeWare

func NewRuntimeWare(prefixes []string, trackPageview bool, logInterval ...time.Duration) Middleware {
	expvar.NewString("at_server_start").Set(time.Now().Format("2006-01-02 15:04:05"))
	expvar.NewInt("cpu_count").Set(int64(runtime.NumCPU()))
	ware := &RuntimeWare{
		serverStarted: time.Now(),
		trackPageview: trackPageview,
		ignoredUrls:   prefixes,
		cQps:          ratecounter.NewRateCounter(time.Minute),
		c4xx:          ratecounter.NewRateCounter(5 * time.Minute),
		c5xx:          ratecounter.NewRateCounter(5 * time.Minute),
		lc:            NewLatencyCounter(50),
		hitsTotal:     expvar.NewInt("hits_total"),
		hitsQps:       expvar.NewInt("hits_per_minute"),
		hits4xx:       expvar.NewInt("hits_4xx_per_5min"),
		hits5xx:       expvar.NewInt("hits_5xx_per_5min"),
		hitsServed:    expvar.NewString("latency_recent"),
		hitsLatMax:    expvar.NewString("latency_max"),
		hitsLatMin:    expvar.NewString("latency_min"),
		hitsLat95:     expvar.NewString("latency_p95"),
		hitsLat50:     expvar.NewString("latency_p50"),
		numGoroutine:  expvar.NewInt("goroutine_count"),
	}
	if trackPageview {
		ware.pageviews = expvar.NewMap("hits_pageviews")
	}
	if len(logInterval) > 0 && logInterval[0] > 0 {
		go ware.logSnapshot(logInterval[0])
	}
	return ware
}
開發者ID:haobaozhong,項目名稱:sweb,代碼行數:30,代碼來源:runtime.go

示例12: init

func init() {
	registry := metrics.NewPrefixedChildRegistry(metrics.DefaultRegistry, "daemon_")
	registry.Register("open_fds", openFDs)
	registry.Register("goroutines", goroutines)
	registry.Register("threads", threads)
	registry.Register("connections", conns)

	registry.Register("hc_openfd", metrics.NewHealthcheck(fdHealthCheck))
	registry.Register("hc_threads", metrics.NewHealthcheck(threadHealthCheck))

	http.Handle("/metrics", exportmetrics.HTTPExport(metrics.DefaultRegistry))

	expvar.NewString("version_info").Set(fmt.Sprintf("version:%s hash:%s build:%s tag:%s",
		version.Version, version.GitHash, version.Build, version.GitTag))
}
開發者ID:noxiouz,項目名稱:stout,代碼行數:15,代碼來源:main.go

示例13: init

func init() {
	currentTar = expvar.NewString("CurrentTar")
	tarBytesRead = expvar.NewInt("TarBytesRead")
	tarsFailed = expvar.NewInt("TarsFailed")
	tarsIndexed = expvar.NewInt("TarsIndexed")
	tarsSkipped = expvar.NewInt("TarsSkipped")
	statsFailed = expvar.NewInt("StatsFailed")
	statsIndexed = expvar.NewInt("StatsIndexed")

	timestampActiveSkipped = expvar.NewInt("TimestampActiveSkipped")
	timestampBismarkExperimentsManagerSkipped = expvar.NewInt("TimestampBismarkExperimentsManagerSkipped")
	timestampBismarkUpdaterSkipped = expvar.NewInt("TimestampBismarkUpdaterSkipped")
	timestampHealthSkipped = expvar.NewInt("TimestampHealthSkipped")
	timestampMacAnalyzerSkipped = expvar.NewInt("TimestampMacAnalyzerSkipped")
	timestampPassiveSkipped = expvar.NewInt("TimestampPassiveSkipped")
	timestampPassiveFrequentSkipped = expvar.NewInt("TimestampPassiveFrequentSkipped")
	timestampOtherSkipped = expvar.NewInt("TimestampOtherSkipped")
}
開發者ID:sburnett,項目名稱:bismark-tools,代碼行數:18,代碼來源:stats.go

示例14: main

func main() {
	var inerInt int64 = 10
	pubInt := expvar.NewInt("Int")
	pubInt.Set(inerInt)
	pubInt.Add(2)

	var inerFloat float64 = 1.2
	pubFloat := expvar.NewFloat("Float")
	pubFloat.Set(inerFloat)
	pubFloat.Add(0.1)

	var inerString string = "hello gophers"
	pubString := expvar.NewString("String")
	pubString.Set(inerString)

	pubMap := expvar.NewMap("Map").Init()
	pubMap.Set("Int", pubInt)
	pubMap.Set("Float", pubFloat)
	pubMap.Set("String", pubString)
	pubMap.Add("Int", 1)
	pubMap.Add("NewInt", 123)
	pubMap.AddFloat("Float", 0.5)
	pubMap.AddFloat("NewFloat", 0.9)
	pubMap.Do(kvfunc)

	expvar.Do(kvfunc)

	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
		fmt.Fprint(w, "hello gophers")
	})
	err := http.ListenAndServe(":8080", nil)
	if err != nil {
		panic(err)
	}

}
開發者ID:JamesJiangCHN,項目名稱:gopkg,代碼行數:36,代碼來源:testExpvar.go

示例15: init

package main

import (
	"expvar"
	"github.com/duego/cryriver/mongodb"
	"log"
	"os"
	"time"
)

var (
	lastEsSeen     *mongodb.Timestamp
	lastEsSeenC    = make(chan *mongodb.Timestamp, 1)
	lastEsSeenStat = expvar.NewString("Last optime seen")
)

func init() {
	// Restore any previously saved timestamp
	lastEsSeen = new(mongodb.Timestamp)
	if f, err := os.Open(*optimeStore); err != nil {
		log.Println("Failed to load previous lastEsSeen timestamp:", err)
	} else {
		lastEsSeen.Load(f)
		f.Close()
	}
	go saveLastEsSeen()
}

// saveLastEsSeen loops the channel to save our progress on what timestamp we have seen so far.
// It will be flushed to disk when our timer ticks.
func saveLastEsSeen() {
開發者ID:ehogberg,項目名稱:cryriver,代碼行數:31,代碼來源:optimestamp.go


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