Xubuntu18.04LTSでConkyを表示


やること

自分のXubuntuのデスクトップにConkyを使って情報を表示する。

使用するマシン

モデル: Let's Note CF-R3
CPU: Intel(R) Pentium(R) M processor 1.10GHz
OS: Xubuntu 18.04.4 LTS (i386)
Kernel: 5.3.0-51-generic
RAM: 256MB+512MB
(スペックくそとか言わないでね)

早速やっていく

まずはConkyを導入

$ sudo apt-get install conky-all

この時、単純に「sudo apt-get install conky」としないように。こいつの実態はconky-stdだから機能が制限されるらしい。

設定ファイル作成

Conkyを実行するとデフォルトの設定ファイルが/etcに作成される。これをホームディレクトリにコピーして使う。

$ conky
#Ctrl+Cで1度終了
$ cp /etc/conky/conky.conf ~/.conkyrc

これでConkyを使う準備が整った。

Conky実行

改めてConkyを実行する。

$ conky


お世辞でも良いとは言えない感じ。見た目の変更が必要ですね。

設定ファイルの編集

今のままだと、Conkyがデスクトップのアイコンにかぶっちゃうし、クリックすると消えちゃうしでろくに使えないため、設定ファイルを編集する。
さっきコピーした.conkyrcをテキストエディタなどで編集する。自分はnanoエディタが1番慣れてるため、以下のようにした。

$ nano ~/.conkyrc

デフォルトでは以下のようになっている。

.conkyrc

-- vim: ts=4 sw=4 noet ai cindent syntax=lua
--[[
Conky, a system monitor, based on torsmo

Any original torsmo code is licensed under the BSD license

All code written since the fork of torsmo is licensed under the GPL

Please see COPYING for details

Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
Copyright (c) 2005-2012 Brenden Matthews, Philip Kovacs, et. al. (see AUTHORS)
All rights reserved.

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
]]

conky.config = {
    alignment = 'top_left',
    background = false,
    border_width = 1,
    cpu_avg_samples = 2,
    default_color = 'white',
    default_outline_color = 'white',
    default_shade_color = 'white',
    draw_borders = false,
    draw_graph_borders = true,
    draw_outline = false,
    draw_shades = false,
    use_xft = true,
    font = 'DejaVu Sans Mono:size=12',
    gap_x = 5,
    gap_y = 60,
    minimum_height = 5,
    minimum_width = 5,
    net_avg_samples = 2,
    no_buffers = true,
    out_to_console = false,
    out_to_stderr = false,
    extra_newline = false,
    own_window = true,
    own_window_class = 'Conky',
    own_window_type = 'desktop',
    stippled_borders = 0,
    update_interval = 1.0,
    uppercase = false,
    use_spacer = 'none',
    show_graph_scale = false,
    show_graph_range = false
}

conky.text = [[
${scroll 16 $nodename - $sysname $kernel on $machine | }
$hr
${color grey}Uptime:$color $uptime
${color grey}Frequency (in MHz):$color $freq
${color grey}Frequency (in GHz):$color $freq_g
${color grey}RAM Usage:$color $mem/$memmax - $memperc% ${membar 4}
${color grey}Swap Usage:$color $swap/$swapmax - $swapperc% ${swapbar 4}
${color grey}CPU Usage:$color $cpu% ${cpubar 4}
${color grey}Processes:$color $processes  ${color grey}Running:$color $running_processes
$hr
${color grey}File systems:
 / $color${fs_used /}/${fs_size /} ${fs_bar 6 /}
${color grey}Networking:
Up:$color ${upspeed eth0} ${color grey} - Down:$color ${downspeed eth0}
$hr
${color grey}Name              PID   CPU%   MEM%
${color lightgrey} ${top name 1} ${top pid 1} ${top cpu 1} ${top mem 1}
${color lightgrey} ${top name 2} ${top pid 2} ${top cpu 2} ${top mem 2}
${color lightgrey} ${top name 3} ${top pid 3} ${top cpu 3} ${top mem 3}
${color lightgrey} ${top name 4} ${top pid 4} ${top cpu 4} ${top mem 4}
]]

まずはConkyが表示される場所を変更する。

〜
    alignment = 'top_right,' #右上に
〜

これで右上に表示できた。

次に、バックグラウンドで実行するようにする。ついでに、背景を半透明にする。

.conkyrc
〜
    background = true, #バックグラウンドで実行
〜
    own_window_type = 'normal',
    own_window_hints = 'undecorated,below,sticky,skip_taskbar,skip_pager',
    own_window_argb_visual = yes,
    own_window_argb_value = 100,
    own_window_color = black,
    #以上で半透明に
〜

上書き保存して、Conkyを実行する。
バックグラウンドで実行されるため、シェルを終了してもConkyは消えない。また、この状態で設定ファイルを更新すると、Conkyにリアルタイムで反映される。
ちなみに、半透明にしているのは、
own_window_type = 'normal'
でConkyを普通のウィンドウとして表示し、
own_window_hints = (略)
で枠とかを消したり1番後ろに表示したりして、
own_window_argb_visual = yes,
own_window_argb_value = 100,
で透明化、透明度の指定をしている。
しかし、今のままでは、Conkyの表示が1秒ごとに点滅してとても見ずらい。これも設定ファイルで改善できる。

.conkyrcのconky.config内に追記
〜
    double_buffer = true,
〜

追記する時は行末の,を忘れないようにする。(自分は思いっきりしくじった)
これでやっと安定した。
現状は以下のようになっている。
あとは表示内容を変えていく。
表示する内容は.conkyrcのconky.text内をいじくる。コマンドの結果を出力したい時は以下のように記述する。

${exec コマンド}

そして最終的に以下のようになった。

.conkyrc

-- vim: ts=4 sw=4 noet ai cindent syntax=lua
--[[
Conky, a system monitor, based on torsmo

Any original torsmo code is licensed under the BSD license

All code written since the fork of torsmo is licensed under the GPL

Please see COPYING for details

Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
Copyright (c) 2005-2012 Brenden Matthews, Philip Kovacs, et. al. (see AUTHORS)
All rights reserved.

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
]]

conky.config = {
    alignment = 'top_right',
    background = true,
    border_width = 1,
    cpu_avg_samples = 2,
    default_color = 'white',
    default_outline_color = 'white',
    default_shade_color = 'white',
    draw_borders = false,
    draw_graph_borders = false,
    draw_outline = false,
    draw_shades = false,
    double_buffer = true,
    use_xft = true,
    font = 'DejaVu Sans Mono:size=9',
    gap_x = 5,
    gap_y = 60,
    minimum_height = 5,
    minimum_width = 5,
    net_avg_samples = 2,
    no_buffers = true,
    out_to_console = false,
    out_to_stderr = false,
    extra_newline = false,
    own_window = true,
    own_window_class = 'Conky',
    own_window_type = 'normal',
    own_window_transparent = false,
    own_window_hints = 'undecorated,below,sticky,skip_taskbar,skip_pager',
    own_window_argb_visual = true,
    own_window_argb_value = 0,
    stippled_borders = 0,
    update_interval = 1.0,
    uppercase = false,
    use_spacer = 'none',
    show_graph_scale = false,
    show_graph_range = false,
}

conky.text = [[
${font Ubuntu:bold:size=12}Let's Note CF-R3EW1AXS $hr${font}
${font Ubuntu:bold:size=9}OS:${font}$color ${execi -1 cat /etc/lsb-release | awk -F "\"" '{print $2}' | sed -n 4p}
${font Ubuntu:bold:size=9}Kernel:${font}$color ${kernel}
${font Ubuntu:bold:size=9}Uptime:${font}$color $uptime
${font Ubuntu:bold:size=9}Battery:${font}$color${exec acpi | awk -F ',' '{print $2}'}
${font Ubuntu:bold:size=9}Processes:${font}
${color grey}Name               PID     CPU     MEM
${color lightgrey} ${top name 1} ${top pid 1} ${top cpu 1}% ${top mem 1}%
${color lightgrey} ${top name 2} ${top pid 2} ${top cpu 2}% ${top mem 2}%
${color lightgrey} ${top name 3} ${top pid 3} ${top cpu 3}% ${top mem 3}%
${color lightgrey} ${top name 4} ${top pid 4} ${top cpu 4}% ${top mem 4}%

${color 4CE64C}${font Ubuntu:bold:size=11}CPU:${font}
${color}Intel(R) Pentium(R) M processor 1.10GHz
${color 4ce64c}${cpugraph cpu0 4ce64c 4ce64c}
$color${alignr}$cpu% ${freq_g}GHz/${exec echo $(($(cat /sys/class/thermal/thermal_zone0/temp) + 1000)) | head -c 2}°C

${color ff8787}${font Ubuntu:bold:size=11}RAM:${font}
${membar 10}$color
${alignr}$mem/$memmax - $memperc%
${color}>>SWAP
${color ff8787}${swapbar 4}
$color${alignr}$swap/$swapmax - $swapperc%

${color 4CCCE6}${font Ubuntu:bold:size=11}HDD:${font} $color${execi 0 cat /proc/scsi/scsi | grep Model | awk '{print $4,$5}' | sed -n 1p
}
${color 4CCCE6}${fs_bar 10}
${alignr}$color${fs_used /}/${fs_size /} ${exec hddtemp /dev/sda | awk '{print$4}'}

${color 295fcc}${font Ubuntu:bold:size=11}Networking:${font}$color wlp2s4${color 295fcc}
${color 295fcc}${font IPAGothic Regurer:size=15}⬆${upspeedgraph wlp2s4 20,110}${alignr}⬇${downspeedgraph wlp2s4 20,110}$font
${color}   ${upspeedf wlp2s4} KB/s${goto 148}   ${downspeedf wlp2s4} KB/s${color 295fcc}${color}
]]

ちなみにCPUの温度は/sys/class/thermal/thermal_zone0/temp の中身を参照しています。本当はlm-sensorでできるんですが、このパソコン対応してませんでした。
HDDの温度はhddtempをapt-getでいれて使ってます。

表示した感じは次のよう。

壁紙とか色々変わってますが気にしないでくださいね()

以上でConkyが無事導入出来ました。

起動時自動実行

起動した時に実行できるように設定します。
xfceの場合は設定からセッションと起動をひらき、自動開始アプリケーションのタブに移動します。
追加のボタンを押して、以下のように記述。

名前: Conky
説明: conky
コマンド: /usr/bin/conky -p 15

名前と説明は任意で構いません。コマンドの'-p 15'というのがミソです。
これはconkyの起動を15秒遅らせるという処理です。こうしないと、ウィンドウマネージャーが起動し終わる前にconkyが起動して、不具合が起きます。
15秒という値はパソコンのスペックに合わせて調整します。

最後に

今回Conkyを実装してみて、CPUの温度がやばい事に気づいた。グリス塗り直します、、、