本文整理匯總了Golang中github.com/funkygao/golib/gofmt.Comma函數的典型用法代碼示例。如果您正苦於以下問題:Golang Comma函數的具體用法?Golang Comma怎麽用?Golang Comma使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Comma函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: showPps
func (this *Pps) showPps(nic string) {
tx := fmt.Sprintf("/sys/class/net/%s/statistics/tx_packets", nic)
rx := fmt.Sprintf("/sys/class/net/%s/statistics/rx_packets", nic)
var lastTx, lastRx int64
s := int64(this.interval.Seconds())
for {
brx, err := ioutil.ReadFile(rx)
swallow(err)
btx, err := ioutil.ReadFile(tx)
swallow(err)
rxN, err := strconv.ParseInt(strings.TrimSpace(string(brx)), 10, 64)
swallow(err)
txN, err := strconv.ParseInt(strings.TrimSpace(string(btx)), 10, 64)
swallow(err)
if lastRx != 0 && lastTx != 0 {
rxPps := (rxN - lastRx) / s
txPps := (txN - lastTx) / s
sumPps := rxPps + txPps
this.Ui.Output(fmt.Sprintf("%10s rx:%-8s tx:%-8s sum:%-8s",
nic, gofmt.Comma(rxPps), gofmt.Comma(txPps), gofmt.Comma(sumPps)))
}
lastRx = rxN
lastTx = txN
time.Sleep(this.interval)
}
}
示例2: printSummary
func (this *Clusters) printSummary(zkzone *zk.ZkZone, clusterPattern string, port string) {
lines := []string{"Zone|Cluster|Brokers|Topics|Partitions|FlatMsg|Cum"}
type summary struct {
zone, cluster string
brokers, topics, partitions int
flat, cum int64
}
summaries := make([]summary, 0, 10)
zkzone.ForSortedClusters(func(zkcluster *zk.ZkCluster) {
if !patternMatched(zkcluster.Name(), clusterPattern) {
return
}
brokers, topics, partitions, flat, cum := this.clusterSummary(zkcluster)
summaries = append(summaries, summary{zkzone.Name(), zkcluster.Name(), brokers, topics, partitions,
flat, cum})
})
sortutil.DescByField(summaries, "cum")
var totalFlat, totalCum int64
for _, s := range summaries {
lines = append(lines, fmt.Sprintf("%s|%s|%d|%d|%d|%s|%s",
s.zone, s.cluster, s.brokers, s.topics, s.partitions,
gofmt.Comma(s.flat), gofmt.Comma(s.cum)))
totalCum += s.cum
totalFlat += s.flat
}
this.Ui.Output(columnize.SimpleFormat(lines))
this.Ui.Output(fmt.Sprintf("Flat:%s Cum:%s", gofmt.Comma(totalFlat), gofmt.Comma(totalCum)))
}
示例3: showStats
func (this *FunServantImpl) showStats() {
ticker := time.NewTicker(config.Engine.Servants.StatsOutputInterval)
defer ticker.Stop()
for _ = range ticker.C {
log.Info("svt: {slow:%s peer.from:%s, peer.to:%s}",
gofmt.Comma(svtStats.callsSlow),
gofmt.Comma(svtStats.callsFromPeer),
gofmt.Comma(svtStats.callsToPeer))
}
}
示例4: render
func (this *routerStats) render(logger *log.Logger, elapsed int) {
logger.Printf("Total:%10s %10s speed:%6s/s %10s/s max: %s/%s",
gofmt.Comma(this.TotalProcessedMsgN),
gofmt.ByteSize(this.TotalProcessedBytes),
gofmt.Comma(int64(this.PeriodProcessedMsgN/int32(elapsed))),
gofmt.ByteSize(this.PeriodProcessedBytes/int64(elapsed)),
gofmt.ByteSize(this.PeriodMaxMsgBytes),
gofmt.ByteSize(this.TotalMaxMsgBytes))
logger.Printf("Input:%10s %10s speed:%6s/s %10s/s",
gofmt.Comma(int64(this.PeriodInputMsgN)),
gofmt.ByteSize(this.PeriodInputBytes),
gofmt.Comma(int64(this.PeriodInputMsgN/int32(elapsed))),
gofmt.ByteSize(this.PeriodInputBytes/int64(elapsed)))
}
示例5: showOffsetGrowth
func (this *Histogram) showOffsetGrowth() ([]time.Time, []int64) {
f, err := os.OpenFile(this.offsetFile, os.O_RDONLY, 0660)
swallow(err)
defer f.Close()
ts := make([]time.Time, 0)
vs := make([]int64, 0)
r := bufio.NewReader(f)
var (
lastN = int64(0)
tm string
)
for {
line, err := r.ReadString('\n')
if err == io.EOF {
break
}
line = strings.TrimSpace(line)
if !strings.Contains(line, "CUM Messages") {
// time info: Thu Jun 16 22:45:01 CST 2016
tm = line
} else {
// offset: -CUM Messages- 255,705,684,384
n := strings.Split(line, "-CUM Messages-")[1]
n = strings.Replace(n, ",", "", -1)
n = strings.TrimSpace(n)
offset, err := strconv.ParseInt(n, 10, 64)
swallow(err)
if lastN > 0 {
t, e := time.Parse("Mon Jan 2 15:04:05 MST 2006", tm)
swallow(e)
ts = append(ts, t)
vs = append(vs, offset-lastN)
this.Ui.Output(fmt.Sprintf("%55s Message+ %15s/%s", tm,
gofmt.Comma(offset-lastN), gofmt.Comma(lastN)))
}
lastN = offset
}
}
return ts, vs
}
示例6: showStats
func (this *TFunServer) showStats(interval time.Duration) {
ticker := time.NewTicker(interval)
defer ticker.Stop()
for _ = range ticker.C {
log.Info("rpc: {session.on:%d/%s, call.err:%s/%s, qps:{1m:%.0f, 5m:%.0f 15m:%.0f avg:%.0f}}",
atomic.LoadInt64(&this.activeSessionN),
gofmt.Comma(atomic.LoadInt64(&this.cumSessions)),
gofmt.Comma(atomic.LoadInt64(&this.cumCallErrs)),
gofmt.Comma(atomic.LoadInt64(&this.cumCalls)),
this.stats.CallPerSecond.Rate1(),
this.stats.CallPerSecond.Rate5(),
this.stats.CallPerSecond.Rate15(),
this.stats.CallPerSecond.RateMean())
}
}
示例7: statusHandler
// @rest GET /v1/status
func (this *manServer) statusHandler(w http.ResponseWriter, r *http.Request, params httprouter.Params) {
log.Info("status %s(%s)", r.RemoteAddr, getHttpRemoteIp(r))
output := make(map[string]interface{})
output["options"] = Options
output["loglevel"] = logLevel.String()
output["manager"] = manager.Default.Dump()
pubConns := int(atomic.LoadInt32(&this.gw.pubServer.activeConnN))
subConns := int(atomic.LoadInt32(&this.gw.subServer.activeConnN))
output["pubconn"] = strconv.Itoa(pubConns)
output["subconn"] = strconv.Itoa(subConns)
output["hh_appends"] = strconv.FormatInt(hh.Default.AppendN(), 10)
output["hh_delivers"] = strconv.FormatInt(hh.Default.DeliverN(), 10)
output["goroutines"] = strconv.Itoa(runtime.NumGoroutine())
var mem runtime.MemStats
runtime.ReadMemStats(&mem)
output["heap"] = gofmt.ByteSize(mem.HeapSys).String()
output["objects"] = gofmt.Comma(int64(mem.HeapObjects))
b, err := json.MarshalIndent(output, "", " ")
if err != nil {
log.Error("%s(%s) %v", r.RemoteAddr, getHttpRemoteIp(r), err)
}
w.Write(b)
}
示例8: main
func main() {
cf := config.NewDefaultProxy()
cf.IoTimeout = time.Hour
cf.TcpNoDelay = tcpNoDelay
prx := proxy.New(cf)
etclib.Dial([]string{zk})
go prx.StartMonitorCluster()
prx.AwaitClusterTopologyReady()
// test pool
if testPool {
testServantPool(prx)
pause("pool tested")
}
go report.run()
wg := new(sync.WaitGroup)
t1 := time.Now()
for k := c1; k <= c2; k += 10 {
Concurrency = k
cf.PoolCapacity = Concurrency
prx = proxy.New(cf)
for i := 0; i < Rounds; i++ {
for j := 0; j < k; j++ {
wg.Add(1)
go runSession(prx, wg, i+1, j)
}
wg.Wait()
}
}
elapsed := time.Since(t1)
log.Printf("Elapsed: %s, calls: {%s, %.1f/s}, sessions: {%s, %.1f/s}, errors: {conn:%d, io:%d call:%d}",
elapsed,
gofmt.Comma(report.callOk),
float64(report.callOk)/elapsed.Seconds(),
gofmt.Comma(int64(report.sessionN)),
float64(report.sessionN)/elapsed.Seconds(),
report.connErrs,
report.ioErrs,
report.callErrs)
}
示例9: getStats
func (this *Haproxy) getStats(statsUri string) (header string, rows []string) {
client := http.Client{Timeout: time.Second * 30}
resp, err := client.Get(statsUri)
swallow(err)
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
swallow(fmt.Errorf("fetch[%s] stats got status: %d", resp.StatusCode))
}
var records map[string]map[string]int64
reader := json.NewDecoder(resp.Body)
err = reader.Decode(&records)
swallow(err)
u, err := url.Parse(statsUri)
swallow(err)
var shortHostname string
if strings.Contains(u.Host, ":") {
u.Host = u.Host[:strings.Index(u.Host, ":")]
}
tuples := strings.SplitN(u.Host, ".", 4)
if len(tuples) < 4 {
shortHostname = u.Host
} else {
shortHostname = tuples[3]
}
if len(shortHostname) > 8 {
shortHostname = shortHostname[:8]
}
sortedSvcs := make([]string, 0)
for svc, _ := range records {
sortedSvcs = append(sortedSvcs, svc)
}
sort.Strings(sortedSvcs)
sortedCols := make([]string, 0)
for k, _ := range records["pub"] {
sortedCols = append(sortedCols, k)
}
sort.Strings(sortedCols)
header = strings.Join(append([]string{"host", "svc"}, sortedCols...), "|")
for _, svc := range sortedSvcs {
stats := records[svc]
var vals = []string{shortHostname, svc}
for _, k := range sortedCols {
v := stats[k]
vals = append(vals, gofmt.Comma(v))
}
rows = append(rows, strings.Join(vals, "|"))
}
return
}
示例10: pump
func (this *Mirror) pump(sub *consumergroup.ConsumerGroup, pub sarama.AsyncProducer, stop chan struct{}) {
defer func() {
log.Println("pump cleanup...")
sub.Close()
log.Println("pump cleanup ok")
stop <- struct{}{} // notify others I'm done
}()
log.Printf("start pumping")
active := false
for {
select {
case <-this.quit:
return
case <-stop:
// yes sir!
return
case <-time.After(time.Second * 10):
active = false
log.Println("idle 10s waiting for new msg")
case msg := <-sub.Messages():
if !active || this.debug {
log.Printf("<-[%d] T:%s M:%s", this.transferN, msg.Topic, string(msg.Value))
}
active = true
pub.Input() <- &sarama.ProducerMessage{
Topic: msg.Topic,
Key: sarama.ByteEncoder(msg.Key),
Value: sarama.ByteEncoder(msg.Value),
}
if this.autoCommit {
sub.CommitUpto(msg)
}
// rate limit, never overflood the limited bandwidth between IDCs
// FIXME when compressed, the bandwidth calculation is wrong
bytesN := len(msg.Topic) + len(msg.Key) + len(msg.Value) + 20 // payload overhead
if !this.bandwidthRateLimiter.Pour(bytesN) {
time.Sleep(time.Second)
this.Ui.Warn(fmt.Sprintf("%d -> bandwidth reached, backoff 1s", bytesN))
}
this.transferBytes += int64(bytesN)
this.transferN++
if this.transferN%this.progressStep == 0 {
log.Println(gofmt.Comma(this.transferN))
}
case err := <-sub.Errors():
this.Ui.Error(err.Error()) // TODO
}
}
}
示例11: makeMirror
func (this *Mirror) makeMirror(c1, c2 *zk.ZkCluster) {
pub, err := this.makePub(c2)
swallow(err)
topics, topicsChanges, err := c1.WatchTopics()
swallow(err)
log.Printf("topics: %+v", topics)
if len(topics) == 0 {
log.Println("empty topics")
return
}
group := fmt.Sprintf("%s.%s._mirror_", c1.Name(), c2.Name())
sub, err := this.makeSub(c1, group, topics)
swallow(err)
pumpStopper := make(chan struct{})
go this.pump(sub, pub, pumpStopper)
LOOP:
for {
select {
case <-topicsChanges:
log.Println("topics changed, stopping pump...")
pumpStopper <- struct{}{} // stop pump
<-pumpStopper // await pump cleanup
// refresh c1 topics
topics, err = c1.Topics()
if err != nil {
// TODO how to handle this err?
log.Println(err)
}
log.Printf("topics: %+v", topics)
sub, err = this.makeSub(c1, group, topics)
if err != nil {
// TODO how to handle this err?
log.Println(err)
}
go this.pump(sub, pub, pumpStopper)
case <-this.quit:
log.Println("awaiting pump cleanup...")
<-pumpStopper
log.Printf("total transferred: %s %smsgs",
gofmt.ByteSize(this.transferBytes),
gofmt.Comma(this.transferN))
break LOOP
}
}
pub.Close()
}
示例12: Run
func (this *Mirror) Run(args []string) (exitCode int) {
cmdFlags := flag.NewFlagSet("mirror", flag.ContinueOnError)
cmdFlags.Usage = func() { this.Ui.Output(this.Help()) }
cmdFlags.StringVar(&this.zone1, "z1", "", "")
cmdFlags.StringVar(&this.zone2, "z2", "", "")
cmdFlags.StringVar(&this.cluster1, "c1", "", "")
cmdFlags.StringVar(&this.cluster2, "c2", "", "")
cmdFlags.StringVar(&this.excludes, "excluded", "", "")
cmdFlags.BoolVar(&this.debug, "debug", false, "")
cmdFlags.StringVar(&this.compress, "compress", "", "")
cmdFlags.Int64Var(&this.bandwidthLimit, "net", 100, "")
cmdFlags.BoolVar(&this.autoCommit, "commit", true, "")
cmdFlags.Int64Var(&this.progressStep, "step", 5000, "")
if err := cmdFlags.Parse(args); err != nil {
return 1
}
if validateArgs(this, this.Ui).
require("-z1", "-z2", "-c1", "-c2").
invalid(args) {
return 2
}
this.topicsExcluded = make(map[string]struct{})
for _, e := range strings.Split(this.excludes, ",") {
this.topicsExcluded[e] = struct{}{}
}
log.SetOutput(os.Stdout)
this.quit = make(chan struct{})
limit := (1 << 20) * this.bandwidthLimit / 8
this.bandwidthRateLimiter = ratelimiter.NewLeakyBucket(limit, time.Second)
log.Printf("[%s]%s -> [%s]%s with bandwidth %sbps",
this.zone1, this.cluster1,
this.zone2, this.cluster2,
gofmt.Comma(int64(limit*8)))
signal.RegisterSignalsHandler(func(sig os.Signal) {
log.Printf("received signal: %s", strings.ToUpper(sig.String()))
log.Println("quiting...")
this.once.Do(func() {
close(this.quit)
})
}, syscall.SIGINT, syscall.SIGTERM)
z1 := zk.NewZkZone(zk.DefaultConfig(this.zone1, ctx.ZoneZkAddrs(this.zone1)))
z2 := zk.NewZkZone(zk.DefaultConfig(this.zone2, ctx.ZoneZkAddrs(this.zone2)))
c1 := z1.NewCluster(this.cluster1)
c2 := z2.NewCluster(this.cluster2)
this.makeMirror(c1, c2)
return
}
示例13: run
func (this *stats) run() {
ticker := time.NewTicker(time.Second)
defer ticker.Stop()
t1 := time.Now()
var lastCalls int64
for _ = range ticker.C {
if neatStat {
log.Printf("c:%6d qps:%20s errs:%10s",
Concurrency,
gofmt.Comma(this.callOk-lastCalls),
gofmt.Comma(this.callErrs))
} else {
log.Printf("%s c:%d sessions:%s calls:%s qps:%s errs:%s conns:%d go:%d",
time.Since(t1),
Concurrency,
gofmt.Comma(int64(atomic.LoadInt32(&this.sessionN))),
gofmt.Comma(atomic.LoadInt64(&this.callOk)),
gofmt.Comma(this.callOk-lastCalls),
gofmt.Comma(this.callErrs),
atomic.LoadInt32(&this.concurrentN),
runtime.NumGoroutine())
}
lastCalls = this.callOk
}
}
示例14: displayGroupOffsets
func (this *Consumers) displayGroupOffsets(zkcluster *zk.ZkCluster, group, topic string, echo bool) []consumerGroupOffset {
offsetMap := zkcluster.ConsumerOffsetsOfGroup(group)
sortedTopics := make([]string, 0, len(offsetMap))
for t, _ := range offsetMap {
sortedTopics = append(sortedTopics, t)
}
sort.Strings(sortedTopics)
r := make([]consumerGroupOffset, 0)
for _, t := range sortedTopics {
if !patternMatched(t, this.topicPattern) || (topic != "" && t != topic) {
continue
}
sortedPartitionIds := make([]string, 0, len(offsetMap[t]))
for partitionId, _ := range offsetMap[t] {
sortedPartitionIds = append(sortedPartitionIds, partitionId)
}
sort.Strings(sortedPartitionIds)
for _, partitionId := range sortedPartitionIds {
r = append(r, consumerGroupOffset{
topic: t,
partitionId: partitionId,
offset: gofmt.Comma(offsetMap[t][partitionId]),
})
if echo {
this.Ui.Output(fmt.Sprintf("\t\t%s/%s Offset:%s",
t, partitionId, gofmt.Comma(offsetMap[t][partitionId])))
}
}
}
return r
}
示例15: showPeriodicalStats
func (this *EsOutput) showPeriodicalStats() {
if !this.showProgress {
return
}
var (
globals = engine.Globals()
total = 0
)
globals.Printf("ES types: %d, within %s", this.counters.Len(), this.reportInterval)
for _, key := range this.counters.SortedKeys() {
val := this.counters.Get(key)
if val > 0 {
total += val
globals.Printf("%-50s %12s", key, gofmt.Comma(int64(val)))
this.counters.Set(key, 0)
}
}
globals.Printf("%50s %12s", "Sum", gofmt.Comma(int64(total)))
}