Skip to content

Td monitor db ce #3053

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

Merged
merged 6 commits into from
May 28, 2025
Merged
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
6 changes: 6 additions & 0 deletions sqle/locale/active.en.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ ApMetaAliRdsMySQLAuditLog = "AliRDS MySQL audit log"
ApMetaAliRdsMySQLSlowLog = "AliRDS MySQL slow log"
ApMetaAllAppExtract = "Application SQL extraction"
ApMetaBaiduRdsMySQLSlowLog = "Baidu Cloud RDS MySQL slow log"
ApMetaMDBSlowLog = "slow log(Monitor DB)"
ApMetaCustom = "Custom"
ApMetaDB2TopSQL = "DB2 Top SQL"
ApMetaDistributedLock = "Distributed Lock"
Expand Down Expand Up @@ -343,3 +344,8 @@ WorkflowStepStateApprove = "Approved"
WorkflowStepStateReject = "Rejected"
WorkflowStepTypeSQLAudit = "Auditing"
WorkflowStepTypeSQLExecute = "Executing"
ApMetricNameLockWaitTimeAvg = "Average lock wait time(ms) "
ApMetricNameLockWaitTimeMax = "Max lock wait time(ms)"
ApMetricNameRowsAffectedMax = "Max affected rows"
ApMetricNameRowsAffectedAvg = "Average affected rows"
ApMetricNameChecksum = "checksum"
6 changes: 6 additions & 0 deletions sqle/locale/active.zh.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ ApMetaAliRdsMySQLAuditLog = "阿里RDS MySQL审计日志"
ApMetaAliRdsMySQLSlowLog = "阿里RDS MySQL慢日志"
ApMetaAllAppExtract = "应用程序SQL抓取"
ApMetaBaiduRdsMySQLSlowLog = "百度云RDS MySQL慢日志"
ApMetaMDBSlowLog = "慢日志(监控库)"
ApMetaCustom = "自定义"
ApMetaDB2TopSQL = "DB2 Top SQL"
ApMetaDistributedLock = "分布式锁"
Expand Down Expand Up @@ -343,3 +344,8 @@ WorkflowStepStateApprove = "通过"
WorkflowStepStateReject = "驳回"
WorkflowStepTypeSQLAudit = "审批"
WorkflowStepTypeSQLExecute = "上线"
ApMetricNameLockWaitTimeAvg = "平均锁等待时间(ms)"
ApMetricNameLockWaitTimeMax = "锁最大等待时间(ms)"
ApMetricNameRowsAffectedMax = "最大影响行数"
ApMetricNameRowsAffectedAvg = "平均影响行数"
ApMetricNameChecksum = "校验和"
6 changes: 6 additions & 0 deletions sqle/locale/message_zh.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,8 @@ var (
ApMetricNameCPUTimeAvg = &i18n.Message{ID: "ApMetricNameCPUTimeAvg", Other: "平均 CPU 时间(μs)"}
ApMetricNameLockWaitTimeTotal = &i18n.Message{ID: "ApMetricNameLockWaitTimeTotal", Other: "锁等待时间(ms)"}
ApMetricNameLockWaitCounter = &i18n.Message{ID: "ApMetricNameLockWaitCounter", Other: "锁等待次数"}
ApMetricNameLockWaitTimeAvg = &i18n.Message{ID: "ApMetricNameLockWaitTimeAvg", Other: "平均锁等待时间(ms)"}
ApMetricNameLockWaitTimeMax = &i18n.Message{ID: "ApMetricNameLockWaitTimeMax", Other: "锁最大等待时间(ms)"}
ApMetricNameActiveWaitTimeTotal = &i18n.Message{ID: "ApMetricNameActiveWaitTimeTotal", Other: "活动等待总时间(ms)"}
ApMetricNameActiveTimeTotal = &i18n.Message{ID: "ApMetricNameActiveTimeTotal", Other: "活动总时间(ms)"}
ApMetricNameLastReceiveTimestamp = &i18n.Message{ID: "ApMetricNameLastReceiveTimestamp", Other: "最后一次匹配到该指纹的时间"}
Expand All @@ -351,6 +353,9 @@ var (
ApMetricNameFirstQueryAt = &i18n.Message{ID: "ApMetricNameFirstQueryAt", Other: "首次执行时间"}
ApMetricNameLastQueryAt = &i18n.Message{ID: "ApMetricNameLastQueryAt", Other: "最后执行时间"}
ApMetricNameMaxQueryTime = &i18n.Message{ID: "ApMetricNameMaxQueryTime", Other: "最长执行时间(s)"}
ApMetricNameRowsAffectedMax = &i18n.Message{ID: "ApMetricNameRowsAffectedMax", Other: "最大影响行数"}
ApMetricNameRowsAffectedAvg = &i18n.Message{ID: "ApMetricNameRowsAffectedAvg", Other: "平均影响行数"}
ApMetricNameChecksum = &i18n.Message{ID: "ApMetricNameChecksum", Other: "校验和"}

ApMetricNameCounterMoreThan = &i18n.Message{ID: "ApMetricNameCounterMoreThan", Other: "出现次数 > "}
ApMetricNameQueryTimeAvgMoreThan = &i18n.Message{ID: "ApMetricNameQueryTimeAvgMoreThan", Other: "平均执行时间(s) > "}
Expand All @@ -367,6 +372,7 @@ var (
ApMetaAllAppExtract = &i18n.Message{ID: "ApMetaAllAppExtract", Other: "应用程序SQL抓取"}
ApMetaTiDBAuditLog = &i18n.Message{ID: "ApMetaTiDBAuditLog", Other: "TiDB审计日志"}
ApMetaSlowLog = &i18n.Message{ID: "ApMetaSlowLog", Other: "慢日志"}
ApMetaMDBSlowLog = &i18n.Message{ID: "ApMetaMDBSlowLog", Other: "慢日志(监控库)"}
ApMetaTopSQL = &i18n.Message{ID: "ApMetaTopSQL", Other: "Top SQL"}
ApMetaDB2TopSQL = &i18n.Message{ID: "ApMetaDB2TopSQL", Other: "DB2 Top SQL"}
ApMetaSchemaMeta = &i18n.Message{ID: "ApMetaSchemaMeta", Other: "库表元数据"}
Expand Down
4 changes: 2 additions & 2 deletions sqle/model/instance_audit_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,12 @@ func (a *AuditPlanV2) GetBaseInfo() BaseAuditPlan {
}
}

func (s *Storage) GetLatestStartTimeAuditPlanSQLV2(sourceId uint) (string, error) {
func (s *Storage) GetLatestStartTimeAuditPlanSQLV2(sourceId uint, typ string) (string, error) {
info := struct {
StartTime string `gorm:"column:max_start_time"`
}{}
err := s.db.Raw(`SELECT MAX(STR_TO_DATE(JSON_UNQUOTE(JSON_EXTRACT(info, '$.start_time_of_last_scraped_sql')), '%Y-%m-%dT%H:%i:%s.%f'))
AS max_start_time FROM sql_manage_records WHERE source_id = ?`, sourceId).Scan(&info).Error
AS max_start_time FROM sql_manage_records WHERE source_id = ? AND source = ? AND deleted_at is NULL`, sourceId, typ).Scan(&info).Error
return info.StartTime, err
}

Expand Down
12 changes: 12 additions & 0 deletions sqle/server/auditplan/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ const MetricNameDiskReadAvg = "disk_read_avg"
const MetricNameBufferReadAvg = "buffer_read_avg"
const MetricNameExplainCost = "explain_cost"

const MetricNameLockTimeAvg string = "lock_time_avg" // 平均锁等待时间
const MetricNameLockTimeMax string = "lock_time_max" // 最大锁等待时间
const MetricNameRowsAffectedMax string = "rows_affected_max" // 最大影响的行数
const MetricNameRowsAffectedAvg string = "rows_affected_avg" // 平均影响的行数
const MetricNameChecksum string = "checksum" // 校验和

// Lock
const MetricNameGrantedLockId string = "granted_lock_id"
const MetricNameWaitingLockId string = "waiting_lock_id"
Expand Down Expand Up @@ -95,6 +101,12 @@ var ALLMetric = map[string]MetricType{
MetricNameLockStatus: MetricTypeString, // Lock
MetricNameEngine: MetricTypeString, // Lock
MetricNameTable: MetricTypeString, // Lock

MetricNameLockTimeAvg: MetricTypeFloat, // TD MYSQL Monitor DB Slow Log
MetricNameLockTimeMax: MetricTypeFloat, // TD MYSQL Monitor DB Slow Log
MetricNameRowsAffectedMax: MetricTypeInt, // TD MYSQL Monitor DB Slow Log
MetricNameRowsAffectedAvg: MetricTypeFloat, // TD MYSQL Monitor DB Slow Log
MetricNameChecksum: MetricTypeString, // TD MYSQL Monitor DB Slow Log
}

func LoadMetrics(info map[string]interface{}, metrics []string) Metrics {
Expand Down
Loading