From: Pavel Rochnyack Date: Fri, 26 Oct 2018 17:29:52 +0000 (+0700) Subject: Merge branch 'collectd-5.8' into master X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=c00630eab6161514c1044e8adb2895f179a535da;p=collectd.git Merge branch 'collectd-5.8' into master Conflicts: src/disk.c src/virt.c --- c00630eab6161514c1044e8adb2895f179a535da diff --cc src/disk.c index c0408cec,2234c02c..c78df4ec --- a/src/disk.c +++ b/src/disk.c @@@ -692,7 -696,10 +692,9 @@@ static int disk_read(void) char *output_name; numfields = strsplit(buffer, fields, 32); - if ((numfields != 14) && (numfields != 7)) + - /* need either 7 fields (partition) - * or at least 14 fields (15 on Linux 2.4) */ - if ((numfields != 7) && (numfields < (14 + fieldshift))) ++ /* need either 7 fields (partition) or at least 14 fields */ ++ if ((numfields != 7) && (numfields < 14)) continue; minor = atoll(fields[1]); @@@ -726,28 -733,26 +728,26 @@@ read_sectors = atoll(fields[4]); write_ops = atoll(fields[5]); write_sectors = atoll(fields[6]); - } else if (numfields == 14) { + } else { - assert(numfields >= (14 + fieldshift)); - read_ops = atoll(fields[3 + fieldshift]); - write_ops = atoll(fields[7 + fieldshift]); ++ assert(numfields >= 14); + read_ops = atoll(fields[3]); + write_ops = atoll(fields[7]); - read_sectors = atoll(fields[5 + fieldshift]); - write_sectors = atoll(fields[9 + fieldshift]); + read_sectors = atoll(fields[5]); + write_sectors = atoll(fields[9]); - if ((fieldshift == 0) || (minor == 0)) { + if (minor == 0) { is_disk = 1; - read_merged = atoll(fields[4 + fieldshift]); - read_time = atoll(fields[6 + fieldshift]); - write_merged = atoll(fields[8 + fieldshift]); - write_time = atoll(fields[10 + fieldshift]); + read_merged = atoll(fields[4]); + read_time = atoll(fields[6]); + write_merged = atoll(fields[8]); + write_time = atoll(fields[10]); - in_progress = atof(fields[11 + fieldshift]); + in_progress = atof(fields[11]); - io_time = atof(fields[12 + fieldshift]); - weighted_time = atof(fields[13 + fieldshift]); + io_time = atof(fields[12]); + weighted_time = atof(fields[13]); } - } else { - DEBUG("numfields = %i; => unknown file format.", numfields); - continue; } { diff --cc src/exec.c index 77b13755,a38026ef..26b8fa7e --- a/src/exec.c +++ b/src/exec.c @@@ -466,9 -494,12 +486,11 @@@ static int fork_child(program_list_t *p goto failed; } + set_environment(); + pid = fork(); if (pid < 0) { - ERROR("exec plugin: fork failed: %s", - sstrerror(errno, errbuf, sizeof(errbuf))); + ERROR("exec plugin: fork failed: %s", STRERRNO); goto failed; } else if (pid == 0) { int fd_num; diff --cc src/virt.c index c52a8a7e,8a44c268..a828c456 --- a/src/virt.c +++ b/src/virt.c @@@ -708,60 -473,11 +702,10 @@@ static int get_block_info(struct lv_blo virErrorPtr err; \ err = (conn) ? virConnGetLastError((conn)) : virGetLastError(); \ if (err) \ - ERROR("%s: %s", (s), err->message); \ + ERROR(PLUGIN_NAME " plugin: %s failed: %s", (s), err->message); \ } while (0) - static void init_lv_info(struct lv_info *info) { - if (info != NULL) - memset(info, 0, sizeof(*info)); - } - - static int lv_domain_info(virDomainPtr dom, struct lv_info *info) { - #ifdef HAVE_CPU_STATS - virTypedParameterPtr param = NULL; - int nparams = 0; - #endif /* HAVE_CPU_STATS */ - int ret = virDomainGetInfo(dom, &(info->di)); - if (ret != 0) { - return ret; - } - - #ifdef HAVE_CPU_STATS - nparams = virDomainGetCPUStats(dom, NULL, 0, -1, 1, 0); - if (nparams < 0) { - VIRT_ERROR(conn, "getting the CPU params count"); - return -1; - } - - param = calloc(nparams, sizeof(virTypedParameter)); - if (param == NULL) { - ERROR("virt plugin: alloc(%i) for cpu parameters failed.", nparams); - return -1; - } - - ret = virDomainGetCPUStats(dom, param, nparams, -1, 1, 0); // total stats. - if (ret < 0) { - virTypedParamsClear(param, nparams); - sfree(param); - VIRT_ERROR(conn, "getting the disk params values"); - return -1; - } - - for (int i = 0; i < nparams; ++i) { - if (!strcmp(param[i].field, "user_time")) - info->total_user_cpu_time = param[i].value.ul; - else if (!strcmp(param[i].field, "system_time")) - info->total_syst_cpu_time = param[i].value.ul; - } - - virTypedParamsClear(param, nparams); - sfree(param); - #endif /* HAVE_CPU_STATS */ - - return 0; - } - static void init_value_list(value_list_t *vl, virDomainPtr dom) { - int n; const char *name; char uuid[VIR_UUID_STRING_BUFLEN]; @@@ -1443,16 -1157,50 +1379,59 @@@ static int get_vcpu_stats(virDomainPtr return 0; } + #ifdef HAVE_CPU_STATS + static int get_pcpu_stats(virDomainPtr dom) { + int nparams = virDomainGetCPUStats(dom, NULL, 0, -1, 1, 0); + if (nparams < 0) { + VIRT_ERROR(conn, "getting the CPU params count"); + return -1; + } + + virTypedParameterPtr param = calloc(nparams, sizeof(virTypedParameter)); + if (param == NULL) { + ERROR(PLUGIN_NAME " plugin: alloc(%i) for cpu parameters failed.", nparams); + return -1; + } + + int ret = virDomainGetCPUStats(dom, param, nparams, -1, 1, 0); // total stats. + if (ret < 0) { + virTypedParamsClear(param, nparams); + sfree(param); + VIRT_ERROR(conn, "getting the CPU params values"); + return -1; + } + + unsigned long long total_user_cpu_time = 0; + unsigned long long total_syst_cpu_time = 0; + + for (int i = 0; i < nparams; ++i) { + if (!strcmp(param[i].field, "user_time")) + total_user_cpu_time = param[i].value.ul; + else if (!strcmp(param[i].field, "system_time")) + total_syst_cpu_time = param[i].value.ul; + } + + if (total_user_cpu_time > 0 || total_syst_cpu_time > 0) + submit_derive2("ps_cputime", total_user_cpu_time, total_syst_cpu_time, dom, + NULL); + + virTypedParamsClear(param, nparams); + sfree(param); + + return 0; + } + #endif /* HAVE_CPU_STATS */ + #ifdef HAVE_DOM_REASON + +static void domain_state_submit(virDomainPtr dom, int state, int reason) { + value_t values[] = { + {.gauge = (gauge_t)state}, {.gauge = (gauge_t)reason}, + }; + + submit(dom, "domain_state", NULL, values, STATIC_ARRAY_SIZE(values)); +} + static int get_domain_state(virDomainPtr domain) { int domain_state = 0; int domain_reason = 0; @@@ -1775,8 -1509,7 +1756,8 @@@ static int get_domain_metrics(domain_t #endif /* Update cached virDomainInfo. It has to be done after cpu_submit */ - memcpy(&domain->info, &info.di, sizeof(domain->info)); + memcpy(&domain->info, &info, sizeof(domain->info)); + return 0; }