require cairo -- функция округления чисел до 01 до одной сотой functio

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
require 'cairo'
-- функция округления чисел до .01 (до одной сотой)
function round(num, idp)
local mult = 10^(idp or 0)
return math.floor(num * mult + 0.5) / mult
end
--MAIN FUNCTION
start=1
function conky_vnstat()
if conky_window == nil then return end
local cs = cairo_xlib_surface_create(conky_window.display, conky_window.drawable, conky_window.visual, conky_window.width, conky_window.height)
cr = cairo_create(cs)
local updates=tonumber(conky_parse('${updates}'))
if updates>5 then
vntable = {}
local updates = tonumber(conky_parse('${updates}'))
local timer = (updates %60)
if start == 1 or timer == 0 then
start = 0
local thismonth = tonumber(os.date("%m"))
local f = io.popen("vnstat -i eth1 --dumpdb")
for line in f:lines() do
table.insert(vntable,line)
end
f:close()
s,f,interface = string.find(vntable[3],"^.*;(.*)")
s,f,totalrx = string.find(vntable[7],"^.*;(.*)")
s,f,totaltx = string.find(vntable[8],"^.*;(.*)")
totalx = tonumber(totalrx) + tonumber(totaltx)
--DAYS ###########################################################################
rx_day_mib = {}
tx_day_mib = {}
total_day_mib = {}
total_avg_day_kbit = {}
rx_avg_day_kbit = {}
tx_avg_day_kbit = {}
total_avg_day_kib = {}
rx_avg_day_kib = {}
tx_avg_day_kib = {}
date_day = {}
rx_day_mb = {}
tx_day_mb = {}
total_day_mb = {}
total_avg_day_kb = {}
rx_avg_day_kb = {}
tx_avg_day_kb = {}
for i = 14, 43 do
local s,f,daydate = string.find(vntable[i],"%a;%d*;(%d*);")
--date formatting here
table.insert(date_day,(os.date("%x",daydate)))
--end of formatting
local s,f,rxdaymib = string.find(vntable[i],"%a;%d*;%d*;(%d*);")
local s,f,txdaymib = string.find(vntable[i],"%a;%d*;%d*;%d*;(%d*);")
local s,f,rxdaykib = string.find(vntable[i],"%a;%d*;%d*;%d*;%d*;(%d*);")
local s,f,txdaykib = string.find(vntable[i],"%a;%d*;%d*;%d*;%d*;%d*;(%d*);")
local rx = (tonumber(rxdaymib) + (tonumber(rxdaykib)/1024))
local tx = (tonumber(txdaymib) + (tonumber(txdaykib)/1024))
table.insert(rx_day_mib, string.format("%.02f",round(rx,2)))
table.insert(tx_day_mib,string.format("%.02f",round(tx,2)))
table.insert(total_day_mib,string.format("%.02f",round((rx+tx),2)))
local h = tonumber(os.date("%H"))*(60*60)
local m = tonumber(os.date("%M"))*(60)
local s = tonumber(os.date("%S"))
if i == 14 then
table.insert(total_avg_day_kbit,string.format("%.02f",round(((rx+tx)/(h+m+s))*1024*8,2)))
table.insert(rx_avg_day_kbit,string.format("%.02f",round(((rx)/(h+m+s))*1024*8,2)))
table.insert(tx_avg_day_kbit,string.format("%.02f",round(((tx)/(h+m+s))*1024*8,2)))
--kib
table.insert(total_avg_day_kib,string.format("%.02f",round(((rx+tx)/(h+m+s))*1024,2)))
table.insert(rx_avg_day_kib,string.format("%.02f",round(((rx)/(h+m+s))*1024,2)))
table.insert(tx_avg_day_kib,string.format("%.02f",round(((tx)/(h+m+s))*1024,2)))
else
table.insert(total_avg_day_kbit,string.format("%.02f",round(((rx+tx)/(24*60*60))*1024*8,2)))
table.insert(rx_avg_day_kbit,string.format("%.02f",round(((rx)/(24*60*60))*1024*8,2)))
table.insert(tx_avg_day_kbit,string.format("%.02f",round(((tx)/(24*60*60))*1024*8,2)))
--kib
table.insert(total_avg_day_kib,string.format("%.02f",round(((rx+tx)/(24*60*60))*1024,2)))
table.insert(rx_avg_day_kib,string.format("%.02f",round(((rx)/(24*60*60))*1024,2)))
table.insert(tx_avg_day_kib,string.format("%.02f",round(((tx)/(24*60*60))*1024,2)))
end
--MB/ KB/s
local rx = rx*1.048576
local tx = tx*1.048576
table.insert(rx_day_mb,string.format("%.02f",round(rx,2)))
table.insert(tx_day_mb,string.format("%.02f",round(tx,2)))
table.insert(total_day_mb,string.format("%.02f",round((rx+tx),2)))
if i == 14 then
table.insert(total_avg_day_kb,string.format("%.02f",round(((rx+tx)/(h+m+s))*1000,2)))
table.insert(rx_avg_day_kb,string.format("%.02f",round(((rx)/(h+m+s))*1000,2)))
table.insert(tx_avg_day_kb,string.format("%.02f",round(((tx)/(h+m+s))*1000,2)))
else
table.insert(total_avg_day_kb,string.format("%.02f",round(((rx+tx)/(24*60*60))*1000,2)))
table.insert(rx_avg_day_kb,string.format("%.02f",round(((rx)/(24*60*60))*1000,2)))
table.insert(tx_avg_day_kb,string.format("%.02f",round(((tx)/(24*60*60))*1000,2)))
end
end
--MONTHS ###########################################################################
rx_month_mib = {}
tx_month_mib = {}
total_month_mib = {}
total_avg_month_kbit = {}
rx_avg_month_kbit = {}
tx_avg_month_kbit = {}
total_avg_month_kib = {}
rx_avg_month_kib = {}
tx_avg_month_kib = {}
date_month = {}
rx_month_mb = {}
tx_month_mb = {}
total_month_mb = {}
total_avg_month_kb = {}
rx_avg_month_kb = {}
tx_avg_month_kb = {}
for i = 44, 55 do
local s,f,monthdate=string.find(vntable[i],"%a;%d*;(%d*);")
--date formatting here
if tonumber(monthdate) ~= 0 then
table.insert(date_month,(os.date("%b %y",monthdate)))
else
table.insert(date_month,"no data")
end
--end of date formatting
local s,f,rxmonthmib=string.find(vntable[i],"%a;%d*;%d*;(%d*);")
local s,f,txmonthmib=string.find(vntable[i],"%a;%d*;%d*;%d*;(%d*);")
local s,f,rxmonthkib=string.find(vntable[i],"%a;%d*;%d*;%d*;%d*;(%d*);")
local s,f,txmonthkib=string.find(vntable[i],"%a;%d*;%d*;%d*;%d*;%d*;(%d*);")
local rx=(tonumber(rxmonthmib)+(tonumber(rxmonthkib)/1024))
local tx=(tonumber(txmonthmib)+(tonumber(txmonthkib)/1024))
table.insert(rx_month_mib,string.format("%.02f",round(rx,2)))
table.insert(tx_month_mib,string.format("%.02f",round(tx,2)))
table.insert(total_month_mib,string.format("%.02f",round((rx+tx),2)))
local year4num=os.date("%Y")
local t1 = os.time( { year=year4num,month=03,day=01,hour=00,min=0,sec=0} );
local t2 = os.time( { year=year4num,month=02,day=01,hour=00,min=0,sec=0} );
local febdaynum=tonumber((os.difftime(t1,t2))/(24*60*60))
monthdays = {31, febdaynum, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
local getdaynum=((thismonth-(i-44)) %12)
if getdaynum==0 then getdaynum=12 end
local daynum=tonumber((monthdays[getdaynum]))
local h=tonumber(os.date("%H"))
local d=tonumber(os.date("%d"))
if i == 44 then
local avg=(((rx+tx)/(24*60*60*((d-1)+(h/24))))*1024)
table.insert(total_avg_month_kbit,string.format("%.02f",round(avg*8,2)))
table.insert(total_avg_month_kib,string.format("%.02f",round(avg,2)))
local avg=(((rx)/(24*60*60*((d-1)+(h/24))))*1024)
table.insert(rx_avg_month_kbit,string.format("%.02f",round(avg*8,2)))
table.insert(rx_avg_month_kbit,string.format("%.02f",round(avg,2)))
local avg=(((tx)/(24*60*60*((d-1)+(h/24))))*1024)
table.insert(tx_avg_month_kbit,string.format("%.02f",round(avg*8,2)))
table.insert(tx_avg_month_kbit,string.format("%.02f",round(avg,2)))
else
local avg=(((rx+tx)/(24*60*60*daynum))*1024)
table.insert(total_avg_month_kbit,string.format("%.02f",round(avg*8,2)))
table.insert(total_avg_month_kbit,string.format("%.02f",round(avg,2)))
local avg=(((rx)/(24*60*60*daynum))*1024)
table.insert(rx_avg_month_kbit,string.format("%.02f",round(avg*8,2)))
table.insert(rx_avg_month_kbit,string.format("%.02f",round(avg,2)))
local avg=(((tx)/(24*60*60*daynum))*1024)
table.insert(tx_avg_month_kbit,string.format("%.02f",round(avg*8,2)))
table.insert(tx_avg_month_kbit,string.format("%.02f",round(avg,2)))
end
--MB/ KB/s
local rx=rx*1.048576
local tx=tx*1.048576
table.insert(rx_month_mb,string.format("%.02f",round(rx,2)))
table.insert(tx_month_mb,string.format("%.02f",round(tx,2)))
table.insert(total_month_mb,string.format("%.02f",round((rx+tx),2)))
if i == 44 then
local avg=(((rx+tx)/(24*60*60*((d-1)+(h/24))))*1000)
table.insert(total_avg_month_kb,string.format("%.02f",round(avg,2)))
local avg=(((rx)/(24*60*60*((d-1)+(h/24))))*1000)
table.insert(rx_avg_month_kb,string.format("%.02f",round(avg,2)))
local avg=(((tx)/(24*60*60*((d-1)+(h/24))))*1000)
table.insert(tx_avg_month_kb,string.format("%.02f",round(avg,2)))
else
local avg=(((rx+tx)/(24*60*60*daynum))*1000)
table.insert(total_avg_month_kb,string.format("%.02f",round(avg,2)))
local avg=(((rx)/(24*60*60*daynum))*1000)
table.insert(rx_avg_month_kb,string.format("%.02f",round(avg,2)))
local avg=(((tx)/(24*60*60*daynum))*1000)
table.insert(tx_avg_month_kb,string.format("%.02f",round(avg,2)))
end
end
--top 10 days ###########################################################################
rx_top10_mib={}
tx_top10_mib={}
total_top10_mib={}
total_avg_top10_kbit={}
rx_avg_top10_kbit={}
tx_avg_top10_kbit={}
total_avg_top10_kib={}
rx_avg_top10_kib={}
tx_avg_top10_kib={}
date_top10={}
rx_top10_mb={}
tx_top10_mb={}
total_top10_mb={}
total_avg_top10_kb={}
rx_avg_top10_kb={}
tx_avg_top10_kb={}
for i = 56, 65 do
local s,f,daydate=string.find(vntable[i],"%a;%d*;(%d*);")
--date formatting here
table.insert(date_top10,(os.date("%x",daydate)))
--end of formatting
local s,f,rxdaymib=string.find(vntable[i],"%a;%d*;%d*;(%d*);")
local s,f,txdaymib=string.find(vntable[i],"%a;%d*;%d*;%d*;(%d*);")
local s,f,rxdaykib=string.find(vntable[i],"%a;%d*;%d*;%d*;%d*;(%d*);")
local s,f,txdaykib=string.find(vntable[i],"%a;%d*;%d*;%d*;%d*;%d*;(%d*);")
local rx=(tonumber(rxdaymib)+(tonumber(rxdaykib)/1024))
local tx=(tonumber(txdaymib)+(tonumber(txdaykib)/1024))
table.insert(rx_top10_mib,string.format("%.02f",round(rx,2)))
table.insert(tx_top10_mib,string.format("%.02f",round(tx,2)))
table.insert(total_top10_mib,string.format("%.02f",round((rx+tx),2)))
local h=tonumber(os.date("%H"))*(60*60)
local m=tonumber(os.date("%M"))*(60)
local s=tonumber(os.date("%S"))
if i == 14 then
table.insert(total_avg_top10_kbit,string.format("%.02f",round(((rx+tx)/(h+m+s))*1024*8,2)))
table.insert(rx_avg_top10_kbit,string.format("%.02f",round(((rx)/(h+m+s))*1024*8,2)))
table.insert(tx_avg_top10_kbit,string.format("%.02f",round(((tx)/(h+m+s))*1024*8,2)))
--kib
table.insert(total_avg_top10_kib,string.format("%.02f",round(((rx+tx)/(h+m+s))*1024,2)))
table.insert(rx_avg_top10_kib,string.format("%.02f",round(((rx)/(h+m+s))*1024,2)))
table.insert(tx_avg_top10_kib,string.format("%.02f",round(((tx)/(h+m+s))*1024,2)))
else
table.insert(total_avg_top10_kbit,string.format("%.02f",round(((rx+tx)/(24*60*60))*1024*8,2)))
table.insert(rx_avg_top10_kbit,string.format("%.02f",round(((rx)/(24*60*60))*1024*8,2)))
table.insert(tx_avg_top10_kbit,string.format("%.02f",round(((tx)/(24*60*60))*1024*8,2)))
--kib
table.insert(total_avg_top10_kib,string.format("%.02f",round(((rx+tx)/(24*60*60))*1024,2)))
table.insert(rx_avg_top10_kib,string.format("%.02f",round(((rx)/(24*60*60))*1024,2)))
table.insert(tx_avg_top10_kib,string.format("%.02f",round(((tx)/(24*60*60))*1024,2)))
end
--MB/ KB/s
local rx=rx*1.048576
local tx=tx*1.048576
table.insert(rx_top10_mb,string.format("%.02f",round(rx,2)))
table.insert(tx_top10_mb,string.format("%.02f",round(tx,2)))
table.insert(total_top10_mb,string.format("%.02f",round((rx+tx),2)))
if i == 14 then
table.insert(total_avg_top10_kb,string.format("%.02f",round(((rx+tx)/(h+m+s))*1000,2)))
table.insert(rx_avg_top10_kb,string.format("%.02f",round(((rx)/(h+m+s))*1000,2)))
table.insert(tx_avg_top10_kb,string.format("%.02f",round(((tx)/(h+m+s))*1000,2)))
else
table.insert(total_avg_top10_kb,string.format("%.02f",round(((rx+tx)/(24*60*60))*1000,2)))
table.insert(rx_avg_top10_kb,string.format("%.02f",round(((rx)/(24*60*60))*1000,2)))
table.insert(tx_avg_top10_kb,string.format("%.02f",round(((tx)/(24*60*60))*1000,2)))
end
end
--HOURS --raw kb kbit###########################################################################
rx_hour_kib={}
tx_hour_kib={}
total_hour_kib={}
total_avg_hour_kbit={}
rx_avg_hour_kbit={}
tx_avg_hour_kbit={}
total_avg_hour_kib={}
rx_avg_hour_kib={}
tx_avg_hour_kib={}
--hours raw kb
rx_hour_kb={}
tx_hour_kb={}
total_hour_kb={}
total_avg_hour_kb={}
rx_avg_hour_kb={}
tx_avg_hour_kb={}
--hours sorted kib/kbit #############################################
rx_hours_kib={}
tx_hours_kib={}
total_hours_kib={}
total_avg_hours_kbit={}
rx_avg_hours_kbit={}
tx_avg_hours_kbit={}
--hours sorted kb
rx_hours_kb={}
tx_hours_kb={}
total_hours_kb={}
total_avg_hours_kb={}
rx_avg_hours_kb={}
tx_avg_hours_kb={}
--time
time_hours={}
for i = 66, 89 do
local s,f,rxhourkib=string.find(vntable[i],"%a;%d*;%d*;(%d*);")
local s,f,txhourkib=string.find(vntable[i],"%a;%d*;%d*;%d*;(%d*)$")
local rx=tonumber(rxhourkib)
local tx=tonumber(txhourkib)
table.insert(rx_hour_kib,rx)
table.insert(tx_hour_kib,tx)
table.insert(total_hour_kib,rx+tx)
local m=tonumber(os.date("%M"))*(60)
local s=tonumber(os.date("%S"))
if i == 66 then
table.insert(total_avg_hour_kbit,((rx+tx)/(m+s))*8)
table.insert(rx_avg_hour_kbit,((rx)/(m+s))*8)
table.insert(tx_avg_hour_kbit,((tx)/(m+s))*8)
--kib
table.insert(total_avg_hour_kib,((rx+tx)/(m+s)))
table.insert(rx_avg_hour_kib,((rx)/(m+s)))
table.insert(tx_avg_hour_kib,((tx)/(m+s)))
else
table.insert(total_avg_hour_kbit,((rx+tx)/(60*60))*8)
table.insert(rx_avg_hour_kbit,((rx)/(60*60))*8)
table.insert(tx_avg_hour_kbit,((tx)/(60*60))*8)
--kib
table.insert(total_avg_hour_kib,((rx+tx)/(60*60)))
table.insert(rx_avg_hour_kib,((rx)/(60*60)))
table.insert(tx_avg_hour_kib,((tx)/(60*60)))
end
--KB
local rx=rx*1.024
local tx=tx*1.024
table.insert(rx_hour_kb,rx)
table.insert(tx_hour_kb,tx)
table.insert(total_hour_kb,(rx+tx))
if i == 66 then
table.insert(total_avg_hour_kb,((rx+tx)/(m+s)))
table.insert(rx_avg_hour_kb,((rx)/(m+s)))
table.insert(tx_avg_hour_kb,((tx)/(m+s)))
else
table.insert(total_avg_hour_kb,((rx+tx)/(60*60)))
table.insert(rx_avg_hour_kb,((rx)/(60*60)))
table.insert(tx_avg_hour_kb,((tx)/(60*60)))
end
end
for i = 1, 24 do
--sort hours into previous list
local h=tonumber(os.date("%H"))
local hr=(((h-(i-1)) % 24))+1
--KiB
table.insert(rx_hours_kib,string.format("%.02f",round(rx_hour_kib[hr],2)))
table.insert(tx_hours_kib,string.format("%.02f",round(tx_hour_kib[hr],2)))
table.insert(total_hours_kib,string.format("%.02f",round(total_hour_kib[hr],2)))
--rates kbit
table.insert(total_avg_hours_kbit,string.format("%.02f",round(total_avg_hour_kbit[hr],2)))
table.insert(rx_avg_hours_kbit,string.format("%.02f",round(rx_avg_hour_kbit[hr],2)))
table.insert(tx_avg_hours_kbit,string.format("%.02f",round(tx_avg_hour_kbit[hr],2)))
--KB
table.insert(rx_hours_kb,string.format("%.02f",round((rx_hour_kb[hr]),2)))
table.insert(tx_hours_kb,string.format("%.02f",round((tx_hour_kb[hr]),2)))
table.insert(total_hours_kb,string.format("%.02f",round((total_hour_kb[hr]),2)))
--rates kb
table.insert(total_avg_hours_kb,string.format("%.02f",round((total_avg_hour_kb[hr]),2)))
table.insert(rx_avg_hours_kb,string.format("%.02f",round((rx_avg_hour_kb[hr]),2)))
table.insert(tx_avg_hours_kb,string.format("%.02f",round((tx_avg_hour_kb[hr]),2)))
--time -- hour in 24 format
table.insert(time_hours,string.format("%02d",hr-1))
end
--of data section
end
vnstat_display()
--#########################################################################################################
end-- if updates>5
cairo_destroy(cr)
cairo_surface_destroy(cs)
cr=nil
return ""
end--end main function
function vnstat_display()
local x = 50
local y = 30
local gapy = 11
local cwid = 80
local fName = "Liberation Sans Mono"
local fSize = 11
local color = 0xffffff
local alpha = 1
-- по дням
text(cr, x, y, "ПО ДНЯМ", fName, fSize, color, alpha, 0, false, false, false)
local line_1 = {"DATE", "RX MiB", "TX MiB", "T MiB", "T Kbit/s"}
for i = 0, 4 do
text(cr, x+i*cwid, y+fSize, line_1[i+1], fName, fSize, color, alpha, 0, true)
end
for i = 1, 12 do
text(cr, x, y+fSize+i*gapy, date_day[i], fName, fSize, color, alpha, 0, true)
text(cr, x+100, y+fSize+i*gapy, rx_day_mib[i], fName, fSize, color, alpha, 0, false, false, true)
text(cr, x+180, y+fSize+i*gapy, tx_day_mib[i], fName, fSize, color, alpha, 0, false, false, true)
text(cr, x+260, y+fSize+i*gapy, total_day_mib[i], fName, fSize, color, alpha, 0, false, false, true)
text(cr, x+340, y+fSize+i*gapy, total_avg_day_kbit[i], fName, fSize, color, alpha, 0, false, false, true)
end
-- по месяцам
local y = 200
text(cr, x, y, "ПО МЕСЯЦАМ", fName, fSize, color, alpha, 0, false, false, false)
for i = 0, 4 do
text(cr, x+i*cwid, y+fSize, line_1[i+1], fName, fSize, color, alpha, 0, true)
end
for i = 1, 12 do
text(cr, x, y+fSize+i*gapy, date_month[i], fName, fSize, color, alpha, 0, true)
text(cr, x+100, y+fSize+i*gapy, rx_month_mib[i], fName, fSize, color, alpha, 0, false, false, true)
text(cr, x+180, y+fSize+i*gapy, tx_month_mib[i], fName, fSize, color, alpha, 0, false, false, true)
text(cr, x+260, y+fSize+i*gapy, total_month_mib[i], fName, fSize, color, alpha, 0, false, false, true)
text(cr, x+340, y+fSize+i*gapy, total_avg_month_kbit[i], fName, fSize, color, alpha, 0, false, false, true)
end
-- топ 10
local y = 380
text(cr, x, y, "TOP-10", fName, fSize, color, alpha, 0, false, false, false)
for i = 0, 4 do
text(cr, x+i*cwid, y+fSize, line_1[i+1], fName, fSize, color, alpha, 0, true)
end
for i = 1, 10 do
text(cr, x, y+fSize+i*gapy, date_top10[i], fName, fSize, color, alpha, 0, true)
text(cr, x+100, y+fSize+i*gapy, rx_top10_mib[i], fName, fSize, color, alpha, 0, false, false, true)
text(cr, x+180, y+fSize+i*gapy, tx_top10_mib[i], fName, fSize, color, alpha, 0, false, false, true)
text(cr, x+260, y+fSize+i*gapy, total_top10_mib[i], fName, fSize, color, alpha, 0, false, false, true)
text(cr, x+340, y+fSize+i*gapy, total_avg_top10_kbit[i], fName, fSize, color, alpha, 0, false, false, true)
end
end
function text(cr, x, y, text, fname, fsize, fgc, fga, rotation, x_align, y_align, right)
-- имя шрифта
cairo_select_font_face (cr, fname, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD)
-- размер шрифта
cairo_set_font_size (cr, fsize)
local te = cairo_text_extents_t:create()
tolua.takeownership(extents)
cairo_text_extents (cr, text, te)
--
if x_align then x = x - (te.width/2 + te.x_bearing) end
if y_align then y = y - (te.height/2 + te.y_bearing) end
if right then x = x - te.width end
cairo_move_to(cr, x, y)
-- цвет шрифта
cairo_set_source_rgba(cr, rgb_to_r_g_b(fgc, fga))
-- поворот текста
cairo_rotate (cr, rotation*math.pi/180)
-- отображение текста
cairo_show_text(cr, text)
end
-- перекодировка цвета
function rgb_to_r_g_b(colour, alpha)
return ((colour / 0x10000) % 0x100) / 255., ((colour / 0x100) % 0x100) / 255., (colour % 0x100) / 255., alpha
end