ubuntu SettingUpConky

原文:https://help.ubuntu.com/community/SettingUpConky

Setting Up Conky

This guide will step you through initial installation and configuration of Conky for Ubuntu. Conky is extremely configurable; there are virtually unlimited ways of configuring it. The nuances of advanced conky configuration are beyond the scope of this article, but many resources exist online regarding this subject. A few are given here for anyone interested:

Installation

First, let’s define the various aspects of conky.

CONKY – Conky is a system monitor for X originally based on the torsmo code.

Since its original conception, Conky has changed a fair bit from its predecessor. Conky can display just about anything, either on your root desktop or in its own window. Conky has many built-in objects, as well as the ability to execute programs and scripts, then display the output from stdout.

First, you need the file “conky” and I’d suggest you look at curl, lm-sensors and hddtemp as well, described below. You may as well get them now, I’ll bet you will in the future if you don’t:

sudo apt-get install conky-all

CURL – Get a file from an HTTP, HTTPS or FTP server

curl is a client to get files from servers using any of the supported protocols. The command is designed to work without user interaction or any kind of interactivity.

curl offers a busload of useful tricks like proxy support, user authentication, FTP upload, HTTP post, file transfer resume and more.

LM-SENSORS – utilities to read temperature/voltage/fan sensors

Lm-sensors is a hardware health monitoring package for Linux. It allows you to access information from temperature, voltage, and fan speed sensors. It works with most newer systems.

This package contains programs to help you set up and read data from lm-sensors.

Homepage

HDDTEMP – hard drive temperature monitoring utility

In order to use the above code without sudo or root to get the hard drive temperature displayed in conky; one can run the following
after the prompt:

sudo dpkg-reconfigure hddtemp

The hddtemp program monitors and reports the temperature of PATA, SATA or SCSI hard drives by reading Self-Monitoring Analysis and Reporting Technology (S.M.A.R.T.) information on drives that support this feature.

If you want all four, it’s easy:

sudo apt-get install conky curl lm-sensors hddtemp

Running & Configuration

To run conky, open a terminal and type:

conky &

and you’ll see a little window open and display a basic conky. That’s the default conky configuration. The file can be found in /etc/conky/conky.conf.

However, you likely want it on your desktop all the time and customized for your system, not in a pop-up window. This can be done by creating and editing a file in your home directory called .conkyrc. Create an empty file in your home folder and name it .conkyrc. The period at the beginning of the filename sets it to hidden, so to view the file in your file manager you must enable viewing hidden files/folders. In most file managers you can activate this by pressing Ctrl+h. It is usually best to start with an existing .conkyrc file and edit to suit your tastes. You can copy the contents of /etc/conky/conky.conf into the new .conkyrc and edit that, or you can find a config file on the web and use it. Regardless, paste the contents of the existing conky file into the new .conkyrc and save.
Conky is very popular and .conkyrc files are available all over the web. One good place to start would be this thread in the Ubuntu forums.

Now restart conky by running

killall -SIGUSR1 conky

It will now be using your new .conkyrc file.

Set Conky To Start At Boot

Conky only becomes useful when it is set to start up at boot. Here’s how in Ubuntu and the various respins.

In Ubuntu/Unity:

Click the gear icon in the upper right hand corner of the top panel. Select Startup Applications. Click Add. In the resulting dialog box give the name as “Conky” and the command as conky. Click add and close.

In Ubuntu/Gnome Shell

Press Alt+F2 to bring up the Run dialog. Type gnome-session-properties. Click the “Add” button. In the resulting dialog box give the name as “Conky” and the command as conky. Click add and close.

In Kubuntu

Go to K-Menu>Computer>System Settings. Select Startup and Shutdown and click the Add Program button. Type conky and click OK.

In Lubuntu

Run the following commands in a terminal:

mkdir -p ~/.config/lxsession/Lubuntu/
touch ~/.config/lxsessions/Lubuntu/autostart
leafpad autostart

Add this line to the autostart file:

@conky

Save and close.

In Xubuntu

In the Applications menu open Settings Manager and select Session and Startup. On the Application Autostart tab click the Add button. In the resulting dialog box give the name as “Conky” and the command as conky.

Running Multiple Conky

You may wish to run multiple instances of Conky on your desktop. You could be running a system info Conky on the left side of your desktop and a weather Conky along the bottom; the options are nearly infinite.
First you need to be sure your Conky are aligned on the desktop differently, so they don’t overlap each other. You can specify the alignment of a Conky in the .conkyrc file by changing the line beginning with “alignment”. The syntax is as follows:

alignment top_right  # top_right, top_left, bottom_left, bottom_right

To set multiple Conky to run at startup, create a folder called .conky.

mkdir ~/.conky

Save your different Conky config files in there. You may want to name them .conkyrc_top, .conkyrc_bottom, etc. You should save all your Conky config files there. Next create a script that will execute all these Conky files. Something like the following:

 #!/bin/bash
conky -c ~/.conky/.conkyrc_top &
conky -c ~/.conky/.conkyrc_bottom

Note that all commands except the last must be appended with an ampersand (&) so that the script will not stop at the first command.
The “conky -c random_file” command simply tells conky to use random_file for configuration instead of the default ~/.conkyrc. Save this file as conky_start in ~/bin; if the folder does not already exist, create it.

mkdir ~/bin

Next set it to exectuable:

chmod a+x ~/bin/conky_start

Now follow the instructions given above on autostarting, only substitute “conky_start” for “conky”. NOTE: In Kubuntu, you must choose “Add Script” rather than “Add Program”.
If you’ve already set “conky” to launch at startup, you must remove it when adding “conky_start”. Although this will get you started with a functioning Conky, this is only the beginning. Enjoy configuring it to your liking, and feel free to share your config files!

conkyrc

Ubuntu 16.04

os.execute(“sleep 1”)

conky.config = {
background = true,
override_utf8_locale = true,
double_buffer = yes,
alignment = ‘top_right’,
border_width = 1,
cpu_avg_samples = 2,
default_color = ‘white’,
default_outline_color = ‘black’,
default_shade_color = ‘black’,
draw_borders = false,
draw_graph_borders = false,
draw_outline = false,
draw_shades = false,
net_avg_samples = 2,
no_buffers = true,
out_to_console = false,
out_to_stderr = false,
extra_newline = false,
own_window = true,
own_window_type = ‘normal’,
own_window_transparent = true,
own_window_argb_visual = true,
own_window_argb_value = 64,

own_window_hints = ‘undecorated,below,sticky,skip_taskbar,skip_pager’,
minimum_width = 300, minimum_height = 0,
stippled_borders = 0,
update_interval = 1.0,
uppercase = false,
use_spacer = ‘none’,
show_graph_scale = false,
show_graph_range = false,
use_xft = true,
xftalpha = 0.1,
font = ‘Droid Sans:size=11’,
color0 = ‘white’,
color1 = ‘EAEAEA’,
color2 = ‘FFA300’,
color3 = ‘grey’
}

conky.text = [[
${font Noto Sans CJK SC:size=20}${time %Y年%m月%d日 星期%a }
${font Noto Sans CJK SC:size=12}${execi 6 /usr/bin/lunar -u -s | grep ‘阴历’| paste -s | cut -c1-36}
${font Noto Sans CJK SC:size=12}${execi 6 /usr/bin/lunar -u -s | grep ‘干支’| paste -s | cut -c1-100}

${font Sans:bold:size=16}${color white}System ${color slate grey}${hr 2}${font}

${color1}Computer name ${alignr}${color}${nodename}
${color1}Kernel version ${alignr}${color}${kernel}-${machine}
$hr
${color grey}Uptime:$color $uptime
${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

${cpugraph 000000 FFFFFF}
CPU1 Temperature: $color${execi 6 /usr/bin/sensors | grep ‘Core 0’| paste -s | cut -c15-18,19-21}°C ${cpu cpu0}% ${color FFFFFF}${cpubar cpu0}$color
CPU2 Temperature: $color${execi 6 /usr/bin/sensors | grep ‘Core 1’| paste -s | cut -c15-18,19-21}°C ${cpu cpu1}% ${color FFFFFF}${cpubar cpu1}$color
#3: Temp: $color${exec sensors|grep ‘Core 2’|awk ‘{print $3}’|sed ‘s/xC2//g’|sed ‘s/xb0//g’}°C ${cpu cpu3}% ${color FFFFFF}${cpubar cpu3}$color
#4: Temp: $color${exec sensors|grep ‘Core 3’|awk ‘{print $3}’|sed ‘s/xC2//g’|sed ‘s/xb0//g’}°C ${cpu cpu4}% ${color FFFFFF}${cpubar cpu4}$color

$hr

${font Sans:bold:size=16}${color white}Networking${font}
Download:$color ${downspeed enp2s0}
${downspeedgraph enp2s0 30}
Upload:$color ${upspeed enp2s0}
${upspeedgraph enp2s0 30}
]]

Ubuntu14.04

.conkyrc
# Conky settings #
background no
update_interval 1
cpu_avg_samples 2
net_avg_samples 2
override_utf8_locale yes
double_buffer yes
no_buffers yes
text_buffer_size 2048
#imlib_cache_size 0
temperature_unit fahrenheit
# Window specifications #
own_window yes
own_window_type override
own_window_transparent yes
own_window_hints undecorate,sticky,skip_taskbar,skip_pager,below
border_inner_margin 0
border_outer_margin 0
minimum_size 200 250
maximum_width 250
alignment tr
gap_x 35
gap_y 55
# Graphics settings #
draw_shades no
draw_outline no
draw_borders no
draw_graph_borders no
# Text settings #
use_xft yes
xftfont caviar dreams:size=12
xftalpha 0.5
uppercase no
temperature_unit celsius
default_color FFFFFF
TEXT
${font Microsoft YaHei:size=16}${time %Y年%m月%d日 星期%a }
#${execi /usr/bin/lunar –utf8 time %Y %m %d}${font :size=12}${time %k:%M:%S}
${font caviar dreams:size=12}${color FFFFFF}CPU0 Temperature${execi 6 /usr/bin/sensors | grep Core 0| paste -s | cut -c15-18,19-21} °C${font}
$color1 Usage: $color2${cpu cpu0}% $color1      ${cpubar cpu0}
${font caviar dreams:size=12}${color FFFFFF}CPU1 Temperature${execi 6 /usr/bin/sensors | grep Core 1| paste -s | cut -c15-18,19-21} °C${font}
$color1 Usage: $color2${cpu cpu1}% $color1      ${cpubar cpu1}
${font caviar dreams:size=12}${color FFFFFF}CPU2 Temperature${execi 6 /usr/bin/sensors | grep Core 2| paste -s | cut -c15-18,19-21} °C${font}
$color1 Usage: $color2${cpu cpu2}% $color1      ${cpubar cpu2}
${font caviar dreams:size=12}${color FFFFFF}CPU3 Temperature${execi 6 /usr/bin/sensors | grep Core 3| paste -s | cut -c15-18,19-21} °C${font}
$color1 Usage: $color2${cpu cpu3}% $color1      ${cpubar cpu3}
#${color2}FAN: $color1${execi 300 /usr/bin/sensors | grep fan | cut -c11-17}rpm      #获取风扇转速
#${color2}GPU:  $color1${execi 300 /usr/bin/sensors | grep temp4 | cut -c15-16}℃      #获取显卡温度
${color2}HDD: $color1${hddtemp /dev/sda} °C${font}  #获取硬盘温度,实际上也可通过获取显卡温度的方法获取硬盘温度,只是该方法比较方便。
${color1}Memory ${color2}($memmax)
${color1}RAM: $color2$mem($memperc%) ${membar}
${color1}Swap: $color2$swap ($swapperc%) ${swapbar}
${color1}Net
${color1}Download: $color2${downspeed eth0}
${downspeedgraph eth0}
${color1}Upload: $color2 ${upspeed eth0}
${upspeedgraph eth0}
${color FFFFFF}${font caviar dreams:size=12}${nodename}
${color FFFFFF}${font caviar dreams:size=12}${pre_exec cat /etc/issue.net}  $machine
${color FFFFFF}${font caviar dreams:size=12}Kernel: ${kernel}