.. versionadded:: 2015.8.0

    Return the disk usage for this minion

    human_readable : False
        If ``True``, usage will be in KB/MB/GB etc.

    CLI Example:

    .. code-block:: bash

        salt '*' status.diskusage path=c:/salt
174206
def diskusage(human_readable=False, path=None):
    '''
    
    '''
    if not path:
        path = 'c:/'

    disk_stats = psutil.disk_usage(path)

    total_val = disk_stats.total
    used_val = disk_stats.used
    free_val = disk_stats.free
    percent = disk_stats.percent

    if human_readable:
        total_val = _byte_calc(total_val)
        used_val = _byte_calc(used_val)
        free_val = _byte_calc(free_val)

    return {'total': total_val,
            'used': used_val,
            'free': free_val,
            'percent': percent}
365824
def working_dir(val, **kwargs):  # pylint: disable=unused-argument
    '''
    
    '''
    try:
        is_abs = os.path.isabs(val)
    except AttributeError:
        is_abs = False
    if not is_abs:
        raise SaltInvocationError('\'{0}\' is not an absolute path'.format(val))
    return val
1156882
def _disk(self):
        """"""
        mountpoints = [
            p.mountpoint for p in psutil.disk_partitions()
            if p.device.endswith(self.device)
        ]
        if len(mountpoints) != 1:
            raise CommandError("Unknown device: {0}".format(self.device))

        value = int(psutil.disk_usage(mountpoints[0]).percent)
        set_metric("disk-{0}".format(self.device), value, category=self.category)
        gauge("disk-{0}".format(self.device), value)
1288135
def current_memory_usage():
    
    import psutil
    proc = psutil.Process(os.getpid())
    #meminfo = proc.get_memory_info()
    meminfo = proc.memory_info()
    rss = meminfo[0]  # Resident Set Size / Mem Usage
    vms = meminfo[1]  # Virtual Memory Size / VM Size  # NOQA
    return rss
792918
def is_cached(self, path, saltenv='base', cachedir=None):
        '''
        
        '''
        if path.startswith('salt://'):
            path, senv = salt.utils.url.parse(path)
            if senv:
                saltenv = senv

        escaped = True if salt.utils.url.is_escaped(path) else False

        # also strip escape character '|'
        localsfilesdest = os.path.join(
            self.opts['cachedir'], 'localfiles', path.lstrip('|/'))
        filesdest = os.path.join(
            self.opts['cachedir'], 'files', saltenv, path.lstrip('|/'))
        extrndest = self._extrn_path(path, saltenv, cachedir=cachedir)

        if os.path.exists(filesdest):
            return salt.utils.url.escape(filesdest) if escaped else filesdest
        elif os.path.exists(localsfilesdest):
            return salt.utils.url.escape(localsfilesdest) \
                if escaped \
                else localsfilesdest
        elif os.path.exists(extrndest):
            return extrndest

        return ''
267950
def _salt_to_os_path(path):
    '''
    
    '''
    return os.path.normpath(path.replace(posixpath.sep, os.path.sep))
1005952
def pretty_memory_info():
    '''
    
    '''
    process = psutil.Process(os.getpid())
    return '{}MB memory usage'.format(int(process.memory_info().rss / 2**20))
1026045
def get_readable_filesize(size):
	
	if(size < 1024):
		return str(size)+' bytes'
	temp = size/1024.0
	level = 1
	while(temp >= 1024 and level< 3):
		temp = temp/1024
		level += 1
	if(level == 1):
		return str(round(temp,2))+' KB'
	elif(level == 2):
		return str(round(temp,2))+' MB'
	else:
		return str(round(temp,2))+' GB'
1313075
def _memory_usage(self, pid='self', category="hwm", container=None):
        
        if container:
            # TODO: Put some debug output here with switch to Logger
            # since this is relatively untested.
            cmd = "docker stats " + container + " --format '{{.MemUsage}}' --no-stream"
            mem_use_str = subprocess.check_output(cmd, shell=True)
            mem_use = mem_use_str.split("/")[0].split()
            
            mem_num = re.findall('[\d\.]+', mem_use_str.split("/")[0])[0]
            mem_scale = re.findall('[A-Za-z]+', mem_use_str.split("/")[0])[0]

            #print(mem_use_str, mem_num, mem_scale)
            mem_num = float(mem_num)
            if mem_scale == "GiB":
                return mem_num * 1e6
            elif mem_scale == "MiB":
                return mem_num * 1e3
            elif mem_scale == "KiB":
                return mem_num
            else:
                # What type is this?
                return 0

        # Thanks Martin Geisler:
        status = None
        result = {'peak': 0, 'rss': 0, 'hwm': 0}
        
        try:
            # This will only work on systems with a /proc file system
            # (like Linux).
            # status = open('/proc/self/status')
            proc_spot = '/proc/%s/status' % pid
            status = open(proc_spot)
            for line in status:
                parts = line.split()
                key = parts[0][2:-1].lower()
                if key in result:
                    result[key] = int(parts[1])
        except:
            return 0

        finally:
            if status is not None:
                status.close()
        # print(result[category])
        return result[category]
1291151
def saltpath():
    '''
    
    '''
    # Provides:
    #   saltpath
    salt_path = os.path.abspath(os.path.join(__file__, os.path.pardir))
    return {'saltpath': os.path.dirname(salt_path)}
484923
def which(exe=None):
    '''
    
    '''

    if not exe:
        log.error('No executable was passed to be searched by salt.utils.path.which()')
        return None

    ## define some utilities (we use closures here because our predecessor used them)
    def is_executable_common(path):
        '''
        This returns truth if posixy semantics (which python simulates on
        windows) states that this is executable.
        '''
        return os.path.isfile(path) and os.access(path, os.X_OK)

    def resolve(path):
        '''
        This will take a path and recursively follow the link until we get to a
        real file.
        '''
        while os.path.islink(path):
            res = os.readlink(path)

            # if the link points to a relative target, then convert it to an
            # absolute path relative to the original path
            if not os.path.isabs(res):
                directory, _ = os.path.split(path)
                res = join(directory, res)
            path = res
        return path

    # windows-only
    def has_executable_ext(path, ext_membership):
        '''
        Extract the extension from the specified path, lowercase it so we
        can be insensitive, and then check it against the available exts.
        '''
        p, ext = os.path.splitext(path)
        return ext.lower() in ext_membership

    ## prepare related variables from the environment
    res = salt.utils.stringutils.to_unicode(os.environ.get('PATH', ''))
    system_path = res.split(os.pathsep)

    # add some reasonable defaults in case someone's PATH is busted
    if not salt.utils.platform.is_windows():
        res = set(system_path)
        extended_path = ['/sbin', '/bin', '/usr/sbin', '/usr/bin', '/usr/local/sbin', '/usr/local/bin']
        system_path.extend([p for p in extended_path if p not in res])

    ## now to define the semantics of what's considered executable on a given platform
    if salt.utils.platform.is_windows():
        # executable semantics on windows requires us to search PATHEXT
        res = salt.utils.stringutils.to_str(os.environ.get('PATHEXT', str('.EXE')))

        # generate two variables, one of them for O(n) searches (but ordered)
        # and another for O(1) searches. the previous guy was trying to use
        # memoization with a function that has no arguments, this provides
        # the exact same benefit
        pathext = res.split(os.pathsep)
        res = {ext.lower() for ext in pathext}

        # check if our caller already specified a valid extension as then we don't need to match it
        _, ext = os.path.splitext(exe)
        if ext.lower() in res:
            pathext = ['']

            is_executable = is_executable_common

        # The specified extension isn't valid, so we just assume it's part of the
        # filename and proceed to walk the pathext list
        else:
            is_executable = lambda path, membership=res: is_executable_common(path) and has_executable_ext(path, membership)

    else:
        # in posix, there's no such thing as file extensions..only zuul
        pathext = ['']

        # executable semantics are pretty simple on reasonable platforms...
        is_executable = is_executable_common

    ## search for the executable

    # check to see if the full path was specified as then we don't need
    # to actually walk the system_path for any reason
    if is_executable(exe):
        return exe

    # now to search through our system_path
    for path in system_path:
        p = join(path, exe)

        # iterate through all extensions to see which one is executable
        for ext in pathext:
            pext = p + ext
            rp = resolve(pext)
            if is_executable(rp):
                return p + ext
            continue
        continue

    ## if something was executable, we should've found it already...
    log.trace(
        '\'%s\' could not be found in the following search path: \'%s\'',
        exe, system_path
    )
    return None
301861
def get_harddisk_sleep():
    '''
    
    '''
    ret = salt.utils.mac_utils.execute_return_result(
        'systemsetup -getharddisksleep')
    return salt.utils.mac_utils.parse_return(ret)
174471
def get_disk_usage(path):
    
    cmd = 'du -sh --block-size=1 {0}'.format(path)
    total = getoutput(cmd).split()[0]
    return int(total)
158696
def memory_usage_psutil():
    
    process = psutil.Process(os.getpid())
    mem = process.memory_info()[0] / float(2 ** 20)
    mem_vms = process.memory_info()[1] / float(2 ** 20)
    return mem, mem_vms
819997
function (path) {
    if ($bc_$4.pN) {
      var _path = path || ($bc_$4.pN.path.tempDir() + 'tmp.txt');
      return $bc_$4.pN.app.diskSizeAtPath(_path)
    }

    return ''
  }
758992
def devices_data():
    
    response = {}
    for part in psutil.disk_partitions():
        device = part.device
        response[device] = {
            'device': device,
            'mountpoint': part.mountpoint,
            'fstype': part.fstype,
            'opts': part.opts,
        }
        if part.mountpoint:
            usage = psutil.disk_usage(part.mountpoint)
            response[device]['usage'] = {
                'size': mark(usage.total, 'bytes'),
                'used': mark(usage.used, 'bytes'),
                'free': mark(usage.free, 'bytes'),
                'percent': mark(usage.percent, 'percentage')
            }
    return response
64543
private static void usage()
  {
    String className = MStress_Client.class.getName();
    System.out.printf("Usage: java %s -s dfs-server -p dfs-port" +
    		"[-t [create|stat|read|readdir|delete|rename] -a planfile-path -c host -n process-name" +
    		" -P prefix]\n",
                      className);
    System.out.printf("   -t: this option requires -a, -c, and -n options.\n");
    System.out.printf("   -P: default prefix is PATH_.\n");
    System.out.printf("eg:\n");
    System.out.printf("    java %s -s <metaserver-host> -p <metaserver-port> -t create" +
    		" -a <planfile> -c localhost -n Proc_00\n", className);
    System.exit(1);
  }