Skip to content

Commit

Permalink
Make LDMSD support interval strings
Browse files Browse the repository at this point in the history
The patch makes LDMSD support time-interval strings. A time-interval
string is an integer followed by a unit string. A unit string is one of
the followings:
  us -- microseconds
  ms -- milliseconds
  s  -- seconds
  min -- minutes
  hr  -- hours
  day -- days

For example, with this patch, to specify a sampling interval of 1 second, '1s' can be
used.
  • Loading branch information
nichamon committed Jul 24, 2023
1 parent 841f538 commit 0a10da5
Show file tree
Hide file tree
Showing 9 changed files with 311 additions and 106 deletions.
69 changes: 59 additions & 10 deletions ldms/man/ldmsctl.man
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,20 @@ The plugin name.
.TP
.BI interval " interval"
.br
The sample interval in microseconds.
The sample interval, which is an integer, followed by a unit string.
If no unit string is given, the default unit is microseconds.
A unit string is one of the followings:
us -- microseconds
ms -- milliseconds
s -- seconds
min -- minutes
hr -- hours
day -- days
.TP
.BI [offset " offset"]
.br
Offset (shift) from the sample mark in microseconds.
Offset (shift) from the sample mark. The value is an integer,
followed by a unit string.
Offset can be positive or negative with magnitude up to 1/2
the sample interval. If this offset is specified, including 0,
collection will be synchronous; if the offset is not specified,
Expand Down Expand Up @@ -214,7 +223,15 @@ The connection type [active, passive]
.TP
.BI reconnect " interval"
.br
The connection retry interval
The connection retry interval, which is an integer, followed by a unit string.
If no unit string is given, the default unit is microseconds.
A unit string is one of the followings:
us -- microseconds
ms -- milliseconds
s -- seconds
min -- minutes
hr -- hours
day -- days
.TP
.BI interval " interval"
.br
Expand Down Expand Up @@ -248,8 +265,16 @@ The producer name
.TP
.BI [interval " interval"]
.br
The connection retry interval in microsec. If unspecified,
the previously configured value will be used. Optional.
The connection retry interval, which is an integer followed by a unit string.
If no unit string is given, the default unit is microseconds.
A unit string is one of the followings:
us -- microseconds
ms -- milliseconds
s -- seconds
min -- minutes
hr -- hours
day -- days
If unspecified, the previously configured value will be used. Optional.
.RE

.SS Start all producers matching a regular expression
Expand All @@ -263,8 +288,16 @@ A regular expression
.TP
.BI [interval " interval"]
.br
The connection retry interval in microsec. If unspecified,
the previously configured value will be used. Optional.
The connection retry interval, which is an integer followed by a unit string.
If no unit string is given, the default unit is microseconds.
A unit string is one of the followings:
us -- microseconds
ms -- milliseconds
s -- seconds
min -- minutes
hr -- hours
day -- days
If unspecified, the previously configured value will be used. Optional.
.RE

.SS Stop a producer
Expand Down Expand Up @@ -325,7 +358,15 @@ any attributes specified for the metric sets or hosts.
.TP
.BI interval " interval"
.br
The update/collect interval
The update/collect interval, which is an integer, followed by a unit string.
If no unit string is given, the default unit is microseconds.
A unit string is one of the followings:
us -- microseconds
ms -- milliseconds
s -- seconds
min -- minutes
hr -- hours
day -- days
.TP
.BI [offset " offset"]
.br
Expand Down Expand Up @@ -442,8 +483,16 @@ The update policy name
.TP
.BI [interval " interval"]
.br
The update interval in micro-seconds. If this is not
specified, the previously configured value will be used. Optional.
The update interval, which is an integer followed by a unit string.
If no unit string is given, the default unit is microseconds.
A unit string is one of the followings:
us -- microseconds
ms -- milliseconds
s -- seconds
min -- minutes
hr -- hours
day -- days
If this is not specified, the previously configured value will be used. Optional.
.TP
.BI [offset " offset"]
.br
Expand Down
73 changes: 60 additions & 13 deletions ldms/man/ldmsd_controller.man
Original file line number Diff line number Diff line change
Expand Up @@ -166,15 +166,22 @@ The plugin name.
.TP
.BI interval " interval"
.br
The sample interval in microseconds.
The sample interval, which is an integer followed by a unit string.
If no unit string is given, the default unit is microseconds.
A unit string is one of the followings:
us -- microseconds
ms -- milliseconds
s -- seconds
min -- minutes
hr -- hours
day -- days
.TP
.BI [offset " offset"]
.br
Offset (shift) from the sample mark in microseconds.
Offset (shift) from the sample mark in the same format as intervals.
Offset can be positive or negative with magnitude up to 1/2
the sample interval. If this offset is specified, including 0,
collection will be synchronous; if the offset is not specified,
collection will be asynchronous. Optional.
the sample interval. The default offset is 0. Collection is always synchronous.

.RE


Expand Down Expand Up @@ -269,7 +276,15 @@ The connection type [active, passive]
.TP
.BI reconnect " interval"
.br
The connection retry interval
The connection retry interval, which is an integer, followed by a unit string.
If no unit string is given, the default unit is microseconds.
A unit string is one of the followings:
us -- microseconds
ms -- milliseconds
s -- seconds
min -- minutes
hr -- hours
day -- days
.TP
.BI interval " interval"
.br
Expand Down Expand Up @@ -321,8 +336,16 @@ The producer name
.TP
.BI [interval " interval"]
.br
The connection retry interval in microsec. If unspecified,
the previously configured value will be used. Optional.
The connection retry interval, which is an integer followed by a unit string.
If no unit string is given, the default unit is microseconds.
A unit string is one of the followings:
us -- microseconds
ms -- milliseconds
s -- seconds
min -- minutes
hr -- hours
day -- days
If unspecified, the previously configured value will be used. Optional.
.RE

.SS Start all producers matching a regular expression
Expand All @@ -336,8 +359,16 @@ A regular expression
.TP
.BI [interval " interval"]
.br
The connection retry interval in microsec. If unspecified,
the previously configured value will be used. Optional.
The connection retry interval, which is an integer followed by a unit stirng.
If no unit string is given, the default unit is microseconds.
A unit string is one of the followings:
us -- microseconds
ms -- milliseconds
s -- seconds
min -- minutes
hr -- hours
day -- days
If unspecified, the previously configured value will be used. Optional.
.RE

.SS Stop a producer
Expand Down Expand Up @@ -397,7 +428,15 @@ any attributes specified for the metric sets or hosts.
.TP
.BI interval " interval"
.br
The update/collect interval
The update/collect interval, which is an integer, followed by a unit string.
If no unit string is given, the default unit is microseconds.
A unit string is one of the followings:
us -- microseconds
ms -- milliseconds
s -- seconds
min -- minutes
hr -- hours
day -- days
.TP
.BI [offset " offset"]
.br
Expand Down Expand Up @@ -514,8 +553,16 @@ The update policy name
.TP
.BI [interval " interval"]
.br
The update interval in micro-seconds. If this is not
specified, the previously configured value will be used. Optional.
The update interval, which is an integer followed by a unit string.
If no unit string is given, the default unit is microseconds.
A unit string is one of the followings:
us -- microseconds
ms -- milliseconds
s -- seconds
min -- minutes
hr -- hours
day -- days
If this is not specified, the previously configured value will be used. Optional.
.TP
.BI [offset " offset"]
.br
Expand Down
14 changes: 0 additions & 14 deletions ldms/python/ldmsd/ldmsd_communicator.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,17 +204,6 @@
'auth_add': {'req_attr': ['name', 'plugin'], 'opt_attr': []},
}

def check_offset(interval_us, offset_us=None):
"""
Ensure that offset provided is valid for ldmsd with given interval
"""
if offset_us:
interval_us = int(interval_us)
offset_us = int(offset_us)
if offset_us/interval_us > .5:
offset_us = interval_us/2
return offset_us

def fmt_status(msg):
"""
Format communicator status response string into json object
Expand Down Expand Up @@ -2027,7 +2016,6 @@ def plugn_start(self, name, interval_us, offset_us=None):
LDMSD_Req_Attr(attr_id=LDMSD_Req_Attr.INTERVAL, value=str(interval_us))
]
if offset_us != None:
offset_us = check_offset(interval_us, offset_us)
req_attrs.append(LDMSD_Req_Attr(attr_id=LDMSD_Req_Attr.OFFSET, value=str(offset_us)))
req = LDMSD_Request(
command_id = LDMSD_Request.PLUGN_START,
Expand Down Expand Up @@ -2406,7 +2394,6 @@ def updtr_add(self, name, interval=1000000, offset=None, push=None, auto=None, p
attrs += [
LDMSD_Req_Attr(attr_id=LDMSD_Req_Attr.INTERVAL, value=str(interval))
]
offset = check_offset(interval, offset)
if offset:
attrs += [
LDMSD_Req_Attr(attr_id=LDMSD_Req_Attr.OFFSET, value=str(offset))
Expand Down Expand Up @@ -2510,7 +2497,6 @@ def updtr_start(self, name, interval=None, offset=None, auto_interval=None):
LDMSD_Req_Attr(attr_id=LDMSD_Req_Attr.NAME, value=name),
]
if interval:
offset = check_offset(interval, offset)
if auto_interval:
return errno.EINVAL, "'auto' is incompatible with 'interval'"
attrs += [
Expand Down
33 changes: 16 additions & 17 deletions ldms/src/ldmsd/ldmsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1075,20 +1075,13 @@ void ldmsd_set_info_delete(ldmsd_set_info_t info)
free(info);
}

int __sampler_set_info_add(struct ldmsd_plugin *pi, char *interval, char *offset)
int __sampler_set_info_add(struct ldmsd_plugin *pi, long interval_us, long offset_us)
{
ldmsd_plugin_set_t set;
int rc;
long interval_us;
long offset_us = 0;

if (pi->type != LDMSD_PLUGIN_SAMPLER)
return EINVAL;
if (!interval)
return EINVAL;
interval_us = strtol(interval, NULL, 0);
if (offset)
offset_us = strtol(offset, NULL, 0);
for (set = ldmsd_plugin_set_first(pi->name); set;
set = ldmsd_plugin_set_next(set)) {
rc = ldmsd_set_update_hint_set(set->set, interval_us, offset_us);
Expand All @@ -1107,15 +1100,14 @@ int __sampler_set_info_add(struct ldmsd_plugin *pi, char *interval, char *offset
*/
int ldmsd_start_sampler(char *plugin_name, char *interval, char *offset)
{
char *endptr;
int rc = 0;
long sample_interval;
long sample_offset = 0;
struct ldmsd_plugin_cfg *pi;

sample_interval = strtol(interval, &endptr, 0);
if ((endptr[0] != '\0') || (sample_interval <= 0))
return EINVAL;
rc = ovis_time_str2us(interval, &sample_interval);
if (rc)
return rc;

pi = ldmsd_get_plugin((char *)plugin_name);
if (!pi)
Expand All @@ -1131,19 +1123,26 @@ int ldmsd_start_sampler(char *plugin_name, char *interval, char *offset)
goto out;
}

rc = __sampler_set_info_add(pi->plugin, interval, offset);
if (rc)
goto out;
pi->sample_interval_us = sample_interval;
if (offset) {
sample_offset = strtol(offset, NULL, 0);
rc = ovis_time_str2us(offset, &sample_offset);
if (rc) {
rc = EDOM;
goto out;
}
if ( !((sample_interval >= 10) &&
(sample_interval >= labs(sample_offset)*2)) ){
rc = EDOM;
rc = -EDOM;
goto out;
}
}
pi->sample_offset_us = sample_offset;

rc = __sampler_set_info_add(pi->plugin, sample_interval,
sample_offset);
if (rc)
goto out;

OVIS_EVENT_INIT(&pi->oev);
pi->oev.param.type = OVIS_EVENT_PERIODIC;
pi->oev.param.periodic.period_us = sample_interval;
Expand Down
Loading

0 comments on commit 0a10da5

Please sign in to comment.