コード例 #1
0
        internal ValueExtractor Fetch(RrdDb rrd, long startTime, long endTime)
        {
            long rrdStep = rrd.RrdDef.Step;

            FetchData[] result = new FetchData[datasources.Length];

            string[] names  = new string[numSources];
            int      tblPos = 0;

            for (int i = 0; i < datasources.Length; i++)
            {
                if (datasources[i].Count > 0)
                {
                    // Set the list of ds names
                    string[] dsNames = new string[datasources[i].Count];
                    string[] vNames  = new string[datasources[i].Count];

                    for (int j = 0; j < dsNames.Length; j++)
                    {
                        string[] spair = (string[])datasources[i][j];
                        dsNames[j] = spair[0];
                        vNames[j]  = spair[1];
                    }

                    // Fetch datasources
                    FetchRequest request = rrd.CreateFetchRequest(cfNames[i], startTime, endTime + rrdStep);
                    request.SetFilter(dsNames);

                    FetchData data = request.FetchData();

                    for (int j = 0; j < vNames.Length; j++)
                    {
                        names[data.GetDsIndex(dsNames[j]) + tblPos] = vNames[j];
                    }
                    tblPos += dsNames.Length;

                    result[i] = data;
                }
            }

            return(new ValueExtractor(names, result));
        }
コード例 #2
0
ファイル: FetchSource.cs プロジェクト: hirst/rrdsharp
        internal ValueExtractor Fetch( RrdDb rrd, long startTime, long endTime )
        {
            long rrdStep			= rrd.RrdDef.Step;
            FetchData[] result		= new FetchData[datasources.Length];

            string[] names 			= new string[numSources];
            int tblPos		= 0;

            for (int i = 0; i < datasources.Length; i++)
            {
                if ( datasources[i].Count > 0 )
                {
                    // Set the list of ds names
                    string[] dsNames 	= new string[ datasources[i].Count ];
                    string[] vNames		= new string[ datasources[i].Count ];

                    for (int j = 0; j < dsNames.Length; j++ )
                    {
                        string[] spair	= (string[]) datasources[i][j];
                        dsNames[j]	 	= spair[0];
                        vNames[j]		= spair[1];
                    }

                    // Fetch datasources
                    FetchRequest request 		= rrd.CreateFetchRequest( cfNames[i], startTime, endTime + rrdStep);
                    request.SetFilter(dsNames);

                    FetchData data				= request.FetchData();

                    for (int j = 0; j < vNames.Length; j++)
                        names[ data.GetDsIndex(dsNames[j]) + tblPos ] = vNames[j];
                    tblPos				+= dsNames.Length;

                    result[i]					= data;
                }
            }

            return new ValueExtractor( names, result );
        }
コード例 #3
0
ファイル: Main.cs プロジェクト: jonaslorander/rrdsharp
        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);
        }