Пример #1
0
        public void Start()
        {
            Log.Info("Watchdog starting...");

            WatchdogState ws = WatchdogState.Create();

            watchList        = new HashSet <string>();
            watchdogWorkerCb = new WaitCallback(WatchdogWorkerRoutine);


            watchList.Add("view");
            watchList.Add("index");
            watchList.Add("add");


            WatchdogTimerState wts = new WatchdogTimerState(ws);

            this.wts = wts;

            workTimer =
                new Timer(new TimerCallback(Check), wts, 10 * 1000, 30 * 1000);


            Log.Info("Watchdog started");
        }
Пример #2
0
        private void WatchdogWorkerRoutine(object obj)
        {
            WatchdogState         ws = (WatchdogState)obj;
            IEnumerable <Process> stillWorkingList;

            if (ws.IsFirstTaken)
            {
                SnapshotProcesses(ws.SecondSnapshot);

                stillWorkingList = Intersect(ws);

                if (stillWorkingList != null)
                {
                    Log.Warning("There is {0} process(es) being hung", stillWorkingList.Count());
                    KillList(stillWorkingList);
                }
                else
                {
                    Log.Info("There is no hang process.");
                }

                ws.Release();
                ws = null;
            }
        }
Пример #3
0
            public static WatchdogState Create()
            {
                WatchdogState ws = new WatchdogState();

                ws.FirstSnapshot  = new List <Process>();
                ws.SecondSnapshot = new List <Process>();

                return(ws);
            }
Пример #4
0
        private IEnumerable <Process> Intersect(WatchdogState ws)
        {
            if (ws.FirstSnapshot.Count == 0)
            {
                yield break;
            }

            foreach (var fsp in ws.FirstSnapshot)
            {
                foreach (var ssp in ws.SecondSnapshot)
                {
                    if (fsp.ProcessName.ToLower() == ssp.ProcessName.ToLower())
                    {
                        yield return(fsp);

                        break;
                    }
                }
            }
        }
Пример #5
0
        private void Check(object obj)
        {
            WatchdogTimerState wts = (WatchdogTimerState)obj;

            if (!wts.Ws.IsFirstTaken)
            {
                SnapshotProcesses(wts.Ws.FirstSnapshot);

                if (wts.Ws.FirstSnapshot.Count > 0)
                {
                    wts.Ws.IsFirstTaken = true;
                    Recalibrate(5 * 1000);
                }
            }
            else
            {
                WatchdogState prevWs = wts.Ws;
                wts.Change(WatchdogState.Create());

                ThreadPool.QueueUserWorkItem(watchdogWorkerCb, prevWs);
                Recalibrate(30 * 1000);
            }
        }
Пример #6
0
 public WatchdogState Change(WatchdogState newWs)
 {
     return(Interlocked.Exchange <WatchdogState>(ref ws, newWs));
 }
Пример #7
0
 public WatchdogTimerState(WatchdogState ws)
 {
     this.ws = ws;
 }