zabgrab.services.dataset¶
The merged view of a file’s fetch groups.
Groups only exist because of how appending works, so reading operations see one dataset: each item’s data joined across groups, sorted by time, with duplicate timestamps resolved in favour of the later group.
Module Attributes
Gaps between fetched ranges up to this long (seconds) still count as covered, since each update starts just after the previous fetch's end. |
Functions
|
Limit a dataset to some items and a time range. |
|
Check whether a series' item ID, name, key or |
|
Merge fetch groups into one dataset. |
|
Find the existing groups that already hold some of a new fetch's data. |
|
Count the points each dataset shares with any of the others. |
|
Select the series that any item spec or pattern matches. |
|
Pick groups by name. |
|
Check whether an item spec selects a series' item, as the Zabbix API would. |
Classes
|
Every series in a file (or selection of its groups), merged. |
|
A fetch group read from a file. |
|
A fetch group's metadata and range, without its data. |
|
Part of a new fetch's range that an existing group already covers. |
- zabgrab.services.dataset.COVERAGE_TOLERANCE = 1.0¶
Gaps between fetched ranges up to this long (seconds) still count as covered, since each update starts just after the previous fetch’s end.
- class zabgrab.services.dataset.Group(*args, **kwargs)[source]¶
Bases:
ProtocolA fetch group read from a file.
See
zabgrab.adapters.formats.hdf5.FetchGroup, which this describes without the services depending on the adapter.
- class zabgrab.services.dataset.Dataset(series, coverage, groups, last_metadata=<factory>)[source]¶
Bases:
objectEvery series in a file (or selection of its groups), merged.
- Parameters:
- zabgrab.services.dataset.merge(groups, ui)[source]¶
Merge fetch groups into one dataset.
Series are matched by server, item, resolution and columns. Each is joined across groups and sorted by time; points with the same time keep the later group’s value. The item’s details come from the latest group.
- Parameters:
- Returns:
Dataset – The merged data.
- Raises:
ZabgrabError – If there are no groups.
- Return type:
- zabgrab.services.dataset.repeated_points(datasets)[source]¶
Count the points each dataset shares with any of the others.
A point is shared if another dataset has the same series (item, resolution and columns) with a point at the same time. Use it with each group read on its own, to see how much of a file is held twice.
- class zabgrab.services.dataset.Overlap(group, start, end, items)[source]¶
Bases:
objectPart of a new fetch’s range that an existing group already covers.
- start, end
The time range covered by both, in POSIX seconds.
- Type:
- class zabgrab.services.dataset.GroupRange(*args, **kwargs)[source]¶
Bases:
ProtocolA fetch group’s metadata and range, without its data.
- zabgrab.services.dataset.overlaps(groups, series, t_from, t_to)[source]¶
Find the existing groups that already hold some of a new fetch’s data.
A group overlaps if it holds any of the same items at the same resolution, and its range and the new fetch’s overlap for longer than an instant (an update starting where the last fetch ended doesn’t count).
- Parameters:
groups (sequence of GroupRange) – The file’s existing groups.
series (sequence of Series) – The newly fetched series.
t_from (float) – The new fetch’s range, in POSIX seconds.
t_to (float) – The new fetch’s range, in POSIX seconds.
- Returns:
list of Overlap – The overlapping groups, in the order they were written.
- Return type:
- zabgrab.services.dataset.select_groups(groups, names)[source]¶
Pick groups by name.
- Parameters:
- Returns:
list of Group – The groups, in the order named.
- Raises:
ZabgrabError – If a name doesn’t match a group.
- Return type:
- zabgrab.services.dataset.filter_dataset(dataset, *, items=(), patterns=(), start=None, end=None)[source]¶
Limit a dataset to some items and a time range.
- Parameters:
dataset (Dataset) – The data.
items (sequence of ItemSpec, optional) – Item specs (
--item; seespec_matches()).patterns (sequence of str, optional) – Glob patterns (
--match; seematches()). A series is kept if any item spec or pattern matches it, or if there are none of either.start (datetime, optional) – The time range to keep (unbounded if not given).
end (datetime, optional) – The time range to keep (unbounded if not given).
- Returns:
Dataset – The selected data, with its coverage cut to the time range.
- Return type:
- zabgrab.services.dataset.select(series, items, patterns)[source]¶
Select the series that any item spec or pattern matches.
- Parameters:
series (sequence of Series) – The series.
items (sequence of ItemSpec) – Item specs (see
spec_matches()).
- Returns:
list of Series – The matching series, in order; all of them if there are no specs or patterns.
- Return type:
- zabgrab.services.dataset.spec_matches(series, spec)[source]¶
Check whether an item spec selects a series’ item, as the Zabbix API would.
Patterns match like the API’s searches (
item.getandhost.getwithsearchWildcardsEnabled): the whole value, ignoring case, with*matching any text and every other character literal. The host matches its technical or visible name. A tag (nameorname:value) must be among the item’s stored tags exactly, as the API’s tag filters compare them. Every field given must match.- Parameters:
- Returns:
bool – Whether it matches.
- Return type:
Examples
>>> from zabgrab.model.config import Resolution, ServerConfig >>> from zabgrab.model.server import Server >>> from zabgrab.model.zabbix import Item, ValueType >>> item = Item(1, 1, "pc2", "Particle counter 2", "0.3 µm particles", "p[0.3]", ... ValueType.FLOAT) >>> one = Series(Server("lab", ServerConfig(url="https://z.example.org")), item, ... Resolution.RAW, {"time": []}) >>> spec_matches(one, ItemSpec(name="0.3*PARTICLES", host="*counter*")) True >>> spec_matches(one, ItemSpec(name="0.3")) False