コード例 #1
0
        public void Update(object sender)
        {
            lock (_lock)
            {
                historyIndex++;

                var usr  = _cpuUserCounter.NextValue();
                var priv = _cpuPrivCounter.NextValue();
                var cs   = new CpuStat
                {
                    SampleID = historyIndex,
                    Idle     = clamp(0, 100, (int)(100 - (usr + priv))),
                    Priv     = (int)priv,
                    User     = (int)usr,
                };
                history.Enqueue(cs);

                if (historyIndex >= 6 && (historyIndex % 6) == 0)
                {
                    historyIndexHour++;
                    AddHistoryItem(history, 6, historyHour, historyIndexHour);
                }
                if (historyIndex >= 144 && (historyIndex % 144) == 0)
                {
                    historyIndexDay++;
                    AddHistoryItem(history, 144, historyDay, historyIndexDay);
                }
            }
        }
コード例 #2
0
        private void AddHistoryItem(FixedSizeQueue <CpuStat> from, int count, FixedSizeQueue <CpuStat> to, long index)
        {
            float cpuUser = 0;
            float cpuPriv = 0;

            for (int i = 1; i <= count; i++)
            {
                CpuStat sample = from.ElementAt(history.Count() - i);
                cpuUser += sample.User;
                cpuPriv += sample.Priv;
            }
            cpuUser /= count;
            cpuPriv /= count;

            var hourSample = new CpuStat
            {
                SampleID = index,
                Idle     = clamp(0, 100, (int)(100 - (cpuUser + cpuPriv))),
                Priv     = cpuPriv,
                User     = cpuUser,
            };

            to.Enqueue(hourSample);
        }
コード例 #3
0
        private void AddHistoryItem(FixedSizeQueue<CpuStat> from, int count, FixedSizeQueue<CpuStat> to, long index)
        {
            float cpuUser = 0;
            float cpuPriv = 0;
            for (int i = 1; i <= count; i++)
              		{
              			CpuStat sample = from.ElementAt(history.Count() - i);
                  cpuUser += sample.User;
                  cpuPriv += sample.Priv;
              		}
             cpuUser /= count;
             cpuPriv /= count;

             var hourSample = new CpuStat
             {
                 SampleID = index,
                 Idle = clamp(0, 100, (int)(100 - (cpuUser + cpuPriv))),
                 Priv = cpuPriv,
                 User = cpuUser,
             };
             to.Enqueue(hourSample);
        }
コード例 #4
0
        public void Update(object sender)
        {
            lock (_lock)
            {
                historyIndex++;

                var usr = _cpuUserCounter.NextValue();
                var priv = _cpuPrivCounter.NextValue();
                var cs = new CpuStat
                {
                    SampleID = historyIndex,
                    Idle = clamp(0, 100, (int)(100 - (usr + priv))),
                    Priv = (int)priv,
                    User = (int)usr,
                };
                history.Enqueue(cs);

                if (historyIndex >= 6 && (historyIndex % 6) == 0)
                {
                    historyIndexHour++;
                    AddHistoryItem(history, 6, historyHour, historyIndexHour);
                }
                if (historyIndex >= 144 && (historyIndex % 144) == 0)
                {
                    historyIndexDay++;
                    AddHistoryItem(history, 144, historyDay, historyIndexDay);
                }
            }
        }