示例#1
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.");
        }
示例#2
0
文件: Main.cs 项目: hirst/rrdsharp
        public void Test4()
        {
            Console.WriteLine("Beginning Test4...");
            // Time Values
            DateTime[] timestamps = {
                                        new DateTime(2004, 2, 1, 0, 0, 0),
                                        new DateTime(2004, 2, 1, 2, 0, 0),
                                        new DateTime(2004, 2, 1, 7, 0, 0),
                                        new DateTime(2004, 2, 1, 14, 0, 0),
                                        new DateTime(2004, 2, 1, 17, 0, 0),
                                        new DateTime(2004, 2, 1, 19, 0, 0),
                                        new DateTime(2004, 2, 1, 23, 0, 0),
                                        new DateTime(2004, 2, 2, 0, 0, 0)
                                    };

            // Corresponding Data Values
            double[] values = { 100, 250, 230, 370, 350, 300, 340, 350 };

            LinearInterpolator linear = new LinearInterpolator(timestamps, values);
            CubicSplineInterpolator spline = new CubicSplineInterpolator(timestamps, values);

            // graph range
            RrdGraphDef gDef = new RrdGraphDef(timestamps[0], timestamps[timestamps.Length - 1]);

            // graph title, time and value axis labels
            gDef.Title = "Plottable demonstration";
            gDef.TimeAxisLabel = "time";
            gDef.VerticalLabel = "water level [inches]";

            // interpolated datasources
            gDef.Datasource("linear", linear);
            gDef.Datasource("spline", spline);

            // splined plot will be an orange filled area
            gDef.Area("spline", Color.Orange, "Spline interpolation");

            // simply interpolated plot will be a red line
            gDef.Line("linear", Color.Red, "Linear inteprolation@r");

            // print average values for both interpolation methods
            gDef.Gprint("spline", "AVERAGE", "Average spline value: @0 inches@r");
            gDef.Gprint("linear", "AVERAGE", "Average linear value: @0 inches@r");

            // create the graph...
            RrdGraph graph = new RrdGraph(gDef);

            // ...and save it somewhere
            string filename = "test4.png";
            graph.SaveAsPNG(filename, 300, 100);
            Console.WriteLine("Test4 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.");
        }