Inheritance: IPerformanceCounter
Exemplo n.º 1
0
        public void Start(Configuration c)
        {
            if (Notifier.StartEventSaved && !Notifier.EndEventSaved)
            {
                // Ensure we do not dispose of the Observers if they are in the middle of an alert cycle.
                return;
            }
            Subscription?.Dispose();
            ConfigurationSync?.Dispose();

            RefreshSettings(c);

            Logger.Trace("New threshold {0}", c.Thresholds.CriticalLoad);
            Logger.Trace("New interval {0}", c.Intervals.CriticalNotification);

            ConfigurationSync = Observable
                                .Interval(TimeSpan.FromMinutes(ConfigurationRefreshTime)) // Refresh the settings and counters every X minutes
                                .Select(i => ConfigurationReader.Read())
                                .DistinctUntilChanged()
                                .Subscribe(Start);

            Counter = new NetworkPerformanceCounter(Hardware, DriveId);
            if (Enabled)
            {
                var alarms = Observable.Interval(c.Intervals.Measurement)       // generate endless sequence of events
                             .Select(i => Counter.Value)                        // convert event index to cpu load value
                             .Select(load => load > c.Thresholds.CriticalLoad); // is critical? convert load to boolean

                Subscription = alarms                                           // here we throttle critical alarms
                               .Where(critical => critical).Sample(c.Intervals.Notification).Merge(
                    // allow critical notification no more often then ...
                    alarms                                                          // here we throttle non critical alarms
                    .Where(critical => !critical).Sample(c.Intervals.Notification)) // allow non critical notification no more often then ...
                               .Subscribe(Notifier.Notify);                         // our action to send notifications
            }
        }
Exemplo n.º 2
0
        public void Start(Configuration c)
        {
            if (Notifier.StartEventSaved && !Notifier.EndEventSaved)
            {
                // Ensure we do not dispose of the Observers if they are in the middle of an alert cycle.
                return;
            }
            Subscription?.Dispose();
            ConfigurationSync?.Dispose();

            RefreshSettings(c);

            Logger.Trace("New threshold {0}", c.Thresholds.CriticalLoad);
            Logger.Trace("New interval {0}", c.Intervals.CriticalNotification);

            ConfigurationSync = Observable
            .Interval(TimeSpan.FromMinutes(ConfigurationRefreshTime)) // Refresh the settings and counters every X minutes
            .Select(i => ConfigurationReader.Read())
            .DistinctUntilChanged()
            .Subscribe(Start);

            Counter = new NetworkPerformanceCounter(Hardware, DriveId);
            if (Enabled)
            {

                var alarms = Observable.Interval(c.Intervals.Measurement) // generate endless sequence of events
                                       .Select(i => Counter.Value) // convert event index to cpu load value
                                       .Select(load => load > c.Thresholds.CriticalLoad); // is critical? convert load to boolean

                Subscription = alarms // here we throttle critical alarms
                    .Where(critical => critical).Sample(c.Intervals.Notification).Merge(
                        // allow critical notification no more often then ...
                        alarms // here we throttle non critical alarms
                            .Where(critical => !critical).Sample(c.Intervals.Notification)) // allow non critical notification no more often then ...
                    .Subscribe(Notifier.Notify); // our action to send notifications
            }
        }