def test_custom_metric():
    client = list_resources.get_client()
    # Use a constant seed so psuedo random number is known ahead of time
    random.seed(1)
    pseudo_random_value = random.randint(0, 10)
    # Reseed it
    random.seed(1)

    INSTANCE_ID = "test_instance"
    METRIC_KIND = "GAUGE"

    create_custom_metric(client, PROJECT_RESOURCE, METRIC_RESOURCE,
                         METRIC_KIND)
    custom_metric = None
    # wait until metric has been created, use the get call to wait until
    # a response comes back with the new metric
    while not custom_metric:
        time.sleep(1)
        custom_metric = get_custom_metric(client, PROJECT_RESOURCE,
                                          METRIC_RESOURCE)

    write_timeseries_value(client, PROJECT_RESOURCE, METRIC_RESOURCE,
                           INSTANCE_ID, METRIC_KIND)
    # Sometimes on new metric descriptors, writes have a delay in being
    # read back. 3 seconds should be enough to make sure our read call
    # picks up the write
    time.sleep(3)
    response = read_timeseries(client, PROJECT_RESOURCE, METRIC_RESOURCE)
    value = int(response['timeSeries'][0]['points'][0]['value']['int64Value'])
    # using seed of 1 will create a value of 1
    assert value == pseudo_random_value
def test_list_monitored_resources(capsys):
    client = list_resources.get_client()
    list_resources.list_monitored_resource_descriptors(client,
                                                       PROJECT_RESOURCE)
    stdout, _ = capsys.readouterr()
    regex = re.compile('An application running')
    assert regex.search(stdout) is not None
def test_list_timeseries(capsys):
    client = list_resources.get_client()
    list_resources.list_timeseries(
        client, PROJECT_RESOURCE, METRIC)
    stdout, _ = capsys.readouterr()
    regex = re.compile(u'list_timeseries response:\n')
    assert regex.search(stdout) is not None
def test_list_metrics(cloud_config, capsys):
    PROJECT_RESOURCE = "projects/{}".format(cloud_config.project)
    client = list_resources.get_client()
    list_resources.list_metric_descriptors(client, PROJECT_RESOURCE, METRIC)
    stdout, _ = capsys.readouterr()
    regex = re.compile(u"Delta CPU", re.I)
    assert regex.search(stdout) is not None
Ejemplo n.º 5
0
def main(project_id):
    # This is the namespace for all custom metrics
    CUSTOM_METRIC_DOMAIN = "custom.googleapis.com"
    # This is our specific metric name
    CUSTOM_METRIC_TYPE = "{}/custom_measurement".format(CUSTOM_METRIC_DOMAIN)
    INSTANCE_ID = "test_instance"
    METRIC_KIND = "GAUGE"

    project_resource = "projects/{0}".format(project_id)
    client = list_resources.get_client()
    create_custom_metric(client, project_resource,
                         CUSTOM_METRIC_TYPE, METRIC_KIND)
    custom_metric = None
    while not custom_metric:
        # wait until it's created
        time.sleep(1)
        custom_metric = get_custom_metric(
            client, project_resource, CUSTOM_METRIC_TYPE)

    write_timeseries_value(client, project_resource,
                           CUSTOM_METRIC_TYPE, INSTANCE_ID, METRIC_KIND)
    # Sometimes on new metric descriptors, writes have a delay in being read
    # back. 3 seconds should be enough to make sure our read call picks up the
    # write
    time.sleep(3)
    timeseries = read_timeseries(client, project_resource, CUSTOM_METRIC_TYPE)
    print('read_timeseries response:\n{}'.format(pprint.pformat(timeseries)))
Ejemplo n.º 6
0
def test_list_metrics(cloud_config, capsys):
    PROJECT_RESOURCE = "projects/{}".format(cloud_config.project)
    client = list_resources.get_client()
    list_resources.list_metric_descriptors(client, PROJECT_RESOURCE, METRIC)
    stdout, _ = capsys.readouterr()
    regex = re.compile(u'Delta CPU', re.I)
    assert regex.search(stdout) is not None
Ejemplo n.º 7
0
def test_list_timeseries(cloud_config, capsys):
    PROJECT_RESOURCE = "projects/{}".format(cloud_config.project)
    client = list_resources.get_client()
    list_resources.list_timeseries(client, PROJECT_RESOURCE, METRIC)
    stdout, _ = capsys.readouterr()
    regex = re.compile(u'list_timeseries response:\n', re.I)
    assert regex.search(stdout) is not None
Ejemplo n.º 8
0
def main(project_id):
    # This is the namespace for all custom metrics
    CUSTOM_METRIC_DOMAIN = "custom.googleapis.com"
    # This is our specific metric name
    CUSTOM_METRIC_TYPE = "{}/custom_measurement".format(CUSTOM_METRIC_DOMAIN)
    INSTANCE_ID = "test_instance"
    METRIC_KIND = "GAUGE"

    project_resource = "projects/{0}".format(project_id)
    client = list_resources.get_client()
    create_custom_metric(client, project_resource,
                         CUSTOM_METRIC_TYPE, METRIC_KIND)
    custom_metric = None
    while not custom_metric:
        # wait until it's created
        time.sleep(1)
        custom_metric = get_custom_metric(
            client, project_resource, CUSTOM_METRIC_TYPE)

    write_timeseries_value(client, project_resource,
                           CUSTOM_METRIC_TYPE, INSTANCE_ID, METRIC_KIND)
    # Sometimes on new metric descriptors, writes have a delay in being read
    # back. 3 seconds should be enough to make sure our read call picks up the
    # write
    time.sleep(3)
    timeseries = read_timeseries(client, project_resource, CUSTOM_METRIC_TYPE)
    print('read_timeseries response:\n{}'.format(pprint.pformat(timeseries)))
def test_custom_metric(cloud_config):
    PROJECT_RESOURCE = "projects/{}".format(cloud_config.project)
    client = list_resources.get_client()
    # Use a constant seed so psuedo random number is known ahead of time
    random.seed(1)
    pseudo_random_value = random.randint(0, 10)
    # Reseed it
    random.seed(1)

    INSTANCE_ID = "test_instance"
    METRIC_KIND = "GAUGE"

    create_custom_metric(
        client, PROJECT_RESOURCE, METRIC_RESOURCE, METRIC_KIND)
    custom_metric = None
    # wait until metric has been created, use the get call to wait until
    # a response comes back with the new metric
    while not custom_metric:
        time.sleep(1)
        custom_metric = get_custom_metric(
            client, PROJECT_RESOURCE, METRIC_RESOURCE)

    write_timeseries_value(client, PROJECT_RESOURCE,
                           METRIC_RESOURCE, INSTANCE_ID,
                           METRIC_KIND)
    # Sometimes on new metric descriptors, writes have a delay in being
    # read back. 3 seconds should be enough to make sure our read call
    # picks up the write
    time.sleep(3)
    response = read_timeseries(client, PROJECT_RESOURCE, METRIC_RESOURCE)
    value = int(
        response['timeSeries'][0]['points'][0]['value']['int64Value'])
    # using seed of 1 will create a value of 1
    assert value == pseudo_random_value
Ejemplo n.º 10
0
def test_custom_metric(cloud_config):
    PROJECT_RESOURCE = "projects/{}".format(cloud_config.project)
    client = list_resources.get_client()
    # Use a constant seed so psuedo random number is known ahead of time
    random.seed(1)
    pseudo_random_value = random.randint(0, 10)
    # Reseed it
    random.seed(1)

    INSTANCE_ID = "test_instance"
    METRIC_KIND = "GAUGE"

    create_custom_metric(client, PROJECT_RESOURCE, METRIC_RESOURCE,
                         METRIC_KIND)

    # wait until metric has been created, use the get call to wait until
    # a response comes back with the new metric
    custom_metric = None
    while not custom_metric:
        time.sleep(1)
        custom_metric = get_custom_metric(client, PROJECT_RESOURCE,
                                          METRIC_RESOURCE)

    write_timeseries_value(client, PROJECT_RESOURCE, METRIC_RESOURCE,
                           INSTANCE_ID, METRIC_KIND)

    # Sometimes on new metric descriptors, writes have a delay in being
    # read back. Use eventually_consistent to account for this.
    @eventually_consistent.call
    def _():
        response = read_timeseries(client, PROJECT_RESOURCE, METRIC_RESOURCE)
        value = int(
            response['timeSeries'][0]['points'][0]['value']['int64Value'])
        # using seed of 1 will create a value of 1
        assert value == pseudo_random_value
def test_list_timeseries(cloud_config, capsys):
    PROJECT_RESOURCE = "projects/{}".format(cloud_config.project)
    client = list_resources.get_client()
    list_resources.list_timeseries(client, PROJECT_RESOURCE, METRIC)
    stdout, _ = capsys.readouterr()
    regex = re.compile(u"list_timeseries response:\n", re.I)
    assert regex.search(stdout) is not None
def test_list_monitored_resources(cloud_config, capsys):
    PROJECT_RESOURCE = "projects/{}".format(cloud_config.project)
    client = list_resources.get_client()
    list_resources.list_monitored_resource_descriptors(client, PROJECT_RESOURCE)
    stdout, _ = capsys.readouterr()
    regex = re.compile("An application running", re.I)
    assert regex.search(stdout) is not None
def test_list_monitored_resources(capsys):
    client = list_resources.get_client()
    list_resources.list_monitored_resource_descriptors(
        client, PROJECT_RESOURCE)
    stdout, _ = capsys.readouterr()
    regex = re.compile(
        'An application running')
    assert regex.search(stdout) is not None
Ejemplo n.º 14
0
def test_list_monitored_resources(cloud_config, capsys):
    PROJECT_RESOURCE = "projects/{}".format(cloud_config.project)
    client = list_resources.get_client()
    list_resources.list_monitored_resource_descriptors(client,
                                                       PROJECT_RESOURCE)
    stdout, _ = capsys.readouterr()
    regex = re.compile('An application running', re.I)
    assert regex.search(stdout) is not None
def test_list_metrics(capsys):
    client = list_resources.get_client()
    list_resources.list_metric_descriptors(
        client, PROJECT_RESOURCE, METRIC)
    stdout, _ = capsys.readouterr()
    regex = re.compile(
        u'Delta CPU usage time')
    assert regex.search(stdout) is not None
def test_list_timeseries(capsys):
    client = list_resources.get_client()
    list_resources.list_timeseries(client, PROJECT_RESOURCE, METRIC)
    stdout, _ = capsys.readouterr()
    regex = re.compile(u'list_timeseries response:\n')
    assert regex.search(stdout) is not None
def test_list_metrics(capsys):
    client = list_resources.get_client()
    list_resources.list_metric_descriptors(client, PROJECT_RESOURCE, METRIC)
    stdout, _ = capsys.readouterr()
    regex = re.compile(u'Delta CPU usage time')
    assert regex.search(stdout) is not None