예제 #1
0
        private static void ValidateCounterExists(string path)
        {
            if (knownCounterPaths.ContainsKey(path))
            {
                return;
            }
            if (File.Exists(path))
            {
                try
                {
                    knownCounterPaths.Add(path, Whipser.Info(path));
                    return;
                }
                catch (CorruptWhisperFileException)
                {
                    File.Delete(path);
                    // corrupt?
                }
            }
            var retention = new List <ArchiveInfo>()
            {
                new ArchiveInfo(10, 180), // 10 seconds * 180 points = 30 min = 2.9 kb
                new ArchiveInfo(60, 60),  // 60 seconds (1min) * 60 points = 1 hr = 3.9 kb
            };

            Whipser.Create(path, retention);
            knownCounterPaths.Add(path, Whipser.Info(path));
        }
예제 #2
0
        public void fetch()
        {
            Assert.Throws <FileNotFoundException>(() => Whipser.Fetch("does_not_exist", 0));

            var retention = new List <ArchiveInfo>()
            {
                new ArchiveInfo(1, 60), new ArchiveInfo(60, 60), new ArchiveInfo(3600, 24), new ArchiveInfo(86400, 365)
            };

            Whipser.Create(db, retention);

            Assert.Throws <InvalidTimeIntervalException>(() => Whipser.Fetch(db, DateTime.Now.Ticks, DateTime.Now.Ticks - 60000));

            var fetch = Whipser.Fetch(db, 0).Value;

            // check time range
            Assert.AreEqual(retention.Last().Retention, fetch.TimeInfo.UntilInterval - fetch.TimeInfo.FromInterval);

            // check number of points
            Assert.AreEqual(retention.Last().Points, fetch.ValueList.Count);

            // check step size
            Assert.AreEqual(retention.Last().SecondsPerPoint, fetch.TimeInfo.Step);

            RemoveDb();
        }
예제 #3
0
        public void create()
        {
            var retention = new List <ArchiveInfo>()
            {
                new ArchiveInfo(1, 60), new ArchiveInfo(60, 60)
            };

            // check if invalid configuration fails successfully
            Assert.Throws <InvalidConfigurationException>(() => Whipser.Create(db, new List <ArchiveInfo>()));

            // create a new db with a valid configuration
            Whipser.Create(db, retention);

            // attempt to create another db in the same file, this should fail
            Assert.Throws <InvalidConfigurationException>(() => Whipser.Create(db, retention));

            var info = Whipser.Info(db);

            Assert.AreEqual(retention.Max(x => x.Retention), info.MaxRetention);
            Assert.AreEqual(AggregationType.Average, info.AggregationType);
            Assert.AreEqual(0.5f, info.xFilesFactor);

            Assert.AreEqual(retention.Count, info.ArchiveList.Count);
            Assert.AreEqual(retention[0].SecondsPerPoint, info.ArchiveList[0].SecondsPerPoint);
            Assert.AreEqual(retention[0].Points, info.ArchiveList[0].Points);
            Assert.AreEqual(retention[1].SecondsPerPoint, info.ArchiveList[1].SecondsPerPoint);
            Assert.AreEqual(retention[1].Points, info.ArchiveList[1].Points);

            RemoveDb();
        }
예제 #4
0
        public void calc_database_size()
        {
            // create a new db with a valid configuration
            var retention = new List <ArchiveInfo>()
            {
                new ArchiveInfo(1, 60), new ArchiveInfo(60, 60), new ArchiveInfo(3600, 24), new ArchiveInfo(86400, 365)
            };

            Whipser.Create(db, retention);
            Debug.WriteLine("File Size = ", new FileInfo(db).Length);
            RemoveDb();
        }
예제 #5
0
        private PointPair[] update(string wsp = null, List <ArchiveInfo> schema = null)
        {
            wsp    = wsp ?? db;
            schema = schema ?? new List <ArchiveInfo>()
            {
                new ArchiveInfo(1, 20)
            };

            var numDataPoints = schema[0].Points;

            Whipser.Create(wsp, schema);

            var tn   = DateTime.UtcNow.ToUnixTime() - numDataPoints;
            var data = new PointPair[numDataPoints];

            for (int i = 0; i < numDataPoints; i++)
            {
                //data[i] = new PointPair(tn + 1 + i, i * 10);
                data[i] = new PointPair(tn + 1 + i, random.Next(1000) * 10);
            }

            //Whipser.Update(wsp, data[0].value, data[0].Timestamp);
            //Whipser.UpdateMany(wsp, data);
            foreach (var item in data)
            {
                Whipser.Update(wsp, item.value, item.Timestamp);
            }

            // add more fake data
            Thread.Sleep(1000);
            Whipser.Update(wsp, random.Next(1000) * 10);
            Thread.Sleep(1000);
            Whipser.Update(wsp, random.Next(1000) * 10);

            return(data);
        }