From: Florian Forster Date: Tue, 16 Nov 2010 08:20:04 +0000 (+0100) Subject: network plugin: Introduce new types for the "high resolution" time fields. X-Git-Tag: collectd-5.0.0-beta0~19^2 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=e94e1ca83a8ac255f045259ec898f944f9118430;p=collectd.git network plugin: Introduce new types for the "high resolution" time fields. --- diff --git a/src/network.c b/src/network.c index 43193cfc..eb32ad15 100644 --- a/src/network.c +++ b/src/network.c @@ -1378,7 +1378,18 @@ static int parse_packet (sockent_t *se, /* {{{ */ if (status == 0) { vl.time = TIME_T_TO_CDTIME_T (tmp); - n.time = TIME_T_TO_CDTIME_T (tmp); + n.time = TIME_T_TO_CDTIME_T (tmp); + } + } + else if (pkg_type == TYPE_TIME_HR) + { + uint64_t tmp = 0; + status = parse_part_number (&buffer, &buffer_size, + &tmp); + if (status == 0) + { + vl.time = (cdtime_t) tmp; + n.time = (cdtime_t) tmp; } } else if (pkg_type == TYPE_INTERVAL) @@ -1389,6 +1400,14 @@ static int parse_packet (sockent_t *se, /* {{{ */ if (status == 0) vl.interval = TIME_T_TO_CDTIME_T (tmp); } + else if (pkg_type == TYPE_INTERVAL_HR) + { + uint64_t tmp = 0; + status = parse_part_number (&buffer, &buffer_size, + &tmp); + if (status == 0) + vl.interval = (cdtime_t) tmp; + } else if (pkg_type == TYPE_HOST) { status = parse_part_string (&buffer, &buffer_size, @@ -2583,18 +2602,16 @@ static int add_to_buffer (char *buffer, int buffer_size, /* {{{ */ if (vl_def->time != vl->time) { - time_t tmp = CDTIME_T_TO_TIME_T (vl->time); - if (write_part_number (&buffer, &buffer_size, TYPE_TIME, - (uint64_t) tmp)) + if (write_part_number (&buffer, &buffer_size, TYPE_TIME_HR, + (uint64_t) vl->time)) return (-1); vl_def->time = vl->time; } if (vl_def->interval != vl->interval) { - /* TODO: Create a new type for sub-second intervals. */ - if (write_part_number (&buffer, &buffer_size, TYPE_INTERVAL, - (uint64_t) CDTIME_T_TO_TIME_T (vl->interval))) + if (write_part_number (&buffer, &buffer_size, TYPE_INTERVAL_HR, + (uint64_t) vl->interval)) return (-1); vl_def->interval = vl->interval; } @@ -3072,14 +3089,11 @@ static int network_notification (const notification_t *n, char *buffer_ptr = buffer; int buffer_free = sizeof (buffer); int status; - time_t tmp; memset (buffer, '\0', sizeof (buffer)); - - tmp = CDTIME_T_TO_TIME_T (n->time); - status = write_part_number (&buffer_ptr, &buffer_free, TYPE_TIME, - (uint64_t) tmp); + status = write_part_number (&buffer_ptr, &buffer_free, TYPE_TIME_HR, + (uint64_t) n->time); if (status != 0) return (-1); diff --git a/src/network.h b/src/network.h index 777616c4..1b354561 100644 --- a/src/network.h +++ b/src/network.h @@ -56,12 +56,14 @@ #define TYPE_HOST 0x0000 #define TYPE_TIME 0x0001 +#define TYPE_TIME_HR 0x0008 #define TYPE_PLUGIN 0x0002 #define TYPE_PLUGIN_INSTANCE 0x0003 #define TYPE_TYPE 0x0004 #define TYPE_TYPE_INSTANCE 0x0005 #define TYPE_VALUES 0x0006 #define TYPE_INTERVAL 0x0007 +#define TYPE_INTERVAL_HR 0x0009 /* Types to transmit notifications */ #define TYPE_MESSAGE 0x0100