ive got this in a lua script so far
Code:
--year usage
wtimer=(updates % 30)+1
monthtotals={}
yeartotal=0
year=os.date('%Y')
if updates==6 or wtimer==1 then
for i=1,12 do
month=months[i]
find=month .. year
n=i
monthtotal=(conky_parse("${exec vnstat -m | grep -n '" .. find .. "' | sed -n 1p | awk -F'|' '{print $3}' | sed -e 's/^[ \t]*//'}"))
monthtotal=string.gsub(monthtotal," ","")
monthtotalnum=tonumber((string.gsub(monthtotal,"%a","")))
monthtotalunit=(string.gsub(monthtotal,"[%p%d]",""))
if monthtotalnum==nil then monthtotalnum=0 end
if monthtotalunit=="MiB" then monthtotalnum=monthtotalnum/1024
else if monthtotalunit=="KiB" then monthtotalnum=monthtotalnum/(1024*1024)
else monthtotalnum=monthtotalnum end end
monthtotals[i]=monthtotalnum
end
for i=1,12 do
yeartotal=yeartotal+monthtotals[i]
end
print (yeartotal, "GiB")
end
i only have january for this year and december for last year... but i took away the year requirement for the search and it added dec 10 to jan 11...so im reasonably sure it will work
also takes into account possible different units for each month and updates every 30 conky cycles
edit - thinking about it, i could probably loose the table creation step and the second for i loop and go straight for the summation of values...
edit - i edited my vnstat.conf to make the searching easier
Code:
# date output formats for -d, -m, -t and -w
# see 'man date' for control codes
DayFormat "%x"
MonthFormat "%b%Y"
TopFormat "%x"
Bookmarks