2014年7月24日 星期四

Conky 系統監測工具

Conky 是 Linux 上的免費 X-Window 監測工具,可以顯示各硬體監測數據。
------

1. 安裝conky
apt-get install conky conky-all


2. 安裝系統感測軟體
apt-get install curl lm-sensors hddtemp


3. conky 執行指令
conky -dq → turn on conky
pkill conky → turn off conky


4. conky設定檔
cp /etc/conky/conky.conf ~/.conkyrc
vi ~/.conkyrc


5. 開機啟動 conky:
vim ~/.xinitrc
sleep 2 && conky -qd


ps.指令位置要下在環境啟動之前,例如我的 Linux GUI 是使用 icewm,而我的 conky 啟動指令要放在 .xinitrc 文件中 exec icewm 這個指令之前。

我的conky 設定內容如下:

#Aligned position on screen(設定conky位置) 
alignment bottom_right

background no
border_width 1
#border_margin 4

cpu_avg_samples 2

default_color white
default_outline_color white
default_shade_color white
draw_borders no
draw_graph_borders yes
draw_outline no
draw_shades no
double_buffer yes

use_xft yes

#字型及大小
xftfont DejaVu Sans Mono:size=12
#xftfont Bitstream Vera Sans Mono:size=16
#font Sans:size=11

#視窗座標
gap_x 20
gap_y 150

minimum_size 5 5
maximum_width 300

net_avg_samples 2
no_buffers yes

out_to_console no
out_to_stderr no

extra_newline no

own_window no
own_window_transparent no
own_window_class Conky
own_window_type desktop

stippled_borders 0

#更新頻率(秒)
update_interval 1.0
uppercase no
use_spacer no

show_graph_scale no
show_graph_range no
#stippled_borders 10

total_run_time 0
###########################################
TEXT
# Kernel
#${color lightgrey}$sysname $kernel ${color}on ${color lightgrey}$machine
# Time
${color lightgrey}Time:${color 00ff00}${time %Y/%m/%d - %R:%S}
# separator
${color grey}$stippled_hr
# File system
${color lightgrey}File systems:
${color lightgrey}root: $color${fs_used /}${color lightgrey}/$color${fs_size /}
${color lightgrey}(free: $color${fs_free /}${color lightgrey} - $color${fs_free_perc /}%${color lightgrey})
#home: $color${fs_used /home/lin}/${fs_size /home/lin}
${color 7f8ed3}${fs_bar 12 /}
# Networking-eth0
${color lightgrey}Eth0:
${color lightgrey}Down:${color} ${downspeed eth0} ${offset 40}Up:${color} ${upspeed eth0}
${color black}${downspeedgraph eth0 35,140 ff0000 0000ff} ${color black}${upspeedgraph eth0 35,140 0000ff ff0000}
#${color 888888}${downspeedgraph eth0 35,130 ff0000 0000ff}       ${color 888888}${upspeedgraph eth0 35,130 0000ff ff0000}
#${color 888888}TOTAL: ${color CCCCCC}${totaldown eth0}  ${color 888888}TOTAL: ${color CCCCCC}${totalup eth0}
# separator
${color grey}$stippled_hr
# CPU
${color lightgrey}Total CPU:${color ddaa00} ${cpu}%
${color 7f8ed3}${cpubar 12}
${color lightgrey}CPU0:         CPU1:
${color 000000}${cpugraph cpu0 35,140 000000 7f8ed3}    ${color 000000}${cpugraph cpu1 35,140 000000 7f8ed3}
${color lightgrey}CPU2:         CPU3:
${color 000000}${cpugraph cpu2 35,140 000000 7f8ed3}    ${color 000000}${cpugraph cpu3 35,140 000000 7f8ed3}
# RAM
${color lightgrey}RAM: ${color}$mem/$memmax - ${color ddaa00}$memperc%
${color 7f8ed3}${membar 12}
# Swap
${color lightgrey}Swap: ${color}$swap/$swapmax - ${color ddaa00}$swapperc%
${color 7f8ed3}${swapbar 12}
# separator
${color grey}$stippled_hr
# process CPU usage
${color ffccaa}CPU usage         PID   CPU%
${color ddaa00} ${top name 1}${top pid 1}${top cpu 1}
${color lightgrey} ${top name 2}${top pid 2}${top cpu 2}
${color lightgrey} ${top name 3}${top pid 3}${top cpu 3}
${color lightgrey} ${top name 4}${top pid 4}${top cpu 4}

# process RAM usage
${color ffccaa}Mem usage         PID   RAM%
${color ddaa00} ${top_mem name 1}${top_mem pid 1}${top mem 1}
${color lightgrey} ${top_mem name 2}${top_mem pid 2}${top mem 2}
${color lightgrey} ${top_mem name 3}${top_mem pid 3}${top mem 3}
${color lightgrey} ${top_mem name 4}${top_mem pid 4}${top mem 4}


第二版,新增CPU、GPU 溫度(排版修改)

但要偵測顯卡溫度前,要先安裝 Nvidia 顯卡驅動

一般 command 查看溫度的方法:
看CPU 溫度: sensors
看GPU 溫度: nvidia-settings -q gpucoretemp

善用 command 擷取,再加到 .conkyrc 內:
加入後的 conky 如下圖:

.conkyrc 設定如下:
# 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-2010 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 .
#
# Possible variables to be used:
#
#      Variable         Arguments                  Description                
#  acpiacadapter                     ACPI ac adapter state.                   
#  acpifan                           ACPI fan state                           
#  acpitemp                          ACPI temperature.                        
#  adt746xcpu                        CPU temperature from therm_adt746x       
#  adt746xfan                        Fan speed from therm_adt746x             
#  battery           (num)           Remaining capasity in ACPI or APM        
#                                    battery. ACPI battery number can be      
#                                    given as argument (default is BAT0).     
#  buffers                           Amount of memory buffered                
#  cached                            Amount of memory cached                  
#  color             (color)         Change drawing color to color            
#  cpu                               CPU usage in percents                    
#  cpubar            (height)        Bar that shows CPU usage, height is      
#                                    bar's height in pixels                   
#  downspeed         net             Download speed in kilobytes              
#  downspeedf        net             Download speed in kilobytes with one     
#                                    decimal                                  
#  exec              shell command   Executes a shell command and displays    
#                                    the output in torsmo. warning: this      
#                                    takes a lot more resources than other    
#                                    variables. I'd recommend coding wanted   
#                                    behaviour in C and posting a patch :-).  
#  execi             interval, shell Same as exec but with specific interval. 
#                    command         Interval can't be less than              
#                                    update_interval in configuration.        
#  fs_bar            (height), (fs)  Bar that shows how much space is used on 
#                                    a file system. height is the height in   
#                                    pixels. fs is any file on that file      
#                                    system.                                  
#  fs_free           (fs)            Free space on a file system available    
#                                    for users.                               
#  fs_free_perc      (fs)            Free percentage of space on a file       
#                                    system available for users.              
#  fs_size           (fs)            File system size                         
#  fs_used           (fs)            File system used space                   
#  hr                (height)        Horizontal line, height is the height in 
#                                    pixels                                   
#  i2c               (dev), type, n  I2C sensor from sysfs (Linux 2.6). dev   
#                                    may be omitted if you have only one I2C  
#                                    device. type is either in (or vol)       
#                                    meaning voltage, fan meaning fan or temp 
#                                    meaning temperature. n is number of the  
#                                    sensor. See /sys/bus/i2c/devices/ on     
#                                    your local computer.                     
#  kernel                            Kernel version                           
#  loadavg           (1), (2), (3)   System load average, 1 is for past 1     
#                                    minute, 2 for past 5 minutes and 3 for   
#                                    past 15 minutes.                         
#  machine                           Machine, i686 for example                
#  mails                             Mail count in mail spool. You can use    
#                                    program like fetchmail to get mails from 
#                                    some server using your favourite         
#                                    protocol. See also new_mails.            
#  mem                               Amount of memory in use                  
#  membar            (height)        Bar that shows amount of memory in use   
#  memmax                            Total amount of memory                   
#  memperc                           Percentage of memory in use              
#  new_mails                         Unread mail count in mail spool.         
#  nodename                          Hostname                                 
#  outlinecolor      (color)         Change outline color                     
#  pre_exec          shell command   Executes a shell command one time before 
#                                    torsmo displays anything and puts output 
#                                    as text.                                 
#  processes                         Total processes (sleeping and running)   
#  running_processes                 Running processes (not sleeping),        
#                                    requires Linux 2.6                       
#  shadecolor        (color)         Change shading color                     
#  stippled_hr       (space),        Stippled (dashed) horizontal line        
#                    (height)        
#  swapbar           (height)        Bar that shows amount of swap in use     
#  swap                              Amount of swap in use                    
#  swapmax                           Total amount of swap                     
#  swapperc                          Percentage of swap in use                
#  sysname                           System name, Linux for example           
#  time              (format)        Local time, see man strftime to get more 
#                                    information about format                 
#  totaldown         net             Total download, overflows at 4 GB on     
#                                    Linux with 32-bit arch and there doesn't 
#                                    seem to be a way to know how many times  
#                                    it has already done that before torsmo   
#                                    has started.                             
#  totalup           net             Total upload, this one too, may overflow 
#  updates                           Number of updates (for debugging)        
#  upspeed           net             Upload speed in kilobytes                
#  upspeedf          net             Upload speed in kilobytes with one       
#                                    decimal                                  
#  uptime                            Uptime                                   
#  uptime_short                      Uptime in a shorter format               
#
#  seti_prog                         Seti@home current progress
#  seti_progbar      (height)        Seti@home current progress bar
#  seti_credit                       Seti@hoome total user credit
#

#Aligned position on screen(設定conky位置) 
#alignment top_right
alignment bottom_right
background no
border_width 1
#border_margin 4

cpu_avg_samples 2

default_color white
default_outline_color white
default_shade_color white
draw_borders no
draw_graph_borders yes
draw_outline no
draw_shades no
double_buffer yes

use_xft yes

#字型及大小
xftfont DejaVu Sans Mono:size=12
#xftfont Bitstream Vera Sans Mono:size=16
#font Sans:size=11

#視窗座標
gap_x 20
gap_y 150

minimum_size 5 5
maximum_width 300

net_avg_samples 2
no_buffers yes

out_to_console no
out_to_stderr no

extra_newline no

# 視窗背景 yes:黑底 ; no:透明
own_window yes
own_window_transparent no
own_window_class Conky
own_window_type desktop

stippled_borders 0

#更新頻率(秒)
update_interval 1.0
uppercase no
use_spacer no

show_graph_scale no
show_graph_range no
#stippled_borders 10

total_run_time 0
###########################################
TEXT
#
# Kernel
#${color lightgrey}$sysname $kernel ${color}on ${color lightgrey}$machine
#
# Time
${color lightgrey}Time:${color 00ff00}${time %Y/%m/%d - %R:%S}
#
# separator
${color grey}$stippled_hr
#
# Networking-eth0
${color lightgrey}Eth0:
${color lightgrey}Down:${color} ${downspeed eth0} ${offset 40}Up:${color} ${upspeed eth0}
${color black}${downspeedgraph eth0 35,140 ff0000 0000ff} ${color black}${upspeedgraph eth0 35,140 0000ff ff0000}
#${color 888888}${downspeedgraph eth0 35,130 ff0000 0000ff}       ${color 888888}${upspeedgraph eth0 35,130 0000ff ff0000}
#${color 888888}TOTAL: ${color CCCCCC}${totaldown eth0}  ${color 888888}TOTAL: ${color CCCCCC}${totalup eth0}
#
# separator
${color grey}$stippled_hr
#
# Total  CPU %
${color lightgrey}Total CPU:${color ddaa00} ${cpu}%
${color 7f8ed3}${cpubar 12}
#
# Tempratures 
${alignc}Temperatures
${color lightgrey}CPU: ${color ddaa00}${exec sensors atk0110-acpi-0|grep "CPU Temp"|cut -d '+' -f 2|cut -d ' ' -f 1}
${color lightgrey}GPU: ${color ddaa00}${exec nvidia-settings -q gpucoretemp -t | tail -n 1} °C
#
# separator
${color grey}$stippled_hr
#
# Per CPU %
#
# CPU 0 & CPU 1
${color lightgrey}CPU0 (${exec sensors coretemp-isa-0000|grep 0:|cut -d '+' -f 2|cut -d ' ' -f 1})              ${color lightgrey}CPU1 (${exec sensors coretemp-isa-0000|grep 1:|cut -d '+' -f 2|cut -d ' ' -f 1})
${color 000000}${cpugraph cpu0 35,140 000000 7f8ed3}    ${color 000000}${cpugraph cpu1 35,140 000000 7f8ed3}
#
# CPU 2 & CPU 3
${color lightgrey}CPU2 (${exec sensors coretemp-isa-0000|grep 2:|cut -d '+' -f 2|cut -d ' ' -f 1})              ${color lightgrey}CPU3 (${exec sensors coretemp-isa-0000|grep 3:|cut -d '+' -f 2|cut -d ' ' -f 1})
${color 000000}${cpugraph cpu2 35,140 000000 7f8ed3}    ${color 000000}${cpugraph cpu3 35,140 000000 7f8ed3}
##
## CPU 4 & CPU 5
#${color lightgrey}CPU4 (${exec sensors coretemp-isa-0000|grep 4:|cut -d '+' -f 2|cut -d ' ' -f 1})             ${color lightgrey}CPU5 (${exec sensors coretemp-isa-0000|grep 5:|cut -d '+' -f 2|cut -d ' ' -f 1})
#${color 000000}${cpugraph cpu4 35,140 000000 7f8ed3}   ${color 000000}${cpugraph cpu5 35,140 000000 7f8ed3}
##
## CPU 6 & CPU 7
#${color lightgrey}CPU6 (${exec sensors coretemp-isa-0000|grep 6:|cut -d '+' -f 2|cut -d ' ' -f 1})             ${color lightgrey}CPU7 (${exec sensors coretemp-isa-0000|grep 7:|cut -d '+' -f 2|cut -d ' ' -f 1})
#${color 000000}${cpugraph cpu6 35,140 000000 7f8ed3}   ${color 000000}${cpugraph cpu7 35,140 000000 7f8ed3}
#
# File system
${color lightgrey}File systems:
${color lightgrey}root: $color${fs_used /}${color lightgrey}/$color${fs_size /}
${color lightgrey}(free: $color${fs_free /}${color lightgrey} - $color${fs_free_perc /}%${color lightgrey})
#home: $color${fs_used /home/lin}/${fs_size /home/lin}
${color 7f8ed3}${fs_bar 12 /}
#
# RAM
${color lightgrey}RAM: ${color}$mem/$memmax - ${color ddaa00}$memperc%
${color 7f8ed3}${membar 12}
#
# Swap
${color lightgrey}Swap: ${color}$swap/$swapmax - ${color ddaa00}$swapperc%
${color 7f8ed3}${swapbar 12}
#
# separator
${color grey}$stippled_hr
#
# process CPU usage
${color ffccaa}CPU usage         PID   CPU%
${color ddaa00} ${top name 1}${top pid 1}${top cpu 1}
${color lightgrey} ${top name 2}${top pid 2}${top cpu 2}
${color lightgrey} ${top name 3}${top pid 3}${top cpu 3}
${color lightgrey} ${top name 4}${top pid 4}${top cpu 4}

#
# process RAM usage
${color ffccaa}Mem usage         PID   RAM%
${color ddaa00} ${top_mem name 1}${top_mem pid 1}${top mem 1}
${color lightgrey} ${top_mem name 2}${top_mem pid 2}${top mem 2}
${color lightgrey} ${top_mem name 3}${top_mem pid 3}${top mem 3}
${color lightgrey} ${top_mem name 4}${top_mem pid 4}${top mem 4}


補充:字型顏色可以參考十六進制色碼表
http://www.wibibi.com/info.php?tid=372






沒有留言:

張貼留言