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