优化日志,而且台账修改时无论什么状态都先关闭连接
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <iostream>
|
||||
#include <atomic>
|
||||
#include <string>
|
||||
#include "../mms/db_interface.h"
|
||||
|
||||
@@ -371,7 +372,7 @@ void rocketmq_consumer_receive(
|
||||
static int currentQueueId = 0;
|
||||
|
||||
// 队列选择器回调函数:轮询选择队列 ID
|
||||
int RoundRobinSelector(int queueNum, CMessage* msg, void* arg) {
|
||||
/*int RoundRobinSelector(int queueNum, CMessage* msg, void* arg) {
|
||||
if (queueNum == 0) {
|
||||
throw std::runtime_error("No available queues");
|
||||
}
|
||||
@@ -381,6 +382,24 @@ int RoundRobinSelector(int queueNum, CMessage* msg, void* arg) {
|
||||
currentQueueId = 0;
|
||||
}
|
||||
return queueId;
|
||||
}*/
|
||||
int RoundRobinSelector(int queueNum, CMessage* msg, void* arg) {
|
||||
static std::atomic<int> currentQueueId(0);
|
||||
|
||||
if (queueNum <= 0) {
|
||||
std::cout << "[MQ][SELECTOR_FAIL] queueNum=" << queueNum << std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int id = currentQueueId.fetch_add(1, std::memory_order_relaxed);
|
||||
int queueId = id % queueNum;
|
||||
|
||||
std::cout << "[MQ][SELECTOR] queueNum=" << queueNum
|
||||
<< ", current=" << id
|
||||
<< ", selected=" << queueId
|
||||
<< std::endl;
|
||||
|
||||
return queueId;
|
||||
}
|
||||
|
||||
// 封装生产者的类
|
||||
@@ -464,9 +483,20 @@ public:
|
||||
);
|
||||
|
||||
if (sendResult == 0) { // 假设返回 0 表示成功
|
||||
std::cout << "Message sent successfully.topic:" << topic <<std::endl;
|
||||
std::cout << "[MQ][SEND_OK]"
|
||||
<< " topic=" << (topic ? topic : "")
|
||||
<< ", tags=" << tags
|
||||
<< ", keys=" << keys
|
||||
<< ", body_len=" << (strbody ? strlen(strbody) : 0)
|
||||
<< std::endl;
|
||||
} else {
|
||||
std::cout << "Failed to send message." << std::endl;
|
||||
std::cout << "[MQ][SEND_FAIL]"
|
||||
<< " ret=" << sendResult
|
||||
<< ", topic=" << (topic ? topic : "")
|
||||
<< ", tags=" << tags
|
||||
<< ", keys=" << keys
|
||||
<< std::endl;
|
||||
DIY_ERRORLOG_CODE("process",0,LOG_CODE_MQ,"【ERROR】前置的%s%d号进程 mq发送失败,请检查mq配置", get_front_msg_from_subdir(), g_front_seg_index);
|
||||
}
|
||||
|
||||
// 销毁消息
|
||||
@@ -559,7 +589,7 @@ void rocketmq_producer_send(const char* strbody, const char* topic)
|
||||
catch (const std::exception& e) {
|
||||
std::cerr << "Failed to send message: " << e.what() << std::endl;
|
||||
// 处理发送失败的情况,例如记录日志或重试
|
||||
DIY_ERRORLOG_CODE("process",LOG_CODE_MQ,"【ERROR】前置的%s%d号进程 mq发送失败,请检查mq配置", get_front_msg_from_subdir(), g_front_seg_index);
|
||||
DIY_ERRORLOG_CODE("process",0,LOG_CODE_MQ,"【ERROR】前置的%s%d号进程 mq发送失败,请检查mq配置", get_front_msg_from_subdir(), g_front_seg_index);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1499,7 +1499,7 @@ int parse_rpt_log_ini()
|
||||
//添加判断,有的监测点没有cpuno为2,直接申请了LD_info[1],没申请LD_info[0]
|
||||
if(ied_usr->LD_info[cpuno].LD_name == NULL){
|
||||
printf("this ld_info didn't palloc space ,maybe this ledger has problem!");
|
||||
DIY_ERRORLOG_CODE("process",LOG_CODE_RPTINIT,"【ERROR】终端%s的监测点序号为%d的监测点无法初始化报告,这个装置的台账存在缺失,请检查装置台账的监测点总数和各监测点的序号",ied_usr->terminal_id,cpuno + 1);
|
||||
DIY_ERRORLOG_CODE("process",0,LOG_CODE_RPTINIT,"【ERROR】终端%s的监测点序号为%d的监测点无法初始化报告,这个装置的台账存在缺失,请检查装置台账的监测点总数和各监测点的序号",ied_usr->terminal_id,cpuno + 1);
|
||||
continue;//跳过防止崩溃
|
||||
}
|
||||
|
||||
@@ -1878,18 +1878,18 @@ int parse_ledger_update_xml(trigger_update_xml_t* trigger_update_xml)
|
||||
//加载一个文件的内容到数据结构
|
||||
if (!load_ledger_update_from_xml(trigger_update_xml, filename)) {
|
||||
std::cout << "read /etc/ledgerupdate/" << filename << " success..." << std::endl;
|
||||
DIY_WARNLOG_CODE("process",LOG_CODE_LEDGER_UPDATE,"【WARN】前置的%s%d号进程 读取台账更新文件成功,开始更新台账", get_front_msg_from_subdir(), g_front_seg_index);
|
||||
DIY_WARNLOG_CODE("process",0,LOG_CODE_LEDGER_UPDATE,"【WARN】前置的%s%d号进程 读取台账更新文件成功,开始更新台账", get_front_msg_from_subdir(), g_front_seg_index);
|
||||
}
|
||||
//处理过的文件删除掉
|
||||
|
||||
if (std::remove(filename.c_str()) != 0) {
|
||||
std::cerr << "Failed to remove file: " << filename << " Error: " << strerror(errno) << std::endl;
|
||||
DIY_ERRORLOG_CODE("process",LOG_CODE_LEDGER_UPDATE,"【ERROR】前置的%s%d号进程 删除已读取的台账更新文件失败!请检查台账更新文件是否残留在/FeProject/etc/ledgerupdate", get_front_msg_from_subdir(), g_front_seg_index);
|
||||
DIY_ERRORLOG_CODE("process",0,LOG_CODE_LEDGER_UPDATE,"【ERROR】前置的%s%d号进程 删除已读取的台账更新文件失败!请检查台账更新文件是否残留在/FeProject/etc/ledgerupdate", get_front_msg_from_subdir(), g_front_seg_index);
|
||||
return APR_EGENERAL;
|
||||
}
|
||||
else{
|
||||
std::cout << "remove file: " << filename << " success..." << std::endl;
|
||||
DIY_INFOLOG("process","【NORMAL】前置的%s%d号进程 删除已读取的台账更新文件成功", get_front_msg_from_subdir(), g_front_seg_index);
|
||||
DIY_INFOLOG_CODE("process",0,LOG_CODE_LEDGER_UPDATE,"【NORMAL】前置的%s%d号进程 删除已读取的台账更新文件成功", get_front_msg_from_subdir(), g_front_seg_index);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2069,7 +2069,7 @@ int parse_3s_xml(trigger_3s_xml_t* trigger_3s_xml)
|
||||
|
||||
printf("/etc/trigger3s/*.xml success...\n");
|
||||
|
||||
DIY_INFOLOG("process","【WARN】前置读取实时数据触发文件成功,即将注册实时数据报告");
|
||||
DIY_INFOLOG_CODE("process",0,LOG_CODE_RT_DATA,"【WARN】前置读取实时数据触发文件成功,即将注册实时数据报告");
|
||||
|
||||
return APR_SUCCESS;
|
||||
}
|
||||
@@ -2382,7 +2382,7 @@ int parse_recall_xml(recall_xml_t* recall_xml, char* id)
|
||||
QDir dir(cfg_dir);
|
||||
if (!dir.exists()) {
|
||||
qDebug() << "folder does not exist!";
|
||||
DIY_ERRORLOG_CODE("process",LOG_CODE_RECALL,"【ERROR】前置的%s%d号进程 无法解析补招文件,补招文件路径/FeProject/etc/recall/不存在", get_front_msg_from_subdir(), g_front_seg_index);
|
||||
DIY_ERRORLOG_CODE("process",0,LOG_CODE_RECALL,"【ERROR】前置的%s%d号进程 无法解析补招文件,补招文件路径/FeProject/etc/recall/不存在", get_front_msg_from_subdir(), g_front_seg_index);
|
||||
return false;
|
||||
}
|
||||
//指定文件后缀名,可指定多种类型
|
||||
@@ -2398,7 +2398,7 @@ int parse_recall_xml(recall_xml_t* recall_xml, char* id)
|
||||
if (!file.open(QIODevice::ReadOnly))
|
||||
{
|
||||
qDebug() << "file.open error";
|
||||
DIY_ERRORLOG_CODE("process",LOG_CODE_RECALL,"【ERROR】前置的%s%d号进程 无法打开补招文件%s", get_front_msg_from_subdir(), g_front_seg_index,qstrRecallPath.toStdString().c_str());
|
||||
DIY_ERRORLOG_CODE("process",0,LOG_CODE_RECALL,"【ERROR】前置的%s%d号进程 无法打开补招文件%s", get_front_msg_from_subdir(), g_front_seg_index,qstrRecallPath.toStdString().c_str());
|
||||
continue; //以只读方式打开
|
||||
}
|
||||
bool ret = doc.setContent(&file);
|
||||
@@ -2406,7 +2406,7 @@ int parse_recall_xml(recall_xml_t* recall_xml, char* id)
|
||||
if (!ret)
|
||||
{
|
||||
qDebug() << "doc.setContent error";
|
||||
DIY_ERRORLOG_CODE("process",LOG_CODE_RECALL,"【ERROR】前置的%s%d号进程 无法解析补招文件%s,补招内容无效", get_front_msg_from_subdir(), g_front_seg_index,qstrRecallPath.toStdString().c_str());
|
||||
DIY_ERRORLOG_CODE("process",0,LOG_CODE_RECALL,"【ERROR】前置的%s%d号进程 无法解析补招文件%s,补招内容无效", get_front_msg_from_subdir(), g_front_seg_index,qstrRecallPath.toStdString().c_str());
|
||||
continue;
|
||||
}
|
||||
//将文件内容读到doc中
|
||||
@@ -2984,7 +2984,7 @@ void DeletcRecallXml() {
|
||||
QDir dir(cfg_dir);
|
||||
if (!dir.exists()) {
|
||||
qDebug() << "folder does not exist!";
|
||||
DIY_ERRORLOG_CODE("process",LOG_CODE_RECALL,"【ERROR】前置的%s%d号进程 删除旧的补招文件失败,补招文件路径/FeProject/etc/recall/不存在", get_front_msg_from_subdir(), g_front_seg_index);
|
||||
DIY_ERRORLOG_CODE("process",0,LOG_CODE_RECALL,"【ERROR】前置的%s%d号进程 删除旧的补招文件失败,补招文件路径/FeProject/etc/recall/不存在", get_front_msg_from_subdir(), g_front_seg_index);
|
||||
return;
|
||||
}
|
||||
QStringList filter(file_name);
|
||||
@@ -2999,7 +2999,7 @@ void DeletcRecallXml() {
|
||||
if (fileInfo.lastModified() < saveDaysAgo) {
|
||||
QFile::remove(fileInfo.absoluteFilePath());
|
||||
|
||||
DIY_INFOLOG("process","【NORMAL】前置的%s%d号进程 删除超过两天的补招文件", get_front_msg_from_subdir(), g_front_seg_index);
|
||||
DIY_INFOLOG_CODE("process",0,LOG_CODE_RECALL,"【NORMAL】前置的%s%d号进程 删除超过两天的补招文件", get_front_msg_from_subdir(), g_front_seg_index);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3016,7 +3016,7 @@ void CreateRecallXml()
|
||||
{
|
||||
printf("insert ID_CJournalRecall_Map!\n");
|
||||
|
||||
DIY_INFOLOG("process","【NORMAL】前置的%s%d号进程 开始写入补招文件", get_front_msg_from_subdir(), g_front_seg_index);
|
||||
DIY_INFOLOG_CODE("process",0,LOG_CODE_RECALL,"【NORMAL】前置的%s%d号进程 开始写入补招文件", get_front_msg_from_subdir(), g_front_seg_index);
|
||||
|
||||
QMap<QString, QList<CJournalRecall> > ID_CJournalRecall_Map;
|
||||
|
||||
@@ -3049,7 +3049,7 @@ void CreateRecallXml()
|
||||
if (!file.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
|
||||
printf("补招查询完成,打开%s失败,无法写入线路补招配置!\n", qstrRecallPath.toAscii().data());
|
||||
|
||||
DIY_ERRORLOG_CODE("process",LOG_CODE_RECALL,"【ERROR】前置的%s%d号进程 无法将补招文件写入补招文件路径/FeProject/etc/recall/", get_front_msg_from_subdir(), g_front_seg_index);
|
||||
DIY_ERRORLOG_CODE("process",0,LOG_CODE_RECALL,"【ERROR】前置的%s%d号进程 无法将补招文件写入补招文件路径/FeProject/etc/recall/", get_front_msg_from_subdir(), g_front_seg_index);
|
||||
|
||||
QMap<QString, QList<CJournalRecall> >().swap(ID_CJournalRecall_Map);
|
||||
return;
|
||||
@@ -3766,14 +3766,14 @@ int terminal_ledger_web(QMap<QString, terminal_dev*>* terminal_dev_map,
|
||||
// 参数验证
|
||||
if (num <= 0) {
|
||||
std::cerr << "Error: 'num' must be greater than 0." << std::endl;
|
||||
DIY_ERRORLOG_CODE("process",LOG_CODE_LEDGER,"【ERROR】前置的多进程最大进程号为:%d,应该为大于0的整数",num);
|
||||
DIY_ERRORLOG_CODE("process",0,LOG_CODE_LEDGER,"【ERROR】前置的多进程最大进程号为:%d,应该为大于0的整数",num);
|
||||
return 1; // 返回适当的错误码
|
||||
}
|
||||
|
||||
index = index - 1;
|
||||
if (index < 0 || index >= num) {
|
||||
std::cerr << "Error: 'index' must be in the range [0, num]." << std::endl;
|
||||
DIY_ERRORLOG_CODE("process",LOG_CODE_LEDGER,"【ERROR】前置当前进程的进程号为:%d,应该为0到最大进程号范围内的整数",index);
|
||||
DIY_ERRORLOG_CODE("process",0,LOG_CODE_LEDGER,"【ERROR】前置当前进程的进程号为:%d,应该为0到最大进程号范围内的整数",index);
|
||||
return 1; // 返回适当的错误码
|
||||
}
|
||||
}
|
||||
@@ -3781,7 +3781,7 @@ int terminal_ledger_web(QMap<QString, terminal_dev*>* terminal_dev_map,
|
||||
// 获取参数
|
||||
if (codes.empty()) {
|
||||
std::cerr << "Error: 'codes' vector is empty." << std::endl;
|
||||
DIY_ERRORLOG_CODE("process",LOG_CODE_LEDGER,"【ERROR】前置的%s%d号进程调用web台账接口的入参为空",get_front_msg_from_subdir(), g_front_seg_index);
|
||||
DIY_ERRORLOG_CODE("process",0,LOG_CODE_LEDGER,"【ERROR】前置的%s%d号进程调用web台账接口的入参为空",get_front_msg_from_subdir(), g_front_seg_index);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -3834,7 +3834,7 @@ int terminal_ledger_web(QMap<QString, terminal_dev*>* terminal_dev_map,
|
||||
}
|
||||
}
|
||||
std::cerr << "data 无效或为空数组,重试" << std::endl;
|
||||
DIY_ERRORLOG_CODE("process",LOG_CODE_LEDGER,"【ERROR】前置从web接口中获取的台账信息为空或者无效信息无法解析,请核对前置使用的入参信息:%s",parm.c_str());
|
||||
DIY_ERRORLOG_CODE("process",0,LOG_CODE_LEDGER,"【ERROR】前置从web接口中获取的台账信息为空或者无效信息无法解析,请核对前置使用的入参信息:%s",parm.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3881,7 +3881,7 @@ int terminal_ledger_web(QMap<QString, terminal_dev*>* terminal_dev_map,
|
||||
break; // 本地台账解析成功且数组非空
|
||||
}
|
||||
}
|
||||
DIY_ERRORLOG_CODE("process",LOG_CODE_LEDGER,"【ERROR】前置从本地台账中获取的台账信息为空或者无效信息无法解析,请核对前置使用的入参信息:%s",parm.c_str());
|
||||
DIY_ERRORLOG_CODE("process",0,LOG_CODE_LEDGER,"【ERROR】前置从本地台账中获取的台账信息为空或者无效信息无法解析,请核对前置使用的入参信息:%s",parm.c_str());
|
||||
}
|
||||
|
||||
free(ledger); // root==null释放内容
|
||||
@@ -4181,7 +4181,7 @@ int parse_device_cfg_web()
|
||||
|
||||
std::cout << "input_jstr: " << input_jstr << std::endl; // 输出结果
|
||||
|
||||
DIY_DEBUGLOG("process","【DEBUG】前置的%s%d号进程调用web接口获取台账使用的请求输入为:%s",get_front_msg_from_subdir(), g_front_seg_index,input_jstr);
|
||||
DIY_DEBUGLOG_CODE("process",0,LOG_CODE_LEDGER,"【DEBUG】前置的%s%d号进程调用web接口获取台账使用的请求输入为:%s",get_front_msg_from_subdir(), g_front_seg_index,input_jstr);
|
||||
|
||||
codes.push_back(input_jstr); //是否需要筛选状态直接在配置文件控制
|
||||
|
||||
@@ -4216,13 +4216,13 @@ int parse_device_cfg_web()
|
||||
//判断是否相等
|
||||
if(max_process_num != max_index){
|
||||
if(max_process_num > 0 && max_process_num < 10){
|
||||
DIY_WARNLOG_CODE("process",LOG_CODE_LEDGER,"【WARN】前置比对台账获取的进程数:%d和本地配置的进程数:%d,不匹配,按照台账进程数重置前置的进程数量",max_process_num,max_index);
|
||||
DIY_WARNLOG_CODE("process",0,LOG_CODE_LEDGER,"【WARN】前置比对台账获取的进程数:%d和本地配置的进程数:%d,不匹配,按照台账进程数重置前置的进程数量",max_process_num,max_index);
|
||||
// 调用执行脚本函数
|
||||
close_listening_socket();
|
||||
execute_bash("reset", max_process_num, "all");
|
||||
}
|
||||
else{
|
||||
DIY_ERRORLOG_CODE("process",LOG_CODE_LEDGER,"【ERROR】前置从台账获取的进程数:%d不符合范围1~9,按照本地配置进程数启动进程",max_process_num);
|
||||
DIY_ERRORLOG_CODE("process",0,LOG_CODE_LEDGER,"【ERROR】前置从台账获取的进程数:%d不符合范围1~9,按照本地配置进程数启动进程",max_process_num);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4231,7 +4231,7 @@ int parse_device_cfg_web()
|
||||
|
||||
std::cout << "terminal_ledger_num:" << count_cfg << std::endl;
|
||||
|
||||
DIY_DEBUGLOG("process","【DEBUG】前置的%s%d号进程调用获取到的台账的数量为:%d",get_front_msg_from_subdir(), g_front_seg_index,count_cfg);
|
||||
DIY_DEBUGLOG_CODE("process",0,LOG_CODE_LEDGER,"【DEBUG】前置的%s%d号进程调用获取到的台账的数量为:%d",get_front_msg_from_subdir(), g_front_seg_index,count_cfg);
|
||||
|
||||
//如果当前进程获取的台账为0,按照配置数量申请空间,台账内容为空
|
||||
g_node->n_clients = count_cfg;
|
||||
@@ -4246,11 +4246,11 @@ int parse_device_cfg_web()
|
||||
//添加提示
|
||||
std::cout << "!!!!!!!!!!single process can not add any ledger unless reboot!!!!!!!"<< std::endl;
|
||||
|
||||
DIY_WARNLOG_CODE("process",LOG_CODE_LEDGER,"【WARN】前置的%s%d号进程获取到的台账的数量大于配置文件中给单个进程配置的台账数量:%d,这个进程将按照获取到的台账的数量来创建台账空间,这个进程不能直接通过台账添加来新增台账,只能通过重启进程或者先删除已有台账再添加台账的方式来添加新台账",get_front_msg_from_subdir(), g_front_seg_index,IED_COUNT);
|
||||
DIY_WARNLOG_CODE("process",0,LOG_CODE_LEDGER,"【WARN】前置的%s%d号进程获取到的台账的数量大于配置文件中给单个进程配置的台账数量:%d,这个进程将按照获取到的台账的数量来创建台账空间,这个进程不能直接通过台账添加来新增台账,只能通过重启进程或者先删除已有台账再添加台账的方式来添加新台账",get_front_msg_from_subdir(), g_front_seg_index,IED_COUNT);
|
||||
}
|
||||
else{
|
||||
g_node->clients = (ied_t**)apr_pcalloc(g_cfg_pool, IED_COUNT * sizeof(ied_t*));//g_node->clients 这块大内存空间存储了 count_cfg 个 ied_t* 类型的指针(即一个指针数组)这是(指向内存块的指针)的指针数组
|
||||
DIY_INFOLOG("process","【NORMAL】前置的%s%d号进程根据配置文件中给单个进程配置的台账数量:%d来创建台账空间",get_front_msg_from_subdir(), g_front_seg_index,IED_COUNT);
|
||||
DIY_INFOLOG_CODE("process",0,LOG_CODE_LEDGER,"【NORMAL】前置的%s%d号进程根据配置文件中给单个进程配置的台账数量:%d来创建台账空间",get_front_msg_from_subdir(), g_front_seg_index,IED_COUNT);
|
||||
}
|
||||
|
||||
//把ied放入数组
|
||||
@@ -4512,7 +4512,7 @@ int parse_device_cfg_web()
|
||||
{
|
||||
isdelta_flag = 1; //存在一个监测点为角型接线则这个前置就要启动第二个配置列表
|
||||
cout << "monitor_id" << monitor_id << "v_wiring_type:" << line_info.v_wiring_type << "is delta wiring:" << isdelta_flag << endl;
|
||||
DIY_WARNLOG_CODE("process",LOG_CODE_LEDGER,"【WARN】前置连接的监测点 %s 是角形接线,对应终端为%s 终端类型是%s",line_info.mp_id,ied_usr->terminal_id,ied_usr->dev_type);
|
||||
DIY_WARNLOG_CODE("process",0,LOG_CODE_LEDGER,"【WARN】前置连接的监测点 %s 是角形接线,对应终端为%s 终端类型是%s",line_info.mp_id,ied_usr->terminal_id,ied_usr->dev_type);
|
||||
}
|
||||
strcpy(line_info.monitor_status, monitor_status);
|
||||
cout << "monitor_status:" << line_info.monitor_status << endl;
|
||||
@@ -4786,7 +4786,7 @@ int parse_model_cfg_web()
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
if(parse_model_web(&icd_model_map,codes)){
|
||||
DIY_ERRORLOG_CODE("process",LOG_CODE_ICD_AND_DOWNLOAD,"【ERROR】前置的%s%d号进程 icd模型接口异常,将使用默认的icd模型,请检查接口配置", get_front_msg_from_subdir(), g_front_seg_index);
|
||||
DIY_ERRORLOG_CODE("process",0,LOG_CODE_ICD_AND_DOWNLOAD,"【ERROR】前置的%s%d号进程 icd模型接口异常,将使用默认的icd模型,请检查接口配置", get_front_msg_from_subdir(), g_front_seg_index);
|
||||
return APR_SUCCESS; //可以使用默认的映射文件所以返回正常
|
||||
}
|
||||
|
||||
@@ -5053,7 +5053,7 @@ int recall_json_handle(const char* jstr)
|
||||
|
||||
if(strcmp(ied_usr->LD_info[m].mp_id,monitorId.toStdString().c_str()) == 0){//匹配上了
|
||||
|
||||
DIY_INFOLOG("process","【NORMAL】前置的%s%d号进程处理监测点%s -id:%s 的数据补招",get_front_msg_from_subdir(), g_front_seg_index,ied_usr->LD_info[m].name,ied_usr->LD_info[m].mp_id);
|
||||
DIY_INFOLOG_CODE("process",0,LOG_CODE_RECALL,"【NORMAL】前置的%s%d号进程处理监测点%s -id:%s 的数据补招",get_front_msg_from_subdir(), g_front_seg_index,ied_usr->LD_info[m].name,ied_usr->LD_info[m].mp_id);
|
||||
mppair = 1;
|
||||
break;//找到就退出监测点循环
|
||||
}
|
||||
@@ -5276,7 +5276,7 @@ void handleUploadResponse(const std::string& response, char* wavepath) {
|
||||
cJSON* json_data = cJSON_Parse(response.c_str());
|
||||
if (json_data == nullptr) {
|
||||
std::cerr << "Error parsing response: " << cJSON_GetErrorPtr() << std::endl;
|
||||
DIY_ERRORLOG_CODE("process",LOG_CODE_TRANSIENT_COMM,"【ERROR】前置上传文件失败,web返回的消息错误,无法解析");
|
||||
DIY_ERRORLOG_CODE("process",0,LOG_CODE_TRANSIENT_COMM,"【ERROR】前置上传文件失败,web返回的消息错误,无法解析");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -5322,11 +5322,11 @@ void handleUploadResponse(const std::string& response, char* wavepath) {
|
||||
|
||||
std::cout << "wavepath: " << wavepath << std::endl;
|
||||
|
||||
DIY_INFOLOG("process","【NORMAL】前置上传文件成功,远端文件名:%s",wavepath);
|
||||
DIY_INFOLOG_CODE("process",0,LOG_CODE_TRANSIENT_COMM,"【NORMAL】前置上传文件成功,远端文件名:%s",wavepath);
|
||||
}
|
||||
} else {
|
||||
std::cerr << "Error: Missing expected fields in JSON response." << std::endl;
|
||||
DIY_ERRORLOG_CODE("process",LOG_CODE_TRANSIENT_COMM,"【ERROR】前置上传文件失败,web返回的消息没有远端文件名");
|
||||
DIY_ERRORLOG_CODE("process",0,LOG_CODE_TRANSIENT_COMM,"【ERROR】前置上传文件失败,web返回的消息没有远端文件名");
|
||||
}
|
||||
|
||||
// 释放 JSON 对象
|
||||
@@ -5443,7 +5443,7 @@ void SendFileWeb(const std::string& strUrl, const char* localpath, const char* c
|
||||
CURLcode res = curl_easy_perform(curl);
|
||||
if (res != CURLE_OK) {
|
||||
std::cerr << "http web failed: " << curl_easy_strerror(res) << std::endl;
|
||||
DIY_ERRORLOG_CODE("process",LOG_CODE_TRANSIENT_COMM,"【ERROR】前置上传暂态录波文件 %s 失败,请检查文件上传接口配置",localpath);
|
||||
DIY_ERRORLOG_CODE("process",0,LOG_CODE_TRANSIENT_COMM,"【ERROR】前置上传暂态录波文件 %s 失败,请检查文件上传接口配置",localpath);
|
||||
} else {
|
||||
std::cout << "http web success, response: " << resPost0 << std::endl;
|
||||
handleUploadResponse(resPost0, wavepath); // 处理响应
|
||||
@@ -6064,7 +6064,7 @@ int parse_rpt_log_ini_one(ied_t* ied)
|
||||
//添加判断,有的监测点没有cpuno为2,直接申请了LD_info[2-1],没申请LD_info[0]
|
||||
if(ied_usr->LD_info[cpuno].LD_name == NULL){
|
||||
printf("this ld_info didn't palloc space ,maybe this ledger has problem!");
|
||||
DIY_ERRORLOG_CODE("process",LOG_CODE_RPTINIT,"【ERROR】终端%s的监测点序号为%d的监测点无法初始化报告,这个装置的台账存在缺失,请检查装置台账的监测点总数和各监测点的序号",ied_usr->terminal_id,cpuno + 1);
|
||||
DIY_ERRORLOG_CODE("process",0,LOG_CODE_RPTINIT,"【ERROR】终端%s的监测点序号为%d的监测点无法初始化报告,这个装置的台账存在缺失,请检查装置台账的监测点总数和各监测点的序号",ied_usr->terminal_id,cpuno + 1);
|
||||
continue;//跳过防止崩溃
|
||||
}
|
||||
|
||||
|
||||
@@ -388,9 +388,10 @@ private:
|
||||
struct RateState {
|
||||
uint64_t hit_count;
|
||||
std::chrono::steady_clock::time_point last_emit;
|
||||
std::chrono::steady_clock::time_point last_reset;
|
||||
bool has_emit;
|
||||
|
||||
RateState() : hit_count(0), last_emit(), has_emit(false) {}
|
||||
RateState() : hit_count(0), last_emit(), last_reset(), has_emit(false) {}
|
||||
};
|
||||
|
||||
static std::unordered_map<std::string, RateState> s_rate_map;
|
||||
@@ -398,7 +399,7 @@ private:
|
||||
|
||||
static std::string make_key(const std::string& logger_name, int level, int code, const std::string& msg) {
|
||||
std::ostringstream oss;
|
||||
oss << logger_name << "|" << level << "|" << code << "|" << msg;
|
||||
oss << logger_name << "|" << level << "|" << code ; //<< "|" << msg;
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
@@ -410,13 +411,31 @@ private:
|
||||
RateState& st = s_rate_map[key];
|
||||
|
||||
const int RESET_SEC = 3600;
|
||||
|
||||
// 🚀 强制时间窗口重置(关键)
|
||||
if (st.has_emit) {
|
||||
auto idle = duration_cast<seconds>(now - st.last_emit).count();
|
||||
if (idle >= RESET_SEC) st.hit_count = 0;
|
||||
auto since_reset = duration_cast<seconds>(now - st.last_reset).count();
|
||||
if (since_reset >= RESET_SEC) {
|
||||
st.hit_count = 0;
|
||||
st.has_emit = false;
|
||||
st.last_reset = now;
|
||||
}
|
||||
} else {
|
||||
// 第一次初始化
|
||||
st.last_reset = now;
|
||||
}
|
||||
|
||||
st.hit_count++;
|
||||
const int period_sec = (st.hit_count > 3) ? 300 : 1;
|
||||
|
||||
// 🚀 前20条:完全放行
|
||||
if (st.hit_count <= 20) {
|
||||
st.last_emit = now;
|
||||
st.has_emit = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
// 🚀 超过20条:1分钟限1条
|
||||
const int period_sec = 60;
|
||||
|
||||
if (!st.has_emit) {
|
||||
st.last_emit = now;
|
||||
@@ -429,6 +448,7 @@ private:
|
||||
st.last_emit = now;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
};
|
||||
@@ -554,7 +574,7 @@ void init_loggers_bydevid(const char* dev_id)
|
||||
Logger device_logger = init_logger(device_key, device_dir, dev_id, device_appender); //用终端id作为日志文件名
|
||||
logger_map[device_key] = TypedLogger(device_logger, LOGTYPE_DEFAULT);
|
||||
|
||||
DIY_INFOLOG(device_key.c_str(),"【NORMAL】终端id:%s终端级日志初始化完毕", ied_usr->terminal_id);
|
||||
DIY_INFOLOG_CODE(device_key.c_str(),1,LOG_CODE_OTHER,"【NORMAL】终端id:%s终端级日志初始化完毕", ied_usr->terminal_id);
|
||||
}
|
||||
|
||||
// 初始化监测点
|
||||
@@ -579,7 +599,7 @@ void init_loggers_bydevid(const char* dev_id)
|
||||
Logger mon_logger = init_logger(mon_key.str(), mon_path.str(), mon_name.str(),monitor_appender);//用监测点号作为日志文件名
|
||||
logger_map[mon_key.str()] = TypedLogger(mon_logger, LOGTYPE_DEFAULT);
|
||||
|
||||
DIY_INFOLOG(mon_key.str().c_str(),"【NORMAL】监测点:%s - id:%s监测点级日志初始化完毕", ied_usr->LD_info[i].name,ied_usr->LD_info[i].mp_id);
|
||||
DIY_INFOLOG_CODE(mon_key.str().c_str(),2,LOG_CODE_OTHER,"【NORMAL】监测点:%s - id:%s监测点级日志初始化完毕", ied_usr->LD_info[i].name,ied_usr->LD_info[i].mp_id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -628,7 +648,7 @@ void init_loggers() {
|
||||
|
||||
logger_map[device_key] = TypedLogger(device_logger, LOGTYPE_DEFAULT);
|
||||
|
||||
DIY_INFOLOG(device_key.c_str(),"【NORMAL】终端id:%s终端级日志初始化完毕", ied_usr->terminal_id);
|
||||
DIY_INFOLOG_CODE(device_key.c_str(),1,LOG_CODE_OTHER,"【NORMAL】终端id:%s终端级日志初始化完毕", ied_usr->terminal_id);
|
||||
|
||||
// 初始化监测点
|
||||
// 监测点 logger 名称格式:monitor.<mp_id>
|
||||
@@ -650,7 +670,7 @@ void init_loggers() {
|
||||
|
||||
logger_map[mon_key.str()] = TypedLogger(mon_logger, LOGTYPE_DEFAULT);
|
||||
|
||||
DIY_INFOLOG(mon_key.str().c_str(),"【NORMAL】监测点:%s - id:%s监测点级日志初始化完毕", ied_usr->LD_info[i].name,ied_usr->LD_info[i].mp_id);
|
||||
DIY_INFOLOG_CODE(mon_key.str().c_str(),2,LOG_CODE_OTHER,"【NORMAL】监测点:%s - id:%s监测点级日志初始化完毕", ied_usr->LD_info[i].name,ied_usr->LD_info[i].mp_id);
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user