You are not logged in.

#1 2010-12-06 22:51:32

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,672
Website

parse xml for conky

I'd like to capture two key outputs and have them displayed in conky.  On my system, GPU load and GPU memory usage are available from the nvidia-smi program.  I can output in xml format which I'd like to parse and harvest to display in conky.  I can brute-force myself through it via grep and sed statements, but I'm looking for some suggestions from more knowledgeable people to do this in a minimal way.  For example, only run the program once, and harvest all data.  My current solution runs twice.

Example output:

$ nvidia-smi -a -x
<?xml version="1.0" ?>
<!DOCTYPE nvsmi_log SYSTEM "./nvsmi.dtd">
<nvsmi_log>
    <timestamp>Mon Dec  6 17:48:50 2010</timestamp>
    <driver_version>260.19.21</driver_version>
    <gpu id="0">
        <prod_name>GeForce 8400 GS</prod_name>
        <pci_device_id>6e410de</pci_device_id>
        <pci_location_id>0:1:0</pci_location_id>
        <serial>2648101198649</serial>
        <display>Connected</display>
        <temp>43 C</temp>
        <utilization>
            <gpu_util>0%</gpu_util>
            <memory_util>8%</memory_util>
        </utilization>
    </gpu>
</nvsmi_log>
[facade@simplicity ~]$ nvidia-smi -a -x
<?xml version="1.0" ?>
<!DOCTYPE nvsmi_log SYSTEM "./nvsmi.dtd">
<nvsmi_log>
    <timestamp>Mon Dec  6 17:49:30 2010</timestamp>
    <driver_version>260.19.21</driver_version>
    <gpu id="0">
        <prod_name>GeForce 8400 GS</prod_name>
        <pci_device_id>6e410de</pci_device_id>
        <pci_location_id>0:1:0</pci_location_id>
        <serial>2648101198649</serial>
        <display>Connected</display>
        <temp>43 C</temp>
        <utilization>
            <gpu_util>5%</gpu_util>
            <memory_util>10%</memory_util>
        </utilization>
    </gpu>
</nvsmi_log>

Or it might be better not to go to xml which I can do by omitting the -x switch:

$ nvidia-smi -a

==============NVSMI LOG==============


Timestamp            : Mon Dec  6 17:50:06 2010

Driver Version            : 260.19.21


GPU 0:
    Product Name        : GeForce 8400 GS
    PCI Device/Vendor ID    : 6e410de
    PCI Location ID        : 0:1:0
    Board Serial        : 2648101198649
    Display            : Connected
    Temperature        : 43 C
    Utilization
        GPU            : 0%
        Memory        : 8%

Thanks!

Last edited by graysky (2014-11-03 08:39:36)


CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Offline

#2 2010-12-06 23:11:00

fsckd
Forum Fellow
Registered: 2009-06-15
Posts: 4,173

Re: parse xml for conky

Proper XML processing is not streamed and would use more resources than grep | sed. But judging by the above, it doesn't look to be much.


aur S & M :: forum rules :: Community Ethos
Resources for Women, POC, LGBT*, and allies

Offline

#3 2010-12-06 23:40:45

skunktrader
Member
From: Brisbane, Australia
Registered: 2010-02-14
Posts: 1,580

Re: parse xml for conky

nvidia-smi -a | awk -F '\t+: ' -v 'ORS= ' '$1 ~ /GPU$|Memory/ { print $2; }'

Deja vu all over again
https://bbs.archlinux.org/viewtopic.php?id=107127

Last edited by skunktrader (2010-12-06 23:55:00)

Offline

#4 2010-12-07 00:02:55

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,672
Website

Re: parse xml for conky

Damn, my memory is truly shit.  Thanks, ST.  The awk syntax is still foreign to me.  How would I segregate the RAM usage from the GPU usage?  I think conky needs the output to be unique for each one in their own script.

EDIT: Got it.

# Swap Usage:$color $swapperc%${color lightgrey}

# the ${template x x x} command uses /sys/bus/platform/devices
# for this to work you need both lm-sensors and hddtemp
# get both from main repos

# set to yes if you want Conky to be forked in the background
background no

own_window yes
own_window_type override
own_window_transparent yes
own_window_hints undecorated,below,sticky,skip_taskbar,skip_pager

out_to_console no

# Use Xft?
use_xft yes

# Xft font when Xft is enabled
#xftfont Bitstream Vera Sans Mono:size=8
xftfont monospace:size=8

#xftalpha 0.8

# Update interval in seconds
update_interval 2

# Create own window instead of using desktop (required in nautilus)
own_window yes

# Use double buffering (reduces flicker, may not work for everyone)
double_buffer yes

# Minimum size of text area
#minimum_size 250 5
maximum_width 258

# Draw shades?
draw_shades no

# Draw outlines?
draw_outline no

# Draw borders around text
draw_borders no

# Stippled borders?
stippled_borders 10

# border margins
#border_margin 4

# border width
border_width 1

# Default colors and also border colors
default_color white
default_shade_color white
default_outline_color white

# Text alignment, other possible values are commented
#alignment top_left
#minimum_size 10 10
#alignment top_right
alignment bottom_left
#alignment bottom_right

# Gap between borders of screen and text
gap_x 12
gap_y 37
# Add spaces to keep things from moving about?  This only affects certain objects.
use_spacer left

# Subtract file system buffers from used memory?
no_buffers yes

# set to yes if you want all text to be in uppercase
uppercase no

default_bar_size 120 6

TEXT
${color #6495ed}$nodename$color - $sysname $kernel on $machine
${color lightgrey}Uptime:$color $uptime ${color lightgrey}- Load:$color $loadavg${color lightgrey}
$color$stippled_hr${color lightgrey}
Processes: $processes  Running:$color$running_processes
${color}Name                   PID    CPU%   MEM%
${color #6495ed} ${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}Mem usage
${color #6495ed} ${top_mem name 1}     ${top_mem pid 1} ${top_mem cpu 1} ${top_mem mem 1}
${color lightgrey} ${top_mem name 2}     ${top_mem pid 2} ${top_mem cpu 2} ${top_mem mem 2}
${color lightgrey} ${top_mem name 3}     ${top_mem pid 3} ${top_mem cpu 3} ${top_mem mem 3}
$color$stippled_hr${color lightgrey}
${color #6495ed}CPU0: ${color lightgrey}Intel Xeon X3360 @ $color${freq_g} GHz${color lightgrey}
${color #6495ed}CPU Fan: $color${platform it87.656 fan 1}${color grey} RPM @ $color${execi 8 cat /sys/class/hwmon/hwmon4/device/pwm1}
${color #6495ed}RAM:$color$mem ($memperc%) ${color lightgrey}of 8.0 GB
${color black}${cpugraph 35,200 5000a0 6495ed}${color white}  ${cpugauge 35}${color lightgrey}
${color lightgrey}Core0:$color${platform coretemp.0 temp 1} °C${color grey} @$color ${cpu cpu1}% ${alignr}${cpubar cpu1 6,120}
${color lightgrey}Core1:$color${platform coretemp.1 temp 1} °C${color grey} @$color ${cpu cpu2}% ${alignr}${cpubar cpu2 6,120}
${color lightgrey}Core2:$color${platform coretemp.2 temp 1} °C${color grey} @$color ${cpu cpu3}% ${alignr}${cpubar cpu3 6,120}
${color lightgrey}Core3:$color${platform coretemp.3 temp 1} °C${color grey} @$color ${cpu cpu4}% ${alignr}${cpubar cpu4 6,120}${color grey}
 ${color grey}CPU:$color${platform it87.656 temp 1} °C  ${color grey}  ${color grey} M/B:$color ${platform it87.656 temp 2} °C    ${color grey} sda:$color ${execi 300 sudo hddtemp /dev/sda | cut -c34-35} °C
$color$stippled_hr${color lightgrey}
${color #6495ed}GPU0:${color lightgrey} nVidia 8800 GS (${nvidia gpufreq}/${nvidia memfreq}) MHz
${color #6495ed}VRAM:${color lightgrey} ${exec nvidia-smi -a | grep -A 2 "Utilization" | tr -d % | grep "Memory" | awk '{print $3}'}% of 512MiB
${color #6495ed}GPU0:${color lightgrey}$color${nvidia temp} °C @ ${exec nvidia-smi -a | grep -A 2 "Utilization" | tr -d % | grep "GPU" | awk '{print $3}'}%       ${execbar nvidia-smi -a | grep -A 2 "Utilization" | tr -d % | grep "Memory" | awk '{print $3}'}
$color$stippled_hr${color lightgrey}
${color lightgrey}RAMDisk: ${color }${fs_used_perc  /dev/shm} %           ${fs_bar /dev/shm 6,120}

Last edited by graysky (2010-12-07 00:54:15)


CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Offline

Board footer

Powered by FluxBB