Removing global variables.
This commit is contained in:
parent
a1fdb73a96
commit
13244d8904
|
@ -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"
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue