本文整理匯總了Golang中github.com/funkygao/gafka/zk.ZkZone類的典型用法代碼示例。如果您正苦於以下問題:Golang ZkZone類的具體用法?Golang ZkZone怎麽用?Golang ZkZone使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了ZkZone類的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: 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: 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)))
}
示例4: generateFlameGraph
func (this *Kateway) generateFlameGraph(zkzone *zk.ZkZone) {
kws, _ := zkzone.KatewayInfos()
for _, kw := range kws {
if kw.Id != this.id {
continue
}
pprofAddr := kw.DebugAddr
if len(pprofAddr) > 0 && pprofAddr[0] == ':' {
pprofAddr = kw.Ip + pprofAddr
}
pprofAddr = fmt.Sprintf("http://%s/debug/pprof/profile", pprofAddr)
cmd := pipestream.New(os.Getenv("GOPATH")+"/bin/go-torch",
"-u", pprofAddr)
err := cmd.Open()
swallow(err)
defer cmd.Close()
scanner := bufio.NewScanner(cmd.Reader())
scanner.Split(bufio.ScanLines)
for scanner.Scan() {
fmt.Println(scanner.Text())
}
this.Ui.Output("torch.svg generated")
}
}
示例5: runSub
func (this *Kateway) runSub(zkzone *zk.ZkZone) {
zone := ctx.Zone(zkzone.Name())
cf := api.DefaultConfig(zone.SmokeApp, zone.SmokeSecret)
cf.Sub.Endpoint = zone.SubEndpoint
cli := api.NewClient(cf)
t1 := time.Now()
err := cli.Sub(api.SubOption{
AppId: zone.SmokeHisApp,
Topic: zone.SmokeTopic,
Ver: zone.SmokeTopicVersion,
Group: zone.SmokeGroup,
AutoClose: false,
}, func(statusCode int, subMsg []byte) error {
now := time.Now()
var e error
if statusCode != http.StatusOK {
e = fmt.Errorf("unexpected http status: %s, body:%s", http.StatusText(statusCode), string(subMsg))
}
this.Ui.Output(fmt.Sprintf("-> %s: %s %v", now.Sub(t1), string(subMsg), e))
time.Sleep(time.Millisecond * 100)
t1 = time.Now()
return e
})
if err != nil {
this.Ui.Error(err.Error())
}
}
示例6: 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")
}
示例7: 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))
}
}
示例8: displayZoneMaxPort
func (this *Topology) displayZoneMaxPort(zkzone *zk.ZkZone) {
maxPort := 0
zkzone.ForSortedBrokers(func(cluster string, liveBrokers map[string]*zk.BrokerZnode) {
for _, broker := range liveBrokers {
if maxPort < broker.Port {
maxPort = broker.Port
}
}
})
this.Ui.Output(fmt.Sprintf("max port in zone[%s]: %d", zkzone.Name(), maxPort))
}
示例9: maxBrokerId
func (this *Brokers) maxBrokerId(zkzone *zk.ZkZone, clusterName string) int {
var maxBrokerId int
zkzone.ForSortedBrokers(func(cluster string, liveBrokers map[string]*zk.BrokerZnode) {
if cluster == clusterName {
for _, b := range liveBrokers {
id, _ := strconv.Atoi(b.Id)
if id > maxBrokerId {
maxBrokerId = id
}
}
}
})
return maxBrokerId
}
示例10: runBenchmark
func (this *Kateway) runBenchmark(zkzone *zk.ZkZone) {
this.Ui.Info(fmt.Sprintf("benchmark[%s] zone[%s] %s.%s.%s %s",
this.benchId, zkzone.Name(),
this.benchApp, this.benchTopic, this.benchVer, this.benchPubEndpoint))
yes, _ := this.Ui.Ask("Are you sure to execute the benchmark? [Y/N]")
if yes == "Y" {
log.SetOutput(os.Stdout)
stress.Flags.Round = 5
stress.Flags.Tick = 5
if this.benchmarkMaster != "" {
stress.Flags.MasterAddr = stress.MasterAddr(this.benchmarkMaster)
}
stress.RunStress(this.benchPub)
}
}
示例11: runPub
func (this *Kateway) runPub(zkzone *zk.ZkZone) {
zone := ctx.Zone(zkzone.Name())
cf := api.DefaultConfig(zone.SmokeApp, zone.SmokeSecret)
cf.Pub.Endpoint = zone.PubEndpoint
cli := api.NewClient(cf)
for {
now := time.Now()
pubMsg := fmt.Sprintf("gk kateway -pub smoke test msg: [%s]", now)
err := cli.Pub("", []byte(pubMsg), api.PubOption{
Topic: zone.SmokeTopic,
Ver: zone.SmokeTopicVersion,
})
this.Ui.Output(fmt.Sprintf("<- %s: %s %v", time.Since(now), pubMsg, err))
time.Sleep(time.Millisecond * 100)
}
}
示例12: 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
}
}
}
示例13: printRegisteredBrokers
func (this *Clusters) printRegisteredBrokers(zkzone *zk.ZkZone) {
this.Ui.Output(zkzone.Name())
zkzone.ForSortedClusters(func(zkcluster *zk.ZkCluster) {
info := zkcluster.RegisteredInfo()
this.Ui.Output(fmt.Sprintf(" %s(%s)", info.Name(), info.Nickname))
registeredBrokers := info.Roster
if len(registeredBrokers) == 0 {
this.Ui.Warn(" brokers not registered")
} else {
for _, b := range registeredBrokers {
if this.ipInNumber {
this.Ui.Output(fmt.Sprintf(" %2d %s", b.Id, b.Addr()))
} else {
this.Ui.Output(fmt.Sprintf(" %2d %s", b.Id, b.NamedAddr()))
}
}
}
})
}
示例14: 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
}
}
示例15: 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))
}
}