summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMika Havela <mika.havela@gmail.com>2011-06-01 11:06:57 +0200
committerMika Havela <mika.havela@gmail.com>2011-06-01 11:06:57 +0200
commit36dd1f7ff194ce85b338e4428708860511a0dfef (patch)
tree0a17a9c98f11b5277cf60453a82ef1a502bb450e
parent4486ad86230d37ee1ca88c8c792f942a7b02a13e (diff)
downloadacf-rrdtool-36dd1f7ff194ce85b338e4428708860511a0dfef.tar.bz2
acf-rrdtool-36dd1f7ff194ce85b338e4428708860511a0dfef.tar.xz
Add notes into the graph image.
Save a script next to the DB so the DB can be recreated if needed (might be used in further improvements of this acf) Display example config when creating a new graph.
-rw-r--r--[l---------]rrdtool-editgraphcfg-html.lsp38
-rw-r--r--rrdtool-model.lua70
-rw-r--r--rrdtool-viewgraph-popup.lsp1
3 files changed, 90 insertions, 19 deletions
diff --git a/rrdtool-editgraphcfg-html.lsp b/rrdtool-editgraphcfg-html.lsp
index 15b1930..6b5a2f3 120000..100644
--- a/rrdtool-editgraphcfg-html.lsp
+++ b/rrdtool-editgraphcfg-html.lsp
@@ -1 +1,37 @@
-../filedetails-html.lsp \ No newline at end of file
+<% local form, viewlibrary, page_info = ... %>
+<% require("viewfunctions") %>
+
+<% if form.type == "form" then %>
+<H1>Configuration</H1>
+<H2>Expert Configuration</H2>
+<% else %>
+<H1>View File</H1>
+<% end %>
+<H3>File Details</H3>
+<DL>
+<%
+displayitem(form.value.filename)
+displayitem(form.value.filesize)
+displayitem(form.value.mtime)
+%>
+</DL>
+
+<H3>File Content</H3>
+<% if form.type == "form" then %>
+<% form.action = page_info.script .. page_info.prefix .. page_info.controller .. "/" .. page_info.action %>
+<% displayformstart(form) %>
+<input type="hidden" name="filename" value="<%= html.html_escape(form.value.filename.value) %>">
+<% else %>
+<DL>
+<% end %>
+<textarea name="filecontent">
+<%= html.html_escape(form.value.filecontent.value) %>
+</textarea>
+<% if form.value.filecontent.errtxt then %><P CLASS='error'><%= string.gsub(html.html_escape(form.value.filecontent.errtxt), "\n", "<BR>") %></P><% end %>
+<% if form.value.filecontent.descr then %><P CLASS='descr'><%= string.gsub(html.html_escape(form.value.filecontent.descr), "\n", "<BR>") %></P><% end %>
+
+<% if form.type == "form" then %>
+<% displayformend(form) %>
+<% else %>
+</DL>
+<% end %>
diff --git a/rrdtool-model.lua b/rrdtool-model.lua
index 3feb6ba..d43875c 100644
--- a/rrdtool-model.lua
+++ b/rrdtool-model.lua
@@ -12,6 +12,7 @@ require("validator")
local configfile = "/etc/rrdtool/acf-rrdtool.conf"
local graphpath = "/etc/rrdtool"
local databases = "/etc/rrdtool/databases"
+local db_scripts = "/etc/rrdtool/databases"
local processname = "rrdtool"
local packagename = "rrdtool"
local header = "rrdtool"
@@ -80,7 +81,7 @@ function setconfigfile(filedetails)
end
function getrrdlist()
- return list_files(databases)
+ return list_files(databases,".*rrd")
end
function createnewrrd()
@@ -125,6 +126,9 @@ function savenewrrd(self, configfile, userid)
path=tostring(databases).."/"..configfile.value.filename.value
configfile.errtxt = "Failed to create file"
local path = configfile.value.filename.value
+ if not fs.is_dir(databases) then
+ fs.create_directory(databases)
+ end
if not string.find(path, "/") then
path = databases .. "/" .. path
elseif not validator.is_valid_filename(path,databases) then
@@ -155,12 +159,26 @@ If you specify path, it should be " .. tostring(databases) .."/"
else
step = ""
end
- local f = io.popen( "/usr/bin/rrdtool create "..
- format.escapespecialcharacters(path) .. " " ..
- format.escapespecialcharacters(start) ..
- format.escapespecialcharacters(step) ..
- tostring(string.gsub(format.dostounix(format.escapespecialcharacters(configfile.value.ds.value)),"\n", " \\\n")) .. " " ..
- tostring(string.gsub(format.dostounix(format.escapespecialcharacters(configfile.value.rra.value)),"\n", " \\\n")) .. " 2>&1")
+
+ local cmd = "/usr/bin/rrdtool create ".. format.escapespecialcharacters(path) .. " " .. format.escapespecialcharacters(start) .. format.escapespecialcharacters(step) .. tostring(string.gsub(format.dostounix(format.escapespecialcharacters(configfile.value.ds.value)),"\n", " \\\n")) .. " " .. tostring(string.gsub(format.dostounix(format.escapespecialcharacters(configfile.value.rra.value)),"\n", " \\\n"))
+
+ local f = io.popen("date")
+ local createdate = f:read("*l") or ""
+ f:close()
+ local cmd_descr = "#!/bin/sh\n# " .. tostring(createdate) .. "\n# This file can be used to recreate '" .. tostring(path) .. "'\n\n" .. string.gsub(string.gsub(cmd," RRA", " \\\nRRA")," DS", " \\\nDS")
+
+ local filedetails={}
+ filedetails.value={}
+ filedetails.value.filename={value=tostring(db_scripts) .. "/" .. string.match(path,".*/(.*)") .. ".cmd"}
+ filedetails.value.filecontent={value=string.gsub(cmd_descr,"\\/","/")}
+
+ if not fs.is_dir(tostring(db_scripts)) then
+ fs.create_directory(tostring(db_scripts))
+ end
+ filedetails = modelfunctions.setfiledetails(filedetails, getgraphlist)
+ filedetails = nil
+
+ local f = io.popen( cmd .. " 2>&1")
success = f:read("*a") or ""
f:close()
configfile.errtxt = tostring(success)
@@ -175,14 +193,24 @@ function list_graphs()
for k,v in pairs(files) do
local filecontent = {}
+ local cont=false
for kk,vv in pairs(fs.read_file_as_array(v)) do
- vv = string.gsub(vv,"\"", "")
+ vv = string.gsub(vv,"\n", "")
local delim = string.find(vv, "\=")
- if delim then
- filecontent[string.sub(vv,1,(delim-1))]=string.sub(vv,(delim+1),#vv)
- end
+ if cont==true then
+ filecontent['value']=tostring(filecontent['value']) .. " " .. tostring(vv)
+ filecontent['plutt']="test"
+ else
+ if delim then
+ filecontent[string.sub(vv,1,(delim-1))]=string.sub(vv,(delim+1),#vv)
+ --TODO: Remove trailing slash \ for each line
+ end
+ end
+ if delim and string.sub(vv,1,(delim-1))=="value" then
+ cont=true
+ end
end
-
+
if not (filecontent.group) then
filecontent.group = "General"
end
@@ -210,7 +238,11 @@ function view_graph(self, graph_grp, graph_id)
local cmd = "/usr/bin/rrdtool graph /usr/share/acf/www" .. tostring(filename) .. " "
- cmd = cmd .. tostring(settings.value)
+ local f = io.popen("date")
+ local imagedate = f:read("*l") or ""
+ f:close()
+
+ cmd = cmd .. tostring(settings.value) .. " --title '" .. tostring(settings.label) .. " - " .. tostring(settings.descr) .. "' -W '" .. tostring(imagedate) .. "'"
settings.cmd_query = cmd
local f = io.popen( tostring(cmd) .. " 2>&1" )
settings.cmd_result = f:read("*a") or ""
@@ -234,10 +266,14 @@ function getgraphfile(path)
local filedetails = modelfunctions.getfiledetails(path)
-- If we create a new file, we want to help the user to know what variables he should use
if not (path) then
- filedetails.value.filecontent.value = [[label=Example name for this graph
-group=General
-descr=Some describing text that helps the user to know what this graph is all about
-value=--start now-3600s --end now --width 680 --height 400 --step 300 DEF...
+ filedetails.value.filecontent.value = [[group=General
+label=Example graph
+descr=Testgraph to show network activity
+value=--start now-3600s --end now --width 680 --height 500 --step 60 --vertical-label 'bit'
+DEF:eth0rx=]] .. tostring(databases) .. [[/mydb.rrd:eth0rx:AVERAGE
+DEF:eth0tx=]] .. tostring(databases) .. [[/mydb.rrd:eth0tx:AVERAGE
+LINE2:eth0rx#006600:
+AREA:eth0tx#99000099:
]]
end
local output = {value={filename=filedetails.value.filename,
diff --git a/rrdtool-viewgraph-popup.lsp b/rrdtool-viewgraph-popup.lsp
index 80b55c0..42194a5 100644
--- a/rrdtool-viewgraph-popup.lsp
+++ b/rrdtool-viewgraph-popup.lsp
@@ -3,7 +3,6 @@ require("viewfunctions")
%>
<% if (data.graph.width) then %>
-<P><%= data.descr %></P>
<IMG SRC='<%= data.output %>' width='<%= data.graph.width or data.option.width %>' height='<%= data.graph.height or data.option.height %>'>
<% else %>
<H1>No valid output available!</H1>