本文整理匯總了Golang中github.com/funkygao/golib/color.Green函數的典型用法代碼示例。如果您正苦於以下問題:Golang Green函數的具體用法?Golang Green怎麽用?Golang Green使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Green函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Run
func (this *Kguard) Run(args []string) (exitCode int) {
cmdFlags := flag.NewFlagSet("kguard", flag.ContinueOnError)
cmdFlags.Usage = func() { this.Ui.Output(this.Help()) }
cmdFlags.StringVar(&this.zone, "z", ctx.ZkDefaultZone(), "")
cmdFlags.BoolVar(&this.longFmt, "l", false, "")
if err := cmdFlags.Parse(args); err != nil {
return 2
}
zkzone := zk.NewZkZone(zk.DefaultConfig(this.zone, ctx.ZoneZkAddrs(this.zone)))
kguards, err := zkzone.KguardInfos()
if err != nil {
this.Ui.Error(fmt.Sprintf("%s %v", zk.KguardLeaderPath, err.Error()))
return
}
leader := kguards[0]
this.Ui.Output(fmt.Sprintf("%s(out of %d candidates) up: %s",
color.Green(leader.Host), leader.Candidates,
gofmt.PrettySince(leader.Ctime)))
if this.longFmt {
this.showKguardVersion(leader.Host)
this.showStats(leader.Host)
}
return
}
示例2: printLeader
func (this *Zookeeper) printLeader(zkzone *zk.ZkZone) {
// FIXME all zones will only show the 1st zone info because it blocks others
for {
this.Ui.Output(color.Blue(zkzone.Name()))
for zkhost, lines := range zkzone.RunZkFourLetterCommand("mntr") {
if this.zkHost != "" && !strings.HasPrefix(zkhost, this.zkHost+":") {
continue
}
parts := strings.Split(lines, "\n")
for _, l := range parts {
if strings.HasPrefix(l, "zk_server_state") && strings.HasSuffix(l, "leader") {
this.Ui.Output(color.Green("%28s", zkhost))
break
}
}
}
if this.watchMode {
time.Sleep(time.Second * 5)
} else {
break
}
}
}
示例3: diagnose
func (this *Ping) diagnose() {
this.zkzone.ForSortedClusters(func(zkcluster *zk.ZkCluster) {
registeredBrokers := zkcluster.RegisteredInfo().Roster
for _, broker := range registeredBrokers {
log.Debug("ping %s", broker.Addr())
kfk, err := sarama.NewClient([]string{broker.Addr()}, sarama.NewConfig())
if err != nil {
log.Error("%25s %30s %s", broker.Addr(), broker.NamedAddr(), color.Red(err.Error()))
continue
}
_, err = kfk.Topics() // kafka didn't provide ping, so use Topics() as ping
if err != nil {
log.Error("%25s %30s %s", broker.Addr(), broker.NamedAddr(), color.Red(err.Error()))
} else {
if !this.problematicMode {
log.Info("%25s %30s %s", broker.Addr(), broker.NamedAddr(), color.Green("ok"))
}
}
kfk.Close()
}
})
}
示例4: displayZoneTop
func (this *Zktop) displayZoneTop(zkzone *zk.ZkZone) {
if this.batchMode {
this.Ui.Output(fmt.Sprintf("%s %s", zkzone.Name(), bjtime.NowBj()))
} else {
this.Ui.Output(color.Green(zkzone.Name()))
}
header := "VER SERVER PORT M OUTST RECVD SENT CONNS ZNODES LAT(MIN/AVG/MAX)"
this.Ui.Output(header)
stats := zkzone.RunZkFourLetterCommand("stat")
sortedHosts := make([]string, 0, len(stats))
for hp, _ := range stats {
sortedHosts = append(sortedHosts, hp)
}
sort.Strings(sortedHosts)
for _, hostPort := range sortedHosts {
host, port, err := net.SplitHostPort(hostPort)
if err != nil {
panic(err)
}
stat := zk.ParseStatResult(stats[hostPort])
if stat.Mode == "" {
if this.batchMode {
stat.Mode = "E"
} else {
stat.Mode = color.Red("E")
}
} else if stat.Mode == "L" && !this.batchMode {
stat.Mode = color.Blue(stat.Mode)
}
var sentQps, recvQps int
if lastRecv, present := this.lastRecvs[hostPort]; present {
r1, _ := strconv.Atoi(stat.Received)
r0, _ := strconv.Atoi(lastRecv)
recvQps = (r1 - r0) / int(this.refreshInterval.Seconds())
s1, _ := strconv.Atoi(stat.Sent)
s0, _ := strconv.Atoi(this.lastSents[hostPort])
sentQps = (s1 - s0) / int(this.refreshInterval.Seconds())
}
this.Ui.Output(fmt.Sprintf("%-15s %-15s %5s %1s %6s %16s %16s %5s %7s %s",
stat.Version, // 15
host, // 15
port, // 5
stat.Mode, // 1
stat.Outstanding, // 6
fmt.Sprintf("%s/%d", stat.Received, recvQps), // 16
fmt.Sprintf("%s/%d", stat.Sent, sentQps), // 16
stat.Connections, // 5
stat.Znodes, // 7
stat.Latency,
))
this.lastRecvs[hostPort] = stat.Received
this.lastSents[hostPort] = stat.Sent
}
}
示例5: clusterBrokers
func (this *Brokers) clusterBrokers(zone, cluster string, brokers map[string]*zk.BrokerZnode) []string {
if !patternMatched(cluster, this.cluster) {
return nil
}
if brokers == nil || len(brokers) == 0 {
return []string{fmt.Sprintf("%s|%s|%s|%s|%s",
zone, cluster, " ", color.Red("empty brokers"), " ")}
}
lines := make([]string, 0, len(brokers))
if this.staleOnly {
// try each broker's aliveness
for brokerId, broker := range brokers {
cf := sarama.NewConfig()
cf.Net.ReadTimeout = time.Second * 4
cf.Net.WriteTimeout = time.Second * 4
kfk, err := sarama.NewClient([]string{broker.Addr()}, cf)
if err != nil {
lines = append(lines, fmt.Sprintf("%s|%s|%s|%s|%s",
zone, cluster,
brokerId, broker.Addr(),
fmt.Sprintf("%s: %v", gofmt.PrettySince(broker.Uptime()), err)))
} else {
kfk.Close()
}
}
return lines
}
// sort by broker id
sortedBrokerIds := make([]string, 0, len(brokers))
for brokerId, _ := range brokers {
sortedBrokerIds = append(sortedBrokerIds, brokerId)
}
sort.Strings(sortedBrokerIds)
for _, brokerId := range sortedBrokerIds {
b := brokers[brokerId]
uptime := gofmt.PrettySince(b.Uptime())
if time.Since(b.Uptime()) < time.Hour*24*7 {
uptime = color.Green(uptime)
}
if this.ipInNumber {
lines = append(lines, fmt.Sprintf("%s|%s|%s|%s|%s",
zone, cluster,
brokerId, b.Addr(),
gofmt.PrettySince(b.Uptime())))
} else {
lines = append(lines, fmt.Sprintf("%s|%s|%s|%s|%s",
zone, cluster,
brokerId, b.NamedAddr(),
gofmt.PrettySince(b.Uptime())))
}
}
return lines
}
示例6: drawDashboard
func (this *TopBroker) drawDashboard() {
termui.Init()
width := termui.TermWidth()
height := termui.TermHeight()
termui.Close()
maxWidth := width - 23
var totalMaxQps, totalMaxBrokerQps float64
for {
time.Sleep(this.interval)
this.startAll()
this.collectAll()
datas, maxQps, totalQps := this.showAndResetCounters()
if maxQps < 1 {
// draw empty lines
for _, data := range datas {
this.Ui.Output(fmt.Sprintf("%20s", data.host))
}
continue
}
if maxQps > totalMaxBrokerQps {
totalMaxBrokerQps = maxQps
}
if totalQps > totalMaxQps {
totalMaxQps = totalQps
}
refreshScreen()
for idx, data := range datas {
if idx >= height-2 {
break
}
if data.qps < 0 {
panic("negative qps")
}
this.renderQpsRow(data.host, data.qps, maxQps, maxWidth)
}
this.Ui.Output(fmt.Sprintf("%20s brokers:%d total:%s cum max[broker:%.1f total:%.1f]",
"-SUMMARY-",
len(datas), color.Green("%.1f", totalQps), totalMaxBrokerQps, totalMaxQps))
}
}
示例7: NewPubStore
func NewPubStore(poolCapcity int, idleTimeout time.Duration, compress bool,
debug bool, dryRun bool) *pubStore {
if debug {
sarama.Logger = l.New(os.Stdout, color.Green("[Sarama]"), l.LstdFlags|l.Lshortfile)
}
return &pubStore{
hostname: ctx.Hostname(),
compress: compress,
idleTimeout: idleTimeout,
pubPoolsCapcity: poolCapcity,
pubPools: make(map[string]*pubPool),
dryRun: dryRun,
shutdownCh: make(chan struct{}),
}
}
示例8: renderQpsRow
func (this *TopBroker) renderQpsRow(host string, qps, maxQps float64, maxWidth int) {
w := int(qps*100/maxQps) * maxWidth / 100
qpsStr := fmt.Sprintf("%.1f", qps)
bar := ""
barColorLen := 0
for i := 0; i < w-len(qpsStr); i++ {
bar += color.Green("|")
barColorLen += 9 // color.Green will add extra 9 chars
}
for i := len(bar) - barColorLen; i < maxWidth-len(qpsStr); i++ {
bar += " "
}
bar += qpsStr
this.Ui.Output(fmt.Sprintf("%20s [%s]", host, bar))
}
示例9: printCluster
func (this *LsZk) printCluster(zkcluster *zk.ZkCluster) {
this.Ui.Output(color.Green(zkcluster.Name()))
children, err := zkcluster.ListChildren(this.recursive)
if err != nil {
this.Ui.Error(fmt.Sprintf("%s%s", strings.Repeat(" ", 4), err))
return
}
for _, c := range children {
this.Ui.Output(fmt.Sprintf("%s%s", strings.Repeat(" ", 4), c))
if strings.HasSuffix(c, "brokers") {
this.Ui.Output(fmt.Sprintf("%s%s/ids", strings.Repeat(" ", 4), c))
this.Ui.Output(fmt.Sprintf("%s%s/topics", strings.Repeat(" ", 4), c))
}
}
}
示例10: verifyBrokers
func (this *Clusters) verifyBrokers(zkzone *zk.ZkZone) {
this.Ui.Output(zkzone.Name())
zkzone.ForSortedBrokers(func(cluster string, liveBrokers map[string]*zk.BrokerZnode) {
zkcluster := zkzone.NewCluster(cluster)
registeredBrokers := zkcluster.RegisteredInfo().Roster
// find diff between registeredBrokers and liveBrokers
// loop1 find liveBrokers>registeredBrokers
for _, broker := range liveBrokers {
foundInRoster := false
for _, b := range registeredBrokers {
bid := strconv.Itoa(b.Id)
if bid == broker.Id && broker.Addr() == b.Addr() {
foundInRoster = true
break
}
}
if !foundInRoster {
// should manually register the broker
this.Ui.Output(strings.Repeat(" ", 4) +
color.Green("+ gk clusters -z %s -s -c %s -addbroker %s:%s",
zkzone.Name(), cluster, broker.Id, broker.Addr()))
}
}
// loop2 find liveBrokers<registeredBrokers
for _, b := range registeredBrokers {
foundInLive := false
for _, broker := range liveBrokers {
bid := strconv.Itoa(b.Id)
if bid == broker.Id && broker.Addr() == b.Addr() {
foundInLive = true
break
}
}
if !foundInLive {
// the broker is dead
this.Ui.Output(strings.Repeat(" ", 4) +
color.Red("cluster[%s] broker[%d] %s is dead", cluster, b.Id, b.Addr()))
}
}
})
}
示例11: printZkStats
func (this *Zookeeper) printZkStats(zkzone *zk.ZkZone) {
for {
this.Ui.Output(color.Blue(zkzone.Name()))
for zkhost, lines := range zkzone.RunZkFourLetterCommand(this.flw) {
if this.zkHost != "" && !strings.HasPrefix(zkhost, this.zkHost+":") {
continue
}
this.Ui.Output(fmt.Sprintf("%s\n%s", color.Green("%28s", zkhost), lines))
}
if this.watchMode {
time.Sleep(time.Second * 5)
} else {
break
}
}
}
示例12: showChildrenRecursively
func (this *Get) showChildrenRecursively(conn *zk.Conn, path string) {
children, _, err := conn.Children(path)
if err != nil {
return
}
sort.Strings(children)
for _, child := range children {
if path == "/" {
path = ""
}
znode := fmt.Sprintf("%s/%s", path, child)
// display znode content
data, stat, err := conn.Get(znode)
must(err)
if stat.EphemeralOwner > 0 {
if patternMatched(znode, this.likePattern) {
this.Ui.Output(color.Yellow(znode))
}
} else {
if patternMatched(znode, this.likePattern) {
this.Ui.Output(color.Green(znode))
}
}
if len(data) > 0 && patternMatched(znode, this.likePattern) {
if this.verbose {
this.Ui.Output(fmt.Sprintf("%s %#v",
strings.Repeat(" ", 3), stat))
this.Ui.Output(fmt.Sprintf("%s %v",
strings.Repeat(" ", 3), data))
}
this.Ui.Output(fmt.Sprintf("%s %s",
strings.Repeat(" ", 3), string(data)))
}
this.showChildrenRecursively(conn, znode)
}
}
示例13: discoverClusters
func (this *Discover) discoverClusters(zkzone *zk.ZkZone) {
this.Ui.Output(zkzone.Name())
existingClusters := zkzone.Clusters()
existingCluserPaths := make(map[string]struct{}, len(existingClusters))
for _, path := range existingClusters {
existingCluserPaths[path] = struct{}{}
}
discoveredClusters, err := zkzone.DiscoverClusters("/")
if err != nil {
this.Ui.Error(zkzone.Name() + ": " + err.Error())
return
}
// print each cluster state: new, normal
for _, zkpath := range discoveredClusters {
if _, present := existingCluserPaths[zkpath]; !present {
this.Ui.Output(strings.Repeat(" ", 4) + color.Green("%s +++",
zkpath))
} else {
this.Ui.Output(strings.Repeat(" ", 4) + zkpath)
}
}
// find the offline clusters
for c, path := range existingClusters {
path = strings.TrimSpace(path)
foundOnline := false
for _, p := range discoveredClusters {
p = strings.TrimSpace(p)
if p == path {
foundOnline = true
break
}
}
if !foundOnline {
this.Ui.Output(strings.Repeat(" ", 4) + color.Red("%s: %s ---", c, path))
}
}
}
示例14: printConsumersByHost
func (this *Consumers) printConsumersByHost(zkzone *zk.ZkZone, clusterPattern string) {
outputs := make(map[string]map[string]map[string]int) // host: {cluster: {topic: count}}
this.Ui.Output(color.Blue(zkzone.Name()))
zkzone.ForSortedClusters(func(zkcluster *zk.ZkCluster) {
if !patternMatched(zkcluster.Name(), clusterPattern) {
return
}
consumerGroups := zkcluster.ConsumerGroups()
for _, group := range consumerGroups {
for _, c := range group {
if _, present := outputs[c.Host()]; !present {
outputs[c.Host()] = make(map[string]map[string]int)
}
if _, present := outputs[c.Host()][zkcluster.Name()]; !present {
outputs[c.Host()][zkcluster.Name()] = make(map[string]int)
}
for topic, count := range c.Subscription {
outputs[c.Host()][zkcluster.Name()][topic] += count
}
}
}
})
sortedHosts := make([]string, 0, len(outputs))
for host, _ := range outputs {
sortedHosts = append(sortedHosts, host)
}
sort.Strings(sortedHosts)
for _, host := range sortedHosts {
tc := outputs[host]
this.Ui.Output(fmt.Sprintf("%s %+v", color.Green("%22s", host), tc))
}
}
示例15: verifyPub
func (this *Verify) verifyPub() {
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"Kafka", "Stock", "PubSub", "Stock", "Diff", "?"})
for _, t := range this.topics {
if t.KafkaTopicName == "" {
continue
}
kafkaCluster := this.kafkaTopics[t.KafkaTopicName]
if kafkaCluster == "" {
this.Ui.Warn(fmt.Sprintf("invalid kafka topic: %s", t.KafkaTopicName))
continue
}
psubTopic := manager.Default.KafkaTopic(t.AppId, t.TopicName, "v1")
offsets := this.pubOffsetDiff(t.KafkaTopicName, kafkaCluster,
psubTopic, this.cluster)
var diff string
if offsets[0] == 0 && offsets[1] != 0 {
diff = color.Yellow("%d", offsets[1]-offsets[0])
} else if math.Abs(float64(offsets[0]-offsets[1])) < 20 {
diff = color.Green("%d", offsets[1]-offsets[0])
} else {
diff = color.Red("%d", offsets[1]-offsets[0])
}
problem := "N"
if _, present := this.problemeticTopics[t.KafkaTopicName]; present {
problem = color.Yellow("Y")
}
table.Append([]string{
t.KafkaTopicName, fmt.Sprintf("%d", offsets[0]),
t.TopicName, fmt.Sprintf("%d", offsets[1]), diff, problem})
}
table.Render()
}