예제 #1
0
        /// <summary>
        /// 初始化监控
        /// </summary>
        private void InitMonitor()
        {
            _logger.LogInformation((int)LogEvent.系统, "初始化监控任务");
            FixedJobTask fixedJobTask = _serviceProvider.GetRequiredService <FixedJobTask>();
            StorageMonitor <LaneFlow, FlowDevice> flowStorageMonitor = _serviceProvider.GetRequiredService <StorageMonitor <LaneFlow, FlowDevice> >();

            flowStorageMonitor.SetBranchBlock(_serviceProvider.GetRequiredService <FlowBranchBlock>());
            StorageMonitor <VideoStruct, FlowDevice> videoStorageMonitor = _serviceProvider.GetRequiredService <StorageMonitor <VideoStruct, FlowDevice> >();

            videoStorageMonitor.SetBranchBlock(_serviceProvider.GetRequiredService <VideoBranchBlock>());
            FlowSwitchMonitor   flowSwitchMonitor   = _serviceProvider.GetRequiredService <FlowSwitchMonitor>();
            VideoSwitchMonitor  videoSwitchMonitor  = _serviceProvider.GetRequiredService <VideoSwitchMonitor>();
            SectionFlowMonitor  sectionFlowMonitor  = _serviceProvider.GetRequiredService <SectionFlowMonitor>();
            SystemStatusMonitor systemStatusMonitor = _serviceProvider.GetRequiredService <SystemStatusMonitor>();

            SystemStatusMonitor.Version = Assembly.GetExecutingAssembly().GetName().Version.ToString();
            DeviceStatusMonitor deviceStatusMonitor = _serviceProvider.GetRequiredService <DeviceStatusMonitor>();

            fixedJobTask.AddFixedJob(systemStatusMonitor, DateTimeLevel.Minute, TimeSpan.Zero, "系统状态检查");
            fixedJobTask.AddFixedJob(sectionFlowMonitor, DateTimeLevel.Minute, TimeSpan.Zero, "路段流量计算");
            fixedJobTask.AddFixedJob(flowSwitchMonitor, BranchDbConvert.DateLevel, _dbSpan, "流量数据分表切换");
            fixedJobTask.AddFixedJob(videoSwitchMonitor, BranchDbConvert.DateLevel, _dbSpan, "视频数据分表切换");
            fixedJobTask.AddFixedJob(deviceStatusMonitor, DateTimeLevel.Minute, TimeSpan.Zero, "设备状态检查");
            fixedJobTask.AddFixedJob(flowStorageMonitor, DateTimeLevel.Minute, TimeSpan.Zero, "流量数据定时保存");
            fixedJobTask.AddFixedJob(videoStorageMonitor, DateTimeLevel.Minute, TimeSpan.Zero, "视频数据定时保存");
            fixedJobTask.Start();
        }
예제 #2
0
 private void WatchForDevices()
 {
     monitor = new DeviceStatusMonitor(DeviceClass.Any, false);
     monitor.StartStatusMonitoring();
     monitor.DeviceNotification += new DeviceNotificationEventHandler(monitor_DeviceNotification);
     addLog("WatchForDevices started...");
 }
예제 #3
0
파일: Form1.cs 프로젝트: hjgode/logging_ce
 private void WatchForDevices()
 {
     monitor = new DeviceStatusMonitor(DeviceClass.Any, false);
     monitor.StartStatusMonitoring();
     monitor.DeviceNotification+=new DeviceNotificationEventHandler(monitor_DeviceNotification);
     addLog("WatchForDevices started...");
 }
예제 #4
0
        public void Check(HashSet <int> diaoxianSet, MyDBConnect myDBConnect, DeviceStatusMonitor deviceStatusMonitor)
        {
            if (diaoxianSet == null || diaoxianSet.Count == 0 || myDBConnect == null || deviceStatusMonitor == null)
            {
                if (diaoxianSet == null)
                {
                    MyLog.log("掉线设备集合引用为空");
                }
                else if (diaoxianSet.Count == 0)
                {
                    MyLog.log("当前没有设备掉线");
                }
                return;
            }
            HashSet <Project> projectSet = new HashSet <Project>();
            string            qian15     = DateTime.Now.AddMinutes(-15).ToString("yyyy-MM-dd HH:mm:ss");
            string            inDiaoxian = "";
            int n = 0;

            foreach (int i in diaoxianSet)
            {
                n++;
                inDiaoxian += i;
                if (n < diaoxianSet.Count)
                {
                    inDiaoxian += ",";
                }
            }

            string sql = "SELECT shangxian.Project_ID projectId, wxuser.openid openid, project.`Project_Name` `name`,project.Project_Address address FROM `tb_qd_projectinuser` prouser LEFT JOIN (SELECT Project_ID FROM tb_monitordata15 tb WHERE tb.`Project_ID` IN (" + inDiaoxian + ") AND tb.`Date` > '" + qian15 + "') shangxian ON shangxian.Project_ID = prouser.Project_ID LEFT JOIN `tb_qd_weixininuser` wxuser ON prouser.userid = wxuser.userid LEFT JOIN `tb_project` project ON prouser.`Project_ID`= project.`Project_ID` WHERE prouser.`Project_ID` IN (" + inDiaoxian + ") AND shangxian.`Project_ID` IS NOT NULL AND wxuser.`openid` IS NOT NULL AND wxuser.`openid` != ''";

            MyLog.log("查询上线的SQL语句:" + sql);
            MySqlDataReader reader = myDBConnect.Reader(sql);

            while (reader.Read())
            {
                Project project = new Project
                {
                    projectId = reader.GetInt32("projectId"),
                    openId    = reader.GetString("openid"),
                    name      = reader.GetString("name"),
                    address   = reader.GetString("address")
                };
                projectSet.Add(project);
            }
            reader.Close();
            foreach (var project in projectSet)
            {
                diaoxianSet.Remove(project.projectId);
                Baojing baojing = new Baojing();
                baojing.text          = project.name + "设备上线";
                baojing.time          = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                baojing.type          = "上线";
                baojing.point         = project.address;
                baojing.BaojingObject = project.name;
                string result = deviceStatusMonitor.SendBaojing(baojing, project.openId);
                MyLog.log("设备上线:" + "openid=" + project.openId + ",name=" + project.name + ",address=" + project.address);
                MyLog.log("上线通知发送结果:" + result);
            }
        }
예제 #5
0
        public Form1()
        {
            dsm = new DeviceStatusMonitor(DeviceClass.Any, true);
            dsm.DeviceNotification += new DeviceNotificationEventHandler(OnDeviceNotification);
            dsm.StartStatusMonitoring();

            InitializeComponent();
        }
예제 #6
0
파일: Form1.cs 프로젝트: hjgode/logging_ce
 private void Form1_Closing(object sender, CancelEventArgs e)
 {
     if (monitor != null)
     {
         monitor.StopStatusMonitoring();
         monitor.Dispose();
         monitor = null;
     }
 }
예제 #7
0
 private void Form1_Closing(object sender, CancelEventArgs e)
 {
     if (monitor != null)
     {
         monitor.StopStatusMonitoring();
         monitor.Dispose();
         monitor = null;
     }
 }
예제 #8
0
        private void InitMonitor()
        {
            _logger.LogInformation((int)LogEvent.系统, "初始化监控任务");

            StorageMonitor <TrafficDensity, DensityDevice> densityStorageMonitor = _serviceProvider.GetRequiredService <StorageMonitor <TrafficDensity, DensityDevice> >();

            densityStorageMonitor.SetBranchBlock(_serviceProvider.GetRequiredService <DensityBranchBlock>());
            DensitySwitchMonitor densitySwitchMonitor = _serviceProvider.GetRequiredService <DensitySwitchMonitor>();
            SystemStatusMonitor  systemStatusMonitor  = _serviceProvider.GetRequiredService <SystemStatusMonitor>();

            SystemStatusMonitor.Version = Assembly.GetExecutingAssembly().GetName().Version.ToString();
            DeviceStatusMonitor deviceStatusMonitor = _serviceProvider.GetRequiredService <DeviceStatusMonitor>();

            FixedJobTask fixedJobTask = _serviceProvider.GetRequiredService <FixedJobTask>();

            fixedJobTask.AddFixedJob(systemStatusMonitor, DateTimeLevel.Minute, TimeSpan.Zero, "系统状态检查");
            fixedJobTask.AddFixedJob(deviceStatusMonitor, DateTimeLevel.Minute, TimeSpan.Zero, "设备状态检查");
            fixedJobTask.AddFixedJob(densitySwitchMonitor, BranchDbConvert.DateLevel, _dbSpan, "密度数据分表切换");
            fixedJobTask.AddFixedJob(densityStorageMonitor, DateTimeLevel.Minute, TimeSpan.Zero, "密度数据定时保存");
            fixedJobTask.Start();
        }
예제 #9
0
        public void Check(MyDBConnect myDBConnect, DeviceStatusMonitor deviceStatusMonitor)
        {
            HashSet <Project> projectSet = new HashSet <Project>();
            string            qian45     = DateTime.Now.AddMinutes(-45).ToString("yyyy-MM-dd HH:mm:ss");
            string            qian30     = DateTime.Now.AddMinutes(-30).ToString("yyyy-MM-dd HH:mm:ss");
            // string sql = "SELECT diaoxian.Project_ID projectId,diaoxian.`max` lasttime,pro.userid userid,wxuser.openid openid,wxuser.nickname FROM `tb_qd_projectinuser` pro LEFT JOIN (SELECT Project_ID,MAX(tb.`Date`) `max` FROM tb_monitordata15 tb WHERE tb.`Date` > '" + qian45 + "' GROUP BY Project_ID HAVING `max` < '" + qian30 + "') diaoxian  ON diaoxian.Project_ID = pro.Project_ID LEFT JOIN `tb_qd_weixininuser` wxuser ON pro.userid = wxuser.userid WHERE diaoxian.Project_ID IS NOT NULL";
            //可以用的
            string sql = "SELECT diaoxian.Project_ID projectId, wxuser.openid openid, project.`Project_Name` `name`,project.Project_Address address FROM `tb_qd_projectinuser` prouser LEFT JOIN (SELECT Project_ID,MAX(tb.`Date`) `max` FROM tb_monitordata15 tb WHERE tb.`Date` > '" + qian45 + "' GROUP BY Project_ID HAVING `max` < '" + qian30 + "') diaoxian  ON diaoxian.Project_ID = prouser.Project_ID LEFT JOIN `tb_qd_weixininuser` wxuser ON prouser.userid = wxuser.userid left join `tb_project` project on prouser.`Project_ID`= project.`Project_ID` WHERE diaoxian.Project_ID IS NOT NULL And wxuser.`openid` is not null and wxuser.`openid` != ''";

            //测试用的
            //string sql = "SELECT wxuser.openid openid, project.`Project_Name` `name`,project.Project_Address address FROM `tb_qd_projectinuser` prouser LEFT JOIN (SELECT Project_ID,MAX(tb.`Date`) `max` FROM tb_monitordata15 tb WHERE tb.`Date` > '" + qian45 + "' GROUP BY Project_ID) diaoxian  ON diaoxian.Project_ID = prouser.Project_ID LEFT JOIN `tb_qd_weixininuser` wxuser ON prouser.userid = wxuser.userid left join `tb_project` project on prouser.`Project_ID`= project.`Project_ID` WHERE diaoxian.Project_ID IS NOT NULL And wxuser.`openid` is not null and wxuser.`openid` != ''";
            MyLog.log("查询掉线的SQL语句:" + sql);
            MySqlDataReader reader = myDBConnect.Reader(sql);

            while (reader.Read())
            {
                Project project = new Project
                {
                    projectId = reader.GetInt32("projectId"),
                    openId    = reader.GetString("openid"),
                    name      = reader.GetString("name"),
                    address   = reader.GetString("address")
                };
                projectSet.Add(project);
            }
            reader.Close();
            foreach (var project in projectSet)
            {
                Baojing baojing = new Baojing();
                baojing.text          = project.name + "设备掉线";
                baojing.time          = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                baojing.type          = "掉线";
                baojing.point         = project.address;
                baojing.BaojingObject = project.name;
                string result = deviceStatusMonitor.SendBaojing(baojing, project.openId);
                MyLog.log("设备掉线:" + "openid=" + project.openId + ",name=" + project.name + ",address=" + project.address);
                MyLog.log("报警发送结果:" + result);
                diaoxianSet.Add(project.projectId);
            }
        }
예제 #10
0
 public void Check(MyDBConnect myDBConnect, DeviceStatusMonitor deviceStatusMonitor)
 {
     try
     {
         Dictionary <int, List <Project> > earlyWarningDic = new Dictionary <int, List <Project> >();
         Dictionary <int, List <Project> > overProofaDic   = new Dictionary <int, List <Project> >();
         Dictionary <int, List <Project> > overProofbDic   = new Dictionary <int, List <Project> >();
         string nowDate = DateTime.Now.ToString("yyyy-MM-dd");
         //检查是否到了该清零的日子
         if (!nowDate.Equals(day))
         {
             day = nowDate;
             overProofaNote.Clear();
             overProofbNote.Clear();
         }
         string qian15 = DateTime.Now.AddMinutes(-15).ToString("yyyy-MM-dd HH:mm:ss");
         string sql    = "SELECT yujing.Project_ID projectId,yujing.`Dust` , yujing.`EarlyWarning` ,yujing.`OverProofa`,yujing.`OverProofaValue`,yujing.`OverProofb`,yujing.`OverProofbValue`,wxuser.openid openid, project.`Project_Name` `name`,project.Project_Address address FROM `tb_qd_projectinuser` prouser LEFT JOIN (SELECT config.Project_ID ,data15.`Dust` , config.`EarlyWarning` ,config.`OverProofa`,config.`OverProofaValue`,config.`OverProofb`,config.`OverProofbValue` FROM tb_projectwarnconfig config LEFT JOIN tb_monitordata15 data15 ON config.`Project_ID` = data15.`Project_ID`WHERE data15.`Date` > '" + qian15 + "' AND ((config.`EarlyWarning` !=0 AND data15.`Dust` >= config.`EarlyWarning`) OR (config.`OverProofa` !=0 AND config.`OverProofaValue` !=0 AND data15.`Dust` >= config.`OverProofaValue`) OR (config.`OverProofb` !=0 AND config.`OverProofbValue` !=0 AND data15.`Dust` >= config.`OverProofbValue`))) yujing ON yujing.Project_ID = prouser.Project_ID LEFT JOIN `tb_qd_weixininuser` wxuser ON prouser.userid = wxuser.userid LEFT JOIN `tb_project` project ON prouser.`Project_ID`= project.`Project_ID` WHERE yujing.Project_ID IS NOT NULL AND wxuser.`openid` IS NOT NULL AND wxuser.`openid` != ''";
         MyLog.log("粉尘检测sql: " + sql);
         myDBConnect.Open();
         MySqlDataReader reader = myDBConnect.Reader(sql);
         while (reader.Read())
         {
             Project project = new Project
             {
                 projectId = reader.GetInt32("projectId"),
                 openId    = reader.GetString("openid"),
                 name      = reader.GetString("name"),
                 address   = reader.GetString("address")
             };
             int    Project_ID      = reader.GetInt32("projectId");
             Double Dust            = reader.GetDouble("Dust");
             Double EarlyWarning    = reader.GetDouble("EarlyWarning");
             int    OverProofa      = reader.GetInt32("OverProofa");
             Double OverProofaValue = reader.GetDouble("OverProofaValue");
             int    OverProofb      = reader.GetInt32("OverProofb");
             Double OverProofbValue = reader.GetDouble("OverProofbValue");
             if (EarlyWarning != 0 && Dust > EarlyWarning)
             {
                 if (!earlyWarningDic.ContainsKey(Project_ID))
                 {
                     earlyWarningDic[Project_ID] = new List <Project>();
                 }
                 earlyWarningDic[Project_ID].Add(project);
             }
             if (OverProofa != 0 && OverProofaValue != 0 && Dust > OverProofaValue)
             {
                 if (!earlyWarningDic.ContainsKey(Project_ID))
                 {
                     overProofaNote[Project_ID] = 0;
                 }
                 overProofaNote[Project_ID]++;
                 if (overProofaNote[Project_ID] >= OverProofa)
                 {
                     overProofaNote[Project_ID] = 0;
                     if (!overProofaDic.ContainsKey(Project_ID))
                     {
                         overProofaDic[Project_ID] = new List <Project>();
                     }
                     overProofaDic[Project_ID].Add(project);
                 }
             }
             if (OverProofb != 0 && OverProofbValue != 0 && Dust > OverProofbValue)
             {
                 try
                 {
                     overProofbNote[Project_ID]++;
                 }
                 catch
                 {
                     overProofbNote[Project_ID] = 1;
                 }
                 if (overProofbNote[Project_ID] >= OverProofb)
                 {
                     overProofbNote[Project_ID] = 0;
                     if (!overProofbDic.ContainsKey(Project_ID))
                     {
                         overProofbDic[Project_ID] = new List <Project>();
                     }
                     overProofbDic[Project_ID].Add(project);
                 }
             }
         }
         reader.Close();
         foreach (var map in earlyWarningDic)
         {
             List <Project> projects = map.Value;
             foreach (var project in projects)
             {
                 MyLog.log("project_id为" + project.projectId + "的设备粉尘超过预警值了");
                 Baojing baojing = new Baojing();
                 baojing.text          = project.name + "设备超出预警";
                 baojing.time          = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                 baojing.type          = "预警";
                 baojing.point         = project.address;
                 baojing.BaojingObject = project.name;
                 string result = deviceStatusMonitor.SendBaojing(baojing, project.openId);
                 MyLog.log("报警发送结果:" + result);
             }
         }
         foreach (var map in overProofaDic)
         {
             List <Project> projects = map.Value;
             foreach (var project in projects)
             {
                 MyLog.log("project_id为" + project.projectId + "的设备粉尘超过OverProofaValue值了");
                 Baojing baojing = new Baojing();
                 baojing.text          = project.name + "设备告警";
                 baojing.time          = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                 baojing.type          = "告警";
                 baojing.point         = project.address;
                 baojing.BaojingObject = project.name;
                 string result = deviceStatusMonitor.SendBaojing(baojing, project.openId);
                 MyLog.log("报警发送结果:" + result);
             }
         }
         foreach (var map in overProofbDic)
         {
             List <Project> projects = map.Value;
             foreach (var project in projects)
             {
                 MyLog.log("project_id为" + project.projectId + "的设备粉尘超过OverProofbValue值了");
                 Baojing baojing = new Baojing();
                 baojing.text          = project.name + "设备告警";
                 baojing.time          = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                 baojing.type          = "告警";
                 baojing.point         = project.address;
                 baojing.BaojingObject = project.name;
                 string result = deviceStatusMonitor.SendBaojing(baojing, project.openId);
                 MyLog.log("报警发送结果:" + result);
             }
         }
     }
     catch (Exception e1)
     {
         MyLog.log("error|代码异常信息:" + e1.ToString());
     }
 }