Windows服务,线上的监控程序,监控指定的服务
高胜
2023-05-08 27306db9a074ea4ebdb5e75237f058e4e9af2167
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using HDLMonitorService.Helper;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
 
namespace HDLMonitorService.ServiceMonitor
{
    public class DeviceCacheServiceMonitor
    {
 
        private static int DeviceCacheExCount = 0;
 
        /// <summary>
        /// 监控Api服务
        /// </summary>
        public static void monitorDeviceCacheServer()
        {
            new Thread(new ThreadStart(() =>
            {
                while (true)
                {
                    try
                    {
 
                        HttpHp.Post<Dictionary<string, string>>(ConfigurationManager.AppSettings["GetDeviceCacheUrl"], Newtonsoft.Json.JsonConvert.SerializeObject(new
                        {
                            MAC = "6BC7FEFFAAA04908",
                            DeviceType = "LightSwitch",
                            SubnetID = 1,
                            DeviceID = 1,
                            LoopID = 1
                        }));
                        DeviceCacheExCount = 0;
                    }
                    catch (Exception exc)
                    {
                        DeviceCacheExCount++;
 
                        if (DeviceCacheExCount == 3)
                        {
                            try
                            {
                                AlarmHp.ApplicationAlarm("LogicAndDataServer", "warn-system", exc.StackTrace, "115.29.191.136", exc.Message);
                            }
                            catch (Exception ex)
                            {
                                LogHp.WriteLog("设备状态缓存异常", Newtonsoft.Json.JsonConvert.SerializeObject(ex));
                            }
 
                        }
                    }
                    Thread.Sleep(1000 * 10);
                }
            }))
            { IsBackground = true }.Start();
        }
 
    }
}