Subversion Repositories HomeAutomation

Rev

Rev 2141 | Rev 2219 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 2141 Rev 2218
Line 26... Line 26...
26
RRD_Tool_Init();
26
RRD_Tool_Init();
27
 
27
 
28
RRD_Tool_timerUpdate = function(timer)
28
RRD_Tool_timerUpdate = function(timer)
29
{
29
{
30
    var alias_string = Storage_GetParameters("LastValues");
30
    var alias_string = Storage_GetParameters("LastValues");
-
 
31
    timer_loop:
31
    for (var name in RRD_Tool_Timers)
32
    for (var name in RRD_Tool_Timers)
32
    {  
33
    {  
33
        if (RRD_Tool_Timers[name] == timer) {
34
        if (RRD_Tool_Timers[name] == timer)
-
 
35
        {
34
            //Log("Timer: "+timer+", named: "+name+" with data: "+RRD_Tool_StoredData[name]["rrd"]["file"]+"\n");
36
            //Log("Timer: "+timer+", named: "+name+" with data: "+RRD_Tool_StoredData[name]["rrd"]["file"]+"\n");
35
            /* Create command to execute...*/
37
            /* Create command to execute...*/
36
            var names = "";
38
            var names = "";
37
            var values = "N";
39
            var values = "N";
38
            var cmd = "/usr/bin/rrdtool update --template ";
40
            var cmd = "/usr/bin/rrdtool update --template ";
39
            var first = 1;
41
            var first = 1;
40
            for (var label in RRD_Tool_StoredData[name]["rrdNames"])
42
            for (var label in RRD_Tool_StoredData[name]["rrdNames"])
41
            {
43
            {
42
                //Log("Found label: "+label+"\n");
44
                //Log("Found label: "+label+"\n");
43
                var data = eval("(" + alias_string[RRD_Tool_StoredData[name]["rrdNames"][label]["Module"]] + ")");
45
                var data = eval("(" + alias_string[RRD_Tool_StoredData[name]["rrdNames"][label]["Module"]] + ")");
-
 
46
                var datatype=RRD_Tool_StoredData[name]["rrdNames"][label]["data"];
-
 
47
                var periodicity=RRD_Tool_StoredData[name]["rrd"]["Period_s"]*1000;
-
 
48
                if ((get_time() - periodicity*2) > data[datatype]["timestamp"])
-
 
49
                {
-
 
50
                    Log("\033[31mError: RRD-store "+name+" could not store data, too old. Current time="+get_time()+", periodicity="+periodicity+", data timestamp="+data[datatype]["timestamp"]+".\033[0m");
-
 
51
                    break timer_loop;
-
 
52
                }
44
                if (first == 1) {
53
                if (first == 1) {
45
                    names += label;
54
                    names += label;
46
                    first = 0;
55
                    first = 0;
47
                } else {
56
                } else {
48
                    names += ":"+label;  
57
                    names += ":"+label;  
49
                }
58
                }
50
                if (typeof data[RRD_Tool_StoredData[name]["rrdNames"][label]["data"]]["value"] == "string")
59
                if (typeof data[RRD_Tool_StoredData[name]["rrdNames"][label]["data"]]["value"] == "string")
51
                {
60
                {
52
                    values += ":"+data[RRD_Tool_StoredData[name]["rrdNames"][label]["data"]]["value"];
61
                    values += ":"+data[RRD_Tool_StoredData[name]["rrdNames"][label]["data"]]["value"].toString;
53
                }
62
                }
54
                else
63
                else
55
                {
64
                {
56
                    values += ":"+data[RRD_Tool_StoredData[name]["rrdNames"][label]["data"]]["value"][RRD_Tool_StoredData[name]["rrdNames"][label]["value"]]     
65
                    values += ":"+data[RRD_Tool_StoredData[name]["rrdNames"][label]["data"]]["value"][RRD_Tool_StoredData[name]["rrdNames"][label]["value"]].toString;
57
                }  
66
                }  
58
            }
67
                }
59
            cmd += names + " "+RRD_Tool_StoredData[name]["rrd"]["file"]+" "+values;
68
                cmd += names + " "+RRD_Tool_StoredData[name]["rrd"]["file"]+" "+values;
60
            //Log("Command: "+cmd);
69
                //Log("Command: "+cmd);
61
            Execute(cmd);
70
                Execute(cmd);
62
            break;
71
                break;
-
 
72
            }
63
        }
73
        }
64
    }
74
    }
65
}
75
}
66
 
76
 
67
/* Tab complete stuff */
77
/* Tab complete stuff */
68
RRD_Tool_Aliases        = function() { return Module_GetAliasNames(); };
78
RRD_Tool_Aliases        = function() { return Module_GetAliasNames(); };
69
RRD_Tool_Intervals      = function() { return [ 5, 10, 30, 60, 120, 150, 300 ]; };
79
RRD_Tool_Intervals      = function() { return [ 5, 10, 30, 60, 120, 150, 300 ]; };
-
 
80
RRD_Tool_MinValues      = function() { return [ -40, 0 ]; };
-
 
81
RRD_Tool_MaxValues      = function() { return [ 50, 100, 10000, 20000 ]; };
70
/* Function returns an array with all CAN variables existing in LastValues storage */
82
/* Function returns an array with all CAN variables existing in LastValues storage */
71
RRD_Tool_Variables      = function()
83
RRD_Tool_Variables      = function()
72
{
84
{
73
    var last_value_string = Storage_GetParameters("LastValues");
85
    var last_value_string = Storage_GetParameters("LastValues");
74
    var last_values = new Array();
86
    var last_values = new Array();
Line 134... Line 146...
134
    /* Start this new config now */
146
    /* Start this new config now */
135
    RRD_Tool_StoredData[store_name] = eval("(" + newString + ")");
147
    RRD_Tool_StoredData[store_name] = eval("(" + newString + ")");
136
    RRD_Tool_Timers[store_name] = Timer_SetTimer(function(timer) {RRD_Tool_timerUpdate(timer)}, RRD_Tool_StoredData[store_name]["rrd"]["Period_s"]*1000, true);
148
    RRD_Tool_Timers[store_name] = Timer_SetTimer(function(timer) {RRD_Tool_timerUpdate(timer)}, RRD_Tool_StoredData[store_name]["rrd"]["Period_s"]*1000, true);
137
    Log("\033[33mCreated: "+store_name+" with update rate of "+RRD_Tool_StoredData[store_name]["rrd"]["Period_s"]+"s.\033[0m\n");
149
    Log("\033[33mCreated: "+store_name+" with update rate of "+RRD_Tool_StoredData[store_name]["rrd"]["Period_s"]+"s.\033[0m\n");
138
}
150
}
139
 
-
 
140
Console_RegisterCommand(RRDTool_AddConfig, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, RRD_Tool_Aliases(), RRD_Tool_Variables(), RRD_Tool_Intervals() ); });
151
Console_RegisterCommand(RRDTool_AddConfig, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, RRD_Tool_Aliases(), RRD_Tool_Variables(), RRD_Tool_Intervals() ); });
-
 
152
 
-
 
153
 
-
 
154
/* Function to add new rrd config and create rrd file on atomic command line interface */
-
 
155
function RRDTool_AddConfigCreateRrd(alias_name, variable_name, push_interval, data_max, data_min, store_name, rrd_filename, rrd_data_source_name)
-
 
156
{
-
 
157
    /* Create new rrd file */
-
 
158
    /* Two avarages, one with 1 value avarage and one with 12 values avarage */
-
 
159
    /* Make sure 1 value avarage last 14 days and 12 value avarage last 10 years, independant of push interval */
-
 
160
   
-
 
161
    /* set data timeout to double push interval */
-
 
162
    /* set step to push interval */
-
 
163
   
-
 
164
}
-
 
165
//Console_RegisterCommand(RRDTool_AddConfigCreateRrd, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, RRD_Tool_Aliases(), RRD_Tool_Variables(), RRD_Tool_Intervals(), RRD_Tool_MaxValues(), RRD_Tool_MinValues() ); });
141
 
166