コード例 #1
0
ファイル: blockdev.c プロジェクト: ipfire/collecty
PyObject* BlockDevice_get_bad_sectors(PyObject* self) {
	BlockDevice* device = (BlockDevice*)self;

	if (BlockDevice_smart_is_available(device)) {
		PyErr_Format(PyExc_OSError, "Device does not support SMART");
		return NULL;
	}

	uint64_t bad_sectors;
	int r = sk_disk_smart_get_bad(device->disk, &bad_sectors);
	if (r)
		return NULL;

	return PyLong_FromUnsignedLongLong((unsigned long long)bad_sectors);
}
コード例 #2
0
ファイル: smart.c プロジェクト: skarlsson/collectd
static void smart_handle_disk (const char *dev)
{
  SkDisk *d = NULL;
  SkBool awake = FALSE;
  SkBool available = FALSE;
  const char *shortname;
  const SkSmartParsedData *spd;
  uint64_t poweron, powercycles, badsectors, temperature;

  shortname = strrchr(dev, '/');
  if (!shortname) return;
  shortname++;
  if (ignorelist_match (ignorelist, shortname) != 0) {
    INFO ("smart plugin: ignoring %s.", dev);
    return;
  }

  INFO ("smart plugin: checking SMART status of %s.",
         dev);

  if (sk_disk_open (dev, &d) < 0)
  {
    ERROR ("smart plugin: unable to open %s.", dev);
    return;
  }
  if (sk_disk_identify_is_available (d, &available) < 0 || !available)
  {
    INFO ("smart plugin: disk %s cannot be identified.", dev);
    /* goto end;*/
  }
  if (sk_disk_smart_is_available (d, &available) < 0 || !available)
  {
    INFO ("smart plugin: disk %s has no SMART support.", dev);
    goto end;
  }
  if (sk_disk_check_sleep_mode (d, &awake) < 0 || !awake)
  {
    INFO ("smart plugin: disk %s is sleeping.", dev);
    goto end;
  }
  if (sk_disk_smart_read_data (d) < 0)
  {
    ERROR ("smart plugin: unable to get SMART data for disk %s.", dev);
    goto end;
  }
  if (sk_disk_smart_parse (d, &spd) < 0)
  {
    ERROR ("smart plugin: unable to parse SMART data for disk %s.", dev);
    goto end;
  }

  /* Get some specific values */
  if (sk_disk_smart_get_power_on (d, &poweron) < 0)
  {
    WARNING ("smart plugin: unable to get milliseconds since power on for %s.",
             dev);
  }
  else
    smart_submit (shortname, "smart_poweron", "", poweron / 1000.);

  if (sk_disk_smart_get_power_cycle (d, &powercycles) < 0)
  {
    WARNING ("smart plugin: unable to get number of power cycles for %s.",
             dev);
  }
  else
    smart_submit (shortname, "smart_powercycles", "", powercycles);

  if (sk_disk_smart_get_bad (d, &badsectors) < 0)
  {
    WARNING ("smart plugin: unable to get number of bad sectors for %s.",
             dev);
  }
  else
    smart_submit (shortname, "smart_badsectors", "", badsectors);

  if (sk_disk_smart_get_temperature (d, &temperature) < 0)
  {
    WARNING ("smart plugin: unable to get temperature for %s.",
             dev);
  }
  else
    smart_submit (shortname, "smart_temperature", "", temperature / 1000. - 273.15);

  /* Grab all attributes */
  if (sk_disk_smart_parse_attributes(d, smart_handle_disk_attribute,
                                     (char *)shortname) < 0)
  {
    ERROR ("smart plugin: unable to handle SMART attributes for %s.",
           dev);
  }

end:
  sk_disk_free(d);
}