
これは私のものですconkyrc
:
conky.config = {
use_xft = true, -- use xft?
font = 'DejaVuSans:size=9', -- font name
xftalpha = 1,
uppercase = false, -- all text in uppercase?
pad_percents = 0,
text_buffer_size = 2048,
override_utf8_locale = true, -- Force UTF8? note that UTF8 support required XFT
use_spacer = 'none', -- Add spaces to keep things from moving about? This only affects certain objects.
update_interval = 1, -- Update interval in seconds
double_buffer = true, -- Use double buffering (reduces flicker, may not work for everyone)
total_run_times = 0, -- This is the number of times Conky will update before quitting. Set to zero to run forever.
-- Create own window instead of using desktop (required in nautilus)
own_window = true,
own_window_class = 'Conky',
own_window_transparent = true,
own_window_argb_visual = true,
own_window_argb_value = 255,
own_window_type = 'desktop', -- transparency seems to work without this line
own_window_hints = 'undecorated,sticky,below,skip_taskbar,skip_pager',
-- Minimum size of text area
minimum_height = 50,
minimum_width = 210,
draw_shades = false, -- draw shades?
draw_outline = false, -- draw outlines?
draw_borders = false, -- draw borders around text?
draw_graph_borders = false, -- draw borders around graphs
stippled_borders = 0, -- stripled borders?
imlib_cache_size = 0, -- Imlib2 image cache size, in bytes. Increase this value if you use $image lots. Set to 0 to disable the image cache.
-- Gap between borders of screen and text. Same thing as passing -x at command line
gap_x = 90,
gap_y = 5,
alignment = 'middle_right', -- alignment on {y_axis}_{x_axis}
cpu_avg_samples = 2, -- number of cpu samples to average. set to 1 to disable averaging
net_avg_samples = 2, -- number of net samples to average. set to 1 to disable averaging
no_buffers = true, -- Subtract file system buffers from used memory?
default_color = 'e0e0e0',
default_shade_color = '000000',
default_outline_color = '000000',
temperature_unit = 'celsius',
color1 = 'ff55ff', -- heading's color
color2 = 'ffffff', -- normal text's color
lua_load = '.conky/netdevs.lua',
};
conky.text = [[
...
${color1}NET: ${hr 2}${color2}${lua_parse conky_show_netdevs}
...
]]
これは.config/netdevs.lua
:
-- conky_show_netdevs : template for network
-- usage : ${lua_parse conky_show_netdevs}
prev_result = ""
function conky_show_netdevs()
updates = tonumber(conky_parse("${updates}"))
interval = 10
timer = (updates % interval)
if timer == 0 or prev_result == "" then
local netdevs_handle = io.popen("ip -j link show up | jq -r '.[] | select(.operstate == \"UP\" and .ifname != \"lo\") | .ifname'")
local result = ""
for netdev in netdevs_handle:lines() do
result = result .. "\nIP (${color1}" .. netdev .. "${color2}): ${alignr}${addr " .. netdev .. "}\n" ..
"${color2}Up: ${color2}${upspeed " .. netdev .. "}/s${color1}${alignr}${upspeedgraph " .. netdev .. " 10,170}\n" ..
"${color2}Down: ${color2}${downspeed " .. netdev .. "}/s${color1}${alignr}${downspeedgraph " .. netdev .. " 10,170}\n" ..
"${color2}Total Down: ${color2}${totaldown " .. netdev .. "}${alignr}Total Up: ${totalup " .. netdev .. "}\n"
end
netdevs_handle:close()
if result ~= "" then
prev_result = result
else
prev_result = "\n"
end
end
return prev_result
end
関数出力に返されるsとsを除いて、すべてがうまく機能しますupspeedgraph
。downspeedgraph
conky_show_netdevs()
これは私が見ることができるチャートイメージです(画像の最後の部分の小さな線、「UP」、「DOWN」テキストが表示される行にあります)。
私が知る限り、この問題は、lua関数が再ロードされるたびにコンテンツをconky解析してグラフが再ロードされる可能性があるために発生するようです。それで、conkyの更新間隔を10秒に増やしました。しかし、まだ幸運ではありません:(
答え1
残念ながら、lua_parse
更新サイクルごとに実行されるため、毎回新しい空のグラフが作成されます。最初に構成のネットワーク部分を一度だけ作成したい場合は、.conkyrc
ファイルが単純なluaファイルであるため、luaコードを入れることができることを利用できます。
これを使用して設定文字列を生成するリビジョン関数を呼び出し、それを変数に関連付けますconky.text
。 (以前はLuaでグローバルにアクセスできましたが、もはや可能ではないようです。)
だから.conkyrc
終了
conky.text = [[
...
${color1}NET: ${hr 2}${color2}
]]
require 'netdevs'
conky.text = conky.text .. conky_show_netdevs()
Luaを編集してconky呼び出しを削除し、設定に戻ります。
-- conky_show_netdevs : template for network
function conky_show_netdevs()
local netdevs_handle = io.popen(...)
local result = ""
for netdev in netdevs_handle:lines() do
result = result ...
netdevs_handle:close()
return result
end