Skip to content

Commit

Permalink
*: update server metrics (pingcap#1749)
Browse files Browse the repository at this point in the history
  • Loading branch information
shenli authored Sep 21, 2016
1 parent bd43d06 commit 453158c
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
5 changes: 2 additions & 3 deletions server/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,10 @@ func (cc *clientConn) handshake() error {
func (cc *clientConn) Close() error {
cc.server.rwlock.Lock()
delete(cc.server.clients, cc.connectionID)
connections := len(cc.server.clients)
cc.server.rwlock.Unlock()
connGauge.Set(float64(connections))
cc.conn.Close()
connGauge.Dec()
if cc.ctx != nil {
return cc.ctx.Close()
}
Expand Down Expand Up @@ -305,8 +306,6 @@ func (cc *clientConn) Run() {
cc.Close()
}()

connGauge.Inc()

for {
cc.alloc.Reset()
data, err := cc.readPacket()
Expand Down
2 changes: 2 additions & 0 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,9 @@ func (s *Server) onConn(c net.Conn) {

s.rwlock.Lock()
s.clients[conn.connectionID] = conn
connections := len(s.clients)
s.rwlock.Unlock()
connGauge.Set(float64(connections))

conn.Run()
}
Expand Down
3 changes: 1 addition & 2 deletions tidb-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,9 @@ func pushMetric(addr string, interval time.Duration) {
func prometheusPushClient(addr string, interval time.Duration) {
// TODO: TiDB do not have uniq name, so we use host+port to compose a name.
job := "tidb"
grouping := map[string]string{"instance": fmt.Sprintf("%s:%s", *host, *port)}
for {
err := push.FromGatherer(
job, grouping,
job, push.HostnameGroupingKey(),
addr,
prometheus.DefaultGatherer,
)
Expand Down

0 comments on commit 453158c

Please sign in to comment.