Report metrics about the volume space usage
7127
def _report_disk_stats(self):
        """"""
        stats = {
            'docker.data.used': None,
            'docker.data.total': None,
            'docker.data.free': None,
            'docker.metadata.used': None,
            'docker.metadata.total': None,
            'docker.metadata.free': None
            # these two are calculated by _calc_percent_disk_stats
            # 'docker.data.percent': None,
            # 'docker.metadata.percent': None
        }
        info = self.docker_util.client.info()
        driver_status = info.get('DriverStatus', [])
        if not driver_status:
            self.log.warning('Disk metrics collection is enabled but docker info did not'
                             ' report any. Your storage driver might not support them, skipping.')
            return
        for metric in driver_status:
            # only consider metrics about disk space
            if len(metric) == 2 and 'Space' in metric[0]:
                # identify Data and Metadata metrics
                mtype = 'data'
                if 'Metadata' in metric[0]:
                    mtype = 'metadata'

                if 'Used' in metric[0]:
                    stats['docker.{0}.used'.format(mtype)] = metric[1]
                elif 'Space Total' in metric[0]:
                    stats['docker.{0}.total'.format(mtype)] = metric[1]
                elif 'Space Available' in metric[0]:
                    stats['docker.{0}.free'.format(mtype)] = metric[1]
        stats = self._format_disk_metrics(stats)
        stats.update(self._calc_percent_disk_stats(stats))
        tags = self._get_tags()
        for name, val in stats.iteritems():
            if val is not None:
                self.gauge(name, val, tags)
481881
def snapshot_allocation(self):
		
		check_cmd = ['lvs', self.volume_path(), '-o', 'snap_percent', '--noheadings']
		output = subprocess.check_output(check_cmd, timeout=self.__class__.__lvm_snapshot_check_cmd_timeout__)
		output = output.decode().strip()
		if len(output) == 0:
			raise RuntimeError('Unable to check general logical volume')
		return float(output.replace(',', '.', 1))
666073
def usage(self, callback=None, errback=None, **kwargs):
        
        stats = Stats(self.config)
        return stats.usage(zone=self.zone, callback=callback, errback=errback,
                           **kwargs)
330147
private static void usage() {
        display("Usage: CSVLoader <params>");
        display("where <params> are:");
        display("   -app <name>         Doradus application name. Default is: {}", CSVConfig.DEFAULT_APPNAME);
        display("   -batchsize <#>      Batch size. Default is: {}", CSVConfig.DEFAULT_BATCH_SIZE);
        display("   -compress [T|F]     Compress messages. Default is: {}", CSVConfig.DEFAULT_COMPRESS);
        display("   -host <host>        Doradus server host name. Default is: {}", CSVConfig.DEFAULT_HOST);
        display("   -id <name>          Column name of ID field. Default is: {}", CSVConfig.DEFAULT_ID_FIELD);
        display("   -increment_ts [T|F] True to increment timestamp fields 1 day per batch. Default is: {}", CSVConfig.DEFAULT_INCREMENT_TS);
        display("   -merge_all [T|F]    (OLAP only): true to merge after every batch. Default is: {}", CSVConfig.DEFAULT_MERGE_ALL);
        display("   -password <pw>      Password for tenant. Default is: {}", CSVConfig.DEFAULT_PASSWORD);
        display("   -port <port>        Doradus server port. Default is: {}", CSVConfig.DEFAULT_PORT);
        display("   -root <folder>      Root folder of CSV files. Default is: {}", CSVConfig.DEFAULT_ROOT);
        display("   -schema <file>      Name of application schema file. Default is: <app name>.xml");
        display("   -skip_undef [T|F]   True to skip fields not declared in the schema. Default is: {}", CSVConfig.DEFAULT_SKIP_UNDEF);
        display("   -shard <name>       (OLAP only): Name of shard to load. Default is: {}", CSVConfig.DEFAULT_SHARD);
        display("   -tenant <name>      Name of tenant to use. Default is: {}", CSVConfig.DEFAULT_TENANT);
        display("   -user <ID>          User ID for tenant. Default is: {}", CSVConfig.DEFAULT_USER);
        display("   -workers <#>        # of worker threads. Default is: {}", CSVConfig.DEFAULT_WORKERS);
        display("To use TLS:");
        display("   -tls [T|F]               True to enable TLS/SSL. Default is: {}", CSVConfig.DEFAULT_TLS);
        display("   -keystore <file>         File name of keystore. Default is: {}", CSVConfig.DEFAULT_KEYSTORE);
        display("   -keystorepassword <pw>   Password of keystore file. Default is: {}", CSVConfig.DEFAULT_KEYSTORE_PW);
        display("   -truststore <file>       File name of truststore. Default is: {}", CSVConfig.DEFAULT_TRUSTSTORE);
        display("   -truststorepassword <pw> Password of truststore file. Default is: {}", CSVConfig.DEFAULT_TRUSTSTORE_PW);
        display("Deletes and recreates OLAP or Spider application defined by 'schema' file, then loads all CSV");
        display("files found in 'root' folder.");
        System.exit(0);
    }
371649
private function checkDiskSpace()
    {
        $retValue = array();
        $freeSpace = disk_free_space($this->directory);
        $totalSpace = disk_total_space($this->directory);
        if (0 === $totalSpace) {
            $retValue[] = new CheckOutcome(
                'check.disk_space.totalzero',
                array('%0%' => $this->directory),
                CheckOutcome::ERROR
            );

            return $retValue;
        }
        $percentage = 100 * ($freeSpace / $totalSpace);

        $maxLevel = 0;
        $maxStrategy = self::STRATEGY_ABSOLUTE;

        foreach ($this->thresholdData as $level => $data) {
            $threshold = $data[0];
            $strategy = $data[1];

            switch ($strategy) {
                case self::STRATEGY_ABSOLUTE:
                    if (($freeSpace < $threshold) && $level > $maxLevel) {
                        $maxLevel = $level;
                        $maxStrategy = self::STRATEGY_ABSOLUTE;
                    }
                    break;
                case self::STRATEGY_PERCENTAGE:
                    if (($percentage < $threshold) && $level > $maxLevel) {
                        $maxLevel = $level;
                        $maxStrategy = self::STRATEGY_PERCENTAGE;
                    }
                    break;
                default:
                    $retValue[] = new CheckOutcome(
                        'check.disk_space.invalid_strategy',
                        array('%0%' => $strategy),
                        CheckOutcome::ERROR
                    );
                    break;
            }
        }

        if ($maxLevel > 0) {
            $retValue[] = new CheckOutcome(
                'check.disk_space.lowspace', array(
                '%0%' => $this->directory,
                '%1%' => $this->formatSpaceLeft($freeSpace, $totalSpace, $maxStrategy),
            ), $maxLevel
            );
        } else {
            $retValue[] = new CheckOutcome('check.disk_space.ok', array(), CheckOutcome::OK);
        }

        return $retValue;
    }
830655
private void checkFreeDiskSpace(List<File> inputFiles) {
    //Check for free space
    long usableSpace = 0;
    long totalSize = 0;
    for (File f : inputFiles) {
      if (f.exists()) {
        totalSize += f.length();
        usableSpace = f.getUsableSpace();
      }
    }
    LOGGER.log(Level.INFO, "Total expected store size is {0} Mb",
        new DecimalFormat("#,##0.0").format(totalSize / (1024 * 1024)));
    LOGGER.log(Level.INFO, "Usable free space on the system is {0} Mb",
        new DecimalFormat("#,##0.0").format(usableSpace / (1024 * 1024)));
    if (totalSize / (double) usableSpace >= 0.66) {
      throw new RuntimeException("Aborting because there isn' enough free disk space");
    }
  }
467219
def reports(self):
        """"""
        if self._metrics is None:
            self.__init()
        self._reports = []
        for r in self._metrics:
            url = self._url + "/%s" % six.moves.urllib.parse.quote_plus(r['reportname'])
            self._reports.append(UsageReport(url=url,
                                             securityHandler=self._securityHandler,
                                             proxy_url=self._proxy_url,
                                             proxy_port=self._proxy_port,
                                             initialize=True))
            del url
        return self._reports
239503
def windows_memory_usage():
    """"""
    from ctypes import windll, Structure, c_uint64, sizeof, byref
    from ctypes.wintypes import DWORD
    class MemoryStatus(Structure):
        _fields_ = [('dwLength', DWORD),
                    ('dwMemoryLoad',DWORD),
                    ('ullTotalPhys', c_uint64),
                    ('ullAvailPhys', c_uint64),
                    ('ullTotalPageFile', c_uint64),
                    ('ullAvailPageFile', c_uint64),
                    ('ullTotalVirtual', c_uint64),
                    ('ullAvailVirtual', c_uint64),
                    ('ullAvailExtendedVirtual', c_uint64),]
    memorystatus = MemoryStatus()
    # MSDN documetation states that dwLength must be set to MemoryStatus
    # size before calling GlobalMemoryStatusEx
    # https://msdn.microsoft.com/en-us/library/aa366770(v=vs.85)
    memorystatus.dwLength = sizeof(memorystatus)
    windll.kernel32.GlobalMemoryStatusEx(byref(memorystatus))
    return float(memorystatus.dwMemoryLoad)
136221
function metrics( clbk ) {
	var m = {},
		mem,
		used,
		total;

	// Get the process id:
	m.pid = process.pid;

	// Get the number of milliseconds the process has been running:
	m.uptime = process.uptime() * 1000; // ms

	// Extract process memory usage:
	mem = process.memoryUsage();
	used = mem.heapUsed;
	total = mem.heapTotal;

	m.mem = {
		'rss': mem.rss / 1000, // KB
		'heapFree': (total-used) / 1000, // KB
		'heapTotal': total / 1000, // KB
		'heapUtilization': used / total
	};

	// Get the average amount of time requests have to wait in Node's event queue before being processed:
	m.lag = toobusy.lag(); // ms

	// Get the CPU and memory consumption:
	pidusage.stat( m.pid, onStats );

	/**
	* FUNCTION: onStats( error, stat )
	*	Callback invoked upon collecting CPU and memory data for the current process.
	*
	* @private
	* @param {Object} error
	* @param {Object} stat - process data
	*/
	function onStats( error, stat ) {
		if ( error ) {
			return clbk( error );
		}
		m.mem.memUsed = stat.memory / 1000; // KB
		m.mem.utilization = stat.memory / os.totalmem();
		m.cpu = {
			'utilization': stat.cpu / 100
		};
		clbk( null, m );
	}
}
202728
def check_disk_usage(filehandle, meta):
    
    # limit it at twenty kilobytes if no default is provided
    MAX_DISK_USAGE = current_app.config.get('MAX_DISK_USAGE', 20 * 1024)
    CURRENT_USAGE = really_bad_du(current_app.config['UPLOAD_PATH'])
    filehandle.seek(0, os.SEEK_END)

    if CURRENT_USAGE + filehandle.tell() > MAX_DISK_USAGE:
        filehandle.close()
        raise UploadError("Upload exceeds allotment.")
    filehandle.seek(0)
    return filehandle
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)
595743
def list_metrics(ctx):
    """"""
    config = ctx.obj["CONFIG"]

    if not exists(config):
        handle_no_cache(ctx)

    from wily.commands.list_metrics import list_metrics

    list_metrics()
41776
def usage(self):
        ''''''
        retval, stderr, stdout = _pysam_dispatch(
            self.collection,
            self.dispatch,
            is_usage=True,
            catch_stdout=True)
        # some tools write usage to stderr, such as mpileup
        if stderr:
            return stderr
        else:
            return stdout
327697
def measuredim(self):
        """"""

        if isinstance(self, PartitionProxy):
            return MeasureDimensionPartition(self._obj)
        else:
            return MeasureDimensionPartition(self)
588159
public void configToLogInfo() {
        logger.info("----- MEMEORY USAGE -----");
        logger.info("BUCKET_MEMORY = {}", BUCKET_MEMORY);
        logger.info("MEMORY_CHUNK = {}", MEMORY_CHUNK);
        logger.info("MAX_MEMORY_PER_BUCKET = {}", MAX_MEMORY_PER_BUCKET);
        logger.info("CHUNKSIZE = {}", SYNC_CHUNK_SIZE);

        logger.info("----- HeaderIndexFile -----");
        logger.info("INITIAL_FILE_SIZE = {}", INITIAL_FILE_SIZE);
        logger.info("INITIAL_INCREMENT_SIZE = {}", INITIAL_INCREMENT_SIZE);
        logger.info("CHUNK_SIZE = {}", FILE_CHUNK_SIZE);
    }
658798
def json_charts(self, req):
        
        disk_used, disk_total, disk_detail = 0, 0, []
        for disk_usage_path in self.cfg.disk_usage_path.split(os.pathsep):
            disk_usage = self.guarded(psutil.disk_usage, os.path.expanduser(disk_usage_path.strip()))
            if disk_usage:
                disk_used += disk_usage.used
                disk_total += disk_usage.total
                disk_detail.append((disk_usage.used, disk_usage.total))

        data = dict(
            engine      = self.json_engine(req),
            uptime      = time.time() - psutil.BOOT_TIME,  # pylint: disable=no-member
            fqdn        = self.guarded(socket.getfqdn),
            cpu_usage   = self.guarded(psutil.cpu_percent, 0),
            ram_usage   = self.guarded(psutil.virtual_memory),
            swap_usage  = self.guarded(psutil.swap_memory),
            disk_usage  = (disk_used, disk_total, disk_detail) if disk_total else None,
            disk_io     = self.guarded(psutil.disk_io_counters),
            net_io      = self.guarded(psutil.net_io_counters),
        )
        return data
749807
def _report_container_state_metrics(self, pod_list, instance_tags):
        """"""
        if pod_list.get('expired_count'):
            self.gauge(self.NAMESPACE + '.pods.expired', pod_list.get('expired_count'), tags=instance_tags)

        for pod in pod_list['items']:
            pod_name = pod.get('metadata', {}).get('name')
            pod_uid = pod.get('metadata', {}).get('uid')

            if not pod_name or not pod_uid:
                continue

            for ctr_status in pod['status'].get('containerStatuses', []):
                c_name = ctr_status.get('name')
                cid = ctr_status.get('containerID')
                if not c_name or not cid:
                    continue

                if self.pod_list_utils.is_excluded(cid, pod_uid):
                    continue

                tags = tagger.tag('%s' % cid, tagger.ORCHESTRATOR) + instance_tags

                restart_count = ctr_status.get('restartCount', 0)
                self.gauge(self.NAMESPACE + '.containers.restarts', restart_count, tags)

                for (metric_name, field_name) in [('state', 'state'), ('last_state', 'lastState')]:
                    c_state = ctr_status.get(field_name, {})

                    for state_name in ['terminated', 'waiting']:
                        state_reasons = WHITELISTED_CONTAINER_STATE_REASONS.get(state_name, [])
                        self._submit_container_state_metric(metric_name, state_name, c_state, state_reasons, tags)