def get_schema(self, get_stats=False): connection = atsd_client.connect_url( self.url, self.configuration.get("username"), self.configuration.get("password"), verify=self.configuration.get("trust_certificate", False), timeout=self.configuration.get("timeout", 600), ) metrics = MetricsService(connection) ml = metrics.list( expression=self.configuration.get("expression", None), minInsertDate=self.configuration.get("min_insert_date", None), limit=self.configuration.get("limit", 5000), ) metrics_list = [i.name.encode("utf-8") for i in ml] metrics_list.append("atsd_series") schema = {} default_columns = [ "entity", "datetime", "time", "metric", "value", "text", "tags", "entity.tags", "metric.tags", ] for table_name in metrics_list: schema[table_name] = { "name": "'{}'".format(table_name), "columns": default_columns, } values = list(schema.values()) return values
def get_schema(self, get_stats=False): connection = atsd_client.connect_url( self.url, self.configuration.get('username'), self.configuration.get('password'), verify=self.configuration.get('trust_certificate', False), timeout=self.configuration.get('timeout', 600)) metrics = MetricsService(connection) ml = metrics.list( expression=self.configuration.get('expression', None), minInsertDate=self.configuration.get('min_insert_date', None), limit=self.configuration.get('limit', 5000)) metrics_list = [i.name.encode('utf-8') for i in ml] metrics_list.append('atsd_series') schema = {} default_columns = [ 'entity', 'datetime', 'time', 'metric', 'value', 'text', 'tags', 'entity.tags', 'metric.tags' ] for table_name in metrics_list: schema[table_name] = { 'name': "'{}'".format(table_name), 'columns': default_columns } values = schema.values() return values
def get_schema(self, get_stats=False): connection = atsd_client.connect_url(self.url, self.configuration.get('username'), self.configuration.get('password'), verify=self.configuration.get('trust_certificate', False), timeout=self.configuration.get('timeout', 600)) metrics = MetricsService(connection) ml = metrics.list(expression=self.configuration.get('expression', None), minInsertDate=self.configuration.get('min_insert_date', None), limit=self.configuration.get('limit', 5000)) metrics_list = [i.name.encode('utf-8') for i in ml] metrics_list.append('atsd_series') schema = {} default_columns = ['entity', 'datetime', 'time', 'metric', 'value', 'text', 'tags', 'entity.tags', 'metric.tags'] for table_name in metrics_list: schema[table_name] = {'name': "'{}'".format(table_name), 'columns': default_columns} values = schema.values() return values
from atsd_client import connect, connect_url from atsd_client.services import MetricsService ''' Locate a collection of metrics that have been created after specified date. ''' # Connect to ATSD server #connection = connect('/path/to/connection.properties') connection = connect_url('https://atsd_hostname:8443', 'username', 'password') # Initialize services metrics_service = MetricsService(connection) # query all metrics created after specified_date metric_list = metrics_service.list(expression="createdDate > '2018-05-16T00:00:00Z'") print('metric_name') for metric in metric_list: print(metric.name)
from atsd_client.services import MetricsService, SeriesService ''' Find series with data older than `now - (metric.retention_days + grace_interval_days)`. ''' # Connect to ATSD server #connection = connect('/path/to/connection.properties') connection = connect_url('https://atsd_hostname:8443', 'username', 'password') # Initialize services svc = SeriesService(connection) metric_service = MetricsService(connection) metric_expression = "enabled AND persistent AND retentionDays > 0" metric_list = metric_service.list(expression=metric_expression) series_count = 0 # ATSD expired data removal schedule frequency, default is one day grace_interval_days = 1 t = PrettyTable(['Metric', 'Entity', 'Tags', 'Retention Days', 'Threshold', 'Presented Sample Date']) for metric in metric_list: # calculate datetime before which there is data threshold = datetime.now() - timedelta(days=metric.retention_days + grace_interval_days) # query series with current metric and all entities from the beginning up to threshold # enough to get at least one value, limit set to 1 sf = SeriesFilter(metric=metric.name) ef = EntityFilter(entity='*') df = DateFilter(start_date="1970-01-01T00:00:00Z", end_date=threshold) cf = ControlFilter(limit=1)
from atsd_client import connect_url from atsd_client.services import MetricsService ''' Locate a collection of metrics that have no last_insert_date. ''' # Connect to an ATSD server connection = connect_url('https://atsd_hostname:8443', 'user', 'password') metric_service = MetricsService(connection) # query entities without last_insert_date metric_list = metric_service.list(max_insert_date="1970-01-01T00:00:00.000Z") metrics_count = 0 print('metric_name') for metric in metric_list: if metric.enabled and metric.persistent \ and metric.retention_days == 0 and metric.series_retention_days == 0: metrics_count += 1 print(metric.name) print("\nMetrics count without last insert date is %d." % metrics_count)
from atsd_client import connect, connect_url from atsd_client.services import MetricsService ''' Locate a collection of metrics that have no last_insert_date. ''' # Connect to ATSD server #connection = connect('/path/to/connection.properties') connection = connect_url('https://atsd_hostname:8443', 'username', 'password') # Initialize services metric_service = MetricsService(connection) # query entities without last_insert_date metric_list = metric_service.list(max_insert_date="1970-01-01T00:00:00.000Z") metrics_count = 0 print('metric_name') for metric in metric_list: if metric.enabled and metric.persistent \ and metric.retention_days == 0 and metric.series_retention_days == 0: metrics_count += 1 print(metric.name) print("\nMetrics count without last insert date is %d." % metrics_count)
from atsd_client import connect_url from atsd_client.models import SeriesFilter, EntityFilter, DateFilter, SeriesQuery from atsd_client.services import MetricsService, SeriesService ''' Retrieve metrics with 'frequency' tag. Load series for this metric. Print values that violate frequency (but not data gaps if the gap is a multiple of the frequency period). ''' # Connect to an ATSD server connection = connect_url('https://atsd_hostname:8443', 'user', 'password') svc = SeriesService(connection) metric_service = MetricsService(connection) # query metrics with not empty frequency tag, include all metric tags to response metric_list = metric_service.list(expression='tags.frequency != ""', tags='*') def resolve_frequency(frequency): """ Transform metric frequency tag into relativedelta instance """ if frequency in ['Daily (D)', 'Daily', 'Daily, 7-Day', 'Daily, Close']: return relativedelta(days=1) elif frequency in [ 'Weekly', 'Weekly, As of Monday', 'Weekly, As of Wednesday', 'Weekly, As of Thursday', 'Weekly, Ending Monday',
from atsd_client.services import MetricsService from atsd_client.utils import print_tags ''' Locate high-cardinality series that have tags more than specified cardinality. ''' # Connect to ATSD server #connection = connect('/path/to/connection.properties') connection = connect_url('https://atsd_hostname:8443', 'username', 'password') # Initialize services metrics_service = MetricsService(connection) # query all metrics that have last_insert_date, i.e. series metrics = metrics_service.list(min_insert_date="1970-01-01T00:00:00.000Z") # set cardinality cardinality = 8 series_count = 0 print('metric,entity,tags,last_insert_date') for metric in metrics: # query series list for each metric series_list = metrics_service.series(metric) for s in series_list: # check tags cardinality for each series in list if len(s.tags) > cardinality: series_count += 1 print("%s,%s,%s,%s" % (s.metric, s.entity, print_tags(s.tags), s.last_insert_date))
from atsd_client.services import MetricsService, SeriesService ''' Retrieve metrics with 'frequency' tag. Load series for this metric. Print values that violate frequency (but not data gaps if the gap is a multiple of the frequency period). ''' # Connect to ATSD server #connection = connect('/path/to/connection.properties') connection = connect_url('https://atsd_hostname:8443', 'username', 'password') # Initialize services svc = SeriesService(connection) metric_service = MetricsService(connection) # query metrics with not empty frequency tag, include all metric tags to response metric_list = metric_service.list(expression='tags.frequency != ""', tags='*') def resolve_frequency(frequency): """ Transform metric frequency tag into relativedelta instance """ if frequency in ['Daily (D)', 'Daily', 'Daily, 7-Day', 'Daily, Close']: return relativedelta(days=1) elif frequency in ['Weekly', 'Weekly, As of Monday', 'Weekly, As of Wednesday', 'Weekly, As of Thursday', 'Weekly, Ending Monday', 'Weekly, Ending Wednesday', 'Weekly, Ending Thursday', 'Weekly, Ending Friday', 'Weekly, Ending Saturday', ]: return relativedelta(weeks=1) elif frequency in ['Biweekly, Beg. of Period', 'Biweekly, Ending Wednesday']: return relativedelta(weeks=2)