Subversion Repositories HomeAutomation

Rev

Rev 1770 | Rev 2042 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | SVN | RSS feed

Rev Author Line No. Line
1770 linlun 1
 
2
 
3
function RRD_Tool(config)
4
{
5
 
6
/* Declaration of instance variables, for static variables remove prototype */
7
 
8
    /* We must always call the parent constructor, initialization
9
       of variables could be done here, but initialize is a better place */
10
    var self = this;
11
 
12
    Log("\033[33mRRD Tool updater starting...\033[0m");
13
 
14
    var last_value_string = Storage_GetParameters(config);
15
    this.StoredData = new Array();
16
    this.Timers = new Array();
17
    for (var name in last_value_string)
18
    {
19
        this.StoredData[name] = eval("(" + last_value_string[name] + ")");
20
        Log("\033[33mFound: "+name+" with update rate of "+this.StoredData[name]["rrd"]["Period_s"]+"s.\033[0m");
21
        this.Timers[name] = Timer_SetTimer(function(timer) {self.timerUpdate2(timer)}, this.StoredData[name]["rrd"]["Period_s"]*1000, true);
22
    }
23
    Log("\033[33mRRD Tool updater created.\033[0m");
24
 
25
}
26
 
27
/* Declaration of instance variables, for static variables remove prototype */
28
RRD_Tool.prototype.myInterval = null;
29
RRD_Tool.prototype.StoredData = null;
30
RRD_Tool.prototype.Timers = null;
31
 
32
 
33
RRD_Tool.prototype.timerUpdate2 = function(timer)
34
{
35
    var alias_string = Storage_GetParameters("LastValues");
36
    for (var name in this.Timers)
37
    {  
38
        if (this.Timers[name] == timer) {
39
            //Log("Timer: "+timer+", named: "+name+" with data: "+this.StoredData[name]["rrd"]["file"]+"\n");
40
            /* Create command to execute...*/
41
            var names = "";
42
            var values = "N";
43
            var cmd = "/usr/bin/rrdtool update --template ";
44
            var first = 1;
45
            for (var label in this.StoredData[name]["rrdNames"])
46
            {
47
                //Log("Found label: "+label+"\n");
48
                var data = eval("(" + alias_string[this.StoredData[name]["rrdNames"][label]["Module"]] + ")");
49
                if (first == 1) {
50
                    names += label;
51
                    first = 0;
52
                } else {
53
                    names += ":"+label;  
54
                }
55
                values += ":"+data[this.StoredData[name]["rrdNames"][label]["data"]][this.StoredData[name]["rrdNames"][label]["value"]];
56
            }
57
            cmd += names + " "+this.StoredData[name]["rrd"]["file"]+" "+values;
58
            //Log("Command: "+cmd);
59
            Execute(cmd);
60
            break;
61
        }
62
    }
63
}