本文整理匯總了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)
}
示例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() }))
}
示例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))
}
示例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)
}
}
示例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{})
}
示例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")
}
示例7: NewMetrics
//NewMetrics creates
//Metrics object
func NewMetrics() *Metrics {
metrics = &Metrics{
true,
expvar.NewInt("comparisons"),
expvar.NewInt("errors"),
expvar.NewString("database"),
}
return metrics
}
示例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]})
}
}
}
示例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))
}
示例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)
}
示例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
}
示例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))
}
示例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")
}
示例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)
}
}
示例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() {