Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/collectors/windows.plugin/GetHardwareInfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ static void netdata_detect_cpu()
temperature_fcnt = netdata_amd_cpu_temp;
}

static int initialize(int update_every)
static int initialize()
{
netdata_detect_cpu();
if (!temperature_fcnt) {
Expand All @@ -254,7 +254,7 @@ static int initialize(int update_every)
ncpus = os_get_system_cpus();
cpus = callocz(ncpus, sizeof(struct cpu_data));

hardware_info_thread = nd_thread_create("hi_threads", NETDATA_THREAD_OPTION_DEFAULT, get_hardware_info_thread, &update_every);
hardware_info_thread = nd_thread_create("hi_threads", NETDATA_THREAD_OPTION_DEFAULT, get_hardware_info_thread, NULL);

return 0;
}
Expand All @@ -270,7 +270,7 @@ static RRDSET *netdata_publish_cpu_chart(int update_every)
"temperature",
"cpu.temperature",
"Core temperature",
"Celcius",
"Celsius",
PLUGIN_WINDOWS_NAME,
"GetHardwareInfo",
NETDATA_CHART_PRIO_CPU_TEMPERATURE,
Expand All @@ -284,11 +284,11 @@ static RRDSET *netdata_publish_cpu_chart(int update_every)
static void netdata_loop_cpu_chart(int update_every)
{
RRDSET *chart = netdata_publish_cpu_chart(update_every);
for (size_t i = 0; i < ncpus; i++) {
for (int i = 0; i < (int)ncpus; i++) {
struct cpu_data *lcpu = &cpus[i];
if (!lcpu->rd_cpu_temp) {
char id[RRD_ID_LENGTH_MAX + 1];
snprintfz(id, RRD_ID_LENGTH_MAX, "cpu%lu.temp", i);
snprintfz(id, RRD_ID_LENGTH_MAX, "cpu%d.temp", i);
lcpu->rd_cpu_temp = rrddim_add(chart, id, NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
}
rrddim_set_by_pointer(chart, lcpu->rd_cpu_temp, lcpu->cpu_temp);
Expand All @@ -301,7 +301,7 @@ int do_GetHardwareInfo(int update_every, usec_t dt __maybe_unused)
static bool initialized = false;
if (unlikely(!initialized)) {
initialized = true;
if (initialize(update_every)) {
if (initialize()) {
return -1;
}
}
Expand All @@ -314,7 +314,7 @@ int do_GetHardwareInfo(int update_every, usec_t dt __maybe_unused)
void do_GetHardwareInfo_cleanup()
{
if (nd_thread_join(hardware_info_thread))
nd_log_daemon(NDLP_ERR, "Failed to join mssql queries thread");
nd_log_daemon(NDLP_ERR, "Failed to join Get Hardware Info thread");

netdata_stop_driver();
}
18 changes: 12 additions & 6 deletions src/collectors/windows.plugin/GetPowerSupply.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ static inline void netdata_update_power_supply_values(
if (bs.Capacity != BATTERY_UNKNOWN_CAPACITY) {
NETDATA_DOUBLE num = bs.Capacity;
NETDATA_DOUBLE den = bi->FullChargedCapacity;
num /= den;
num = (den) ? num/ den : 0;

power_supply_root->capacity->value = (unsigned long long)(num * 100.0);
}
Expand Down Expand Up @@ -84,7 +84,7 @@ int do_GetPowerSupply(int update_every, usec_t dt __maybe_unused)
SP_DEVICE_INTERFACE_DATA did = {0};
did.cbSize = sizeof(did);

for (LONG i = 0; i < 32 && SetupDiEnumDeviceInterfaces(hdev, 0, &GUID_DEVCLASS_BATTERY, 0, &did); i++) {
for (LONG i = 0; i < 32 && SetupDiEnumDeviceInterfaces(hdev, 0, &GUID_DEVCLASS_BATTERY, i, &did); i++) {
DWORD cbRequired = 0;
PSP_DEVICE_INTERFACE_DETAIL_DATA pdidd = NULL;
HANDLE hBattery = NULL;
Expand Down Expand Up @@ -124,8 +124,8 @@ int do_GetPowerSupply(int update_every, usec_t dt __maybe_unused)
&bqi.BatteryTag,
sizeof(bqi.BatteryTag),
&dwOut,
NULL) &&
bqi.BatteryTag)
NULL) ||
!bqi.BatteryTag)
goto endPowerSupply;

BATTERY_INFORMATION bi = {0};
Expand All @@ -141,8 +141,14 @@ int do_GetPowerSupply(int update_every, usec_t dt __maybe_unused)
char name[RRD_ID_LENGTH_MAX + 1];
snprintfz(name, sizeof(name), "BAT%d", i + 1);

power_supply_root->name = name;
power_supply_root->capacity->filename = power_supply_root->name;
if (likely(power_supply_root->name))
freez(power_supply_root->name);
if (likely(power_supply_root->capacity->filename))
freez(power_supply_root->capacity->filename);

power_supply_root->name = power_supply_root->capacity->filename = NULL;
power_supply_root->name = strdupz(name);
power_supply_root->capacity->filename = strdupz(power_supply_root->name);

netdata_update_power_supply_values(hBattery, &voltage, &bi, &bqi);

Expand Down
36 changes: 28 additions & 8 deletions src/collectors/windows.plugin/GetSensors.c
Original file line number Diff line number Diff line change
Expand Up @@ -346,23 +346,37 @@ struct sensor_data {
DICTIONARY *sensors;

// Microsoft appends additional data
#define ADDTIONAL_UUID_STR_LEN (UUID_STR_LEN + 8)
#define ADDTIONAL_UUID_STR_LEN (UUID_STR_LEN + 17)

static void netdata_clsid_to_char(char *output, const GUID *pguid)
static bool netdata_clsid_to_char(char *output, size_t output_len, const GUID *pguid)
{
if (unlikely(!output))
return false;

LPWSTR wguid = NULL;
if (SUCCEEDED(StringFromCLSID(pguid, &wguid)) && wguid) {
size_t len = wcslen(wguid);
wcstombs(output, wguid, len);
CoTaskMemFree(wguid);
HRESULT hr = StringFromCLSID(pguid, &wguid);
output[0] = '\0';
if (FAILED(hr) || unlikely(!wguid))
return false;

size_t converted = wcstombs(output, wguid, output_len - 1);
CoTaskMemFree(wguid);

if (unlikely(converted == (size_t)-1)) {
output[0] = '\0';
return false;
}

output[converted] = '\0';

return true;
}

static inline char *netdata_convert_guid_to_string(HRESULT hr, GUID *value)
{
if (SUCCEEDED(hr)) {
char cguid[ADDTIONAL_UUID_STR_LEN];
netdata_clsid_to_char(cguid, value);
netdata_clsid_to_char(cguid, ADDTIONAL_UUID_STR_LEN, value);
return strdupz(cguid);
}
return NULL;
Expand Down Expand Up @@ -540,6 +554,7 @@ static void netdata_get_sensors()
ULONG count = 0;
hr = pSensorCollection->lpVtbl->GetCount(pSensorCollection, &count);
if (FAILED(hr)) {
pSensorCollection->lpVtbl->Release(pSensorCollection);
return;
}

Expand All @@ -555,9 +570,14 @@ static void netdata_get_sensors()
GUID id = {0};
hr = pSensor->lpVtbl->GetID(pSensor, &id);
if (FAILED(hr)) {
pSensor->lpVtbl->Release(pSensor);
continue;
}

if (!netdata_clsid_to_char(thread_values, sizeof(thread_values), &id)) {
pSensor->lpVtbl->Release(pSensor);
continue;
}
netdata_clsid_to_char(thread_values, &id);

struct sensor_data *sd = dictionary_set(sensors, thread_values, NULL, sizeof(*sd));

Expand Down
23 changes: 19 additions & 4 deletions src/collectors/windows.plugin/GetServicesStatus.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ static void initialize(void)

static BOOL fill_dictionary_with_content()
{
static PVOID buffer = NULL;
PVOID buffer = NULL;
static DWORD bytes_needed = 0;

LPENUM_SERVICE_STATUS_PROCESS service, services;
DWORD total_services = 0;
SC_HANDLE ndSCMH = OpenSCManager(NULL, NULL, SC_MANAGER_ENUMERATE_SERVICE | SC_MANAGER_CONNECT);
if (!ndSCMH) {
if (unlikely(!ndSCMH)) {
return FALSE;
}

Expand All @@ -64,11 +64,24 @@ static BOOL fill_dictionary_with_content()
NULL,
NULL);

if (GetLastError() == ERROR_MORE_DATA) {
if (!buffer)
DWORD test = GetLastError();
if (test == ERROR_MORE_DATA) {
if (unlikely(!buffer))
buffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, bytes_needed);
else
buffer = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, buffer, bytes_needed);
} else {
switch (test) {
case ERROR_ACCESS_DENIED:
case ERROR_INVALID_PARAMETER:
case ERROR_INVALID_HANDLE:
case ERROR_INVALID_LEVEL:
case ERROR_SHUTDOWN_IN_PROGRESS:
ret = FALSE;
goto endServiceCollection;
default:
ret = TRUE;
}
}

if (!buffer) {
Expand Down Expand Up @@ -112,6 +125,8 @@ static BOOL fill_dictionary_with_content()
ret = TRUE;

endServiceCollection:
if (buffer)
HeapFree(GetProcessHeap(), 0, buffer);

CloseServiceHandle(ndSCMH);
return ret;
Expand Down
Loading