コード例 #1
0
ファイル: conf.c プロジェクト: noushi/bmon
static void configfile_read_attrs(void)
{
	int i, nattrs, t;

	nattrs = cfg_size(cfg, "attr");

	for (i = 0; i < nattrs; i++) {
		struct unit *u;
		cfg_t *attr;
		const char *name, *description, *unit, *type;
		int flags = 0;

		if (!(attr = cfg_getnsec(cfg, "attr", i)))
			BUG();

		if (!(name = cfg_title(attr)))
			BUG();

		description = cfg_getstr(attr, "description");
		unit = cfg_getstr(attr, "unit");
		type = cfg_getstr(attr, "type");

		if (!unit)
			quit("Attribute '%s' is missing unit specification\n",
			     name);

		if (!type)
			quit("Attribute '%s' is missing type specification\n",
			     name);

		if (!(u = unit_lookup(unit)))
			quit("Unknown unit \'%s\' attribute '%s'\n",
				unit, name);

		if (!strcasecmp(type, "counter"))
			t = ATTR_TYPE_COUNTER;
		else if (!strcasecmp(type, "rate"))
			t = ATTR_TYPE_RATE;
		else if (!strcasecmp(type, "percent"))
			t = ATTR_TYPE_PERCENT;
		else
			quit("Unknown type \'%s\' in attribute '%s'\n",
				type, name);

		if (cfg_getbool(attr, "history"))
			flags |= ATTR_DEF_FLAG_HISTORY;

		attr_def_add(name, description, u, t, flags);
	}
}
コード例 #2
0
/*
 * Print the disk geometry information. Take an optional modifier
 * to indicate the units that should be used for display.
 */
int
DISK_printmetrics(disk_t *disk, char *units)
{
	const int secsize = unit_types[SECTORS].conversion;
	double size;
	int i;

	i = unit_lookup(units);
	size = ((double)disk->real->size * secsize) / unit_types[i].conversion;
	printf("Disk: %s\t", disk->name);
	if (disk->real) {
		printf("geometry: %d/%d/%d [%.0f ",
		    disk->real->cylinders, disk->real->heads,
		    disk->real->sectors, size);
		if (i == SECTORS && secsize != DEV_BSIZE)
			printf("%d-byte ", secsize);
		printf("%s]\n", unit_types[i].lname);
	} else
		printf("geometry: <none>\n");

	return (0);
}