Exemple #1
0
func (g *GraphOptions) Prefix(host string, metricType string) string {
	prefix := ""
	statsdHostKey := util.StatsdHostKey(host)
	prefixWithHost := strings.Replace(g.StatsdPrefix, "%s", statsdHostKey, -1)
	if prefixWithHost[len(prefixWithHost)-1] != '.' {
		prefixWithHost += "."
	}
	if g.UseStatsdPrefix && metricType == "counter" {
		prefix += "stats_counts."
	} else if g.UseStatsdPrefix && metricType == "gauge" {
		prefix += "stats.gauges."
	}
	prefix += prefixWithHost
	return prefix
}
Exemple #2
0
func main() {
	flag.Parse()

	hostname, err := os.Hostname()
	if err != nil {
		log.Fatal(err)
	}

	if *showVersion {
		fmt.Println(util.Version("nsqd"))
		return
	}

	if *workerId == 0 {
		h := md5.New()
		io.WriteString(h, hostname)
		*workerId = int64(crc32.ChecksumIEEE(h.Sum(nil)) % 1024)
	}

	tcpAddr, err := net.ResolveTCPAddr("tcp", *tcpAddress)
	if err != nil {
		log.Fatal(err)
	}

	httpAddr, err := net.ResolveTCPAddr("tcp", *httpAddress)
	if err != nil {
		log.Fatal(err)
	}

	if *broadcastAddress == "" {
		*broadcastAddress = hostname
	}

	log.Println(util.Version("nsqd"))
	log.Printf("worker id %d", *workerId)

	exitChan := make(chan int)
	signalChan := make(chan os.Signal, 1)
	go func() {
		<-signalChan
		exitChan <- 1
	}()
	signal.Notify(signalChan, syscall.SIGINT, syscall.SIGTERM)

	// flagToDuration will fatally error if it is invalid
	msgTimeoutDuration := flagToDuration(*msgTimeout, time.Millisecond, "--msg-timeout")

	if *maxDeflateLevel < 1 || *maxDeflateLevel > 9 {
		log.Fatalf("--max-deflate-level must be [1,9]")
	}

	options := NewNsqdOptions()
	options.maxRdyCount = *maxRdyCount
	options.maxMessageSize = *maxMessageSize
	options.maxBodySize = *maxBodySize
	options.memQueueSize = *memQueueSize
	options.dataPath = *dataPath
	options.maxBytesPerFile = *maxBytesPerFile
	options.syncEvery = *syncEvery
	options.syncTimeout = *syncTimeout
	options.msgTimeout = msgTimeoutDuration
	options.maxMsgTimeout = *maxMsgTimeout
	options.broadcastAddress = *broadcastAddress
	options.maxHeartbeatInterval = *maxHeartbeatInterval
	options.maxOutputBufferSize = *maxOutputBufferSize
	options.maxOutputBufferTimeout = *maxOutputBufferTimeout
	options.tlsCert = *tlsCert
	options.tlsKey = *tlsKey
	options.deflateEnabled = *deflateEnabled
	options.maxDeflateLevel = *maxDeflateLevel
	options.snappyEnabled = *snappyEnabled
	options.e2eProcessingLatencyWindowTime = *e2eProcessingLatencyWindowTime
	options.e2eProcessingLatencyPercentiles = e2eProcessingLatencyPercentiles

	if *statsdAddress != "" {
		// flagToDuration will fatally error if it is invalid
		options.statsdInterval = flagToDuration(*statsdInterval, time.Second, "--statsd-interval")
		statsdHostKey := util.StatsdHostKey(net.JoinHostPort(*broadcastAddress, strconv.Itoa(httpAddr.Port)))
		prefixWithHost := strings.Replace(*statsdPrefix, "%s", statsdHostKey, -1)
		if prefixWithHost[len(prefixWithHost)-1] != '.' {
			prefixWithHost += "."
		}
		options.statsdPrefix = prefixWithHost
		options.statsdAddress = *statsdAddress
	}

	nsqd := NewNSQd(*workerId, options)
	nsqd.tcpAddr = tcpAddr
	nsqd.httpAddr = httpAddr
	nsqd.lookupdTCPAddrs = lookupdTCPAddrs

	// Set the random seed
	rand.Seed(time.Now().UTC().UnixNano())

	nsqd.LoadMetadata()
	err = nsqd.PersistMetadata()
	if err != nil {
		log.Fatalf("ERROR: failed to persist metadata - %s", err.Error())
	}
	nsqd.Main()
	<-exitChan
	nsqd.Exit()
}