# exclude entities that have no required tags
entities = [entity for entity in entities_list if entity.tags]

entities_service = EntitiesService(connection)

# prepare property query
ef = EntityFilter('entity')
df = DateFilter(start_date="1970-01-01T00:00:00Z", end_date=datetime.now())
property_query = PropertiesQuery(entity_filter=ef,
                                 date_filter=df,
                                 type=property_type)

print('entity_name,entity_label,tags')
for entity in entities:
    pretty_tags = print_tags(entity.tags)
    for key in entity.tags:
        entity.tags[key] = ''

    # set actual entity and execute property query
    property_query.set_entity_filter(EntityFilter(entity.name))
    properties_list = properties_service.query(property_query)
    # set entity tags from property tags
    if properties_list:
        property_tags = properties_list[0].tags
        for key, value in six.iteritems(property_tags):
            entity.tags['env.%s' % key] = value

    print('%s,%s,%s' % (entity.name, print_str(entity.label), pretty_tags))
    # Uncomment next line to delete tags
    # entities_service.update(entity)
from atsd_client import connect_url
from atsd_client.services import EntitiesService
from atsd_client.utils import print_str

'''
Locate a collection of entities that have no last_insert_date.
'''

# Connect to an ATSD server
connection = connect_url('https://atsd_hostname:8443', 'user', 'password')

entities_service = EntitiesService(connection)
# query entities without last_insert_date
entity_list = entities_service.list(max_insert_date="1970-01-01T00:00:00.000Z")

print('entity_name,entity_label')
for entity in entity_list:
    print('%s,%s' % (entity.name, print_str(entity.label)))

print("\nEntities count without last insert date is %d." % (len(entity_list)))
entities_service = EntitiesService(connection)
metrics_service = MetricsService(connection)

# query required metric meta data
metric = metrics_service.get(metric_name)
if metric is None:
    print('No metric with name %s' % metric_name)
    sys.exit()
elif metric.last_insert_date is None:
    print('No data for metric name %s' % metric_name)
    sys.exit()

# calculate the upper boundary for the allowed last_insert_date values excluding grace interval
max_insert_date = metric.last_insert_date - timedelta(seconds=grace_interval_hours * 3600)

# query series list for the metric
series_list = metrics_service.series(metric, min_insert_date=min_insert_date, max_insert_date=max_insert_date)

# make dictionary from entity and last_insert_date, store maximum value of last_insert_date
various_entities = dict()
for series in series_list:
    last_insert_date = various_entities.get(series.entity)
    if last_insert_date is None or last_insert_date < series.last_insert_date:
        various_entities[series.entity] = series.last_insert_date

print('entity_name,entity_label,last_insert_date')
for entity in various_entities:
    label = entities_service.get(entity).label
    last_insert_date = various_entities[entity]
    print('%s,%s,%s' % (entity, print_str(label), last_insert_date))
Exemplo n.º 4
0
# query required metric meta data
metric = metrics_service.get(metric_name)
if metric is None:
    print('No metric with name %s' % metric_name)
    sys.exit()
elif metric.last_insert_date is None:
    print('No data for metric name %s' % metric_name)
    sys.exit()

# calculate the upper boundary for the allowed last_insert_date values excluding grace interval
max_insert_date = metric.last_insert_date - timedelta(
    seconds=grace_interval_hours * 3600)

# query series list for the metric
series_list = metrics_service.series(metric,
                                     min_insert_date=min_insert_date,
                                     max_insert_date=max_insert_date)

# make dictionary from entity and last_insert_date, store maximum value of last_insert_date
various_entities = dict()
for series in series_list:
    last_insert_date = various_entities.get(series.entity)
    if last_insert_date is None or last_insert_date < series.last_insert_date:
        various_entities[series.entity] = series.last_insert_date

print('entity_name,entity_label,last_insert_date')
for entity in various_entities:
    label = entities_service.get(entity).label
    last_insert_date = various_entities[entity]
    print('%s,%s,%s' % (entity, print_str(label), last_insert_date))
from atsd_client.utils import print_tags, print_str

'''
Delete entity tags with names starting with the specified prefix from entities that belongs specific entity group.
'''

# Connect to ATSD server
#connection = connect('/path/to/connection.properties')
connection = connect_url('https://atsd_hostname:8443', 'username', 'password')

# Initialize services

# set the name of entity_group and prefix for tag key
entity_group_name = 'docker-images'
tag_expression = 'env.*'

eg_service = EntityGroupsService(connection)
entities_service = EntitiesService(connection)
entities_list = eg_service.get_entities(entity_group_name, tags=tag_expression)
# exclude entities that have no required tags
entities = [entity for entity in entities_list if entity.tags]

print('entity_name,entity_label,tags')
for entity in entities:
    pretty_tags = print_tags(entity.tags)
    for key in entity.tags:
        entity.tags[key] = ''
    print('%s,%s,%s' % (entity.name, print_str(entity.label), pretty_tags))
    # Uncomment next line to delete tags
    # entities_service.update(entity)
Exemplo n.º 6
0
Delete specific entity tags by name from entities that match an expression.
'''

# Connect to ATSD server
#connection = connect('/path/to/connection.properties')
connection = connect_url('https://atsd_hostname:8443', 'username', 'password')

# Initialize services
entities_service = EntitiesService(connection)

# set an expression to query entities with non-empty 'category' and 'subcategory' tags
expression = "tags.category != '' AND tags.subcategory != ''"
# list the tags to be deleted
tags_to_delete = ['original_price', 'last_price', 'last_average_price', 'last_amount']

entities_list = entities_service.list(expression=expression, tags=tags_to_delete)

print('entity_name,entity_label')
for entity in entities_list:
    need_update = False
    actual_tags = entity.tags
    for key in tags_to_delete:
        if key in actual_tags:
            actual_tags[key] = ''
            # mark entity to be updated
            need_update = True
    if need_update:
        print('%s,%s' % (entity.name, print_str(entity.label)))
        # Uncomment next line to delete tags
        # entities_service.update(entity)