Windows服务,线上的监控程序,监控指定的服务
1
高胜
2023-05-23 cf31c5a262ad9f8fe66e884c4ca82d6c060422ff
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
using HDLMonitorService.Entity;
using HDLMonitorService.Helper;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
 
namespace HDLMonitorService.ServiceMonitor
{
    public class AlexaMonitor
    {
        private static int DeviceCacheExCount = 0;
 
        public static void monitor()
        {
            new Thread(new ThreadStart(() =>
            {
                while (true)
                {
                    try
                    {
                        var reqPack = File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + "Json//AlexaReqPack.json");
                        var result = HttpHp.Post<AlexaResponse>(ConfigurationManager.AppSettings["AelxaApi"], reqPack);
 
                        if (result == null)
                        {
                            throw new Exception("响应数据异常");
                        }
                        DeviceCacheExCount = 0;
                    }
                    catch (Exception exc)
                    {
                        DeviceCacheExCount++;
                        if (DeviceCacheExCount == 3)
                        {
                            try
                            {
                                AlarmHp.ApplicationAlarm("AlexaApi", "warn-system", exc.StackTrace, "118.31.3.103", exc.Message);
                            }
                            catch (Exception ex)
                            {
                                LogHp.WriteLog("Alexa异常", Newtonsoft.Json.JsonConvert.SerializeObject(ex));
                            }
 
                        }
                    }
                    Thread.Sleep(1000 * 10);
                }
            }))
            { IsBackground = true }.Start();
        }
    }
}