Skip to content

Commit 0c9d228

Browse files
authored
domain/metrics: add a metric for lease expired time (#47730)
close #47729
1 parent 204d780 commit 0c9d228

File tree

4 files changed

+121
-0
lines changed

4 files changed

+121
-0
lines changed

pkg/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 {

pkg/metrics/domain.go

+11
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ import (
2020

2121
// Metrics for the domain package.
2222
var (
23+
// LeaseExpireTime records the lease expire time.
24+
LeaseExpireTime prometheus.Gauge
25+
2326
// LoadSchemaCounter records the counter of load schema.
2427
LoadSchemaCounter *prometheus.CounterVec
2528

@@ -51,6 +54,14 @@ var (
5154

5255
// InitDomainMetrics initializes domain metrics.
5356
func InitDomainMetrics() {
57+
LeaseExpireTime = NewGauge(
58+
prometheus.GaugeOpts{
59+
Namespace: "tidb",
60+
Subsystem: "domain",
61+
Name: "lease_expire_time",
62+
Help: "When the last time the lease is expired, it is in seconds",
63+
})
64+
5465
LoadSchemaCounter = NewCounterVec(
5566
prometheus.CounterOpts{
5667
Namespace: "tidb",

pkg/metrics/grafana/tidb.json

+108
Original file line numberDiff line numberDiff line change
@@ -12901,6 +12901,114 @@
1290112901
"align": false,
1290212902
"alignLevel": null
1290312903
}
12904+
},
12905+
{
12906+
"aliasColors": {},
12907+
"bars": false,
12908+
"dashLength": 10,
12909+
"dashes": false,
12910+
"datasource": "${DS_TEST-CLUSTER}",
12911+
"description": "How much longer until the lease expires?",
12912+
"editable": true,
12913+
"error": false,
12914+
"fieldConfig": {
12915+
"defaults": {},
12916+
"overrides": []
12917+
},
12918+
"fill": 0,
12919+
"fillGradient": 0,
12920+
"grid": {},
12921+
"gridPos": {
12922+
"h": 7,
12923+
"w": 12,
12924+
"x": 0,
12925+
"y": 31
12926+
},
12927+
"hiddenSeries": false,
12928+
"id": 23763572002,
12929+
"legend": {
12930+
"alignAsTable": true,
12931+
"avg": false,
12932+
"current": true,
12933+
"max": false,
12934+
"min": false,
12935+
"rightSide": true,
12936+
"show": true,
12937+
"total": false,
12938+
"values": true
12939+
},
12940+
"lines": true,
12941+
"linewidth": 1,
12942+
"links": [],
12943+
"nullPointMode": "null as zero",
12944+
"options": {
12945+
"alertThreshold": true
12946+
},
12947+
"percentage": false,
12948+
"pluginVersion": "7.5.11",
12949+
"pointradius": 5,
12950+
"points": false,
12951+
"renderer": "flot",
12952+
"seriesOverrides": [],
12953+
"spaceLength": 10,
12954+
"stack": false,
12955+
"steppedLine": false,
12956+
"targets": [
12957+
{
12958+
"exemplar": true,
12959+
"expr": "tidb_domain_lease_expire_time{k8s_cluster=\"$k8s_cluster\", tidb_cluster=\"$tidb_cluster\"} - time()",
12960+
"format": "time_series",
12961+
"interval": "",
12962+
"intervalFactor": 2,
12963+
"legendFormat": "{{instance}}",
12964+
"metric": "tidb_domain_load_schema_duration_count",
12965+
"refId": "A",
12966+
"step": 10
12967+
}
12968+
],
12969+
"thresholds": [],
12970+
"timeFrom": null,
12971+
"timeRegions": [],
12972+
"timeShift": null,
12973+
"title": "Lease Duration",
12974+
"tooltip": {
12975+
"msResolution": false,
12976+
"shared": true,
12977+
"sort": 0,
12978+
"value_type": "individual"
12979+
},
12980+
"type": "graph",
12981+
"xaxis": {
12982+
"buckets": null,
12983+
"mode": "time",
12984+
"name": null,
12985+
"show": true,
12986+
"values": []
12987+
},
12988+
"yaxes": [
12989+
{
12990+
"$$hashKey": "object:541",
12991+
"format": "dtdurations",
12992+
"label": null,
12993+
"logBase": 1,
12994+
"max": null,
12995+
"min": null,
12996+
"show": true
12997+
},
12998+
{
12999+
"$$hashKey": "object:542",
13000+
"format": "short",
13001+
"label": null,
13002+
"logBase": 1,
13003+
"max": null,
13004+
"min": null,
13005+
"show": false
13006+
}
13007+
],
13008+
"yaxis": {
13009+
"align": false,
13010+
"alignLevel": null
13011+
}
1290413012
}
1290513013
],
1290613014
"repeat": null,

pkg/metrics/metrics.go

+1
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ func RegisterMetrics() {
158158
prometheus.MustRegister(JobsGauge)
159159
prometheus.MustRegister(LoadPrivilegeCounter)
160160
prometheus.MustRegister(InfoCacheCounters)
161+
prometheus.MustRegister(LeaseExpireTime)
161162
prometheus.MustRegister(LoadSchemaCounter)
162163
prometheus.MustRegister(LoadSchemaDuration)
163164
prometheus.MustRegister(MetaHistogram)

0 commit comments

Comments
 (0)