示例#1
0
        private static void createVectorGraphPNG(string rrdPath, string pngPath, string ds, DateTime start, DateTime end, string vertLabel, double lower = 0, double upper = 0)
        {
            RrdGraphDef graphDef = new RrdGraphDef();
            graphDef.SetTimePeriod(getUnixTimeStamp(start), getUnixTimeStamp(end));
            graphDef.VerticalLabel = vertLabel;

            if (lower != upper)
            {
                graphDef.SetGridRange(lower, upper, true);
            }

            string dsx = ds + ".X";
            string dsy = ds + ".Y";
            string dsz = ds + ".Z";

            graphDef.Datasource(dsx, rrdPath, dsx, "AVERAGE");
            graphDef.Datasource(dsy, rrdPath, dsy, "AVERAGE");
            graphDef.Datasource(dsz, rrdPath, dsz, "AVERAGE");

            graphDef.Line(dsx, Color.Blue, dsx, 2);
            graphDef.Line(dsy, Color.Green, dsy, 2);
            graphDef.Line(dsz, Color.Red, dsz, 2);

            RrdGraph graph = new RrdGraph(graphDef);
            graph.SaveAsPNG(pngPath, 800, 600);
        }
示例#2
0
文件: Main.cs 项目: hirst/rrdsharp
        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.");
        }
示例#3
0
文件: Main.cs 项目: hirst/rrdsharp
        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.");
        }
示例#4
0
文件: Main.cs 项目: hirst/rrdsharp
        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.");
        }