Exemplo n.º 1
0
func newPubServer(httpAddr, httpsAddr string, maxClients int, gw *Gateway) *pubServer {
	this := &pubServer{
		webServer:        newWebServer("pub_server", httpAddr, httpsAddr, maxClients, Options.HttpReadTimeout, gw),
		throttlePub:      ratelimiter.NewLeakyBuckets(Options.PubQpsLimit, time.Minute),
		throttleBadAppid: ratelimiter.NewLeakyBuckets(3, time.Minute),
	}
	this.pubMetrics = NewPubMetrics(this.gw)
	this.onConnNewFunc = this.onConnNew
	this.onConnCloseFunc = this.onConnClose

	this.webServer.onStop = func() {
		this.pubMetrics.Flush()
	}

	this.auditor = log.NewDefaultLogger(log.TRACE)
	this.auditor.DeleteFilter("stdout")

	_ = os.Mkdir("audit", os.ModePerm)
	rotateEnabled, discardWhenDiskFull := true, false
	filer := log.NewFileLogWriter("audit/pub_audit.log", rotateEnabled, discardWhenDiskFull, 0644)
	if filer == nil {
		panic("failed to open pub audit log")
	}
	filer.SetFormat("[%d %T] [%L] (%S) %M")
	if Options.LogRotateSize > 0 {
		filer.SetRotateSize(Options.LogRotateSize)
	}
	filer.SetRotateLines(0)
	filer.SetRotateDaily(true)
	this.auditor.AddFilter("file", logLevel, filer)

	return this
}
Exemplo n.º 2
0
func (this *controller) setupAuditor() {
	this.auditor = log.NewDefaultLogger(log.TRACE)
	this.auditor.DeleteFilter("stdout")

	_ = os.Mkdir("audit", os.ModePerm)
	rotateEnabled, discardWhenDiskFull := true, false
	filer := log.NewFileLogWriter("audit/actord.log", rotateEnabled, discardWhenDiskFull, 0644)
	if filer == nil {
		panic("failed to open audit log")
	}
	filer.SetFormat("[%d %T] [%L] (%S) %M")
	filer.SetRotateLines(0)
	filer.SetRotateDaily(true)
	this.auditor.AddFilter("file", log.TRACE, filer)
}
Exemplo n.º 3
0
func newSubServer(httpAddr, httpsAddr string, maxClients int, gw *Gateway) *subServer {
	this := &subServer{
		webServer:        newWebServer("sub_server", httpAddr, httpsAddr, maxClients, Options.HttpReadTimeout, gw),
		closedConnCh:     make(chan string, 1<<10),
		idleConns:        make(map[net.Conn]struct{}, 200),
		wsReadLimit:      8 << 10,
		wsPongWait:       time.Minute,
		timer:            timewheel.NewTimeWheel(time.Second, 120),
		throttleBadGroup: ratelimiter.NewLeakyBuckets(3, time.Minute),
		goodGroupClients: make(map[string]struct{}, 100),
		ackShutdown:      0,
		ackCh:            make(chan ackOffsets, 100),
		ackedOffsets:     make(map[string]map[string]map[string]map[int]int64),
	}
	this.subMetrics = NewSubMetrics(this.gw)
	this.waitExitFunc = this.waitExit
	this.connStateFunc = this.connStateHandler

	if this.httpsServer != nil {
		this.httpsServer.ConnState = this.connStateFunc
	}

	if this.httpServer != nil {
		this.httpServer.ConnState = this.connStateFunc
	}

	this.auditor = log.NewDefaultLogger(log.TRACE)
	this.auditor.DeleteFilter("stdout")

	_ = os.Mkdir("audit", os.ModePerm)
	rotateEnabled, discardWhenDiskFull := true, false
	filer := log.NewFileLogWriter("audit/sub_audit.log", rotateEnabled, discardWhenDiskFull, 0644)
	if filer == nil {
		panic("failed to open sub audit log")
	}
	filer.SetFormat("[%d %T] [%L] (%S) %M")
	if Options.LogRotateSize > 0 {
		filer.SetRotateSize(Options.LogRotateSize)
	}
	filer.SetRotateLines(0)
	filer.SetRotateDaily(true)
	this.auditor.AddFilter("file", logLevel, filer)

	return this
}