Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

server: add Uptime status counter #8888

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ type Server struct {
concurrentLimiter *TokenLimiter
clients map[uint32]*clientConn
capability uint32
startTime time.Time

// stopListenerCh is used when a critical error occurred, we don't want to exit the process, because there may be
// a supervisor automatically restart it, then new client connection will be created, but we can't server it.
Expand Down Expand Up @@ -178,6 +179,7 @@ func NewServer(cfg *config.Config, driver IDriver) (*Server, error) {
rwlock: &sync.RWMutex{},
clients: make(map[uint32]*clientConn),
stopListenerCh: make(chan struct{}, 1),
startTime: time.Now(),
}
s.loadTLSCertificates()

Expand Down Expand Up @@ -222,6 +224,8 @@ func NewServer(cfg *config.Config, driver IDriver) (*Server, error) {
return nil, errors.Trace(err)
}

variable.RegisterStatistics(s)

// Init rand seed for randomBuf()
rand.Seed(time.Now().UTC().UnixNano())
return s, nil
Expand Down
37 changes: 37 additions & 0 deletions server/stat.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright 2018 PingCAP, Inc.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Copyright 2018 PingCAP, Inc.
// Copyright 2019 PingCAP, Inc.

//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// limitations under the License.

package server

import (
"time"

"github.com/pingcap/tidb/sessionctx/variable"
)

var (
uptime = "Uptime"
)

// GetScope gets the status variables scope.
func (s *Server) GetScope(status string) variable.ScopeFlag {
// Now server status variables scope are all default scope.
return variable.DefaultStatusVarScopeFlag
}

// Stats returns the server statistics.
func (s *Server) Stats(vars *variable.SessionVars) (map[string]interface{}, error) {
m := make(map[string]interface{})
m[uptime] = int(time.Since(s.startTime).Seconds())
return m, nil
}