public void AddHistoryItem(FixedSizeQueue <SensorStatQueue> from, int count, FixedSizeQueue <SensorStatQueue> to, long index)
        {
            if (from.Count() < count)
            {
                return;
            }

            float value = 0;

            for (int i = 1; i <= count; i++)
            {
                SensorStatQueue sample = from.ElementAt(history.Count() - i);
                value += sample.Value;
            }
            value /= count;

            var hourSample = new SensorStatQueue
            {
                SampleID = index,
                Value    = value
            };

            to.Enqueue(hourSample);
        }
        public string samples(int mode, int index)
        {
            if (mode > 2)
            {
                return("");
            }

            var data = new StringBuilder();

            lock (_lock)
            {
                foreach (var s in _sensors)
                {
                    FixedSizeQueue <SensorStatQueue> from = s.HistoryForMode(mode);

                    data.Append(string.Format("<item i=\"0\" n=\"{0}\" type=\"{1}\" uuid=\"{2}\">", s.name, s.type, s.name));
                    var sensorSample = from.Last();
                    if (index == -1)
                    {
                        if (sensorSample != null)
                        {
                            data.Append(string.Format("<s id=\"{0}\" v=\"{1}\"></s>", sensorSample.SampleID, sensorSample.Value));
                        }
                    }
                    else
                    {
                        foreach (var sample in from.Where(c => c.SampleID > index))
                        {
                            data.Append(string.Format("<s id=\"{0}\" v=\"{1}\"></s>", sample.SampleID, sample.Value));
                        }
                    }
                    data.Append("</item>");
                }
            }
            return(data.ToString());
        }
示例#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
        private void AddHistoryItem(FixedSizeQueue <DiskActivityStatQueue> from, int count, FixedSizeQueue <DiskActivityStatQueue> to, long index)
        {
            if (from.Count() < count)
            {
                return;
            }
            double read  = 0;
            double write = 0;

            for (int i = 1; i <= count; i++)
            {
                DiskActivityStatQueue sample = from.ElementAt(history.Count() - i);
                read  += sample.read;
                write += sample.write;
            }
            read  /= count;
            write /= count;

            var hourSample = new DiskActivityStatQueue
            {
                SampleID  = index,
                read      = read,
                write     = write,
                readIOPS  = 0,
                writeIOPS = 0
            };

            to.Enqueue(hourSample);
        }
        public void AddHistoryItem(FixedSizeQueue <NetworkStatQueue> from, int count, FixedSizeQueue <NetworkStatQueue> to, long index)
        {
            if (from.Count() < count)
            {
                return;
            }
            double down = 0;
            double up   = 0;

            for (int i = 1; i <= count; i++)
            {
                NetworkStatQueue sample = from.ElementAt(history.Count() - i);
                down += sample.Download;
                up   += sample.Upload;
            }
            down /= count;
            up   /= count;

            var hourSample = new NetworkStatQueue
            {
                SampleID = index,
                Download = down,
                Upload   = up
            };

            to.Enqueue(hourSample);
        }