Skip to content

Commit 81c377a

Browse files
Temajackysp
authored and
GitHub Enterprise
committed
domain/metrics: add a metric for lease expired time (pingcap#47730) (pingcap#47819) (pingcap#22)
close pingcap#47729 Co-authored-by: Jack Yu <jackysp@gmail.com>
1 parent a168746 commit 81c377a

File tree

4 files changed

+118
-0
lines changed

4 files changed

+118
-0
lines changed

domain/schema_validator.go

+1
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ func (s *schemaValidator) Update(leaseGrantTS uint64, oldVer, currVer int64, cha
138138
leaseGrantTime := oracle.GetTimeFromTS(leaseGrantTS)
139139
leaseExpire := leaseGrantTime.Add(s.lease - time.Millisecond)
140140
s.latestSchemaExpire = leaseExpire
141+
metrics.LeaseExpireTime.Set(float64(leaseExpire.Unix()))
141142

142143
// Update the schema deltaItem information.
143144
if currVer != oldVer {

metrics/domain.go

+8
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ import (
2121
// Metrics for the domain package.
2222
var (
2323
// LoadSchemaCounter records the counter of load schema.
24+
LeaseExpireTime = prometheus.NewGauge(
25+
prometheus.GaugeOpts{
26+
Namespace: "tidb",
27+
Subsystem: "domain",
28+
Name: "lease_expire_time",
29+
Help: "When the last time the lease is expired, it is in seconds",
30+
})
31+
2432
LoadSchemaCounter = prometheus.NewCounterVec(
2533
prometheus.CounterOpts{
2634
Namespace: "tidb",

metrics/grafana/tidb.json

+108
Original file line numberDiff line numberDiff line change
@@ -12187,6 +12187,114 @@
1218712187
"align": false,
1218812188
"alignLevel": null
1218912189
}
12190+
},
12191+
{
12192+
"aliasColors": {},
12193+
"bars": false,
12194+
"dashLength": 10,
12195+
"dashes": false,
12196+
"datasource": "${DS_TEST-CLUSTER}",
12197+
"description": "How much longer until the lease expires?",
12198+
"editable": true,
12199+
"error": false,
12200+
"fieldConfig": {
12201+
"defaults": {},
12202+
"overrides": []
12203+
},
12204+
"fill": 0,
12205+
"fillGradient": 0,
12206+
"grid": {},
12207+
"gridPos": {
12208+
"h": 7,
12209+
"w": 12,
12210+
"x": 0,
12211+
"y": 31
12212+
},
12213+
"hiddenSeries": false,
12214+
"id": 23763572002,
12215+
"legend": {
12216+
"alignAsTable": true,
12217+
"avg": false,
12218+
"current": true,
12219+
"max": false,
12220+
"min": false,
12221+
"rightSide": true,
12222+
"show": true,
12223+
"total": false,
12224+
"values": true
12225+
},
12226+
"lines": true,
12227+
"linewidth": 1,
12228+
"links": [],
12229+
"nullPointMode": "null as zero",
12230+
"options": {
12231+
"alertThreshold": true
12232+
},
12233+
"percentage": false,
12234+
"pluginVersion": "7.5.11",
12235+
"pointradius": 5,
12236+
"points": false,
12237+
"renderer": "flot",
12238+
"seriesOverrides": [],
12239+
"spaceLength": 10,
12240+
"stack": false,
12241+
"steppedLine": false,
12242+
"targets": [
12243+
{
12244+
"exemplar": true,
12245+
"expr": "tidb_domain_lease_expire_time{k8s_cluster=\"$k8s_cluster\", tidb_cluster=\"$tidb_cluster\"} - time()",
12246+
"format": "time_series",
12247+
"interval": "",
12248+
"intervalFactor": 2,
12249+
"legendFormat": "{{instance}}",
12250+
"metric": "tidb_domain_load_schema_duration_count",
12251+
"refId": "A",
12252+
"step": 10
12253+
}
12254+
],
12255+
"thresholds": [],
12256+
"timeFrom": null,
12257+
"timeRegions": [],
12258+
"timeShift": null,
12259+
"title": "Lease Duration",
12260+
"tooltip": {
12261+
"msResolution": false,
12262+
"shared": true,
12263+
"sort": 0,
12264+
"value_type": "individual"
12265+
},
12266+
"type": "graph",
12267+
"xaxis": {
12268+
"buckets": null,
12269+
"mode": "time",
12270+
"name": null,
12271+
"show": true,
12272+
"values": []
12273+
},
12274+
"yaxes": [
12275+
{
12276+
"$$hashKey": "object:541",
12277+
"format": "dtdurations",
12278+
"label": null,
12279+
"logBase": 1,
12280+
"max": null,
12281+
"min": null,
12282+
"show": true
12283+
},
12284+
{
12285+
"$$hashKey": "object:542",
12286+
"format": "short",
12287+
"label": null,
12288+
"logBase": 1,
12289+
"max": null,
12290+
"min": null,
12291+
"show": false
12292+
}
12293+
],
12294+
"yaxis": {
12295+
"align": false,
12296+
"alignLevel": null
12297+
}
1219012298
}
1219112299
],
1219212300
"repeat": null,

metrics/metrics.go

+1
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ func RegisterMetrics() {
127127
prometheus.MustRegister(KeepAliveCounter)
128128
prometheus.MustRegister(LoadPrivilegeCounter)
129129
prometheus.MustRegister(InfoCacheCounters)
130+
prometheus.MustRegister(LeaseExpireTime)
130131
prometheus.MustRegister(LoadSchemaCounter)
131132
prometheus.MustRegister(LoadSchemaDuration)
132133
prometheus.MustRegister(MetaHistogram)

0 commit comments

Comments
 (0)