本文整理匯總了Golang中github.com/funkygao/golib/color.Red函數的典型用法代碼示例。如果您正苦於以下問題:Golang Red函數的具體用法?Golang Red怎麽用?Golang Red使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Red函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: printControllers
// Print all controllers of all clusters within a zone.
func (this *Controllers) printControllers(zkzone *zk.ZkZone) {
this.Ui.Output(zkzone.Name())
zkzone.ForSortedControllers(func(cluster string, controller *zk.ControllerMeta) {
if !patternMatched(cluster, this.cluster) {
return
}
this.Ui.Output(strings.Repeat(" ", 4) + cluster)
if controller == nil {
this.Ui.Output(fmt.Sprintf("\t%s", color.Red("empty")))
} else {
epochSince := time.Since(controller.Mtime.Time())
epochSinceStr := gofmt.PrettySince(controller.Mtime.Time())
if epochSince < time.Hour*2*24 {
epochSinceStr = color.Red(epochSinceStr)
}
this.Ui.Output(fmt.Sprintf("\t%-2s %21s epoch:%2s/%-20s uptime:%s",
controller.Broker.Id, controller.Broker.Addr(),
controller.Epoch,
epochSinceStr,
gofmt.PrettySince(controller.Broker.Uptime())))
}
})
}
示例2: 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()
}
})
}
示例3: installGuide
func (this *Kateway) installGuide(zkzone *zk.ZkZone) {
this.Ui.Output(color.Red("manager db GRANT access rights to this ip"))
this.Ui.Output(color.Red("gk deploy -kfkonly"))
this.Ui.Output("")
this.Ui.Output("mkdir -p /var/wd/kateway/sbin")
this.Ui.Output("cd /var/wd/kateway")
kateways, err := zkzone.KatewayInfos()
swallow(err)
nextId := 1
for _, kw := range kateways {
id, _ := strconv.Atoi(kw.Id)
if nextId < id {
nextId = id
}
}
nextId++
zone := ctx.Zone(this.zone)
influxAddr := zone.InfluxAddr
if influxAddr != "" && !strings.HasPrefix(influxAddr, "http://") {
influxAddr = "http://" + influxAddr
}
var influxInfo string
if influxAddr != "" {
influxInfo = "-influxdbaddr " + influxAddr
}
this.Ui.Output(fmt.Sprintf(`nohup ./sbin/kateway -zone prod -id %d -debughttp ":10194" -level trace -log kateway.log -crashlog panic %s &`,
nextId, influxInfo))
this.Ui.Output("")
this.Ui.Output("yum install -y logstash")
this.Ui.Output("/etc/logstash/conf.d/kateway.conf")
this.Ui.Output(strings.TrimSpace(fmt.Sprintf(`
input {
file {
path => "/var/wd/kateway/kateway.log"
type => "kateway"
}
file {
path => "/var/wd/kateway/panic"
type => "kateway_panic"
}
}
output {
kafka {
bootstrap_servers => "%s:11003,%s:11003"
topic_id => "pubsub_log"
}
}
`, color.Red("k11003a.mycorp.kfk.com"), color.Red("k11003b.mycorp.kfk.com"))))
this.Ui.Output("")
this.Ui.Output("chkconfig --add logstash")
this.Ui.Output("/etc/init.d/logstash start")
}
示例4: invalid
func (this *argsRule) invalid(args []string) bool {
argSet := make(map[string]struct{}, len(args))
for _, arg := range args {
argSet[arg] = struct{}{}
}
// required
for _, req := range this.requires {
if _, present := argSet[req]; !present {
this.ui.Error(color.Red("%s required", req))
this.ui.Output(this.cmd.Help())
return true
}
}
// conditions
for when, requires := range this.conditions {
if _, present := argSet[when]; present {
for _, req := range requires {
if _, found := argSet[req]; !found {
this.ui.Error(color.Red("%s required when %s present",
req, when))
this.ui.Output(this.cmd.Help())
return true
}
}
}
}
// admin required
adminAuthRequired := false
for _, arg := range args {
if _, present := this.adminRequires[arg]; present {
adminAuthRequired = true
break
}
}
if adminAuthRequired {
if pass := os.Getenv("GK_PASS"); Authenticator("", pass) {
return false
}
pass, err := this.ui.AskSecret("password for admin(or GK_PASS): ")
this.ui.Output("")
if err != nil {
this.ui.Error(err.Error())
return true
}
if !Authenticator("", pass) {
this.ui.Error("invalid admin password, bye!")
return true
}
}
return false
}
示例5: Debugf
func Debugf(format string, args ...interface{}) {
if Debug {
pc, file, line, ok := runtime.Caller(1)
if !ok {
file = "<?>"
line = 0
} else {
if i := strings.LastIndex(file, "/"); i >= 0 {
file = file[i+1:]
}
}
fn := runtime.FuncForPC(pc).Name()
fnparts := strings.Split(fn, "/")
t := time.Now()
hour, min, sec := t.Clock()
nanosec := t.Nanosecond() / 1e3
debugLock.Lock()
fmt.Printf("DEBUG: [%02d:%02d:%02d.%04d] %s:%d(%s): %s\n",
hour, min, sec, nanosec,
file, line, color.Red(fnparts[len(fnparts)-1]),
fmt.Sprintf(format, args...))
debugLock.Unlock()
}
}
示例6: 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
}
}
示例7: debug
func (t *routingTable) debug(format string, v ...interface{}) {
if t.logLevel <= LogLevelDebug {
pc, file, line, ok := runtime.Caller(1)
if !ok {
file = "<?>"
line = 0
} else {
if i := strings.LastIndex(file, "/"); i >= 0 {
file = file[i+1:]
}
}
fn := runtime.FuncForPC(pc).Name()
fnparts := strings.Split(fn, "/")
t1 := time.Now()
hour, min, sec := t1.Clock()
nanosec := t1.Nanosecond() / 1e3
debugLock.Lock()
fmt.Printf(t.self.ID.String()+" [%d:%d:%d.%04d] %s:%d(%s): %s\n",
hour, min, sec, nanosec,
file, line, color.Red(fnparts[len(fnparts)-1]),
fmt.Sprintf(format, v...))
debugLock.Unlock()
}
}
示例8: 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
}
示例9: printSwallowedErrors
func printSwallowedErrors(ui cli.Ui, zkzone *zk.ZkZone) {
errs := zkzone.Errors()
if len(errs) == 0 {
return
}
for _, e := range errs {
ui.Error(color.Red("%v", e))
}
}
示例10: debug
func (c *Cluster) debug(format string, v ...interface{}) {
if c.logLevel <= LogLevelDebug {
pc, file, line, ok := runtime.Caller(1)
if !ok {
file = "<?>"
line = 0
} else {
if i := strings.LastIndex(file, "/"); i >= 0 {
file = file[i+1:]
}
}
fn := runtime.FuncForPC(pc).Name()
fnparts := strings.Split(fn, "/")
t := time.Now()
hour, min, sec := t.Clock()
nanosec := t.Nanosecond() / 1e3
debugLock.Lock()
var nodePrefix string = c.self.ID.String()
switch c.color {
case "red":
nodePrefix = color.Red(c.self.ID.String())
case "blue":
nodePrefix = color.Blue(c.self.ID.String())
case "yellow":
nodePrefix = color.Yellow(c.self.ID.String())
case "green":
nodePrefix = color.Green(c.self.ID.String())
}
fmt.Printf(nodePrefix+" [%d:%d:%d.%04d] %s:%d(%s): %s\n",
hour, min, sec, nanosec,
file, line, color.Red(fnparts[len(fnparts)-1]),
fmt.Sprintf(format, v...))
debugLock.Unlock()
}
}
示例11: RunZkFourLetterCommand
// Returns {zkHost: outputLines}
func (this *ZkZone) RunZkFourLetterCommand(cmd string) map[string]string {
servers := this.conf.ZkServers()
r := make(map[string]string, len(servers))
for _, server := range servers {
b, err := zkFourLetterWord(server, cmd, time.Minute)
if err != nil {
r[server] = color.Red(err.Error())
} else {
r[server] = string(b)
}
}
return r
}
示例12: sub
func sub(id int) {
cf := api.DefaultConfig("app2", "mysecret")
cf.Debug = true
cf.Sub.Endpoint = addr
c := api.NewClient(cf)
i := 0
t0 := time.Now()
var err error
opt := api.SubOption{
AppId: appid,
Topic: topic,
Ver: "v1",
Group: group,
Tag: tag,
}
err = c.SubX(opt, func(statusCode int, msg []byte,
r *api.SubXResult) error {
i++
if n > 0 && i >= n {
return api.ErrSubStop
}
if i%step == 0 {
log.Println(statusCode, string(msg))
}
if sleep > 0 {
time.Sleep(sleep)
}
r.Bury = api.ShadowRetry
log.Println(color.Red("shadow"))
log.Println()
return nil
})
if err != nil {
log.Println(err)
}
elapsed := time.Since(t0)
log.Printf("%d msgs in %s, tps: %.2f\n", n, elapsed, float64(n)/elapsed.Seconds())
}
示例13: 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()))
}
}
})
}
示例14: 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))
}
}
}
示例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()
}