예제 #1
0
        private static void Main()
        {
            DeleteMenu(GetSystemMenu(GetConsoleWindow(), false), SC_CLOSE, MF_BYCOMMAND);
            var storageConnection = ConfigurationManager.AppSettings["AzureStorageConnectionString"];
            ServiceBusConnectionStringBuilder builder = new ServiceBusConnectionStringBuilder(ConfigurationManager.AppSettings["Microsoft.ServiceBus.ConnectionString.Listen"]);

            EventHubName = ConfigurationManager.AppSettings["EventHubName"];
            var hubProcessor = new EventHubProcessor(builder.ToString(), EventHubName);
            AnalyzerEngineProgram engineProgram = new AnalyzerEngineProgram(Engine, Logger, ErrorLogger, new StatusSnapShotGenerator(ConfigurationManager.AppSettings["jsonPath"], ErrorLogger), hubProcessor);


            var alarmQueueConnS = ConfigurationManager.AppSettings["ServiceBus.Queue.Connectionstring"];
            var alarmQueueName  = ConfigurationManager.AppSettings["ServiceBus.Queue.Name"];

            var alarmQueue  = new ServiceBusConnection <AlarmMessage>(alarmQueueConnS, alarmQueueName);
            var alarmManger = new AlarmMessageManager(alarmQueue);
            var ruleStorage = new DocumentDBRuleStorage(ConfigurationManager.AppSettings["DocDBEndPointUrl"], ConfigurationManager.AppSettings["AuthorizationKey"], ConfigurationManager.AppSettings["RuleDatabaseId"], ConfigurationManager.AppSettings["RuleCollectionId"]);

            var eventStore = new SQLEventStore(Logger, ConfigurationManager.AppSettings["sqleventstoreConnection"]);

            var restartInput = new RestartInput()
            {
                RuleStorage = ruleStorage, AlarmMessageManager = alarmManger, EngineProgram = engineProgram
            };
            var engineRestartTimer = new Timer(RestartLoop, restartInput, 0, 5000);

            Timers.Add(engineRestartTimer);

            var eventProcessorThread = new Thread(() =>
            {
                var recTask = hubProcessor.StartReceiver <EventProcessor>(storageConnection);
                EventProcessor.Init(Engine, Logger, ErrorLogger, eventStore);
                recTask.Wait();
            });

            eventProcessorThread.Name = nameof(eventProcessorThread);

            var gui       = new GuiHandler(engineProgram);
            var guiThread = new Thread(gui.Run);

            guiThread.IsBackground = true;
            guiThread.Start();
            guiThread.Name = nameof(guiThread);
            eventProcessorThread.Priority = ThreadPriority.AboveNormal;
            eventProcessorThread.Start();
        }
예제 #2
0
        private static void Main(string[] args)
        {
            SetWindowSize(WindowWidth, WindowHeight);
            Clear();
            var storageConnection = ConfigurationManager.AppSettings["AzureStorageConnectionString"];
            var eventhubConnS     = ConfigurationManager.AppSettings["Microsoft.ServiceBus.ConnectionString.Listen"];

            Eventhubpath = ConfigurationManager.AppSettings["EventHubPath"];
            var alarmQueueConnS = ConfigurationManager.AppSettings["ServiceBus.Queue.Connectionstring"];
            var alarmQueueName  = ConfigurationManager.AppSettings["ServiceBus.Queue.Name"];

            WriteLineAndLog("Starting analyzer for hub: " + Eventhubpath);

            var alarmQueue  = new ServiceBusConnection <AlarmMessage>(alarmQueueConnS, alarmQueueName);
            var alarmManger = new AlarmMessageManager(alarmQueue);
            var ruleStorage = new DocumentDBRuleStorage(ConfigurationManager.AppSettings["DocDBEndPointUrl"], ConfigurationManager.AppSettings["AuthorizationKey"], ConfigurationManager.AppSettings["RuleDatabaseId"], ConfigurationManager.AppSettings["RuleCollectionId"]);

            Engine = new AnalyzerEngine();
            ServiceBusConnectionStringBuilder builder = new ServiceBusConnectionStringBuilder(eventhubConnS);

            builder.TransportType = TransportType.Amqp;
            var connection = new EventHubProcessor(builder.ToString(), Eventhubpath);

            WriteLineAndLog("Starting event receiver.");
            var recTask = connection.StartReceiver <EventProc>(storageConnection);

            recTask.Wait();

            WriteLineAndLog("Receiver waiting.");
            var engineStartCounter = 0;
            var maxEngineRestarts  = 10;

            try
            {
                new Thread(() =>
                {
                    Thread.CurrentThread.IsBackground = true;
                    while (true)
                    {
                        if (!AwaitingInput)
                        {
                            Render();
                            Thread.Sleep(500);
                        }
                    }
                }).Start();
                new Thread(() =>
                {
                    Thread.CurrentThread.IsBackground = true;
                    while (true)
                    {
                        ParseInput();
                    }
                }).Start();


                while (true)
                {
                    MessageAggregator.Collection.Clear();
                    for (var i = 0; i < 500; ++i)
                    {
                        TimeStampedMessage <string> msg;
                        if (Engine.EngineMessages.TryDequeue(out msg))
                        {
                            MessageAggregator.AddMessage(msg, msg.Message.GenerateMessageIdentifierFromString());
                        }
                    }
                    foreach (var messageTracker in MessageAggregator.Collection)
                    {
                        MesseageOutputQueue.Enqueue($"{messageTracker.Value.Message} | {messageTracker.Value.AmountCounter} times from {messageTracker.Value.FirstOccurrence} to {messageTracker.Value.LastOccurrence}");
                    }
                    if (Engine.State == State.ShuttingDown)
                    {
                        continue;
                    }
                    if (Engine.State == State.Stopped)
                    {
                        Engine.StartEngine(ruleStorage, alarmManger);
                        if (maxEngineRestarts <= engineStartCounter++)
                        {
                            var message = $"AnalyserEngine main task has been restared {engineStartCounter - 1} times. Engine is down and can not recover! Resetting start counter.";
                            Logger.AddRow(message);
                            MesseageOutputQueue.Enqueue(message);
                            var alarm = new AlarmMessage(AlarmLevel.High, AppDomain.CurrentDomain.FriendlyName, message);
                            alarmManger.RaiseAlarm(alarm);
                            engineStartCounter = 0;
                        }
                    }
                    var timer = new Stopwatch();
                    timer.Start();
                    while (!Engine.EngineIsRunning && timer.ElapsedMilliseconds < 30000)
                    {
                        MesseageOutputQueue.Enqueue("Awaiting engine start. Waited " + timer.ElapsedMilliseconds + " ms");
                        Thread.Sleep(1000);
                    }
                    timer.Reset();
                }
            }
            catch (Exception ex)
            {
                var alarm = new AlarmMessage(AlarmLevel.High, AppDomain.CurrentDomain.FriendlyName, $"Exception in main loop.", ex.Message);
                alarmManger.RaiseAlarm(alarm);
                WriteLineAndLog($"Exception in main loop.");
                WriteLineAndLog(ex.ToString());
            }

            WriteLineAndLog("End of program.");
        }
예제 #3
0
        void App_Startup(object sender, StartupEventArgs e)
        {
            MainWindow mainWindow = new MainWindow(Logger);


            mainWindow.SnapShotGenerator = new StatusSnapShotGenerator(ConfigurationManager.AppSettings["jsonPath"], Logger);

            var storageConnection = ConfigurationManager.AppSettings["AzureStorageConnectionString"];
            ServiceBusConnectionStringBuilder builder = new ServiceBusConnectionStringBuilder(ConfigurationManager.AppSettings["Microsoft.ServiceBus.ConnectionString.Listen"]);


            var eventhubConnS   = ConfigurationManager.AppSettings["Microsoft.ServiceBus.ConnectionString.Listen"];
            var alarmQueueConnS = ConfigurationManager.AppSettings["ServiceBus.Queue.Connectionstring"];
            var alarmQueueName  = ConfigurationManager.AppSettings["ServiceBus.Queue.Name"];

            var alarmQueue  = new ServiceBusConnection <AlarmMessage>(alarmQueueConnS, alarmQueueName);
            var alarmManger = new AlarmMessageManager(alarmQueue);
            var ruleStorage = new DocumentDBRuleStorage(ConfigurationManager.AppSettings["DocDBEndPointUrl"], ConfigurationManager.AppSettings["AuthorizationKey"], ConfigurationManager.AppSettings["RuleDatabaseId"], ConfigurationManager.AppSettings["RuleCollectionId"]);

            EventHubName = ConfigurationManager.AppSettings["EventHubName"];
            var engineStartCounter = 0;
            var maxEngineRestarts  = 10;

            Task.Run(() =>
            {
                while (RunRestartLoop)
                {
                    if (Engine.State == State.ShuttingDown)
                    {
                        continue;
                    }
                    if (Engine.State == State.Stopped)
                    {
                        Engine.StartEngine(ruleStorage, alarmManger);
                        if (maxEngineRestarts <= engineStartCounter++)
                        {
                            var message = $"AnalyzerEngine main task has been restared {engineStartCounter - 1} times. Engine is down and can not recover! Resetting start counter.";
                            Logger.AddRow(message);
                            mainWindow.MesseageOutputQueue.Enqueue(message);
                            var alarm = new AlarmMessage(AlarmLevel.High, AppDomain.CurrentDomain.FriendlyName, message);
                            alarmManger.RaiseAlarm(alarm);
                            engineStartCounter = 0;
                        }
                        var timer = new Stopwatch();
                        timer.Start();
                        while (!Engine.EngineIsRunning && timer.ElapsedMilliseconds < 20000)
                        {
                            mainWindow.MesseageOutputQueue.Enqueue("Awaiting engine start. Waited " + timer.ElapsedMilliseconds + " ms");
                            Task.Delay(1000).Wait();
                        }
                        timer.Reset();
                    }
                }
            });

            Task.Run(() =>
            {
                var connection = new EventHubProcessor(builder.ToString(), EventHubName);
                var recTask    = connection.StartReceiver <EventProcessor>(storageConnection);
                // EventProcessor.Init(Engine, Logger, storageConnection, ConfigurationManager.AppSettings["OperationStorageTable"]);
                recTask.Wait();
            });

            mainWindow.SnapShotGenerator.StartGenerator();
            mainWindow.Show();
        }