本文整理汇总了Golang中github.com/percona/percona-agent/pct.NewLogger函数的典型用法代码示例。如果您正苦于以下问题:Golang NewLogger函数的具体用法?Golang NewLogger怎么用?Golang NewLogger使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewLogger函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
}
示例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)
}
示例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)
}
示例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
}
示例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()
}
示例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)
}
示例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
}
示例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")
}
示例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
}
示例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,
)
}
示例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)
}
示例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})
}
示例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()
}
示例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
}
示例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
}