Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Mount points im mnt #30

Closed
wants to merge 1 commit into
from

Conversation

Projects
None yet
3 participants

My mount point are mounted in /mnt directory structure. There'no script to this in the HD's scripts provided by default.
So, i created a new script, based on conkyHD1.py. But i ḿ not sure if this is right thing to do... I guess the best way to do this is set the "watched" directory in the conky_colors binary.

@fabioluciano fabioluciano reopened this Oct 30, 2012

Collaborator

android-808 commented Oct 30, 2012

Sorry, but this doesn't appear to be the correct way to do it. I could fix it for you but I don't want to steal your thunder :p

conkyHD{1,2,3,4} relate to the HDD monitors theme/layout: Default, Meerkat, Mix and Simple. As such, your script as far as I can tell will not be called unless you add a new layout, which is not what your goal appears to be.

I think what you need to do is add another block of code to each of the existing scripts to look for alternate paths. Taking conkyHD1 as an example:

First we poll the root fs.
Next we check /home, only if it is a separate mount point.
Next we check /media for mount points, excluding cdrom.
Next we need your modification to test /mnt

This should be in place for all conkyHD scripts before the push request is accepted. Simply copy a paste the /media section from each theme and modify /media to /mnt.

On a side note, this does reveal a potential problem should it be used on any distro with irregular mount points. Thinking of GoboLinux IIRC which does away with traditional /usr, /home etc. A stanza would need to be added for each and every possible mount point to support them all out of the box. Maybe another method of obtaining the mount points is required.

Collaborator

android-808 commented Oct 30, 2012

Found a possible solution for parsing /proc/mounts that may solve for all custom mount points. Please re-submit patch with modifications suggested above because it may take some time to put together. I've been a bit slow the last few weeks. Several projects, work, very tired and a bit of Minecraft to blame.

I'm thinking of doing this using the output of command and arguments 'df -x tmpfs -x devtmpfs -P | cut -d" " -f 1'. If i use the output of "file" /proc/mounts, i 'can't' parse the file to get what i need: Only the local mount points. See what i get:

Sist.
/dev/mapper/hermes-slash
/dev/mapper/hermes-opt
/dev/mapper/hermes-doc
/dev/mapper/hermes-server
/dev/mapper/hermes-vdi

PS: To you, i guess you need to rest :-)

Collaborator

android-808 commented Oct 31, 2012

Please give the following a try from the command line, it uses python2 like the rest of the scripts which should make it easier to port each HDD layout if it works correctly. Please let me have the output of the script.

It opens /proc/mounts, scans each line to see if it starts with a /, to filter out tmpfs, proc etc etc. It should find your /dev/mapper/.. as a result. It then processes the required information, obtains free space measurements and stores them in an array. After reading all the lines, it returns the array. This is just for illustration prints so it can print values to the console.

rootfs is listed in the file twice, but will skip the first because of the previous check:
rootfs / rootfs rw 0 0
/dev/sda1 / ext4 rw,relatime 0 0

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os

def collect():
    try:
        f = open('/proc/mounts')
    except IOError:
        f = []

    descriptors = []
    for line in f:
        if line.startswith('/'):
            info = line.split()
            disk = os.statvfs(info[1])
            disk_size = (disk.f_blocks * disk.f_frsize) / float(2**30)
            disk_fperc = (float(disk.f_bavail) / float(disk.f_blocks)) * 100
            disk_fgb = (disk.f_bavail * disk.f_frsize) / float(2**30) # GB

            descriptors.append({
                'mount': info[1],
                'size': disk_size,
                'freegb': disk_fgb,
                'freeperc': disk_fperc
            })

    return descriptors

# the following code is for debugging and testing
if __name__ == '__main__':
    descriptors = collect()
    for d in descriptors:
        print '%s : %i%% F:%.1fGB T:%.1fGB' % (d['mount'], d['freeperc'], d['freegb'], d['size'])

If this works, I can use it in current scripts to find working mount points and just use conky's built in routines for disk usage. I'll also make it skip root and /home so they can be separate to make sure they are still listed first.

To me works well too. The follow lines is the ouput when i running your script

/ : 84% F:77.1GB T:91.7GB
/opt : 84% F:7.7GB T:9.2GB
/mnt/srv : 92% F:42.4GB T:45.8GB
/mnt/vdi : 60% F:55.9GB T:91.7GB
/mnt/doc : 76% F:684.6GB T:893.1GB

Collaborator

android-808 commented Oct 31, 2012

Not bad for a python newb :p

I'll have a look at integrating it over the next few days. To fit in with the current labelling, I'll try to trim off the final directory of the mount point and capitalise the first letter (Opt, Srv, Vdi and Doc as posted above). To get the same display (1 decimal place for larger amounts, 2 for less than 10GB), I'll try hooking in to Conky's functions.

Collaborator

android-808 commented Nov 10, 2012

not got round to it until tonight, off out in minutes. just need to filter out root and home correctly and i'll post it

Collaborator

android-808 commented Nov 10, 2012

Ok, here is the first version. Please test it and let me know if it works OK for you. Backup the existing /usr/share/conkycolors/scripts/conkyHD1.py and replace it with the file below. It will still output / and /home first as they're probably the most useful and common, and then it parses /proc/mounts for the rest. Space calculations are handled exactly the same as the original script.

NOTE: NOT tested with mount points containing spaces, often used in removable media.

#!/usr/bin/env python2
# -*- coding: utf-8 -*-

import os

# Prioritise root and home as they are the most common.

# root filesystem
print ("${voffset 0}${offset 0}${color0}${font Poky:size=14}y${font}${color}${offset 6}${voffset -7}Root: ${font Ubuntu:style=Bold:size=8}${color1}${fs_free_perc /}%${color}${font}\n")
print ("${voffset -10}${offset 1}${color0}${fs_bar 4,18 /}${color}${offset 8}${voffset -2}F: ${font Ubuntu:style=Bold:size=8}${color2}${fs_free /}${color}${font} U: ${font Ubuntu:style=Bold:size=8}${color2}${fs_used /}${color}${font}\n")

# /home folder (if its a separate mount point)
if os.path.ismount("/home"):
    print ("${voffset -10}${offset 0}${color0}${font Poky:size=14}y${font}${color}${offset 6}${voffset -7}Home: ${font Ubuntu:style=Bold:size=8}${color1}${fs_free_perc /home}%${color}${font}\n")
    print ("${voffset -10}${offset 1}${color0}${fs_bar 4,18 /home}${color}${offset 8}${voffset -2}F: ${font Ubuntu:style=Bold:size=8}${color2}${fs_free /home}${color}${font} U: ${font Ubuntu:style=Bold:size=8}${color2}${fs_used /home}${color}${font}\n")

# Now parse /proc/mounts for the rest.

try:
    f = open('/proc/mounts')
except IOError:
    f = []

for line in f:
    if line.startswith('/'):
        device = line.split()[1]
        if device != "/" and (device != "/home"):
            print ("${voffset -10}${offset 0}${color0}${font Poky:size=14}y${font}${color}${offset 6}${voffset -7}"+os.path.basename(device).capitalize()+": ${font Ubuntu:style=Bold:size=8}${color1}${fs_free_perc "+device+"}%${color}${font}\n")
            print ("${voffset -10}${offset 1}${color0}${fs_bar 4,18 "+device+"}${color}${offset 8}${voffset -2}F: ${font Ubuntu:style=Bold:size=8}${color2}${fs_free "+device+"}${color}${font} U: ${font Ubuntu:style=Bold:size=8}${color2}${fs_used "+device+"}${color}${font}\n")
print ("${voffset -10}")

This sounds great. Just a little thing left... the last item appears with these equals at the end.

Look: http://i.imgur.com/bKG2o.png

Collaborator

android-808 commented Nov 17, 2012

I've had to do a little creative testing (removing root and home from the beginning and adding them into the loop, not enough hard drives) to try to get it to reproduce the error you experienced but I've still not had it occur for me.

Here is an updated version of the script.

  • Requires an extra import, string, so allow it to capitalize all of the words in a mount point.
  • /proc/mounts is now opened read only.
  • /proc/mounts stores spaces as \040, so we now replace them with a real space.
  • 'Seems' to correctly handle mount points containing spaces as a result of the above.
  • Adds a vim: code at the bottom to make it easier to edit.

The only error I've had is from conky, which reported statvfs64 mount point not found or something like that because the path still contained a \040 even after stripping it out. It may have been the scripts wan't correctly reloaded after an edit so please let me know if anyone encounters it.

#!/usr/bin/env python2
# -*- coding: utf-8 -*-

import os, string

# Prioritise root and home as they are the most common.
# Also ensures correct layout as the voffset is different.

# root filesystem
print ("${voffset 0}${offset 0}${color0}${font Poky:size=14}y${font}${color}${offset 6}${voffset -7}Root: ${font Ubuntu:style=Bold:size=8}${color1}${fs_free_perc /}%${color}${font}\n")
print ("${voffset -10}${offset 1}${color0}${fs_bar 4,18 /}${color}${offset 8}${voffset -2}F: ${font Ubuntu:style=Bold:size=8}${color2}${fs_free /}${color}${font} U: ${font Ubuntu:style=Bold:size=8}${color2}${fs_used /}${color}${font}\n")

# /home folder (if its a separate mount point)
if os.path.ismount("/home"):
    print ("${voffset -10}${offset 0}${color0}${font Poky:size=14}y${font}${color}${offset 6}${voffset -7}Home: ${font Ubuntu:style=Bold:size=8}${color1}${fs_free_perc /home}%${color}${font}\n")
    print ("${voffset -10}${offset 1}${color0}${fs_bar 4,18 /home}${color}${offset 8}${voffset -2}F: ${font Ubuntu:style=Bold:size=8}${color2}${fs_free /home}${color}${font} U: ${font Ubuntu:style=Bold:size=8}${color2}${fs_used /home}${color}${font}\n")

# Now parse /proc/mounts for the rest.

try:
    f = open('/proc/mounts', 'r')
except IOError:
    f = []

for line in f:
    if line.startswith('/'):
        device = line.strip().split()[1]
        device = device.replace('\\040', ' ')
        if device != "/" and (device != "/home"):
            print ("${voffset -10}${offset 0}${color0}${font Poky:size=14}y${font}${color}${offset 6}${voffset -7}"+string.capwords(os.path.basename(device))+": ${font Ubuntu:style=Bold:size=8}${color1}${fs_free_perc "+device+"}%${color}${font}\n")
            print ("${voffset -10}${offset 1}${color0}${fs_bar 4,18 "+device+"}${color}${offset 8}${voffset -2}F: ${font Ubuntu:style=Bold:size=8}${color2}${fs_free "+device+"}${color}${font} U: ${font Ubuntu:style=Bold:size=8}${color2}${fs_used "+device+"}${color}${font}\n")
print ("${voffset -10}")

# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
Owner

helmuthdu commented Jul 11, 2013

The script was rewritten in python 3, it now detect mountpoint instead of folders inside the /media directory.
Bug fixed! :)

@helmuthdu helmuthdu closed this Jul 11, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment