Groups#
Groups for the Google Stackdriver Monitoring API (V3).
-
class
google.cloud.monitoring.group.
Group
(client, group_id=None, display_name=None, parent_id=None, filter_string=None, is_cluster=False)[source]# Bases:
object
A dynamic collection of monitored resources.
Parameters: - client (
google.cloud.monitoring.client.Client
) – A client for operating on the metric descriptor. - group_id (string or None) – The ID of the group.
- display_name (string or None) – A user-assigned name for this group, used only for display purposes.
- parent_id (string or None) – The ID of the group’s parent, if it has one.
- filter_string (string or None) – The filter string used to determine which monitored resources belong to this group.
- is_cluster (boolean) – If true, the members of this group are considered to be a cluster. The system can perform additional analysis on groups that are clusters.
-
create
()[source]# Create a new group based on this object via a
POST
request.Example:
>>> filter_string = 'resource.type = "gce_instance"' >>> group = client.group( ... display_name='My group', ... filter_string=filter_string, ... parent_id='5678', ... is_cluster=True) >>> group.create()
The
name
attribute is ignored in preparing the creation request. All attributes are overwritten by the values received in the response (normally affecting onlyname
).
-
delete
()[source]# Delete the group via a
DELETE
request.Example:
>>> group = client.group('1234') >>> group.delete()
Only the
client
andname
attributes are used.Warning
This method will fail for groups that have one or more children groups.
-
exists
()[source]# Test for the existence of the group via a
GET
request.Return type: bool Returns: Boolean indicating existence of the group.
-
fetch_parent
()[source]# Returns the parent group of this group via a
GET
request.Return type: Group
or NoneReturns: The parent of the group.
-
id
# Returns the group ID.
Return type: str or None Returns: the ID of the group based on it’s name.
-
list_ancestors
()[source]# Lists all ancestors of this group via a
GET
request.The groups are returned in order, starting with the immediate parent and ending with the most distant ancestor. If the specified group has no immediate parent, the results are empty.
Return type: list of Group
Returns: A list of group instances.
-
list_children
()[source]# Lists all children of this group via a
GET
request.Returns groups whose parent_name field contains the group name. If no groups have this parent, the results are empty.
Return type: list of Group
Returns: A list of group instances.
-
list_descendants
()[source]# Lists all descendants of this group via a
GET
request.This returns a superset of the results returned by the
children()
method, and includes children-of-children, and so forth.Return type: list of Group
Returns: A list of group instances.
-
list_members
(filter_string=None, end_time=None, start_time=None)[source]# Lists all members of this group via a
GET
request.If no
end_time
is provided then the group membership over the last minute is returned.Example:
>>> for member in group.list_members(): ... print(member)
List members that are Compute Engine VM instances:
>>> filter_string = 'resource.type = "gce_instance"' >>> for member in group.list_members(filter_string=filter_string): ... print(member)
List historical members that existed between 4 and 5 hours ago:
>>> import datetime >>> t1 = datetime.datetime.utcnow() - datetime.timedelta(hours=4) >>> t0 = t1 - datetime.timedelta(hours=1) >>> for member in group.list_members(end_time=t1, start_time=t0): ... print(member)
Parameters: - filter_string (string or None) – An optional list filter describing the members to be returned. The filter may reference the type, labels, and metadata of monitored resources that comprise the group. See the filter documentation.
- end_time (
datetime.datetime
or None) – The end time (inclusive) of the time interval for which results should be returned, as a datetime object. Ifstart_time
is specified, then this must also be specified. - start_time (
datetime.datetime
or None) – The start time (exclusive) of the time interval for which results should be returned, as a datetime object.
Return type: list of
Resource
Returns: A list of resource instances.
Raises: ValueError
if thestart_time
is specified, but theend_time
is missing.
-
name
# Returns the fully qualified name of the group.
Return type: str or None Returns: The fully qualified name of the group in the format “projects/<project>/groups/<id>”.
-
parent_name
# Returns the fully qualified name of the parent group.
Return type: str or None Returns: The fully qualified name of the parent group.
-
path
# URL path to this group.
Return type: str Returns: the path based on project and group name. Raises: ValueError
ifname
is not specified.
- client (