X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fvirt.c;h=b9b224e18ca26b06e5ced408865713812ab5a63c;hb=2e5e386539ad6514fb01d7d1e02b2da66a538334;hp=933b59ecd661e14ec1d73e320dd29fc4c3a335e3;hpb=7401da0aa5289f58ee1a99507ad4edda04514629;p=collectd.git diff --git a/src/virt.c b/src/virt.c index 933b59ec..b9b224e1 100644 --- a/src/virt.c +++ b/src/virt.c @@ -946,7 +946,8 @@ static void memory_stats_submit(gauge_t value, virDomainPtr dom, "last_update", "disk_caches"}; if ((tag_index < 0) || (tag_index >= (int)STATIC_ARRAY_SIZE(tags))) { - ERROR("virt plugin: Array index out of bounds: tag_index = %d", tag_index); + ERROR(PLUGIN_NAME " plugin: Array index out of bounds: tag_index = %d", + tag_index); return; } @@ -1567,7 +1568,7 @@ static int get_perf_events(virDomainPtr domain) { ERROR(PLUGIN_NAME " plugin: virDomainListGetStats failed with status %i.", status); - virErrorPtr err = virConnGetLastError(conn); + virErrorPtr err = virGetLastError(); if (err->code == VIR_ERR_NO_SUPPORT) { ERROR(PLUGIN_NAME " plugin: Disabled unsupported ExtraStats selector: perf"); @@ -1624,7 +1625,7 @@ static int get_vcpu_stats(virDomainPtr domain, unsigned short nr_virt_cpu) { ERROR(PLUGIN_NAME " plugin: virDomainGetVcpus failed with status %i.", status); - virErrorPtr err = virConnGetLastError(conn); + virErrorPtr err = virGetLastError(); if (err->code == VIR_ERR_NO_SUPPORT) { if (extra_stats & ex_stats_vcpu) ERROR(PLUGIN_NAME @@ -1658,7 +1659,7 @@ static int get_pcpu_stats(virDomainPtr dom) { if (nparams < 0) { VIRT_ERROR(conn, "getting the CPU params count"); - virErrorPtr err = virConnGetLastError(conn); + virErrorPtr err = virGetLastError(); if (err->code == VIR_ERR_NO_SUPPORT) { ERROR(PLUGIN_NAME " plugin: Disabled unsupported ExtraStats selector: pcpu"); @@ -1758,7 +1759,7 @@ static int get_memory_stats(virDomainPtr domain) { mem_stats); sfree(minfo); - virErrorPtr err = virConnGetLastError(conn); + virErrorPtr err = virGetLastError(); if (err->code == VIR_ERR_NO_SUPPORT) { ERROR(PLUGIN_NAME " plugin: Disabled unsupported ExtraStats selector: memory"); @@ -1823,7 +1824,7 @@ static int get_disk_err(virDomainPtr domain) { ERROR(PLUGIN_NAME " plugin: failed to get preferred size of disk errors array"); - virErrorPtr err = virConnGetLastError(conn); + virErrorPtr err = virGetLastError(); if (err->code == VIR_ERR_NO_SUPPORT) { ERROR(PLUGIN_NAME @@ -1878,7 +1879,7 @@ static int get_block_device_stats(struct block_device *block_dev) { ERROR(PLUGIN_NAME " plugin: virDomainGetBlockInfo failed for path: %s", block_dev->path); - virErrorPtr err = virConnGetLastError(conn); + virErrorPtr err = virGetLastError(); if (err->code == VIR_ERR_NO_SUPPORT) { if (extra_stats & ex_stats_disk_allocation) @@ -1982,7 +1983,7 @@ static int get_fs_info(virDomainPtr domain) { ERROR(PLUGIN_NAME " plugin: virDomainGetFSInfo failed: %d", mount_points_cnt); - virErrorPtr err = virConnGetLastError(conn); + virErrorPtr err = virGetLastError(); if (err->code == VIR_ERR_NO_SUPPORT) { ERROR(PLUGIN_NAME " plugin: Disabled unsupported ExtraStats selector: fs_info"); @@ -2047,7 +2048,7 @@ static int get_job_stats(virDomainPtr domain) { if (ret != 0) { ERROR(PLUGIN_NAME " plugin: virDomainGetJobStats failed: %d", ret); - virErrorPtr err = virConnGetLastError(conn); + virErrorPtr err = virGetLastError(); // VIR_ERR_INVALID_ARG returned when VIR_DOMAIN_JOB_STATS_COMPLETED flag is // not supported by driver if (err->code == VIR_ERR_NO_SUPPORT || err->code == VIR_ERR_INVALID_ARG) { @@ -2203,6 +2204,9 @@ static int domain_lifecycle_event_cb(__attribute__((unused)) virConnectPtr con_, return 0; } +static void virt_eventloop_timeout_cb(int timer ATTRIBUTE_UNUSED, + void *timer_info) {} + static int register_event_impl(void) { if (virEventRegisterDefaultImpl() < 0) { virErrorPtr err = virGetLastError(); @@ -2212,6 +2216,14 @@ static int register_event_impl(void) { return -1; } + if (virEventAddTimeout(CDTIME_T_TO_MS(plugin_get_interval()), + virt_eventloop_timeout_cb, NULL, NULL) < 0) { + virErrorPtr err = virGetLastError(); + ERROR(PLUGIN_NAME " plugin: virEventAddTimeout failed: %s", + err && err->message ? err->message : "Unknown error"); + return -1; + } + return 0; } @@ -2407,6 +2419,21 @@ static int lv_read(user_data_t *ud) { return 0; } + int ret = virConnectIsAlive(conn); + if (ret == 0) { /* Connection lost */ + if (inst->id == 0) { + c_complain(LOG_ERR, &conn_complain, + PLUGIN_NAME " plugin: Lost connection."); + + if (!persistent_notification) + stop_event_loop(¬if_thread); + + lv_disconnect(); + last_refresh = 0; + } + return -1; + } + time_t t; time(&t);