本文整理汇总了Golang中expvar.Publish函数的典型用法代码示例。如果您正苦于以下问题:Golang Publish函数的具体用法?Golang Publish怎么用?Golang Publish使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Publish函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: init
/*
* Initializations
*/
func init() {
flag.Parse()
status.InputEventCount = expvar.NewInt("input_event_count")
status.OutputEventCount = expvar.NewInt("output_event_count")
status.ErrorCount = expvar.NewInt("error_count")
expvar.Publish("connection_status",
expvar.Func(func() interface{} {
res := make(map[string]interface{}, 0)
res["last_connect_time"] = status.LastConnectTime
res["last_error_text"] = status.LastConnectError
res["last_error_time"] = status.ErrorTime
if status.IsConnected {
res["connected"] = true
res["uptime"] = time.Now().Sub(status.LastConnectTime).Seconds()
} else {
res["connected"] = false
res["uptime"] = 0.0
}
return res
}))
expvar.Publish("uptime", expvar.Func(func() interface{} {
return time.Now().Sub(status.StartTime).Seconds()
}))
expvar.Publish("subscribed_events", expvar.Func(func() interface{} {
return config.EventTypes
}))
results = make(chan string, 100)
output_errors = make(chan error)
status.StartTime = time.Now()
}
开发者ID:carbonblack,项目名称:cb-event-forwarder,代码行数:37,代码来源:main.go
示例2: init
func init() {
expvar.Publish(kapacitor.ClusterIDVarName, cidVar)
expvar.Publish(kapacitor.ServerIDVarName, sidVar)
expvar.Publish(kapacitor.HostVarName, hostVar)
expvar.Publish(kapacitor.ProductVarName, productVar)
expvar.Publish(kapacitor.VersionVarName, versionVar)
}
开发者ID:md14454,项目名称:kapacitor,代码行数:7,代码来源:server.go
示例3: StartDebugServer
func StartDebugServer(address string, sink *lager.ReconfigurableSink, metrics Metrics) (ifrit.Process, error) {
expvar.Publish("numCPUS", expvar.Func(func() interface{} {
return metrics.NumCPU()
}))
expvar.Publish("numGoRoutines", expvar.Func(func() interface{} {
return metrics.NumGoroutine()
}))
expvar.Publish("loopDevices", expvar.Func(func() interface{} {
return metrics.LoopDevices()
}))
expvar.Publish("backingStores", expvar.Func(func() interface{} {
return metrics.BackingStores()
}))
expvar.Publish("depotDirs", expvar.Func(func() interface{} {
return metrics.DepotDirs()
}))
server := http_server.New(address, handler(sink))
p := ifrit.Invoke(server)
select {
case <-p.Ready():
case err := <-p.Wait():
return nil, err
}
return p, nil
}
开发者ID:nagyistoce,项目名称:garden-linux,代码行数:30,代码来源:debug.go
示例4: init
func init() {
besticon.SetCacheMaxSize(128)
expvar.Publish("cacheBytes", expvar.Func(func() interface{} { return besticon.GetCacheStats().Bytes }))
expvar.Publish("cacheItems", expvar.Func(func() interface{} { return besticon.GetCacheStats().Items }))
expvar.Publish("cacheGets", expvar.Func(func() interface{} { return besticon.GetCacheStats().Gets }))
expvar.Publish("cacheHits", expvar.Func(func() interface{} { return besticon.GetCacheStats().Hits }))
expvar.Publish("cacheEvictions", expvar.Func(func() interface{} { return besticon.GetCacheStats().Evictions }))
}
开发者ID:undernewmanagement,项目名称:besticon,代码行数:9,代码来源:server.go
示例5: init
func init() {
expvar.Publish("now", expvar.Func(func() interface{} {
return time.Now().Format("\"2006-01-02 15:04:05\"")
}))
stats = &Stats{}
expvar.Publish("stats", stats)
hits = expvar.NewMap("hits").Init()
}
开发者ID:EthanCai,项目名称:ethancai.github.io,代码行数:11,代码来源:expvarsample.go
示例6: fanout
func fanout(
pubc chan Line,
subc, unsubc chan Subscription,
histc <-chan HistoryRequest,
histSize int,
) {
var (
hist = NewHistory(histSize)
reg = registry{}
publishs = expvar.NewMap("publishs")
subscribes = expvar.NewMap("subscribes")
unsubscribes = expvar.NewMap("unsubscribes")
)
expvar.Publish("history", hist)
expvar.Publish("subscriptions", reg)
for {
select {
case l := <-pubc:
for _, s := range reg[l.Topic()] {
s.In() <- l
}
hist.Store(l)
publishs.Add(l.Topic(), 1)
case s := <-subc:
_, ok := reg[s.Topic()]
if !ok {
reg[s.Topic()] = map[string]Subscription{}
}
reg[s.Topic()][s.ID()] = s
subscribes.Add(s.Topic(), 1)
logf("fanout: subscribed %s\n", s.ID())
case s := <-unsubc:
subs, ok := reg[s.Topic()]
if !ok {
continue
}
_, ok = subs[s.ID()]
if !ok {
continue
}
delete(subs, s.ID())
unsubscribes.Add(s.Topic(), 1)
logf("fanout: unsubscribed %s\n", s.ID())
case req := <-histc:
req.Respond(hist.Get(req.Topic(), req.Size()))
}
}
}
开发者ID:mehulsbhatt,项目名称:log,代码行数:53,代码来源:bazooka-log.go
示例7: initDebug
func initDebug(mux *http.ServeMux) {
stats.prev = time.Now()
expvar.Publish("dcp", expvar.Func(dcp))
expvar.Publish("goroutines", expvar.Func(goroutines))
mux.Handle("/debug/vars/", http.HandlerFunc(expvarHandler))
mux.Handle("/debug/pprof/", http.HandlerFunc(pprof.Index))
mux.Handle("/debug/pprof/cmdline", http.HandlerFunc(pprof.Cmdline))
mux.Handle("/debug/pprof/profile", http.HandlerFunc(pprof.Profile))
mux.Handle("/debug/pprof/symbol", http.HandlerFunc(pprof.Symbol))
mux.Handle("/debug/pprof/trace", http.HandlerFunc(pprof.Trace))
}
开发者ID:couchbaselabs,项目名称:dcpl,代码行数:13,代码来源:debug.go
示例8: main
func main() {
flag.Parse()
if err := loadContext(); err != nil {
panic(err)
}
ctx := context()
expvar.Publish("config", &ctx.Config)
expvar.Publish("codemanager", expvar.Func(func() interface{} {
return context().InputManager
}))
expvar.Publish("queues", expvar.Func(func() interface{} {
return context().QueueManager
}))
expvar.Publish("inflight_runs", expvar.Func(func() interface{} {
return context().InflightMonitor
}))
cachePath := path.Join(ctx.Config.Grader.RuntimePath, "cache")
go ctx.InputManager.PreloadInputs(
cachePath,
grader.NewGraderCachedInputFactory(cachePath),
&sync.Mutex{},
)
// Database
db, err := sql.Open(
ctx.Config.Db.Driver,
ctx.Config.Db.DataSourceName,
)
if err != nil {
panic(err)
}
if err := db.Ping(); err != nil {
panic(err)
}
setupMetrics(ctx)
ctx.Log.Info("omegaUp grader started")
mux := http.DefaultServeMux
if ctx.Config.Grader.V1.Enabled {
registerV1CompatHandlers(mux, db)
go common.RunServer(&ctx.Config.TLS, mux, ctx.Config.Grader.V1.Port, *insecure)
mux = http.NewServeMux()
}
registerHandlers(mux, db)
common.RunServer(&ctx.Config.TLS, mux, ctx.Config.Grader.Port, *insecure)
}
开发者ID:lhchavez,项目名称:quark,代码行数:51,代码来源:main.go
示例9: init
func init() {
expvar.Publish("snmp_request_cache", expvar.Func(func() interface{} {
requests_mutex.Lock()
size := requests_cache.Size()
requests_mutex.Unlock()
return size
}))
expvar.Publish("snmp_bytes_cache", expvar.Func(func() interface{} {
bytes_mutex.Lock()
size := bytes_cache.Size()
bytes_mutex.Unlock()
return size
}))
}
开发者ID:runner-mei,项目名称:snmpclient,代码行数:15,代码来源:udp_client.go
示例10: NewStatistics
// NewStatistics creates an expvar-based map. Within there "name" is the Measurement name, "tags" are the tags,
// and values are placed at the key "values".
// The "values" map is returned so that statistics can be set.
func NewStatistics(name string, tags map[string]string) *expvar.Map {
expvarMu.Lock()
defer expvarMu.Unlock()
key := uuid.NewV4().String()
m := &expvar.Map{}
m.Init()
expvar.Publish(key, m)
// Set the name
nameVar := &expvar.String{}
nameVar.Set(name)
m.Set("name", nameVar)
// Set the tags
tagsVar := &expvar.Map{}
tagsVar.Init()
for k, v := range tags {
value := &expvar.String{}
value.Set(v)
tagsVar.Set(k, value)
}
m.Set("tags", tagsVar)
// Create and set the values entry used for actual stats.
statMap := &expvar.Map{}
statMap.Init()
m.Set("values", statMap)
return statMap
}
开发者ID:md14454,项目名称:kapacitor,代码行数:35,代码来源:stats.go
示例11: hook
func hook(m measurable.Measurable, event measurable.HookEvent) {
switch m.MsType() {
case measurable.CounterType, measurable.GaugeType:
// ok
default:
return // not supported
}
name := m.MsName()
switch event {
case measurable.RegisterEvent, measurable.RegisterCatchupEvent:
a := &adaptor{
measurable: m,
}
measurablesMutex.Lock()
defer measurablesMutex.Unlock()
measurables[name] = a
expvar.Publish(name, a)
case measurable.UnregisterEvent:
a := measurables[name]
if a != nil { // this should always be the case, but whatever
a.mutex.Lock()
defer a.mutex.Unlock()
a.measurable = nil
}
}
}
开发者ID:hlandau,项目名称:easymetric,代码行数:32,代码来源:adaptexpvar.go
示例12: NewCounters
func NewCounters(name string) *Counters {
c := &Counters{counts: make(map[string]int64)}
if name != "" {
expvar.Publish(name, c)
}
return c
}
开发者ID:Eric-Chen,项目名称:vitess,代码行数:7,代码来源:counters.go
示例13: NewSimpleMovingPercentile
// Create a new simple moving percentile expvar.Var. It will be
// published under `name` and maintain `size` values for
// calculating the percentile.
//
// percentile must be between 0 and 1
//
// An empty name will cause it to not be published
func NewSimpleMovingPercentile(name string, percentile float64, size int) *SimpleMovingStat {
sm := new(SimpleMovingStat)
sm.size = size
sm.mutex = new(sync.Mutex)
sm.values = ring.New(size)
sm.calculate = func(s *SimpleMovingStat) float64 {
ary := make([]float64, 0)
s.values.Do(func(val interface{}) {
if val != nil {
ary = append(ary, val.(float64))
}
})
length := len(ary)
if length == 0 {
return 0.0
}
sort.Float64s(ary)
mid := int(float64(len(ary)) * percentile)
return ary[mid]
}
if name != "" {
expvar.Publish(name, sm)
}
return sm
}
开发者ID:brianm,项目名称:variant,代码行数:35,代码来源:smav.go
示例14: NewTimings
func NewTimings(name string) *Timings {
t := &Timings{Histograms: make(map[string]*Histogram)}
if name != "" {
expvar.Publish(name, t)
}
return t
}
开发者ID:bodogbo,项目名称:OSG-Server-Go,代码行数:7,代码来源:timings.go
示例15: main
func main() {
// Initialise our configuration from flags
var nodeName = flag.String("name", REQUIRED, "Node network name and port, e.g. localhost:3000")
var gobName = flag.String("gob", "", "Alternative gob network name and port for clients, allowing clients to connect over a different physical interface to nodes.")
var httpName = flag.String("http", "", "Network name and port for the http ExpVar to listen on.")
var cborName = flag.String("cbor", "", "Network name and port for the CBOR RPC interface to listen on.")
var nodePath = flag.String("path", REQUIRED, "Node root path for configuration and log files")
var clusterID = flag.String("id", "", "Cluster ID that this node is part of")
flag.Parse()
if flag.Lookup("help") != nil || flag.Lookup("h") != nil {
flag.PrintDefaults()
return
}
if *nodeName == REQUIRED {
log.Printf("name missing.\n")
flag.PrintDefaults()
return
}
if *nodePath == REQUIRED {
log.Printf("path missing.\n")
flag.PrintDefaults()
return
}
// Create our server
serverNode, err := server.NewServerNode(*nodeName, *gobName, *httpName, *cborName, *nodePath, *clusterID)
if err != nil {
log.Fatalf("Unable to start server due to errors.\n")
}
expvar.Publish("node", expvar.Func(serverNode.ExpVar))
//dataLog := &memlog.MemoryLog{}
// Start a listener to handle incoming requests from other peers
err = serverNode.ListenConnections()
if err != nil {
log.Fatalf("Error starting listener: %v\n", err)
}
// Setup signal handling to catch interrupts.
sigc := make(chan os.Signal, 1)
signal.Notify(sigc,
os.Interrupt,
os.Kill)
go func() {
<-sigc
serverNode.RequestShutdown("Request to terminate process detected.")
}()
serverNode.WaitForShutdown()
}
开发者ID:owlfish,项目名称:forestbus-server,代码行数:59,代码来源:server.go
示例16: init
func init() {
raft.SetLogger(capnslog.NewPackageLogger("github.com/coreos/etcd", "raft"))
expvar.Publish("raft.status", expvar.Func(func() interface{} {
raftStatusMu.Lock()
defer raftStatusMu.Unlock()
return raftStatus()
}))
}
开发者ID:XiangrongFan,项目名称:etcd,代码行数:8,代码来源:raft.go
示例17: init
func init() {
flag.Usage = func() {
fmt.Fprintln(os.Stderr, "Usage of inbucket [options] <conf file>:")
flag.PrintDefaults()
}
expvar.Publish("uptime", expvar.Func(uptime))
}
开发者ID:hotei,项目名称:inbucket,代码行数:8,代码来源:inbucket.go
示例18: StartSelfMonitor
// StartSelfMonitor starts http server on random port and exports expvars.
//
// It tries 1024 ports, starting from startPort and registers some expvars if ok.
func StartSelfMonitor() (string, error) {
for port := startPort; port < startPort+1024; port++ {
bind := fmt.Sprintf("localhost:%d", port)
l, err := net.Listen("tcp", bind)
if err != nil {
continue
}
l.Close()
expvar.Publish("Goroutines", expvar.Func(goroutines))
expvar.Publish("Uptime", expvar.Func(uptime))
go http.ListenAndServe(bind, nil)
return bind, nil
}
return "", fmt.Errorf("no free ports found")
}
开发者ID:cofyc,项目名称:expvarmon,代码行数:20,代码来源:self.go
示例19: 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
示例20: initExpvars
func initExpvars() {
expvar.Publish("__binary_path", expvar.Func(func() interface{} { return &binaryPath }))
expvar.Publish("__config_path", expvar.Func(func() interface{} { return &configPath }))
expvar.Publish("_command_line", expvar.Func(func() interface{} { return &commandLine }))
expvar.Publish("_version", expvar.Func(func() interface{} { return VersionInfo }))
expvar.Publish("_hostname", expvar.Func(func() interface{} { return hostname }))
expvar.Publish("_config", expvar.Func(func() interface{} {
cf, err := structs.BadooStripSecretFields(config) // makes a copy of `config`
if err != nil {
return struct {
Error string `json:"error"`
}{err.Error()}
}
return cf
}))
expvar.Publish("_service-stats", expvar.Func(func() interface{} {
stats, err := GatherServiceStats()
if err != nil {
return struct {
Error string `json:"error"`
}{err.Error()}
}
return stats
}))
}
开发者ID:badoo,项目名称:thunder,代码行数:27,代码来源:service.go
注:本文中的expvar.Publish函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论