diff --git a/examples/cloud-operations/network-dashboard/cloud-function/main.py b/examples/cloud-operations/network-dashboard/cloud-function/main.py index 4889980c..f8dc2675 100644 --- a/examples/cloud-operations/network-dashboard/cloud-function/main.py +++ b/examples/cloud-operations/network-dashboard/cloud-function/main.py @@ -49,8 +49,6 @@ def main(event, context): Returns: 'Function executed successfully' ''' - global client, interval - client, interval = create_client() metrics_dict = create_metrics() @@ -462,6 +460,8 @@ def get_quota_current_usage(project_link, metric_name): Returns: results_list (list of string): Current usage. ''' + client, interval = create_client() + results = client.list_time_series(request={ "name": project_link, "filter": f'metric.type = "{metric_name}"', @@ -481,6 +481,8 @@ def get_quota_current_limit(project_link, metric_name): Returns: results_list (list of string): Current limit. ''' + client, interval = create_client() + results = client.list_time_series(request={ "name": project_link, "filter": f'metric.type = "{metric_name}"', @@ -600,6 +602,8 @@ def write_data_to_metric(monitored_project_id, value, metric_name, network_name) usage (int): Current usage for that network. limit (int): Current usage for that network. ''' + client = monitoring_v3.MetricServiceClient() + series = monitoring_v3.TimeSeries() series.metric.type = f"custom.googleapis.com/{metric_name}" series.resource.type = "global" diff --git a/examples/cloud-operations/network-dashboard/cloud-function/metrics.yaml b/examples/cloud-operations/network-dashboard/cloud-function/metrics.yaml index d576034f..233dc9be 100644 --- a/examples/cloud-operations/network-dashboard/cloud-function/metrics.yaml +++ b/examples/cloud-operations/network-dashboard/cloud-function/metrics.yaml @@ -1,3 +1,18 @@ +# +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# --- metrics_per_network: instance_per_network: