Skip to content

Commit 6682575

Browse files
authored
proxy, metrics: add metrics on QPS distribution and connection lifetime (#1040)
1 parent f8d6536 commit 6682575

3 files changed

Lines changed: 22 additions & 0 deletions

File tree

pkg/metrics/metrics.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ func init() {
107107
KeepAliveCounter,
108108
QueryTotalCounter,
109109
QueryDurationHistogram,
110+
QueryTimeSinceConnCreationHistogram,
111+
ConnLifetimeHistogram,
110112
HandshakeDurationHistogram,
111113
BackendStatusGauge,
112114
GetBackendHistogram,

pkg/metrics/session.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,22 @@ var (
3939
Help: "Bucketed histogram of processing time (s) of handshakes.",
4040
Buckets: prometheus.ExponentialBuckets(0.0005, 2, 29), // 0.5ms ~ 1.5days
4141
}, []string{LblBackend})
42+
43+
QueryTimeSinceConnCreationHistogram = prometheus.NewHistogram(
44+
prometheus.HistogramOpts{
45+
Namespace: ModuleProxy,
46+
Subsystem: LabelSession,
47+
Name: "query_time_since_conn_creation_seconds",
48+
Help: "Bucketed histogram of query start time (s) since connection creation.",
49+
Buckets: prometheus.ExponentialBuckets(1, 2, 21), // 1s ~ 24days
50+
})
51+
52+
ConnLifetimeHistogram = prometheus.NewHistogram(
53+
prometheus.HistogramOpts{
54+
Namespace: ModuleProxy,
55+
Subsystem: LabelSession,
56+
Name: "conn_lifetime_seconds",
57+
Help: "Bucketed histogram of connection lifetime (s).",
58+
Buckets: prometheus.ExponentialBuckets(0.1, 2, 25), // 1s ~ 38days
59+
})
4260
)

pkg/proxy/backend/backend_conn_mgr.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,7 @@ func (mgr *BackendConnManager) ExecuteCmd(ctx context.Context, request []byte) (
376376
}
377377
mgr.lastActiveTime = now
378378
mgr.processLock.Unlock()
379+
metrics.QueryTimeSinceConnCreationHistogram.Observe(startTime.Sub(mgr.createTime).Seconds())
379380
}()
380381
if len(request) < 1 {
381382
err = mysql.ErrMalformPacket
@@ -835,6 +836,7 @@ func (mgr *BackendConnManager) Close() error {
835836
mgr.cpt.Capture([]byte{pnet.ComQuit.Byte()}, time.Now(), mgr.connectionID, nil)
836837
}
837838
mgr.closeStatus.Store(statusClosed)
839+
metrics.ConnLifetimeHistogram.Observe(time.Since(mgr.createTime).Seconds())
838840
return errors.Collect(ErrCloseConnMgr, connErr, handErr)
839841
}
840842

0 commit comments

Comments
 (0)