Example #1
0
func New(opts *Options) *NSQD {
	n := &NSQD{
		flag:                 flagHealthy,
		startTime:            time.Now(),
		topicMap:             make(map[string]*Topic),
		idChan:               make(chan MessageID, 4096),
		exitChan:             make(chan int),
		notifyChan:           make(chan interface{}),
		optsNotificationChan: make(chan struct{}, 1),
		ci:                   clusterinfo.New(opts.Logger, http_api.NewClient(nil)),
	}
	n.swapOpts(opts)

	if opts.MaxDeflateLevel < 1 || opts.MaxDeflateLevel > 9 {
		n.logf("FATAL: --max-deflate-level must be [1,9]")
		os.Exit(1)
	}

	if opts.ID < 0 || opts.ID >= 1024 {
		n.logf("FATAL: --worker-id must be [0,1024)")
		os.Exit(1)
	}

	if opts.StatsdPrefix != "" {
		_, port, err := net.SplitHostPort(opts.HTTPAddress)
		if err != nil {
			n.logf("ERROR: failed to parse HTTP address (%s) - %s", opts.HTTPAddress, err)
			os.Exit(1)
		}
		statsdHostKey := statsd.HostKey(net.JoinHostPort(opts.BroadcastAddress, port))
		prefixWithHost := strings.Replace(opts.StatsdPrefix, "%s", statsdHostKey, -1)
		if prefixWithHost[len(prefixWithHost)-1] != '.' {
			prefixWithHost += "."
		}
		opts.StatsdPrefix = prefixWithHost
	}

	if opts.TLSClientAuthPolicy != "" && opts.TLSRequired == TLSNotRequired {
		opts.TLSRequired = TLSRequired
	}

	tlsConfig, err := buildTLSConfig(opts)
	if err != nil {
		n.logf("FATAL: failed to build TLS config - %s", err)
		os.Exit(1)
	}
	if tlsConfig == nil && opts.TLSRequired != TLSNotRequired {
		n.logf("FATAL: cannot require TLS client connections without TLS key and cert")
		os.Exit(1)
	}
	n.tlsConfig = tlsConfig

	n.logf(version.String("nsqd"))
	n.logf("ID: %d", opts.ID)

	return n
}
Example #2
0
func (g *GraphOptions) Prefix(host string, metricType string) string {
	prefix := ""
	statsdHostKey := statsd.HostKey(host)
	prefixWithHost := strings.Replace(g.ctx.nsqadmin.opts.StatsdPrefix, "%s", statsdHostKey, -1)
	if prefixWithHost[len(prefixWithHost)-1] != '.' {
		prefixWithHost += "."
	}
	if g.ctx.nsqadmin.opts.UseStatsdPrefixes && metricType == "counter" {
		prefix += "stats_counts."
	} else if g.ctx.nsqadmin.opts.UseStatsdPrefixes && metricType == "gauge" {
		prefix += "stats.gauges."
	}
	prefix += prefixWithHost
	return prefix
}