• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang pct.NewLogger函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/percona/percona-agent/pct.NewLogger函数的典型用法代码示例。如果您正苦于以下问题:Golang NewLogger函数的具体用法?Golang NewLogger怎么用?Golang NewLogger使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了NewLogger函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: SetUpSuite

func (s *ManagerTestSuite) SetUpSuite(t *C) {
	s.logChan = make(chan *proto.LogEntry, 10)
	s.logger = pct.NewLogger(s.logChan, "sysconfig-manager-test")

	s.mockMonitor = mock.NewSysconfigMonitor()
	s.factory = mock.NewSysconfigMonitorFactory([]sysconfig.Monitor{s.mockMonitor})

	s.tickChan = make(chan time.Time)

	s.dataChan = make(chan interface{}, 1)
	s.spool = mock.NewSpooler(s.dataChan)

	var err error
	s.tmpDir, err = ioutil.TempDir("/tmp", "agent-test")
	t.Assert(err, IsNil)

	if err := pct.Basedir.Init(s.tmpDir); err != nil {
		t.Fatal(err)
	}
	s.configDir = pct.Basedir.Dir("config")

	links := map[string]string{
		"agent":     "http://localhost/agent",
		"instances": "http://localhost/instances",
	}
	s.api = mock.NewAPI("http://localhost", "http://localhost", "123", "abc-123-def", links)

	s.im = instance.NewRepo(pct.NewLogger(s.logChan, "im-test"), s.configDir, s.api)
}
开发者ID:huangzhiyong,项目名称:percona-agent,代码行数:29,代码来源:sysconfig_test.go


示例2: SetUpSuite

func (s *ManagerTestSuite) SetUpSuite(t *C) {
	s.dsn = os.Getenv("PCT_TEST_MYSQL_DSN")
	if s.dsn == "" {
		t.Fatal("PCT_TEST_MYSQL_DSN is not set")
	}

	s.logChan = make(chan *proto.LogEntry, 10)
	s.logger = pct.NewLogger(s.logChan, query.SERVICE_NAME+"-manager-test")

	var err error
	s.tmpDir, err = ioutil.TempDir("/tmp", "agent-test")
	t.Assert(err, IsNil)

	if err := pct.Basedir.Init(s.tmpDir); err != nil {
		t.Fatal(err)
	}
	s.configDir = pct.Basedir.Dir("config")

	// Real instance repo
	s.repo = instance.NewRepo(pct.NewLogger(s.logChan, "im-test"), s.configDir, s.api)
	data, err := json.Marshal(&proto.MySQLInstance{
		Hostname: "db1",
		DSN:      s.dsn,
	})
	t.Assert(err, IsNil)
	s.repo.Add("mysql", 1, data, false)
	s.mysqlInstance = proto.ServiceInstance{Service: "mysql", InstanceId: 1}

	links := map[string]string{
		"agent":     "http://localhost/agent",
		"instances": "http://localhost/instances",
	}
	s.api = mock.NewAPI("http://localhost", "http://localhost", "123", "abc-123-def", links)
}
开发者ID:hg3rdrock,项目名称:percona-agent,代码行数:34,代码来源:query_test.go


示例3: SetUpSuite

func (s *ManagerTestSuite) SetUpSuite(t *C) {
	s.dsn = os.Getenv("PCT_TEST_MYSQL_DSN")
	if s.dsn == "" {
		t.Fatal("PCT_TEST_MYSQL_DSN is not set")
	}
	s.realmysql = mysql.NewConnection(s.dsn)
	if err := s.realmysql.Connect(1); err != nil {
		t.Fatal(err)
	}
	s.reset = []mysql.Query{
		mysql.Query{Set: "SET GLOBAL slow_query_log=OFF"},
		mysql.Query{Set: "SET GLOBAL long_query_time=10"},
	}

	s.nullmysql = mock.NewNullMySQL()

	s.logChan = make(chan *proto.LogEntry, 1000)
	s.logger = pct.NewLogger(s.logChan, "qan-test")

	s.intervalChan = make(chan *qan.Interval, 1)
	s.iter = mock.NewMockIntervalIter(s.intervalChan)
	s.iterFactory = &mock.IntervalIterFactory{
		Iters:     []qan.IntervalIter{s.iter},
		TickChans: make(map[qan.IntervalIter]chan time.Time),
	}

	s.dataChan = make(chan interface{}, 2)
	s.spool = mock.NewSpooler(s.dataChan)
	s.workerFactory = &qan.SlowLogWorkerFactory{}

	var err error
	s.tmpDir, err = ioutil.TempDir("/tmp", "agent-test")
	t.Assert(err, IsNil)

	if err := pct.Basedir.Init(s.tmpDir); err != nil {
		t.Fatal(err)
	}
	s.configDir = pct.Basedir.Dir("config")

	s.im = instance.NewRepo(pct.NewLogger(s.logChan, "im-test"), s.configDir, s.api)
	data, err := json.Marshal(&proto.MySQLInstance{
		Hostname: "db1",
		DSN:      s.dsn,
	})
	t.Assert(err, IsNil)
	s.im.Add("mysql", 1, data, false)
	s.mysqlInstance = proto.ServiceInstance{Service: "mysql", InstanceId: 1}

	links := map[string]string{
		"agent":     "http://localhost/agent",
		"instances": "http://localhost/instances",
	}
	s.api = mock.NewAPI("http://localhost", "http://localhost", "123", "abc-123-def", links)
}
开发者ID:huangzhiyong,项目名称:percona-agent,代码行数:54,代码来源:qan_test.go


示例4: Make

func (f *Factory) Make(service string, instanceId uint, data []byte) (mm.Monitor, error) {
	var monitor mm.Monitor
	switch service {
	case "mysql":
		// Load the MySQL instance info (DSN, name, etc.).
		mysqlIt := &proto.MySQLInstance{}
		if err := f.ir.Get(service, instanceId, mysqlIt); err != nil {
			return nil, err
		}

		// Parse the MySQL sysconfig config.
		config := &mysql.Config{}
		if err := json.Unmarshal(data, config); err != nil {
			return nil, err
		}

		// The user-friendly name of the service, e.g. sysconfig-mysql-db101:
		alias := "mm-mysql-" + mysqlIt.Hostname

		// Make a MySQL metrics monitor.
		monitor = mysql.NewMonitor(
			alias,
			config,
			pct.NewLogger(f.logChan, alias),
			mysqlConn.NewConnection(mysqlIt.DSN),
			f.mrm,
		)
	case "server":
		// Parse the system mm config.
		config := &system.Config{}
		if err := json.Unmarshal(data, config); err != nil {
			return nil, err
		}

		// Only one system for now, so no SystemInstance and no  "-instanceName" suffix.
		alias := "mm-system"

		// Make a MySQL metrics monitor.
		monitor = system.NewMonitor(
			alias,
			config,
			pct.NewLogger(f.logChan, alias),
		)
	default:
		return nil, errors.New("Unknown metrics monitor type: " + service)
	}
	return monitor, nil
}
开发者ID:hg3rdrock,项目名称:percona-agent,代码行数:48,代码来源:factory.go


示例5: SetUpSuite

func (s *WorkerTestSuite) SetUpSuite(t *C) {
	s.dsn = os.Getenv("PCT_TEST_MYSQL_DSN")
	s.logChan = make(chan *proto.LogEntry, 100)
	s.logger = pct.NewLogger(s.logChan, "qan-worker")
	s.now = time.Now()
	s.mysqlInstance = proto.ServiceInstance{Service: "mysql", InstanceId: 1}
	s.config = qan.Config{
		ServiceInstance: s.mysqlInstance,
		Start: []mysql.Query{
			mysql.Query{Set: "SET GLOBAL slow_query_log=OFF"},
			mysql.Query{Set: "SET GLOBAL long_query_time=0.123"},
			mysql.Query{Set: "SET GLOBAL slow_query_log=ON"},
		},
		Stop: []mysql.Query{
			mysql.Query{Set: "SET GLOBAL slow_query_log=OFF"},
			mysql.Query{Set: "SET GLOBAL long_query_time=10"},
		},
		Interval:          60,         // 1 min
		MaxSlowLogSize:    1073741824, // 1 GiB
		RemoveOldSlowLogs: true,
		ExampleQueries:    true,
		WorkerRunTime:     60, // 1 min
		CollectFrom:       "slowlog",
	}
	s.nullmysql = mock.NewNullMySQL()
}
开发者ID:hg3rdrock,项目名称:percona-agent,代码行数:26,代码来源:slowlog_test.go


示例6: SetUpSuite

func (s *UpdateTestSuite) SetUpSuite(t *C) {
	var err error
	s.tmpDir, err = ioutil.TempDir("/tmp", "percona-agent-test-pct-update")
	t.Assert(err, IsNil)

	s.logChan = make(chan *proto.LogEntry, 1000)
	s.logger = pct.NewLogger(s.logChan, "qan-test")

	links := map[string]string{
		"agent":     "http://localhost/agent",
		"instances": "http://localhost/instances",
		"update":    "http://localhost/update",
	}
	s.api = mock.NewAPI("http://localhost", "http://localhost", "123", "abc-123-def", links)

	test.CopyFile(test.RootDir+"/pct/fake-percona-agent-1.0.1.go", s.tmpDir)

	cwd, err := os.Getwd()
	t.Assert(err, IsNil)
	defer os.Chdir(cwd)

	err = os.Chdir(s.tmpDir)
	t.Assert(err, IsNil)

	out, err := exec.Command("go", "build", "fake-percona-agent-1.0.1.go").Output()
	if err != nil {
		t.Logf("%s", out)
		t.Fatal(err)
	}
	s.bin, s.sig, err = test.Sign(filepath.Join(s.tmpDir, "fake-percona-agent-1.0.1"))
	t.Assert(err, IsNil)

	s.pubKey, err = ioutil.ReadFile(filepath.Join(test.RootDir, "pct", "key.pub"))
	t.Assert(err, IsNil)
}
开发者ID:huangzhiyong,项目名称:percona-agent,代码行数:35,代码来源:update_test.go


示例7: writeInstances

func (i *Installer) writeInstances(si *proto.ServerInstance, mi *proto.MySQLInstance) error {
	// We could write the instance structs directly, but this is the job of an
	// instance repo and it's easy enough to create one, so do the right thing.
	logChan := make(chan *proto.LogEntry, 100)
	logger := pct.NewLogger(logChan, "instance-repo")
	repo := instance.NewRepo(logger, pct.Basedir.Dir("config"), i.api)
	if si != nil {
		bytes, err := json.Marshal(si)
		if err != nil {
			return err
		}
		if err := repo.Add("server", si.Id, bytes, true); err != nil {
			return err
		}
	}
	if mi != nil {
		bytes, err := json.Marshal(mi)
		if err != nil {
			return err
		}
		if err := repo.Add("mysql", mi.Id, bytes, true); err != nil {
			return err
		}
	}
	return nil
}
开发者ID:huangzhiyong,项目名称:percona-agent,代码行数:26,代码来源:config.go


示例8: TestNoSlowLogTakeOver

// Test that a disabled slow log rotation in Percona Server (or MySQL) does not change analizer config
func (s *AnalyzerTestSuite) TestNoSlowLogTakeOver(t *C) {

	/*
		PS can be configured to rotate slow log, making qan break.
		Since qan cannot handle the situation where a slow log is rotated by a third party we take over Percona Server
		rotation and disable it on DB.
	*/
	a := qan.NewRealAnalyzer(
		pct.NewLogger(s.logChan, "qan-analyzer"),
		s.config,
		s.iter,
		s.nullmysql,
		s.restartChan,
		s.worker,
		s.clock,
		s.spool,
	)

	err := a.Start()
	t.Assert(err, IsNil)
	test.WaitStatus(1, a, "qan-analyzer", "Idle")

	// Disable DB rotation by setting max_slowlog_size to a value < 4096
	s.nullmysql.SetGlobalVarNumber("max_slowlog_size", 1000)
	// Trigger our PS slow log rotation take-over, everything should stay the same since max_slowlog_size is < 4096
	a.TakeOverPerconaServerRotation()
	t.Check(a.Config().MaxSlowLogSize, Equals, MAX_SLOW_LOG_SIZE)
	err = a.Stop()
	t.Assert(err, IsNil)
	test.WaitStatus(1, a, "qan-analyzer", "Stopped")
	t.Check(a.String(), Equals, "qan-analyzer")
}
开发者ID:hg3rdrock,项目名称:percona-agent,代码行数:33,代码来源:analyzer_test.go


示例9: SetUpSuite

func (s *DiskvSpoolerTestSuite) SetUpSuite(t *C) {
	s.logChan = make(chan *proto.LogEntry, 10)
	s.logger = pct.NewLogger(s.logChan, "data_test")

	dir, _ := ioutil.TempDir("/tmp", "pct-data-spooler-test")
	s.dataDir = dir
}
开发者ID:huangzhiyong,项目名称:percona-agent,代码行数:7,代码来源:data_test.go


示例10: Make

func (f *RealAnalyzerFactory) Make(
	config qan.Config,
	name string,
	mysqlConn mysql.Connector,
	restartChan <-chan bool,
	tickChan chan time.Time,
) qan.Analyzer {
	var worker qan.Worker
	analyzerType := config.CollectFrom
	switch analyzerType {
	case "slowlog":
		worker = f.slowlogWorkerFactory.Make(name+"-worker", config, mysqlConn)
	case "perfschema":
		worker = f.perfschemaWorkerFactory.Make(name+"-worker", mysqlConn)
	default:
		panic("Invalid analyzerType: " + analyzerType)
	}
	return qan.NewRealAnalyzer(
		pct.NewLogger(f.logChan, name),
		config,
		f.iterFactory.Make(analyzerType, mysqlConn, tickChan),
		mysqlConn,
		restartChan,
		worker,
		f.clock,
		f.spool,
	)
}
开发者ID:hg3rdrock,项目名称:percona-agent,代码行数:28,代码来源:analyzer.go


示例11: SetUpSuite

func (s *AgentTestSuite) SetUpSuite(t *C) {
	var err error
	s.tmpDir, err = ioutil.TempDir("/tmp", "agent-test")
	t.Assert(err, IsNil)

	if err := pct.Basedir.Init(s.tmpDir); err != nil {
		t.Fatal(err)
	}
	s.configFile = filepath.Join(s.tmpDir, pct.CONFIG_DIR, "agent"+pct.CONFIG_FILE_SUFFIX)

	// Log
	// todo: use log.Manager instead
	s.logChan = make(chan *proto.LogEntry, 10)
	s.logger = pct.NewLogger(s.logChan, "agent-test")

	// Agent
	s.config = &agent.Config{
		AgentUuid:   "abc-123-def",
		ApiKey:      "789",
		ApiHostname: agent.DEFAULT_API_HOSTNAME,
	}

	s.sendChan = make(chan *proto.Cmd, 5)
	s.recvChan = make(chan *proto.Reply, 5)
	s.sendDataChan = make(chan interface{}, 5)
	s.recvDataChan = make(chan interface{}, 5)
	s.client = mock.NewWebsocketClient(s.sendChan, s.recvChan, s.sendDataChan, s.recvDataChan)
	s.client.ErrChan = make(chan error)

	s.readyChan = make(chan bool, 2)
	s.traceChan = make(chan string, 10)
	s.doneChan = make(chan bool, 1)
}
开发者ID:huangzhiyong,项目名称:percona-agent,代码行数:33,代码来源:agent_test.go


示例12: TestIter

func (s *WorkerTestSuite) TestIter(t *C) {
	tickChan := make(chan time.Time, 1)
	i := perfschema.NewIter(pct.NewLogger(s.logChan, "iter"), tickChan)
	t.Assert(i, NotNil)

	iterChan := i.IntervalChan()
	t.Assert(iterChan, NotNil)

	i.Start()
	defer i.Stop()

	t1, _ := time.Parse("2006-01-02 15:04:05", "2015-01-01 00:01:00")
	t2, _ := time.Parse("2006-01-02 15:04:05", "2015-01-01 00:02:00")
	t3, _ := time.Parse("2006-01-02 15:04:05", "2015-01-01 00:03:00")

	tickChan <- t1
	got := <-iterChan
	t.Check(got, DeepEquals, &qan.Interval{Number: 1, StartTime: time.Time{}, StopTime: t1})

	tickChan <- t2
	got = <-iterChan
	t.Check(got, DeepEquals, &qan.Interval{Number: 2, StartTime: t1, StopTime: t2})

	tickChan <- t3
	got = <-iterChan
	t.Check(got, DeepEquals, &qan.Interval{Number: 3, StartTime: t2, StopTime: t3})
}
开发者ID:hg3rdrock,项目名称:percona-agent,代码行数:27,代码来源:perfschema_test.go


示例13: TestIsSupportedMySQLVersion

func (i *InstallerTestSuite) TestIsSupportedMySQLVersion(t *C) {
	var got bool
	var err error

	agentConfig := &agent.Config{}
	flags := installer.Flags{}

	apiConnector := pct.NewAPI()
	api := api.New(apiConnector, false)
	logChan := make(chan *proto.LogEntry, 100)
	logger := pct.NewLogger(logChan, "instance-repo")
	instanceRepo := instance.NewRepo(logger, pct.Basedir.Dir("config"), apiConnector)
	terminal := term.NewTerminal(os.Stdin, false, true)
	inst := installer.NewInstaller(terminal, "", api, instanceRepo, agentConfig, flags)
	conn := mock.NewNullMySQL()
	errSomethingWentWrong := fmt.Errorf("Something went wrong")

	conn.SetAtLeastVersion(false, errSomethingWentWrong)
	got, err = inst.IsVersionSupported(conn)
	t.Assert(conn.Version, Equals, agent.MIN_SUPPORTED_MYSQL_VERSION)
	t.Assert(err, Equals, errSomethingWentWrong)
	t.Assert(got, Equals, false)

	conn.SetAtLeastVersion(true, nil)
	got, err = inst.IsVersionSupported(conn)
	t.Assert(conn.Version, Equals, agent.MIN_SUPPORTED_MYSQL_VERSION)
	t.Assert(err, IsNil)
	t.Assert(got, Equals, true)

	conn.Close()
}
开发者ID:hg3rdrock,项目名称:percona-agent,代码行数:31,代码来源:installer_test.go


示例14: Make

func (f *Factory) Make(service string, instanceId uint, data []byte) (sysconfig.Monitor, error) {
	var monitor sysconfig.Monitor
	switch service {
	case "mysql":
		// Load the MySQL instance info (DSN, name, etc.).
		mysqlIt := &proto.MySQLInstance{}
		if err := f.ir.Get(service, instanceId, mysqlIt); err != nil {
			return nil, err
		}

		// Parse the MySQL sysconfig config.
		config := &mysql.Config{}
		if err := json.Unmarshal(data, config); err != nil {
			return nil, err
		}

		// The user-friendly name of the service, e.g. sysconfig-mysql-db101:
		alias := "sysconfig-mysql-" + mysqlIt.Hostname

		// Make a MySQL sysconfig monitor.
		monitor = mysql.NewMonitor(
			alias,
			config,
			pct.NewLogger(f.logChan, alias),
			mysqlConn.NewConnection(mysqlIt.DSN),
		)
	default:
		return nil, errors.New("Unknown sysconfig monitor type: " + service)
	}
	return monitor, nil
}
开发者ID:hg3rdrock,项目名称:percona-agent,代码行数:31,代码来源:factory.go


示例15: Start

// @goroutine[0]
func (m *Manager) Start() error {
	m.mux.Lock()
	defer m.mux.Unlock()

	if m.config != nil {
		return pct.ServiceIsRunningError{Service: "log"}
	}

	// Load config from disk.
	config := &Config{}
	if err := pct.Basedir.ReadConfig("log", config); err != nil {
		if !os.IsNotExist(err) {
			return err
		}
	}
	if err := m.validateConfig(config); err != nil {
		return err
	}

	// Start relay (it buffers and sends log entries to API).
	level := proto.LogLevelNumber[config.Level]
	m.relay = NewRelay(m.client, m.logChan, config.File, level, config.Offline)
	go m.relay.Run()

	m.logger = pct.NewLogger(m.relay.LogChan(), "log")
	m.config = config
	m.running = true

	m.logger.Info("Started")
	m.status.Update("log", "Running")
	return nil
}
开发者ID:hg3rdrock,项目名称:percona-agent,代码行数:33,代码来源:manager.go


示例16: SetUpSuite

func (s *AggregatorTestSuite) SetUpSuite(t *C) {
	s.logChan = make(chan *proto.LogEntry, 10)
	s.logger = pct.NewLogger(s.logChan, "mm-manager-test")
	s.tickChan = make(chan time.Time)
	s.collectionChan = make(chan *mm.Collection)
	s.dataChan = make(chan interface{}, 1)
	s.spool = mock.NewSpooler(s.dataChan)
}
开发者ID:huangzhiyong,项目名称:percona-agent,代码行数:8,代码来源:mm_test.go


示例17: SetUpSuite

func (s *SenderTestSuite) SetUpSuite(t *C) {
	s.logChan = make(chan *proto.LogEntry, 10)
	s.logger = pct.NewLogger(s.logChan, "data_test")
	s.tickerChan = make(chan time.Time, 1)

	s.dataChan = make(chan []byte, 5)
	s.respChan = make(chan interface{})
	s.client = mock.NewDataClient(s.dataChan, s.respChan)
}
开发者ID:hg3rdrock,项目名称:percona-agent,代码行数:9,代码来源:data_test.go


示例18: SetUpSuite

func (s *ManagerTestSuite) SetUpSuite(t *C) {
	s.logChan = make(chan *proto.LogEntry, 10)
	s.logger = pct.NewLogger(s.logChan, "system-monitor-test")

	s.tickChan = make(chan time.Time)
	s.collectionChan = make(chan *mm.Collection, 1)

	s.name = "localhost"
}
开发者ID:hg3rdrock,项目名称:percona-agent,代码行数:9,代码来源:system_test.go


示例19: createMysqlInstance

func (m *Monitor) createMysqlInstance(dsn string) (mi *MysqlInstance, err error) {
	m.logger.Debug("createMysqlInstance:call:" + mysql.HideDSNPassword(dsn))
	defer m.logger.Debug("createMysqlInstance:return:" + mysql.HideDSNPassword(dsn))

	mysqlConn := m.mysqlConnFactory.Make(dsn)
	// todo: fix
	logger := pct.NewLogger(m.logger.LogChan(), "mrms-monitor-mysql")
	subscribers := NewSubscribers(logger)
	return NewMysqlInstance(logger, mysqlConn, subscribers)
}
开发者ID:hg3rdrock,项目名称:percona-agent,代码行数:10,代码来源:monitor.go


示例20: NewManager

func NewManager(logger *pct.Logger, configDir string, api pct.APIConnector) *Manager {
	repo := NewRepo(pct.NewLogger(logger.LogChan(), "instance-repo"), configDir, api)
	m := &Manager{
		logger:    logger,
		configDir: configDir,
		// --
		status: pct.NewStatus([]string{"instance", "instance-repo"}),
		repo:   repo,
	}
	return m
}
开发者ID:huangzhiyong,项目名称:percona-agent,代码行数:11,代码来源:manager.go



注:本文中的github.com/percona/percona-agent/pct.NewLogger函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang pct.NewStatus函数代码示例发布时间:2022-05-28
下一篇:
Golang mysql.DSN类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap