Exemple #1
0
        private void LoadDatabaseView(RrdDef rrDef, DateTime lastUpdated, double lastValue)
        {
            dataSourceListView.Columns.Clear();
            dataSourceListView.Columns.Add("Name");
            dataSourceListView.Columns.Add("Value", 200);

            dataSourceListView.Items.Clear();
            if (rrDef == null)
            {
                return;
            }
            ListViewItem lvi = dataSourceListView.Items.Add("Tick");

            lvi.SubItems.Add(rrDef.getStepTimeSpan().ToString());
            lvi = dataSourceListView.Items.Add(dataSourceNodesName);
            lvi.SubItems.Add(rrDef.getDsCount().ToString());
            lvi = dataSourceListView.Items.Add(archiveNodesName);
            lvi.SubItems.Add(rrDef.getArcCount().ToString());
            lvi = dataSourceListView.Items.Add("Estimated size");
            lvi.SubItems.Add(rrDef.getEstimatedSize().ToString());
            if (lastUpdated != DateTime.MinValue)
            {
                lvi = dataSourceListView.Items.Add("Last update time");
                lvi.SubItems.Add(lastUpdated.ToString());
            }
            lvi = dataSourceListView.Items.Add("Last Value");
            lvi.SubItems.Add(lastValue.ToString());
        }
Exemple #2
0
        public DatabaseData SetDatabaseAsEdit(DatabaseData srcDatabaseData)
        {
            if (!databases.ContainsKey(srcDatabaseData.Definition.Path))
            {
                throw new ApplicationException("Database not open in model");
            }

            // Make a clone of the source database definition and give it a new name
            RrdDb rrdDb = new RrdDb(srcDatabaseData.Definition.Path, true);

            databaseDefinition = rrdDb.getRrdDef();
            rrdDb.close();

            DatabaseData dstDatabaseData = new DatabaseData();

            dstDatabaseData.SourceDatabasePath = srcDatabaseData.Definition.Path;
            dstDatabaseData.Saved           = false;
            dstDatabaseData.Definition      = databaseDefinition;
            dstDatabaseData.Definition.Path = Path.GetFileNameWithoutExtension(databaseDefinition.Path) + "_";
            dstDatabaseData.LastUpdated     = dstDatabaseData.Definition.getStartDateTime();
            dstDatabaseData.LastValue       = double.NaN;
            DatabaseDirty       = true;
            EditingDatabaseData = dstDatabaseData;
            databases.Add(dstDatabaseData.Definition.Path, dstDatabaseData);
            return(dstDatabaseData);
        }
Exemple #3
0
        public RrdDef CreateDatabaseDef()
        {
            long     start;
            DateTime startDateTime;
            string   startOption = getOptionValue("b", "start", DEFAULT_START);

            try
            {
                if (DateTime.TryParse(startOption, out startDateTime))
                {
                    start = Util.getTimestamp(startDateTime);
                }
                else
                {
                    start = long.Parse(startOption);
                }
            }
            catch (FormatException ex)
            {
                throw new ApplicationException("Bad date format:[" + startOption + "]." + ex.Message);
            }

            String stepOption = getOptionValue("s", "step", DEFAULT_STEP);
            long   step       = long.Parse(stepOption);

            String[] words = getRemainingWords();
            if (words.Length < 3)
            {
                throw new ArgumentException("To few arguments! Use: create name DS:name:heartbeat:min:max [RRAdef]");
            }
            if (words[0] != "create")
            {
                throw new ArgumentException("Wrong command format! Use: create name DS:name:heartbeat:min:max [RRAdef]");
            }
            RrdDef rrdDef = new RrdDef(words[1], start, step);

            for (int i = 2; i < words.Length; i++)
            {
                if (words[i].StartsWith("DS:"))
                {
                    rrdDef.addDatasource(parseDef(words[i]));
                }
                else if (words[i].StartsWith("RRA:"))
                {
                    rrdDef.addArchive(parseRra(words[i]));
                }
                else
                {
                    throw new ArgumentException("Invalid rrdcreate syntax. Not a DSDef or RRADef  " + words[i] + "\nUse: create name DS:name:heartbeat:min:max [RRAdef]");
                }
            }
            if (rrdDef.getDsCount() == 0)
            {
                throw new ArgumentException("No a Data source defined.\nUse: create name DS:name:heartbeat:min:max [RRAdef]");
            }

            return(rrdDef);
        }
Exemple #4
0
 internal Header(RrdDb parentDb, RrdDef rrdDef)
 {
     this.parentDb = parentDb;
     signature = new RrdString(SIGNATURE, this);
     step = new RrdLong(rrdDef.Step, this);
     dsCount = new RrdInt(rrdDef.DsCount, this);
     arcCount = new RrdInt(rrdDef.ArcCount, this);
     lastUpdateTime = new RrdLong(rrdDef.StartTime, this);
 }
Exemple #5
0
 public DatabaseData CreateDatabase(RrdDef rrdDef)
 {
     EditingDatabaseData                    = new DatabaseData();
     EditingDatabaseData.Definition         = rrdDef;
     EditingDatabaseData.LastUpdated        = rrdDef.getStartDateTime();
     EditingDatabaseData.LastValue          = double.NaN;
     EditingDatabaseData.SourceDatabasePath = null;
     DatabaseDirty = true;
     return(EditingDatabaseData);
 }
Exemple #6
0
        public RrdDb GetDb()
        {
            const int heartBeat = 5 * 60;             // * 1000

            string _dbPath = Settings.Default.GetAppDataPath() + "xgsnapshots.db";

            try
            {
                var db           = new RrdDb(_dbPath);
                var sourcesToAdd = new HashSet <int>();

                for (int a = 0; a <= 29; a++)
                {
                    if (!db.containsDs(a + ""))
                    {
                        sourcesToAdd.Add(a);
                    }
                }

                if (sourcesToAdd.Count > 0)
                {
                    db.close();
                    foreach (int a in sourcesToAdd)
                    {
                        var dsDef = new DsDef(a + "", DsTypes.DT_GAUGE, heartBeat * 2, 0, Double.MaxValue);
                        RrdToolkit.addDatasource(_dbPath, _dbPath + ".new", dsDef);
                        FileSystem.DeleteFile(_dbPath);
                        FileSystem.MoveFile(_dbPath + ".new", _dbPath);
                    }
                    db = new RrdDb(_dbPath);
                }

                return(db);
            }
            catch (FileNotFoundException)
            {
                var rrdDef = new RrdDef(_dbPath, heartBeat);
                for (int a = 0; a <= 29; a++)
                {
                    rrdDef.addDatasource(a + "", DsTypes.DT_GAUGE, heartBeat * 2, 0, Double.MaxValue);
                }

                rrdDef.addArchive(ConsolFuns.CF_AVERAGE, 0.5, 1, 12 * 24);                 // one day > 1 step = 5 minutes, 12 times per hour * 24 hours
                rrdDef.addArchive(ConsolFuns.CF_AVERAGE, 0.5, 12, 24 * 7);                 // one week > 12 steps = 1 hour, 24 times per day * 7 days
                rrdDef.addArchive(ConsolFuns.CF_AVERAGE, 0.5, 4 * 12, 6 * 31);             // one month > 4 * 12 steps = 4 hours, 6 times per day * 31 days
                rrdDef.addArchive(ConsolFuns.CF_AVERAGE, 0.5, 2 * 24 * 12, 183);           // one year > 2 * 24 * 12 steps = 2 days, 183 days

                try
                {
                    new RrdDb(rrdDef).close();
                }
                catch (NullReferenceException) {}
                return(new RrdDb(_dbPath));
            }
        }
Exemple #7
0
        public RrdDb GetDb()
        {
            const int heartBeat = 5 * 60; // * 1000

            string _dbPath = Settings.Default.GetAppDataPath() + "xgsnapshots.db";
            try
            {
                var db = new RrdDb(_dbPath);
                var sourcesToAdd = new HashSet<int>();

                for (int a = 0; a <= 29; a++)
                {
                    if (!db.containsDs(a + ""))
                    {
                        sourcesToAdd.Add(a);
                    }
                }

                if (sourcesToAdd.Count > 0)
                {
                    db.close();
                    foreach (int a in sourcesToAdd)
                    {
                        var dsDef = new DsDef(a + "", DsTypes.DT_GAUGE, heartBeat * 2, 0, Double.MaxValue);
                        RrdToolkit.addDatasource(_dbPath, _dbPath + ".new", dsDef);
                        FileSystem.DeleteFile(_dbPath);
                        FileSystem.MoveFile(_dbPath + ".new", _dbPath);
                    }
                    db = new RrdDb(_dbPath);
                }

                return db;
            }
            catch (FileNotFoundException)
            {
                var rrdDef = new RrdDef(_dbPath, heartBeat);
                for (int a = 0; a <= 29; a++)
                {
                    rrdDef.addDatasource(a + "", DsTypes.DT_GAUGE, heartBeat * 2, 0, Double.MaxValue);
                }

                rrdDef.addArchive(ConsolFuns.CF_AVERAGE, 0.5, 1, 12 * 24); // one day > 1 step = 5 minutes, 12 times per hour * 24 hours
                rrdDef.addArchive(ConsolFuns.CF_AVERAGE, 0.5, 12, 24 * 7); // one week > 12 steps = 1 hour, 24 times per day * 7 days
                rrdDef.addArchive(ConsolFuns.CF_AVERAGE, 0.5, 4 * 12, 6 * 31); // one month > 4 * 12 steps = 4 hours, 6 times per day * 31 days
                rrdDef.addArchive(ConsolFuns.CF_AVERAGE, 0.5, 2 * 24 * 12, 183); // one year > 2 * 24 * 12 steps = 2 days, 183 days

                try
                {
                    new RrdDb(rrdDef).close();
                }
                catch (NullReferenceException) {}
                return new RrdDb(_dbPath);
            }
        }
        public void SetDatabaseDefinition(string command)
        {
            RrdDbParser parser = new RrdDbParser(command);
            RrdDef      rrdDef = parser.CreateDatabaseDef();

            if (model.DatabaseExist(rrdDef.Path))
            {
                throw new ApplicationException("Datbase " + rrdDef.Path + " already exist!");
            }
            model.CreateDatabase(rrdDef);
        }
        private void LoadTree(DatabaseData databaseData)
        {
            RrdDef   databaseDefinition = databaseData.Definition;
            string   databaseName       = Path.GetFileNameWithoutExtension(databaseDefinition.Path);
            TreeNode databaseNode;

            TreeNode[] databaseNodes = rrdDbTreeView.Nodes.Find(databaseDefinition.Path, true);
            if (databaseNodes.Length == 0)
            {
                databaseNode = rrdDbTreeView.Nodes.Add(databaseDefinition.Path, databaseName);
                if (!databaseData.Saved)
                {
                    databaseNode.Text += "*";
                }
            }
            else
            {
                databaseNode = databaseNodes[0];
                if (!databaseData.Saved &&
                    !databaseNode.Text.Contains("*"))
                {
                    databaseNode.Text += "*";
                }
            }


            databaseNode.Tag = databaseData;

            databaseNode.Nodes.Clear();
            var datasources = databaseNode.Nodes.Add(dataSourceNodesName, dataSourceNodesName);

            foreach (var datasource in databaseDefinition.getDsDefs())
            {
                TreeNode datasourceNode = datasources.Nodes.Add(datasource.DsName);
                datasourceNode.Tag = datasource;
                foreach (var arcDef in databaseDefinition.getArcDefs())
                {
                    string nodeText = string.Format("RRA:{0}:{1}:{2}:{3}", arcDef.getConsolFun().Name,
                                                    arcDef.Xff, arcDef.Steps, arcDef.Rows);
                    var archiveNode = datasourceNode.Nodes.Add(nodeText);
                    archiveNode.Tag = arcDef;
                }
            }
            databaseNode.Nodes.Add(archiveNodesName, archiveNodesName);
        }
Exemple #10
0
        private void LoadTree(RrdDef databaseDefinition)
        {
            rrdDbTreeView.Nodes.Clear();

            var databaseNode = rrdDbTreeView.Nodes.Add("databasenode", Path.GetFileNameWithoutExtension(databaseDefinition.Path));
            var datasources  = databaseNode.Nodes.Add(dataSourceNodesName, dataSourceNodesName);

            foreach (var datasource in databaseDefinition.getDsDefs())
            {
                var datasourceNode = datasources.Nodes.Add(datasource.DsName);
                datasourceNode.Tag = datasource;
                foreach (var arcDef in databaseDefinition.getArcDefs())
                {
                    string nodeText = string.Format("RRA:{0}:{1}:{2}:{3}", arcDef.getConsolFun().Name,
                                                    arcDef.Xff, arcDef.Steps, arcDef.Rows);
                    var archiveNode = datasourceNode.Nodes.Add(nodeText);
                    archiveNode.Tag = arcDef;
                }
            }
            databaseNode.Nodes.Add(archiveNodesName, archiveNodesName);
        }
Exemple #11
0
        public void CreateDatabase(string databasePath)
        {
            if (model.EditingDatabaseData == null)
            {
                throw new ApplicationException("Not in edit mode");
            }

            string oldpath     = model.EditingDatabaseData.Definition.Path;
            RrdDb  srcDatabase = null;

            if (!string.IsNullOrEmpty(model.EditingDatabaseData.SourceDatabasePath))
            {
                srcDatabase = new RrdDb(model.EditingDatabaseData.SourceDatabasePath);
            }
            RrdDef rrdDef = model.EditingDatabaseData.Definition;

            rrdDef.setPath(databasePath);
            RrdDb dstDatabase = new RrdDb(rrdDef);

            if (srcDatabase != null)
            {
                srcDatabase.copyStateTo(dstDatabase);
            }

            if (srcDatabase != null)
            {
                srcDatabase.close();
            }
            dstDatabase.close();
            model.DatabaseDirty       = false;
            model.EditingDatabaseData = null;
            DatabaseData databaseData = model.AddDatabase(databasePath);

            rrdDbForm.SetDatabaseDefinition(databaseData);

            TreeForm.RemoveDatabaseDefinition(oldpath);
            TreeForm.SetDatabaseDefinition(databaseData);
            TreeForm.SetEditMode(false);
        }
Exemple #12
0
 public void SetDatabaseData(RrdDef rrdDef, DateTime lastUpdated, double lastValue)
 {
     LoadDatabaseView(rrdDef, lastUpdated, lastValue);
 }
Exemple #13
0
        public void Test3()
        {
            long start = Util.Time, end = start + 300 * 300;
            string rrdFile = "test3.rrd";
            string pngFile = "test3.png";

            Console.WriteLine("Beginning Test3...");
            RrdDef rrdDef = new RrdDef(rrdFile, start - 1, 300);
            rrdDef.AddDatasource("a", "GAUGE", 600, Double.NaN, Double.NaN);
            rrdDef.AddArchive("AVERAGE", 0.5, 1, 300);
            rrdDef.AddArchive("MIN", 0.5, 12, 300);
            rrdDef.AddArchive("MAX", 0.5, 12, 300);
            RrdDb rrdDb = new RrdDb(rrdDef);
            // update
            for(long t = start; t <  end; t += 300)
            {
                Sample sample = rrdDb.CreateSample(t);
                sample.SetValue("a", Math.Sin(t / 3000.0) * 50 + 50);
                sample.Update();
            }
            rrdDb.Close();
            // graph
            RrdGraphDef gDef = new RrdGraphDef();
            gDef.SetTimePeriod(start, start + 86400);
            gDef.Title = "RRDTool's MINMAX.pl demo";
            gDef.TimeAxisLabel = "time";
            gDef.Datasource("a", rrdFile, "a", "AVERAGE");
            gDef.Datasource("b", rrdFile, "a", "MIN");
            gDef.Datasource("c", rrdFile, "a", "MAX");
            gDef.Area("a", Color.LightBlue, "real");
            gDef.Line("b", Color.Blue, "min");
            gDef.Line("c", Color.Lime, "max");
            RrdGraph graph = new RrdGraph(gDef);
            graph.SaveAsPNG(pngFile, 450, 0);
            Console.WriteLine("Test3 Complete.");
        }
Exemple #14
0
        public void StressTest()
        {
            string RRD_PATH = "stress.rrd";
            long RRD_START = 946710000L;
            long RRD_STEP = 30;
            string RRD_DATASOURCE_NAME = "T";
            int RRD_DATASOURCE_COUNT = 6;
            long TIME_START = 1060142010L;
            long TIME_END = 1080013472L;
            string PNG_PATH = "stress.png";
            int PNG_WIDTH = 400;
            int PNG_HEIGHT = 250;

            //Stress test
            DateTime testBegin = DateTime.UtcNow;
            printLapTime("Beginning Stress Test at " + testBegin.ToString());
            // create RRD database
            printLapTime("Creating RRD definition");
            RrdDef def = new RrdDef(RRD_PATH);
            def.StartTime = RRD_START;
            def.Step = RRD_STEP;
            for(int i = 0; i < RRD_DATASOURCE_COUNT; i++)
            {
                def.AddDatasource(RRD_DATASOURCE_NAME + i, "GAUGE", 90, -60, 85);
            }
            def.AddArchive("LAST", 0.5, 1, 5760);
            def.AddArchive("MIN", 0.5, 1, 5760);
            def.AddArchive("MAX", 0.5, 1, 5760);
            def.AddArchive("AVERAGE", 0.5, 5, 13824);
            def.AddArchive("MIN", 0.5, 5, 13824);
            def.AddArchive("MAX", 0.5, 5, 13824);
            def.AddArchive("AVERAGE", 0.5, 60, 16704);
            def.AddArchive("MIN", 0.5, 60, 16704);
            def.AddArchive("MAX", 0.5, 60, 16704);
            def.AddArchive("AVERAGE", 0.5, 1440, 50000);
            def.AddArchive("MIN", 0.5, 1440, 50000);
            def.AddArchive("MAX", 0.5, 1440, 50000);
            printLapTime("Definition created, creating RRD file");

            RrdDb rrd = new RrdDb(def);
            printLapTime("RRD file created: " + RRD_PATH);

            FileStream fs = File.OpenRead("stress-test.txt");
            byte[] memBuffer = new byte[fs.Length];
            fs.Read(memBuffer, 0, memBuffer.Length);
            fs.Close();
            StreamReader memoryReader = new StreamReader(new MemoryStream(memBuffer));

            //StreamReader diskReader = File.OpenText("stress-test.txt");
            //string allLines = diskReader.ReadToEnd();
            //diskReader.Close();
            //StringReader memoryReader = new StringReader(allLines);

            //StreamReader memoryReader = File.OpenText("stress-test.txt");

            printLapTime("Input data loaded into memory, processing data");

            int count = 0;
            DateTime updateStart = DateTime.UtcNow;
            string line;

            while ((line = memoryReader.ReadLine()) != null)
            {
                Sample sample = rrd.CreateSample();
                try
                {
                    sample.SetAndUpdate(line);
                    if(++count % 1000 == 0)
                    {
                        DateTime now = DateTime.UtcNow;
                        long speed = (long)(count * 1000.0 / (Util.TicksToMillis(now.Ticks) - Util.TicksToMillis(updateStart.Ticks)));
                        printLapTime(count + " samples stored, " + speed + " updates/sec");
                    }
                }
                catch(RrdException)
                {
                    printLapTime("RRD ERROR: " + line);
                }
            }
            memoryReader.Close();
            rrd.Close();

            printLapTime("FINISHED: " + count + " samples stored");

            // GRAPH
            printLapTime("Creating composite graph definition");
            RrdGraphDef gdef = new RrdGraphDef(TIME_START, TIME_END);
            gdef.Title = "Temperatures";
            gdef.VerticalLabel = "Fahrenheit";
            Color [] colors =  {Color.Red, Color.Lime, Color.Blue, Color.Magenta,Color.Cyan, Color.Orange };
            // datasources
            for(int i = 0; i < RRD_DATASOURCE_COUNT; i++)
            {
                string name = RRD_DATASOURCE_NAME + i;
                gdef.Datasource(name, RRD_PATH, name, "AVERAGE");
            }
            // lines
            for(int i = 0; i < RRD_DATASOURCE_COUNT; i++)
            {
                string name = RRD_DATASOURCE_NAME + i;
                gdef.Line(name, colors[i], name);
            }
            gdef.Comment("@c");
            gdef.Comment("\nOriginal data provided by diy-zoning.sf.net@c");
            printLapTime("Graph definition created");
            RrdGraph g = new RrdGraph(gdef);
            g.SaveAsPNG(PNG_PATH, PNG_WIDTH, PNG_HEIGHT);
            printLapTime("Graph saved: " + PNG_PATH);
            DateTime testEnd = DateTime.UtcNow;
            printLapTime("Finished at " + testEnd.ToString());
            Console.WriteLine("Total Time: " + testEnd.Subtract(testBegin).ToString());
        }
Exemple #15
0
        public void Test2()
        {
            Console.WriteLine("Beginning Test2...");
            RrdDef rrdDef = new RrdDef("test2.rrd");
            rrdDef.StartTime = 920804400L;
            rrdDef.AddDatasource("speed", "COUNTER", 600, Double.NaN, Double.NaN);
            rrdDef.AddArchive("AVERAGE", 0.5, 1, 24);
            rrdDef.AddArchive("AVERAGE", 0.5, 6, 10);
            RrdDb rrdDb = new RrdDb(rrdDef);
            rrdDb.Close();

            rrdDb = new RrdDb("test2.rrd");
            Sample sample = rrdDb.CreateSample();
            sample.SetAndUpdate("920804700:12345");
            sample.SetAndUpdate("920805000:12357");
            sample.SetAndUpdate("920805300:12363");
            sample.SetAndUpdate("920805600:12363");
            sample.SetAndUpdate("920805900:12363");
            sample.SetAndUpdate("920806200:12373");
            sample.SetAndUpdate("920806500:12383");
            sample.SetAndUpdate("920806800:12393");
            sample.SetAndUpdate("920807100:12399");
            sample.SetAndUpdate("920807400:12405");
            sample.SetAndUpdate("920807700:12411");
            sample.SetAndUpdate("920808000:12415");
            sample.SetAndUpdate("920808300:12420");
            sample.SetAndUpdate("920808600:12422");
            sample.SetAndUpdate("920808900:12423");
            rrdDb.Close();

            RrdGraphDef graphDef = new RrdGraphDef();
            graphDef.SetTimePeriod(920804400L, 920808000L);
            graphDef.Datasource("myspeed", "test2.rrd", "speed", "AVERAGE");
            graphDef.Datasource("realspeed", "myspeed,1000,*");
            graphDef.Line("realspeed", Color.Red, "speed", 2);
            RrdGraph graph = new RrdGraph(graphDef);
            graph.SaveAsPNG("test2a.png", 400, 100);

            graphDef = new RrdGraphDef();
            graphDef.SetTimePeriod(920804400L, 920808000L);
            graphDef.VerticalLabel = "km/h";
            graphDef.Overlay = "Sunset.jpg";
            graphDef.Datasource("myspeed", "test2.rrd", "speed", "AVERAGE");
            graphDef.Datasource("kmh", "myspeed,3600,*");
            graphDef.Datasource("fast", "kmh,100,GT,kmh,0,IF");
            graphDef.Datasource("good", "kmh,100,GT,0,kmh,IF");
            graphDef.Area("good", Color.Lime, "Good speed");
            graphDef.Area("fast", Color.Red, "Too fast");
            graphDef.Hrule(100, Color.Blue, "Maximum allowed");
            graph = new RrdGraph(graphDef);
            graph.SaveAsPNG("test2b.png", 400, 100);
            Console.WriteLine("Test2 Complete.");
        }
Exemple #16
0
        public void Test1()
        {
            Console.WriteLine("Beginning Test1...");
            RrdDef rrdDef = new RrdDef("test1.rrd");
            rrdDef.StartTime = 978300900L;
            rrdDef.AddDatasource("a", "COUNTER", 600, Double.NaN, Double.NaN);
            rrdDef.AddDatasource("b", "GAUGE", 600, Double.NaN, Double.NaN);
            rrdDef.AddDatasource("c", "DERIVE", 600, Double.NaN, Double.NaN);
            rrdDef.AddDatasource("d", "ABSOLUTE", 600, Double.NaN, Double.NaN);
            rrdDef.AddArchive("AVERAGE", 0.5, 1, 10);
            RrdDb rrdDb = new RrdDb(rrdDef);
            Sample sample = rrdDb.CreateSample();
            sample.SetAndUpdate("978301200:300:1:600:300");
            sample.SetAndUpdate("978301500:600:3:1200:600");
            sample.SetAndUpdate("978301800:900:5:1800:900");
            sample.SetAndUpdate("978302100:1200:3:2400:1200");
            sample.SetAndUpdate("978302400:1500:1:2400:1500");
            sample.SetAndUpdate("978302700:1800:2:1800:1800");
            sample.SetAndUpdate("978303000:2100:4:0:2100");
            sample.SetAndUpdate("978303300:2400:6:600:2400");
            sample.SetAndUpdate("978303600:2700:4:600:2700");
            sample.SetAndUpdate("978303900:3000:2:1200:3000");
            rrdDb.Close();

            RrdGraphDef graphDef = new RrdGraphDef();
            graphDef.SetTimePeriod(978300600L, 978304200L);
            graphDef.Title = "This is a cool title";
            graphDef.VerticalLabel = "Vertical Label";
            graphDef.Datasource("linea", "test1.rrd", "a", "AVERAGE");
            graphDef.Datasource("lineb", "test1.rrd", "b", "AVERAGE");
            graphDef.Datasource("linec", "test1.rrd", "c", "AVERAGE");
            graphDef.Datasource("lined", "test1.rrd", "d", "AVERAGE");
            graphDef.Line("linea", Color.Red,  "Line A", 3);
            graphDef.Line("lineb", Color.Lime,  "Line B", 3);
            graphDef.Line("linec", Color.Blue,  "Line C", 3);
            graphDef.Line("lined", Color.Cyan,  "Line D", 3);
            RrdGraph graph = new RrdGraph(graphDef);
            graph.SaveAsPNG("test1.png", 400, 400);
            Console.WriteLine("Test1 Complete.");
        }
Exemple #17
0
 public RrdDb RequestRrdDb(RrdDef rrdDef)
 {
     string path = rrdDef.Path;
     string keypath = GetCanonicalPath(path);
     ValidateInactive(keypath);
     RrdDb rrdDb = new RrdDb(rrdDef);
     Put(keypath, rrdDb);
     return rrdDb;
 }
Exemple #18
0
        public void JonasTest2()
        {
            UInt32 start_time = 1370000000; // 31th may 2013, 11:33:20
            UInt32 end_time = start_time + 300 * 300;
            RrdDef rrdDef = new RrdDef("jonas.rrd");
            rrdDef.StartTime = start_time;
            rrdDef.AddDatasource("battery", "GAUGE", 300, 1.0, 5.0); // Five minutes
            rrdDef.AddArchive("LAST", 0.5, 1, 576);         //
            rrdDef.AddArchive("MIN", 0.5, 1, 576);          // 24 hours average, 2.5 minutes resolution
            rrdDef.AddArchive("MAX", 0.5, 1, 576);          // 24 hours average, 2.5 minutes resolution
            rrdDef.AddArchive("AVERAGE", 0.5, 6, 672);     // 7 days average, 15 min resolution
            rrdDef.AddArchive("MIN", 0.5, 6, 672);         // 7 days average, 15 min resolution
            rrdDef.AddArchive("MAX", 0.5, 6, 672);         // 7 days average, 15 min resolution
            rrdDef.AddArchive("AVERAGE", 0.5, 24, 87600);   // 10 year average, 1 hour resolution
            rrdDef.AddArchive("MIN", 0.5, 24, 87600);       // 10 year average, 1 hour resolution
            rrdDef.AddArchive("MAX", 0.5, 24, 87600);       // 10 year average, 1 hour resolution
            RrdDb db = new RrdDb(rrdDef);
            db.Close();

            RrdDb rrd = new RrdDb("jonas.rrd");
            Random rand = new Random();
            //Sample s = rrd.CreateSample();
            // update
            for(long t = start_time + 300; t <= end_time; t += 300)
            {
                double r = (double)rand.Next(1, 6);
                //s.SetAndUpdate(String.Format("{0}:{1}", t, r));
                Sample sample = rrd.CreateSample(t);
                sample.SetValue("battery", (double)r);
                sample.Update();
                Console.WriteLine(r);
            }

            FetchRequest fr = rrd.CreateFetchRequest("LAST", start_time, end_time - 300);
            FetchData fd = fr.FetchData();
            for (int i = 0; i < fd.RowCount; i++)
            {
                FetchPoint fp = fd.GetRow(i);
                Console.WriteLine("{0}: {1}", fp.Time, fp.Values[0]);
            }

            rrd.Close();

            // Create new graph for the last 12 hours
            RrdGraphDef gdef = new RrdGraphDef(new DateTime(2013, 05, 31, 12, 00, 00), new DateTime(2013, 05, 31, 18, 59, 59));
            gdef.Title = "Battery voltage";
            gdef.VerticalLabel = "U (V)";
            gdef.SetValueAxis(1.0, 1.0);
            gdef.SetGridRange(1.000, 5.000, true);
            gdef.Datasource("vbat", "jonas.rrd", "battery", "LAST");
            //gdef.Datasource("vbat_avg", "jonas.rrd", "battery", "AVERAGE");
            gdef.Datasource("vbat_trend", "vbat,900,TREND");
            gdef.Line("vbat", System.Drawing.Color.Green, "Battery voltage", 1);
            //gdef.Line("vbat_avg", System.Drawing.Color.Red, "Average over 15 min", 1);
            gdef.Line("vbat_trend", System.Drawing.Color.Red, "Trend over 15 min", 1);
            gdef.Gprint("vbat", "LAST", "Current: @2V@r");
            gdef.Gprint("vbat", "AVERAGE", "Average: @2V@r");
            gdef.Gprint("vbat", "MAX", "Max: @2V@r");
            gdef.Gprint("vbat", "MIN", "Min: @2V@r");
            RrdGraph graph = new RrdGraph(gdef);
            graph.SaveAsPNG("battery2_2h.png", 700, 300);
        }
Exemple #19
0
            private void CreateOne(CoCEnum.EventNotify id)
            {
                string path = CoCRrdUtil.getRrdDbPath(id, this._parent._rootpath);

                if ((string.IsNullOrWhiteSpace(path)) || (File.Exists(path)))
                {
                    return;
                }
                stCoCRrdData data = this._data.Where(o => (o.Key == id)).Select(o =>
                {
                    return((stCoCRrdData)o.Value);
                }).FirstOrDefault();

                if (data == null)
                {
                    return;
                }

                RrdDef rrdDef = null;
                RrdDb  rrdDb  = null;

                try
                {
                    rrdDef           = new RrdDef(path);
                    rrdDef.StartTime = this._startTime;
                    rrdDef.Step      = (this._periodTime * 60);

                    rrdDef.AddDatasource("a", data.type, (rrdDef.Step * 2), Double.NaN, Double.NaN);

                    rrdDef.AddArchive("AVERAGE", 0, 1, 1);
                    rrdDef.AddArchive("AVERAGE", 0, 1, RrdPeriod.Week(this._periodTime));
                    rrdDef.AddArchive("AVERAGE", 0, 1, RrdPeriod.Month(this._periodTime));
                    rrdDef.AddArchive("AVERAGE", 0, 1, RrdPeriod.Year(this._periodTime));

                    rrdDef.AddArchive("MIN", 0, 1, RrdPeriod.Day(this._periodTime));
                    rrdDef.AddArchive("MIN", 0, 1, RrdPeriod.Week(this._periodTime));
                    rrdDef.AddArchive("MIN", 0, 1, RrdPeriod.Month(this._periodTime));
                    rrdDef.AddArchive("MIN", 0, 1, RrdPeriod.Year(this._periodTime));

                    rrdDef.AddArchive("MAX", 0, 1, RrdPeriod.Day(this._periodTime));
                    rrdDef.AddArchive("MAX", 0, 1, RrdPeriod.Week(this._periodTime));
                    rrdDef.AddArchive("MAX", 0, 1, RrdPeriod.Month(this._periodTime));
                    rrdDef.AddArchive("MAX", 0, 1, RrdPeriod.Year(this._periodTime));

                    rrdDb = new RrdDb(rrdDef);
                }
                catch (Exception e)
                {
                    if (this._parent.isLogEnable)
                    {
                        this._parent._ilog.LogError(e.Message);
                    }
                }
                finally
                {
                    if (rrdDb != null)
                    {
                        rrdDb.Close();
                    }
                }
            }
Exemple #20
0
 public void SetDatabaseData(RrdDef rrdDef, DateTime lastUpdated, double lastValue)
 {
 }
Exemple #21
0
 public void SetDatabaseDefinition(RrdDef rrdDef, bool dirty)
 {
     LoadTree(rrdDef);
     Text = string.Format("RrdDb Configuration [{0}{1}]", Path.GetFileNameWithoutExtension(rrdDef.Path), dirty ? "*" : "");
 }
Exemple #22
0
 private void DatabaseSelected(RrdDef databaseDefinition)
 {
     //rrdDbForm.SetDatabaseData(model.EditingDatabaseData.Definition, model.DatabaseLastUpdateTime, model.LastValue);
 }