Beispiel #1
0
            protected override Task OnStart(IMessageSession session)
            {
                counter = PerformanceCounterHelper.InstantiatePerformanceCounter("SLA violation countdown", counterInstanceName);
                timer   = new Timer(RemoveOldDataPoints, null, 0, 2000);

                return(TaskEx.CompletedTask);
            }
        static void SetupCriticalTimePerformanceCounter(FeatureConfigurationContext context)
        {
            var criticalTimeCounter    = PerformanceCounterHelper.InstantiateCounter("Critical Time", context.Settings.EndpointName());
            var criticalTimeCalculator = new CriticalTimeCalculator(criticalTimeCounter);

            context.Container.RegisterSingleton(criticalTimeCalculator);
        }
Beispiel #3
0
        static void SetupSLABreachCounter(FeatureConfigurationContext context, TimeSpan endpointSla)
        {
            var slaBreachCounter          = PerformanceCounterHelper.InstantiateCounter("SLA violation countdown", context.Settings.EndpointName());
            var timeToSLABreachCalculator = new EstimatedTimeToSLABreachCalculator(endpointSla, slaBreachCounter);

            context.Container.RegisterSingleton(timeToSLABreachCalculator);
        }
            private void Proaction(Datagram dgram)
            {
                try
                {
                    _udp.ReceivedBytes.Inc((ulong)dgram.Size);

                    //Update Performance Counters
                    var cat = new BackendCategory();
                    PerformanceCounterHelper.Increment(cat.CategoryName, cat.GatewayUDP);

                    LogBandwidthUsed(dgram.Size, 0);

                    ReplicateReport(dgram);

                    var link = _udp.DataLinkLayer.OnLinkTranslation(_udp, dgram.RemoteAddress, dgram);

                    if (link != null)
                    {
                        dgram.DeviceId = link.GetDeviceId();
                    }

                    if (!_udp.DataLinkLayer.OnFrameReceived(link, dgram, _udp.Parser))
                    {
                        return;
                    }

                    LogBandwidthUsed(0, dgram.Size + dgram.Size2);

                    SendTo(dgram);
                }
                catch (Exception e)
                {
                    STrace.Exception(typeof(UnderlayingNetworkLayerUDP).FullName, e);
                }
            }
Beispiel #5
0
        private void InitPerformanceCounters(IEnumerable <Hospital> hospitals)
        {
            if (PerformanceCounterCategory.Exists(PerformanceCounterHelper.MainCategory))
            {
                PerformanceCounterCategory.Delete(PerformanceCounterHelper.MainCategory);
            }

            var dc = new CounterCreationDataCollection();

            foreach (var h in hospitals)
            {
                dc.Add(new CounterCreationData(PerformanceCounterHelper.GetPerformanceCounterName(StatisticType.AvgTimeToSeeADoctor, h.Id),
                                               PerformanceCounterHelper.CounterAvgTimeToSeeADoctor, PerformanceCounterType.NumberOfItems64));

                dc.Add(new CounterCreationData(PerformanceCounterHelper.GetPerformanceCounterName(StatisticType.Illness, h.Id),
                                               PerformanceCounterHelper.CounterPerDisease, PerformanceCounterType.NumberOfItems64));

                dc.Add(new CounterCreationData(PerformanceCounterHelper.GetPerformanceCounterName(StatisticType.AvgAppointmentDuration, h.Id),
                                               PerformanceCounterHelper.CounterAvgAppointmentDuration, PerformanceCounterType.NumberOfItems64));

                dc.Add(new CounterCreationData(PerformanceCounterHelper.GetPerformanceCounterName(StatisticType.EstimatedTimeToSeeADoctor, h.Id),
                                               PerformanceCounterHelper.CounterEstimatedTimeToSeeADoctor, PerformanceCounterType.NumberOfItems64));

                dc.Add(new CounterCreationData($"(H{h.Id}) Messages par seconde pour {PerformanceCounterHelper.CounterAvgTimeToSeeADoctor}",
                                               "Actor messages per second", PerformanceCounterType.RateOfCountsPerSecond64));
            }

            PerformanceCounterCategory.Create(PerformanceCounterHelper.MainCategory, "Catégorie pour Système de surveillance médicale", PerformanceCounterCategoryType.SingleInstance, dc);
        }
        /// <summary>
        /// <see cref="Feature.Setup"/>
        /// </summary>
        protected internal override void Setup(FeatureConfigurationContext context)
        {
            var criticalTimeCounter    = PerformanceCounterHelper.InstantiatePerformanceCounter("Critical Time", context.Settings.EndpointName());
            var criticalTimeCalculator = new CriticalTimeCalculator(criticalTimeCounter);

            context.Container.RegisterSingleton(criticalTimeCalculator);
            context.Pipeline.Register <CriticalTimeBehavior.Registration>();
        }
Beispiel #7
0
        public void GetPerformanceCounterCategoryNames()
        {
            var names = PerformanceCounterHelper.GetPerformanceCounterCategoryNames();

            foreach (var name in names)
            {
                Console.WriteLine(name);
            }
        }
Beispiel #8
0
        bool SetupCounter(string counterName, out PerformanceCounter counter)
        {
            if (!PerformanceCounterHelper.TryToInstantiatePerformanceCounter(counterName, receiveAddress.Queue, out counter))
            {
                return(false);
            }

            Logger.DebugFormat("'{0}' counter initialized for '{1}'", counterName, receiveAddress);

            return(true);
        }
Beispiel #9
0
        public IEnumerable <string> GetCounterNames(string categoryName, string machineName)
        {
            var cat = PerformanceCounterHelper.GetPerformanceCounterCategory(categoryName, machineName);

            var instances = cat.CategoryType == PerformanceCounterCategoryType.SingleInstance ? new string[] { null } : cat.GetInstanceNames();

            foreach (var instance in instances)
            {
                var coutners = string.IsNullOrEmpty(instance) ? cat.GetCounters().Select(x => x.CounterName) : cat.GetCounters(instance).Select(x => x.CounterName);
                foreach (var counter in coutners)
                {
                    yield return(counter);
                }
            }
        }
Beispiel #10
0
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        public static void LoadAndRun(String[] args)
        {
            var appFile = String.Format(@"{0}\{1}", Process.GetApplicationFolder(), ((args.Length == 0) ? "AutoRun.xml" : args[0]));

            STrace.Debug(typeof(ApplicationLoader).FullName, "Creating Backend Category into PerformanceCounterHelper");
            PerformanceCounterHelper.Create(new BackendCategory());
            //STrace.Debug(typeof(ApplicationLoader).FullName, "Launching Debugger...");
            //Debugger.LaunchDebugger(1);

            STrace.Debug(typeof(ApplicationLoader).FullName, "Initiating AppDomain...");
            Process.InitAppDomain();

            try
            {
                STrace.Debug(typeof(ApplicationLoader).FullName, "Loading MetadataDirectory...");
                MetadataDirectory.Load();
            }
            catch (Exception e)
            {
                STrace.Exception(typeof(ApplicationLoader).FullName, e, "No se pudieron cargar los assemblies, borre y vuelva a copiar todos los archivos .exe .dll y .pdb");
                Thread.Sleep(2000);
                return;
            }

            if (!IOUtils.FileExists(appFile))
            {
                STrace.Error(typeof(ApplicationLoader).FullName, String.Format("No existe el archivo '{0}'", appFile));
            }

            var mode = FrameworkApplication.GetRunMode(appFile);

            switch (mode)
            {
            case RunMode.WinService: ServiceMain(appFile, args[1]); break;

            case RunMode.WinForm: WindowsMain(appFile); break;

            case RunMode.Hidden: HiddenInstallMain(appFile); break;

            case RunMode.Console: ConsoleMain(appFile); break;

            default: STrace.Error(typeof(ApplicationLoader).FullName, "No se pudo determinar el modo requerido de ejecucion para la aplicacion."); break;
            }
            Environment.Exit(0);
        }
Beispiel #11
0
        /// <summary>
        /// <see cref="Feature.Setup"/>
        /// </summary>
        protected internal override void Setup(FeatureConfigurationContext context)
        {
            if (context.Settings.GetOrDefault <bool>("Endpoint.SendOnly"))
            {
                return;
            }

            TimeSpan endpointSla;

            if (!TryGetSLA(context, out endpointSla))
            {
                return;
            }

            var slaBreachCounter          = PerformanceCounterHelper.InstantiatePerformanceCounter("SLA violation countdown", context.Settings.EndpointName());
            var timeToSLABreachCalculator = new EstimatedTimeToSLABreachCalculator(endpointSla, slaBreachCounter);

            context.Container.RegisterSingleton(timeToSLABreachCalculator);
            context.Pipeline.Register <SLABehavior.Registration>();
        }
        /// <summary>
        ///     Initializes a new instance of the <see cref="GameEngine"/> class.
        /// </summary>
        public GameEngine(GameEngineSettings settings)
        {
            #region Argument Check

            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            #endregion

            if (SettingsCache.Instance.UsePerformanceCounters)
            {
                PerformanceCounterHelper.Initialize();
            }

            // Pre-initialized fields and properties
            _paintCallback        = settings.PaintCallback;
            _positionCallback     = settings.PositionCallback.EnsureNotNull();
            this.Data             = new GameEngineData(settings.NominalSize);
            _moveCount            = new ThreadSafeValue <long>();
            _winningTeam          = new ThreadSafeValue <GameTeam?>();
            _lastGamePresentation = new ThreadSafeValue <GamePresentation>();

            // Post-initialized fields and properties
            _lightTeamLogicExecutor = CreateLogicExecutor(this, settings.LightTeamSettings, GameTeam.Light);
            _darkTeamLogicExecutor  = CreateLogicExecutor(this, settings.DarkTeamSettings, GameTeam.Dark);
            _logicExecutors         = new[] { _lightTeamLogicExecutor, _darkTeamLogicExecutor }.ToArray().AsReadOnly();

            _allChickens = _logicExecutors.SelectMany(item => item.Units).ToArray().AsReadOnly();
            _allChickens.DoForEach((item, index) => item.UniqueId = new GameObjectId(index + 1));

            _aliveChickensDirect = new List <ChickenUnit>();
            this.AliveChickens   = _aliveChickensDirect.AsReadOnly();

            _shotUnitsDirect = new List <ShotUnit>(_allChickens.Count);
            this.ShotUnits   = _shotUnitsDirect.AsReadOnly();

            _moveInfos      = new Dictionary <ChickenUnit, MoveInfo>(_allChickens.Count);
            _moveInfoStates = new Dictionary <ChickenUnit, MoveInfoStates>(_allChickens.Count);
            _previousMoves  = new Dictionary <ChickenUnit, MoveInfo>(_allChickens.Count);
            _newShotUnits   = new List <ShotUnit>(_allChickens.Count);

            #region Argument Check

            var maxChickenCount = this.Data.NominalSize.Width * this.Data.NominalSize.Height / 2;
            if (_allChickens.Count > maxChickenCount)
            {
                throw new ArgumentException(
                          string.Format(
                              "Too many chickens ({0}) for the board of nominal size {1}x{2}. Maximum is {3}.",
                              _allChickens.Count,
                              this.Data.NominalSize.Width,
                              this.Data.NominalSize.Height,
                              maxChickenCount),
                          "settings");
            }

            #endregion

            ResetInternal();
        }
Beispiel #13
0
 protected override Task OnStart(IMessageSession session)
 {
     counter = PerformanceCounterHelper.InstantiatePerformanceCounter("Critical Time", counterInstanceName);
     timer   = new Timer(ResetCounterValueIfNoMessageHasBeenProcessedRecently, null, 0, 2000);
     return(TaskEx.CompletedTask);
 }
Beispiel #14
0
        private IEnumerable <PerformanceCounter> GetPerformanceCounters(string categoryName, string counterName, string instanceName, string machineName)
        {
            var response = new List <PerformanceCounter>();

            try
            {
                if (counterName.Contains("*") || (instanceName != null && (instanceName.Contains("*") || instanceName.Contains("|"))))
                {
                    var cat = PerformanceCounterHelper.GetPerformanceCounterCategory(categoryName, machineName);

                    List <string> instances = new List <string>();

                    if (instanceName == null)
                    {
                        instances.Add(null);
                    }
                    else if (instanceName.Contains("|"))
                    {
                        foreach (String instancePart in instanceName.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries))
                        {
                            if (instancePart.Contains("*"))
                            {
                                instances.AddRange(cat.GetInstanceNames().Where(x => Match(x, instancePart)));
                            }
                            else
                            {
                                instances.Add(instancePart);
                            }
                        }

                        if (instances.Count == 0)
                        {
                            instances.Add(null);
                        }
                    }
                    else if (instanceName.Contains("*"))
                    {
                        instances.AddRange(cat.GetInstanceNames().Where(x => Match(x, instanceName)));
                        //TODO: If this response gives no instances, this means that this counter should use null, for instance
                        if (instances.Count == 0)
                        {
                            instances.Add(null);
                        }
                    }
                    else
                    {
                        instances.Add(instanceName);
                    }

                    var counterNames = new[] { counterName };
                    if (counterName.Contains("*"))
                    {
                        foreach (var instance in instances)
                        {
                            if (string.IsNullOrEmpty(instance))
                            {
                                counterNames = cat.GetCounters().Where(x => Match(x.CounterName, counterName)).Select(x => x.CounterName).ToArray();
                            }
                            else
                            {
                                counterNames = cat.GetCounters(instance).Where(x => Match(x.CounterName, counterName)).Select(x => x.CounterName).ToArray();
                            }
                        }
                    }

                    foreach (var counter in counterNames)
                    {
                        foreach (var instance in instances)
                        {
                            if (!string.IsNullOrEmpty(machineName))
                            {
                                response.Add(new PerformanceCounter(categoryName, counter, instance, machineName));
                            }
                            else
                            {
                                response.Add(new PerformanceCounter(categoryName, counter, instance));
                            }
                        }
                    }
                }
                else
                {
                    if (!string.IsNullOrEmpty(machineName))
                    {
                        response.Add(new PerformanceCounter(categoryName, counterName, instanceName, machineName));
                    }
                    else
                    {
                        response.Add(new PerformanceCounter(categoryName, counterName, instanceName));
                    }
                }
            }
            catch (Exception exception)
            {
                OnGetPerformanceCounters(exception, categoryName, counterName, instanceName, machineName);
            }

            return(response);
        }
        public async override Task <bool> InvokeAsync(string paramList)
        {
            var index = 0;

            var addAnother = true;
            var collectors = new List <ICounter>();

            while (addAnother)
            {
                var machineName = QueryParam("Machine", GetParam(paramList, index++), new Dictionary <string, string> {
                    { System.Environment.MachineName, System.Environment.MachineName }
                });

                var categoryNames = _counterBusiness.GetCategoryNames();
                var categoryName  = QueryParam("Category", GetParam(paramList, index++), categoryNames.Select(x => new KeyValuePair <string, string>(x, x)));

                var counterNames = _counterBusiness.GetCounterNames(categoryName, machineName);
                var counterName  = QueryParam("Counter", GetParam(paramList, index++), counterNames.Select(x => new KeyValuePair <string, string>(x, x)));

                string instanceName = null;
                var    cat          = PerformanceCounterHelper.GetPerformanceCounterCategory(categoryName, machineName);

                if (cat.CategoryType == PerformanceCounterCategoryType.MultiInstance)
                {
                    var instanceNames = _counterBusiness.GetInstances(categoryName, counterName, machineName);
                    instanceName = QueryParam("Instance", GetParam(paramList, index++), instanceNames.Select(x => new KeyValuePair <string, string>(x, x)));
                }

                var fieldName = QueryParam <string>("FieldName", GetParam(paramList, index++));

                addAnother = QueryParam("Add another counter?", GetParam(paramList, index++), new Dictionary <bool, string> {
                    { true, "Yes" }, { false, "No" }
                });

                var collector = new Collector.Entities.Counter(categoryName, counterName, instanceName, fieldName, null, null, null, machineName);
                collectors.Add(collector);
            }

            var groupName       = QueryParam <string>("Group Name", GetParam(paramList, index++));
            var secondsInterval = QueryParam <int>("Seconds Interval", GetParam(paramList, index++));

            var refreshInstanceInterval = 0;

            if (collectors.Any(x => x.InstanceName.Contains("*") || x.InstanceName.Contains("?")))
            {
                refreshInstanceInterval = QueryParam <int>("Refresh Instance Interval", GetParam(paramList, index++));
            }

            var collectorEngineType = QueryParam("Collector Engine Type", GetParam(paramList, index++), new Dictionary <CollectorEngineType, string> {
                { CollectorEngineType.Safe, CollectorEngineType.Safe.ToString() }, { CollectorEngineType.Exact, CollectorEngineType.Exact.ToString() }
            });

            var initaiteBusiness = new DataInitiator(_configBusiness, _counterBusiness);
            var response         = initaiteBusiness.CreateCounter(groupName, secondsInterval, refreshInstanceInterval, collectors, collectorEngineType);

            OutputLine(response.Item2.Item1, response.Item2.Item2);

            TestNewCounterGroup(response.Item1);

            return(false);
        }
        public BackwardReply Dispatch(IMessage msg)
        {
            try
            {
                if (msg == null)
                {
                    STrace.Debug(GetType().FullName, "Message: null");
                    return(BackwardReply.None);
                }

                var msgType = msg.GetType();
                if (msgType.FullName == null)
                {
                    STrace.Debug(GetType().FullName, "Message: null type");
                    return(BackwardReply.None);
                }

                var pcInstanceName = STrace.Module + "_" + msg.GetType().Name;
                //Update Performance Counters
                //   PerformanceCounterHelper.Increment(BackendCategory.Instance.CategoryName, BackendCategory.Instance.DispatcherProcess, pcInstanceName);
                PerformanceCounterHelper.Increment(BackendCategory.Instance.CategoryName, BackendCategory.Instance.DispatcherProcess);

                var sw = Stopwatch.StartNew();

                var handlers = GetHandlers(msgType);
                //STrace.Debug(GetType().FullName, 0, String.Format("Dispatch {0} T={1} Id={2} HCount={3}", msg.Tiempo, msg.GetType().Name, msg.DeviceId, (Handlers == null) ? -1 : Handlers.Count()));
                if ((handlers != null) && (handlers.Count() != 0))
                {
                    using (var session = NHibernateHelper.GetCurrentSession())
                    {
                        foreach (var handler in handlers)
                        {
                            //lock (handler)
                            {
                                object ret = null;
                                try
                                {
                                    ret = handler(msg);
                                }
                                catch (Exception e)
                                {
                                    STrace.Exception(GetType().FullName, e, msg.DeviceId, String.Format("mType:{0} hType:{1} failure on delivering", msgType.Name, handler.GetType().Name));
                                }
                                if (ret == null || (!(ret is HandleResults)))
                                {
                                    return(BackwardReply.Release);
                                }
                                var result = (HandleResults)ret;
                                if (result == HandleResults.UnspecifiedFailure)
                                {
                                    Thread.Sleep(100);
                                    return(BackwardReply.Release);
                                }
                                if (result == HandleResults.BreakSuccess)
                                {
                                    break;
                                }
                            }
                        }
                        NHibernateHelper.CloseSession();
                    }
                    //     PerformanceCounterHelper.IncrementBy(BackendCategory.Instance.CategoryName,
                    //       BackendCategory.Instance.DispatcherProcess, pcInstanceName, sw.ElapsedTicks);
                    PerformanceCounterHelper.IncrementBy(BackendCategory.Instance.CategoryName,
                                                         BackendCategory.Instance.DispatcherProcess, STrace.Module, sw.ElapsedTicks);
                }
            }
            catch (Exception e)
            {
                STrace.Exception(typeof(ReflectionIMessageDispatcher).FullName, e);
            }
            return(BackwardReply.None);
        }
Beispiel #17
0
        public IEnumerable <string> GetInstances(string category, string counterName, string machineName)
        {
            var cat = PerformanceCounterHelper.GetPerformanceCounterCategory(category, machineName);

            return(cat.GetInstanceNames());
        }