Click here to Skip to main content
15,893,381 members
Articles / Programming Languages / C#

"C# Hooks For RRDtool"

Rate me:
Please Sign up or sign in to vote.
4.79/5 (26 votes)
26 May 2010GPL35 min read 240K   3.1K   37  
C# (.NET and Mono) library provider for RRDtool
/* 
Copyright (C) 2008 Michael Corley  
All rights reserved.

Copyright (c) 1997-2008 Tobias Oetiker
All rights reserved.

                                            
NHAWK GPL License Info.
======================

This file is part of the NHAWK project.
NHAWK is free software; you can redistribute it and/or modify                        
it under the terms of the GNU General Public License as published by                 
the Free Software Foundation; either version 3 of the License, or                    
(at your option) any later version.                                                  
                                                                                         
NHAWK is distributed in the hope that it will be useful,                             
but WITHOUT ANY WARRANTY; without even the implied warranty of                       
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                        
GNU General Public License for more details.                                         
                                                                                         
You should have received a copy of the GNU General Public License                    
along with NHAWK; if not, write to the Free Software Foundation, Inc.,               
59 Temple Place - Suite 330, Boston, MA  02111-1307, USA  
                           
                                                                                        
RRDTool GPL License Info.
========================

RRDTool is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your option)
any later version.

RRDTool is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
more details.

You should have received a copy of the GNU General Public License along
with this RRDTool; if not, write to the Free Software Foundation, Inc.,
59 Temple Place - Suite 330, Boston, MA  02111-1307, USA

FLOSS License Exception 
=======================
(Adapted from http://www.mysql.com/company/legal/licensing/foss-exception.html)

I want specified Free/Libre and Open Source Software ("FLOSS")
applications to be able to use specified GPL-licensed RRDtool
libraries (the "Program") despite the fact that not all FLOSS licenses are
compatible with version 2 of the GNU General Public License (the "GPL").

As a special exception to the terms and conditions of version 2.0 of the GPL:

You are free to distribute a Derivative Work that is formed entirely from
the Program and one or more works (each, a "FLOSS Work") licensed under one
or more of the licenses listed below, as long as:

1. You obey the GPL in all respects for the Program and the Derivative
Work, except for identifiable sections of the Derivative Work which are
not derived from the Program, and which can reasonably be considered
independent and separate works in themselves,

2. all identifiable sections of the Derivative Work which are not derived
from the Program, and which can reasonably be considered independent and
separate works in themselves,

1. are distributed subject to one of the FLOSS licenses listed
below, and

2. the object code or executable form of those sections are
accompanied by the complete corresponding machine-readable source
code for those sections on the same medium and under the same FLOSS
license as the corresponding object code or executable forms of
those sections, and

3. any works which are aggregated with the Program or with a Derivative
Work on a volume of a storage or distribution medium in accordance with
the GPL, can reasonably be considered independent and separate works in
themselves which are not derivatives of either the Program, a Derivative
Work or a FLOSS Work.

If the above conditions are not met, then the Program may only be copied,
modified, distributed or used under the terms and conditions of the GPL.

FLOSS License List
==================
License name	Version(s)/Copyright Date
Academic Free License		2.0
Apache Software License	1.0/1.1/2.0
Apple Public Source License	2.0
Artistic license		From Perl 5.8.0
BSD license			"July 22 1999"
Common Public License		1.0
GNU Library or "Lesser" General Public License (LGPL)	2.0/2.1
IBM Public License, Version    1.0
Jabber Open Source License	1.0
MIT License (As listed in file MIT-License.txt)	-
Mozilla Public License (MPL)	1.0/1.1
Open Software License		2.0
OpenSSL license (with original SSLeay license)	"2003" ("1998")
PHP License			3.0
Python license (CNRI Python License)	-
Python Software Foundation License	2.1.1
Sleepycat License		"1999"
W3C License			"2001"
X11 License			"2001"
Zlib/libpng License		-
Zope Public License		2.0/2.1
*/
using System;
using System.Drawing;
using NHAWK;

    public class Program
    {
        static void Main(string[] args)
        {
           //uncomment this (below) and set to correct path for rrdtool.exe for win32
           //NHawkCommand.Instance.RRDCommandPath = @"e:\downloads\rrdtool\release\rrdtool.exe";
           
           //uncomment this (below) for linux
           //NHawkCommand.Instance.RRDCommandPath = "/home/linux/Desktop/rrdtool";
            
           RRD rrd1 = new RRD("test.rrd", 920804400);
           rrd1.addDS(new DS("speed",  DS.TYPE.COUNTER, 600, DS.U, DS.U)) ;
           rrd1.addRRA(new RRA(RRA.CF.AVERAGE, 0.5, 1, 24));
           rrd1.addRRA(new RRA(RRA.CF.AVERAGE, 0.5, 6, 10));
           rrd1.create(true);

     
           rrd1.update(920804700, new string[] { "12345" });
           rrd1.update(920805000, new object[] { 12357 });
           rrd1.update(920805300, new object[] { 12363 });
           rrd1.update(920805600, new object[] { 12363 });
           rrd1.update(920805900, new object[] { 12363 });
           rrd1.update(920806200, new object[] { 12373 });
           rrd1.update(920806500, new object[] { 12383 });
           rrd1.update(920806800, new object[] { 12393 });
           rrd1.update(920807100, new object[] { 12399 });
           rrd1.update(920807400, new object[] { 12405 });
           rrd1.update(920807700, new object[] { 12411 });
           rrd1.update(920808000, new object[] { 12415 });
           rrd1.update(920808300, new object[] { 12420 });
           rrd1.update(920808600, new object[] { 12422 });
           rrd1.update(920808900, new object[] { 12423 });

           
            Console.WriteLine("Graph test # 1");
           GRAPH gr1 = new GRAPH("speed.png", "920804400", "920808000");
           gr1.addDEF(new DEF("myspeed", "test.rrd", "speed", RRA.CF.AVERAGE));
           gr1.addGELEM(new LINE(2, "myspeed", Color.Red));
           gr1.graph();
           

           Console.WriteLine("Graph test # 2");
           GRAPH gr2 = new GRAPH("speed2.png", "920804400", "920808000");
           gr2.yaxislabel = "m/s";
           gr2.addDEF(new DEF("myspeed", rrd1, "speed", RRA.CF.AVERAGE));
           gr2.addCDEF(new CDEF("realspeed", "myspeed, 1000, *"));
           gr2.addGELEM(new LINE(2,"realspeed", Color.Red));
           gr2.graph();

           Console.WriteLine("Graph test # 3");
           GRAPH gr3 = new GRAPH("speed3.png", "920804400", "920808000");
           gr3.yaxislabel = "km/h";
           gr3.addDEF(new DEF("myspeed", rrd1, "speed", RRA.CF.AVERAGE));
           gr3.addCDEF(new CDEF("kmh", "myspeed,3600,*"));
           gr3.addCDEF(new CDEF("fast", "kmh,100,   GT,kmh,0,IF"));
           gr3.addCDEF(new CDEF("good", "kmh,  100,GT,0,kmh, IF"));
           gr3.addGELEM(new HRULE("100", Color.Blue, "Maximum allowed"));
           gr3.addGELEM(new AREA("good", Color.Green, "good speed"));
           gr3.addGELEM(new AREA("fast", Color.Red, "Too fast"));
           gr3.graph();

            
           Console.WriteLine("Graph test # 4");
           GRAPH gr4 = new GRAPH("speed4.png", "920804400", "920808000");
           gr4.yaxislabel = "km/h";
           gr4.addDEF(new DEF("myspeed", rrd1, "speed", RRA.CF.AVERAGE));
           gr4.addCDEF(new CDEF("kmh", "myspeed,3600,*"));
           gr4.addCDEF(new CDEF("fast", "kmh,100,GT,kmh,0,IF"));
           gr4.addCDEF(new CDEF("over", "kmh,100,GT,kmh,100,-,0,IF"));
           gr4.addCDEF(new CDEF("good", "kmh,100,GT,0,kmh,IF"));
           gr4.addGELEM(new HRULE("100", Color.Blue, "Maximum allowed"));
           gr4.addGELEM(new AREA("good", Color.Green, "Good speed"));
           gr4.addGELEM(new AREA("fast", Color.Brown, "Too fast"));
           gr4.addGELEM(new AREA("over", Color.Red, "Over speed",true));
           gr4.graph();


           Console.WriteLine("Testing Deserialization of gr4 -> instantiating gr5");
           GRAPH gr5 = new GRAPH(gr4.ToString(), "./");
           
           Console.WriteLine("gr4 hashcode: {0} ", gr4.GetHashCode());
           Console.WriteLine("Serialization of gr4: {0}\n", gr4.ToString());

           Console.WriteLine("gr5 hashcode: {0} ", gr5.GetHashCode());
           Console.WriteLine("Serialization of gr5: {0}\n", gr5.ToString());

           Console.WriteLine("Testing DeepClone of gr5, creating gr6");
           GRAPH gr6 = GRAPH.DeepClone(gr5);
           
           Console.WriteLine("gr6 hashcode: {0} ", gr6.GetHashCode());
           Console.WriteLine("Serialization of gr6: {0}", gr6.ToString());

           Console.WriteLine("\nTesting shallow copy of gr6, creating gr7 (notice gr6 and gr7 hashcodes)");
           GRAPH gr7 = gr6;
           Console.WriteLine("gr7 hashcode: {0} ", gr7.GetHashCode());
           Console.WriteLine("Serialization of gr7: {0}", gr7.ToString());
        }
    }

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)


Written By
Software Developer (Senior)
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions