--[[
    conkyrc
    Gabriel Marques 
    snortt@gmail.com
    Mon May 1 2023
--]]

-- Just let people know we're rolling...
print("Loading Conky configs...")

conky.config = {
    -- Alignment tips:
    -- As long as you stick to left-aligned columns, you can add spaces
    -- with ${alignl}${goto N}, where N is the amount of spaces to shift

    -- Color variables [ color0 to color9 ]
    -- In addition, you can use names (white, red, blue, yellow, green, etc.)
    -- using ${color} inside text area resets to the default one
    -- -----------------------------------
    -- Color theme based on golden shades:
    color0 = 'FFAF00', -- Default Gold for static items
    color1 = 'FFFFFF', -- White for dynamic data
    color2 = '999999', -- Grey for processes

    -- Conky won't read colorN variables in here (just in the text section).
    -- Just match these with the color codes from above variables.
    default_color = 'FFAF00',       -- default text color

    -- conky draws to the root window. It could flicker. This should fix it: 
    double_buffer = true,
    own_window = true,
    
    -- Sets the background color
    own_window_colour = 'black', -- background color (needs the one above)

    -- Additional settings regarding widget appearance:
    own_window_argb_visual = true, -- conflicts with own_window_type override
    own_window_argb_value = 25,  -- sets opacity (from 0 to 255 -> 0% - 100%)

    -- This one does the same as argb_visual + argb_value 
    --own_window_transparent = true, -- 0% opacity (comment the pair above) 

    own_window_class = 'Conky',
    own_window_type = 'normal',  -- normal | panel works for most cases
    own_window_hints = 'undecorated,below,sticky,skip_taskbar,skip_pager',

    -- Widget alignment and position:
    alignment = 'top_right',
    -- xinerama_head = 1,   -- select the screen you want

    -- Margin options:
    minimum_height = 200,
    minimum_width = 100,
    gap_x = 0,     -- pixels from the right/left border
    gap_y = 0,     -- pixels from the top/bottom border

    -- Border settings:
    draw_borders = false,
    border_width = 1,
    stippled_borders = 0,
    border_inner_margin = 3, -- Adjust minimum HxW if using this one. ;)

    -- Graph settings:
    draw_graph_borders = true,
    show_graph_range = false,
    show_graph_scale = false,
    --draw_outline = true,     -- enables outlining
    --draw_shades = true,      -- enables shading
    --default_outline_color = '00ff00', -- outline color
    --default_shade_color = 'ff0000',   -- shading and border color
 
    -- Units options:
    format_human_readable = true, -- Use MiB/GiB/... instead of total bytes
    short_units = true,           -- Use M/G/... instead of MiB/GiB/...

    -- Font settings:
    -- xft will replace the default MonoSpaced font.
    use_xft = true,
    font = 'Hack:regular:size=9',  -- Default font
    font1 = 'Hack:bold:size=10',    -- Header font
    --font2 = 'Hack:bold:size=9',  -- Default bold font 

    uppercase = false, -- disables all caps text
    xftalpha = 0.2,     -- xft alpha (between 0.0 and 1.0)
    text_buffer_size = 1024, -- default is 256

    -- Sampling: 
    -- Number of samples to average for resource monitoring
    cpu_avg_samples = 2,
    net_avg_samples = 2,

    -- Misc settings:
    total_run_times = 0,    -- makes conky run forever
    background = false,     -- Don't send conky process to the background
    update_interval = 1.0,  -- refresh time (in seconds)
    top_cpu_separate = false, -- top shows all processors usage
    extra_newline = false,  -- adds newline when writing to stdout

    -- Where to print the output messages
    out_to_console = false,
    out_to_ncurses = false,
    out_to_stderr = false,
    out_to_x = true,
    
    -- Pad percentages to this many decimals (0 = no padding)
    --pad_percents = 1,

    -- Subtract (file system) buffers from used memory? 
    no_buffers = true,

}

conky.text = [[
# Host name 
${hr 1}
# Cool Banner (or read it from .conky_banner below)
${font1}${alignc}[ BLACKSTAR ]${color}${font}
#${font Hack:regular:size3}${cat .conky_banner}
${goto 2}${voffset 3}${goto 32}\
${alignc}${font1}${time %A, %d/%m/%Y | %H:%M}${font}
# ---------------------------------------------
# System info
${hr 1}
${font1}System${font}
${goto 2}${voffset 3}${goto 32}\
CPU: ${color1}${alignr}\
${execi 1000 grep 'model name' /proc/cpuinfo | awk -F " " '{print $6 " " $8 " [" $4 " " $5 "]"}' | uniq}${color}
${goto 2}${voffset 3}${goto 32}\
CPU Frequency: ${color1}${alignr}${freq_g} GHz [$freq Hz]${color}
${goto 2}${voffset 3}${goto 32}\
CPU Temperature: ${color1}${alignr}${acpitemp} °C${color}
${goto 2}${voffset 3}${goto 32}\
CPU Usage: ${color1}${alignr}$cpu%${color}#cpu0 is the total usage 
${goto 2}${voffset 15}${goto 32}\
${cpubar 7 cpu0}
${goto 2}${voffset 3}${goto 32}\
RAM Usage: ${color1}${alignr}$mem/$memmax [$memperc%]${color}
${goto 2}${voffset 3}${goto 32}\
${membar 7}
${goto 2}${voffset 3}${goto 32}\
Swap Usage: ${color1}${alignr}$swap/$swapmax [$swapperc%]${color}
${goto 2}${voffset 3}${goto 32}\
${swapbar 7}
${goto 2}${voffset 3}${goto 32}\
Kernel: ${color1}${alignr}$kernel${color}
${goto 2}${voffset 3}${goto 32}\
Uptime: ${color1}${alignr}$uptime${color}
# ------------------------------------------
# Power
${hr 1}
${font1}Power${font}
${if_match "${acpiacadapter ACAD}" == "on-line"}\
${goto 2}${voffset 3}${goto 32}\
AC: ${color1}${alignr}${acpiacadapter ACAD}${color}
${goto 2}${voffset 3}${goto 32}\
Battery: ${color1}${alignr}${battery BAT1}${color}
${else}\
${goto 2}${voffset 3}${goto 32}\
Battery: ${color1}${alignr}${battery BAT1}${color}
${goto 2}${voffset 3}${goto 32}\
${color1}${alignr}${battery_time BAT1}${color}
${goto 2}${voffset 3}${goto 32}\
${color0}${alignr}${battery_bar 7,70 BAT1}${color}
${endif}\
# Processes
${hr 1}
${font1}Processes${font}
${goto 2}${voffset 3}${goto 32}\
Total Processes: ${color1}${alignr}$processes${color} Running: ${color1}$running_processes${color}
${goto 2}${voffset 3}${goto 32}\
Total Threads: ${color1}${alignr}${exec grep -c ^processor /proc/cpuinfo }${color} Running: ${color1}$running_threads${color}
${goto 2}${voffset 3}${goto 32}\
${hr 1}
${goto 6}${voffset 3}${goto 32}\
Name              PID     CPU%   MEM%
${color2}${goto 6}${goto 32}\
${top name 1} ${top pid 1} ${top cpu 1} ${top mem 1}
${goto 6}${goto 32}\
${top name 2} ${top pid 2} ${top cpu 2} ${top mem 2}
${goto 6}${goto 32}\
${top name 3} ${top pid 3} ${top cpu 3} ${top mem 3}
${goto 6}${goto 32}\
${top name 4} ${top pid 4} ${top cpu 4} ${top mem 4}${color}
# ---------------------------------------------
#GPU SECTION
${hr 1}
${font1}${if_match ${exec lsmod | grep 'nvidia' -c} > 0}${color0}${exec nvidia-smi --query-gpu=name --format=csv,noheader}${font}
${goto 6}${voffset 3}${goto 32}\
Temperature: ${color1}${alignr}${color1}${exec nvidia-smi --query-gpu=temperature.gpu --format=csv,noheader,nounits} °C${color}
${goto 6}${voffset 3}${goto 32}\
#Usage: ${color1}${alignr}${exec nvidia-settings -tq GPUUtilization | awk -F '[,= ]' '{ print $2 }'}%${color}
Usage: ${color1}${alignr}${exec nvidia-smi -q -d utilization | grep Gpu | awk -F " " '{print $3$4}'}${color}
${goto 6}${voffset 3}${goto 32}\
Memory:${color1}${alignr}${exec nvidia-smi --query-gpu=memory.used --format=csv,noheader} / ${exec nvidia-smi --query-gpu=memory.total --format=csv,noheader}${color}
${else}\
${goto 6}${voffset 3}${goto 32}OFF
${endif}\
# ---------------------------------------------
# File systems:
${hr 1}
${font1}File Systems                    ${alignr}[I/O]${font}
${goto 6}${voffset 3}${goto 32}\
nvme1: ${color1}${fs_type /}${alignr}${fs_size /} [Free: ${fs_free /}]${color} \
${goto 24}${alignr}${diskiograph /dev/nvme0n1p2 15,50 FF0000 00FF00}${voffset 3}
${goto 6}${voffset 3}${goto 32}${fs_bar 7 /}
${goto 6}${voffset 3}${goto 32}${voffset 5}\
sda1: ${color1}${fs_type /mnt/local/dados} ${alignr}${fs_size /mnt/local/dados} [Free: ${fs_free /mnt/local/dados}]${color} \
${goto 24}${alignr}${diskiograph /dev/sda1 15,50 FF0000 00FF00}${voffset 3}
${goto 6}${voffset 3}${goto 32}${fs_bar 7 /mnt/local/dados}
${goto 6}${voffset 3}${goto 32}${voffset 5}\
nvme0: ${color1}${fs_type /mnt/local/nvme0} ${alignr}${fs_size /mnt/local/nvme0} [Free: ${fs_free /mnt/local/nvme0}]${color} \
${goto 24}${alignr}${diskiograph /dev/nvme0n1p1 15,50 FF0000 00FF00}${voffset 3}
${goto 6}${voffset 3}${goto 32}${fs_bar 7 /mnt/local/nvme0}\

# ---------------------------------------------
# Networking:
${hr 1}
${font1}Networking${font}
${goto 6}${voffset 3}${goto 32}\
Internet: ${alignr}${color1}${execi 1000 wget -q -O- http://ipecho.net/plain; echo}${color}${voffset 5}\
${if_match "No Address" != "${addr wlp0s20f3}"}
${goto 6}${voffset 3}${goto 32}\
WiFi: ${alignr}${color1}${addr wlp0s20f3}${voffset 3}${color}
${goto 50}Down: ${alignr}${color1}${downspeed wlp0s20f3} / ${totaldown wlp0s20f3}${color} \
${goto 24}${alignr}${downspeedgraph wlp0s20f3 14,70 FF0000 00FF00}${voffset 3}
${goto 50}Up: ${alignr}${color1}${upspeed wlp0s20f3} / ${totalup wlp0s20f3}${color} \
${goto 24}${alignr}${upspeedgraph wlp0s20f3 14,70 FF0000 00FF00}\
${endif}${voffset 3}\
${if_match "No Address" != "${addr enp2s0}"}
${goto 6}${voffset 3}${goto 32}\
Ethernet: ${alignr}${color1}${addr enp2s0}${voffset 3}${color}
${goto 50}Down: ${alignr}${color1}${downspeed enp2s0} / ${totaldown enp2s0}${color} \
${goto 24}${alignr}${downspeedgraph enp2s0 14,70 FF0000 00FF00}${voffset 3}
${goto 50}Up: ${alignr}${color1}${upspeed enp2s0} / ${totalup enp2s0}${color} \
${goto 24}${alignr}${upspeedgraph enp2s0 14,70 FF0000 00FF00} 
${endif}${voffset 3}\
${if_match "No Address" != "${addr virbr0}"}
${goto 6}${voffset 3}${goto 32}\
KVM: ${alignr}${color1}${addr virbr0}${voffset 3}${color}
${goto 50}Down: ${alignr}${color1}${downspeed virbr0} / ${totaldown virbr0}${color} \
${goto 24}${alignr}${downspeedgraph virbr0 14,70 FF0000 00FF00}${voffset 3}
${goto 50}Up: ${alignr}${color1}${upspeed virbr0} / ${totalup virbr0}${color} \
${goto 24}${alignr}${upspeedgraph virbr0 14,70 FF0000 00FF00}\
${endif}${voffset 3}\
${if_match "No Address" != "${addr tun0}"}
${goto 6}${voffset 3}${goto 32}\
VPN [Xeon]: ${alignr}${color1}${addr tun0}${voffset 3}${color}
${goto 50}Down: ${alignr}${color1}${downspeed tun0} / ${totaldown tun0}${color} \
${goto 24}${alignr}${downspeedgraph tun0 14,70 FF0000 00FF00}${voffset 3}
${goto 50}Up: ${alignr}${color1}${upspeed tun0} / ${totalup tun0}${color} \
${goto 24}${alignr}${upspeedgraph tun0 14,70 FF0000 00FF00}\
${endif}${voffset 3}
# ---------------------------------------------
]]
