Example #1
0
void AtasmartSensorDriver::read_temps() const
{
	SkBool disk_sleeping = false;

	if (unlikely(dnd_disk && (sk_disk_check_sleep_mode(disk_, &disk_sleeping) < 0))) {
		string msg = strerror(errno);
		throw SystemError("sk_disk_check_sleep_mode(" + path_ + "): " + msg);
	}

	if (unlikely(disk_sleeping)) {
		temp_state.add_temp(0);
	}
	else {
		uint64_t mKelvin;
		double tmp;

		if (unlikely(sk_disk_smart_read_data(disk_) < 0)) {
			string msg = strerror(errno);
			throw SystemError("sk_disk_smart_read_data(" + path_ + "): " + msg);
		}
		if (unlikely(sk_disk_smart_get_temperature(disk_, &mKelvin)) < 0) {
			string msg = strerror(errno);
			throw SystemError("sk_disk_smart_get_temperature(" + path_ + "): " + msg);
		}

		tmp = mKelvin / 1000.0f;
		tmp -= 273.15f;

		if (unlikely(tmp > std::numeric_limits<int>::max() || tmp < std::numeric_limits<int>::min())) {
			throw SystemError(MSG_T_GET(path_) + std::to_string(tmp) + " isn't a valid temperature.");
		}

		temp_state.add_temp(tmp);
	}
}
Example #2
0
int BlockDevice_check_sleep_mode(BlockDevice* device) {
	SkBool awake = FALSE;

	int r = sk_disk_check_sleep_mode(device->disk, &awake);
	if (r)
		return -1;

	if (awake)
		return 0;

	return 1;
}
Example #3
0
int get_hd_health(const char *disk, hd_health *hdh) {
  int ret = -1;
  SkDisk *skdisk;
  SkBool smart_available = 0;
  uint64_t disk_temp = 0;
  uint64_t disk_ontime = 0;

  if (sk_disk_open(disk, &skdisk) < 0) {
    fprintf(stderr, "Failed to open disk %s: %s(%d)\n", disk, strerror(errno), errno);
    return -1;
  }

  if (sk_disk_smart_is_available(skdisk, &smart_available) < 0) {
    fprintf(stderr, "Failed to query whether SMART is available %s: %s(%d)\n", disk, strerror(errno), errno);
    goto done;
  }
  if (!smart_available) {
    fprintf(stderr, "%s is not support SMART\n", disk);
    goto done;
  }

  if (sk_disk_smart_read_data(skdisk) < 0) {
    fprintf(stderr, "Failed to read SMART data %s: %s(%d)\n", disk, strerror(errno), errno);
    goto done;
  }
  ret = 0;

  if (sk_disk_smart_get_temperature(skdisk, &disk_temp) == 0) {
    uint64_t celsius = (disk_temp - 273150) / 1000;  /* convert milli kelvin to celsius */
    hdh->temperature = celsius;
  }

  if (sk_disk_smart_get_power_on(skdisk, &disk_ontime) == 0) {
    uint64_t onhour = disk_ontime / 1000 / 3600;
    hdh->ontime = onhour;
  }

  sk_disk_check_sleep_mode(skdisk, &hdh->awake);
  sk_disk_smart_status(skdisk, &hdh->status);

  hdh->caution = 0;
  if (sk_disk_smart_parse_attributes(skdisk, (SkSmartAttributeParseCallback) check_caution_cb, &hdh->caution) < 0) {
    fprintf(stderr, "Failed to get attribute: %s(%d)\n", strerror(errno), errno);
    goto done;
  }

done:
  sk_disk_free(skdisk);

  return ret;
}
Example #4
0
void AtasmartSensorDriver::read_temps() const
{
    SkBool disk_sleeping = false;

    if (unlikely(dnd_disk && (sk_disk_check_sleep_mode(disk_, &disk_sleeping) < 0))) {
        string msg = strerror(errno);
        fail(TF_ERR) << SystemError("sk_disk_check_sleep_mode(" + path_ + "): " + msg) << flush;
    }

    if (unlikely(disk_sleeping)) {
        *temp_state.temp_idx = 0;
        update_tempstate(correction_[0]);
    }
    else {
        uint64_t mKelvin;
        double tmp;

        if (unlikely(sk_disk_smart_read_data(disk_) < 0)) {
            string msg = strerror(errno);
            fail(TF_ERR) << SystemError("sk_disk_smart_read_data(" + path_ + "): " + msg) << flush;
        }
        if (unlikely(sk_disk_smart_get_temperature(disk_, &mKelvin)) < 0) {
            string msg = strerror(errno);
            fail(TF_ERR) << SystemError("sk_disk_smart_get_temperature(" + path_ + "): " + msg) << flush;
        }

        tmp = mKelvin / 1000.0f;
        tmp -= 273.15f;

        if (unlikely(tmp > std::numeric_limits<int>::max() || tmp < std::numeric_limits<int>::min())) {
            fail(TF_ERR) << MSG_T_GET(path_) << SystemError(std::to_string(tmp) + " isn't a valid temperature.") << flush;
        }

        *temp_state.temp_idx = tmp;
        update_tempstate(correction_[0]);
    }
}
Example #5
0
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);
}