feat: 增加Kafka数据库连接失败警报功能,调整入库数据检查时间为2分钟,更新相关日志记录

This commit is contained in:
2026-02-10 09:07:46 +08:00
parent 7a60c62166
commit aa835bbe47

View File

@@ -439,6 +439,7 @@ namespace AutoNotificatPhone.Models
if (string.IsNullOrWhiteSpace(connectionString))
{
logger.Error("Postgres配置缺失无法检查Kafka入库心跳");
ExecuteKafkaDbConnectionAlert();
return;
}
@@ -451,18 +452,19 @@ namespace AutoNotificatPhone.Models
if (result == null || result == DBNull.Value)
{
ExecuteKafkaInactiveAlert();
ExecuteKafkaDbConnectionAlert();
return;
}
if (!long.TryParse(result.ToString(), out long lastTsMs))
{
logger.Error("Kafka入库心跳ts_ms解析失败");
ExecuteKafkaDbConnectionAlert();
return;
}
long nowMs = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
if (nowMs - lastTsMs > TimeSpan.FromMinutes(5).TotalMilliseconds)
if (nowMs - lastTsMs > TimeSpan.FromMinutes(2).TotalMilliseconds)
{
ExecuteKafkaInactiveAlert();
}
@@ -470,6 +472,7 @@ namespace AutoNotificatPhone.Models
catch (Exception ex)
{
logger.Error($"Kafka入库心跳检查错误: {ex.Message}");
ExecuteKafkaDbConnectionAlert();
}
await Task.CompletedTask;
}
@@ -530,13 +533,26 @@ namespace AutoNotificatPhone.Models
private void ExecuteKafkaInactiveAlert()
{
SendAlert(
smsContent: "[BLV运维提示] BLS数据库5分钟内入库数据为0。",
callContent: "BLV运维提示 BLS数据库5分钟内入库数据为0",
smsContent: "[BLV运维提示] BLS数据库1分钟内入库数据为0。",
callContent: "BLV运维提示 BLS数据库1分钟内入库数据为0",
alertType: "BLS-数据库入库警报",
extendedDeadline: true
);
}
/// <summary>
/// 执行Kafka入库数据库连接失败警报
/// </summary>
private void ExecuteKafkaDbConnectionAlert()
{
SendAlert(
smsContent: "[BLV运维提示] 数据库连接失败!",
callContent: "[BLV运维提示] 数据库连接失败",
alertType: "BLS-数据库连接警报",
extendedDeadline: true
);
}
/// <summary>
/// 解析CPU值字符串为整数列表
/// </summary>