From e3ced6bd718dcf657f9c3a034cb6fde96e7067be Mon Sep 17 00:00:00 2001 From: seolmin Date: Fri, 10 May 2024 13:37:27 +0900 Subject: [PATCH] fix: add Metric yaml files of BigQuery service Signed-off-by: seolmin --- .../manager/bigquery/sql_workspace_manager.py | 9 +++++ .../SQLWorkspace/sqlworkspace_count.yaml | 25 ++++++++++++++ .../BigQuery/SQLWorkspace/table_count.yaml | 26 ++++++++++++++ .../ComputeEngine/Instance/disk_size.yaml | 34 +++++++++++++++++++ .../model/bigquery/sql_workspace/data.py | 1 + 5 files changed, 95 insertions(+) create mode 100644 src/spaceone/inventory/metrics/BigQuery/SQLWorkspace/sqlworkspace_count.yaml create mode 100644 src/spaceone/inventory/metrics/BigQuery/SQLWorkspace/table_count.yaml create mode 100644 src/spaceone/inventory/metrics/ComputeEngine/Instance/disk_size.yaml diff --git a/src/spaceone/inventory/manager/bigquery/sql_workspace_manager.py b/src/spaceone/inventory/manager/bigquery/sql_workspace_manager.py index 2dcf358..449076c 100644 --- a/src/spaceone/inventory/manager/bigquery/sql_workspace_manager.py +++ b/src/spaceone/inventory/manager/bigquery/sql_workspace_manager.py @@ -110,6 +110,15 @@ def collect_cloud_service(self, params): data_set_id, google_cloud_monitoring_filters, ), + "stats": { + "table_count": len( + [ + table + for table in updated_bq_tables + if table["type"] == "TABLE" + ] + ) + }, } ) big_query_data = BigQueryWorkSpace(bq_dataset, strict=False) diff --git a/src/spaceone/inventory/metrics/BigQuery/SQLWorkspace/sqlworkspace_count.yaml b/src/spaceone/inventory/metrics/BigQuery/SQLWorkspace/sqlworkspace_count.yaml new file mode 100644 index 0000000..53f3faf --- /dev/null +++ b/src/spaceone/inventory/metrics/BigQuery/SQLWorkspace/sqlworkspace_count.yaml @@ -0,0 +1,25 @@ +--- +metric_id: metric-gcp-bigquery-workspace-count +name: SQLWorkspace Count +metric_type: GAUGE +resource_type: inventory.CloudService:google_cloud.BigQuery.SQLWorkspace +query_options: + group_by: + - key: region_code + name: Region + search_key: region_code + reference: + resource_type: inventory.Region + reference_key: region_code + - key: account + name: Project ID + search_key: account + - key: data.location + name: Location + search_key: data.location + fields: + value: + operator: count +unit: Count +namespace_id: ns-gcp-bigquery-sqlworkspace +version: '1.0' \ No newline at end of file diff --git a/src/spaceone/inventory/metrics/BigQuery/SQLWorkspace/table_count.yaml b/src/spaceone/inventory/metrics/BigQuery/SQLWorkspace/table_count.yaml new file mode 100644 index 0000000..25e20b6 --- /dev/null +++ b/src/spaceone/inventory/metrics/BigQuery/SQLWorkspace/table_count.yaml @@ -0,0 +1,26 @@ +--- +metric_id: metric-gcp-bigquery-table-count +name: Table Count +metric_type: GAUGE +resource_type: inventory.CloudService:google_cloud.BigQuery.SQLWorkspace +query_options: + group_by: + - key: region_code + name: Region + search_key: region_code + reference: + resource_type: inventory.Region + reference_key: region_code + - key: account + name: Project ID + search_key: account + - key: data.location + name: Location + search_key: data.location + fields: + value: + key: data.stats.table_count + operator: count +unit: Count +namespace_id: ns-gcp-bigquery-sqlworkspace +version: '1.0' \ No newline at end of file diff --git a/src/spaceone/inventory/metrics/ComputeEngine/Instance/disk_size.yaml b/src/spaceone/inventory/metrics/ComputeEngine/Instance/disk_size.yaml new file mode 100644 index 0000000..c9e2815 --- /dev/null +++ b/src/spaceone/inventory/metrics/ComputeEngine/Instance/disk_size.yaml @@ -0,0 +1,34 @@ +--- +metric_id: metric-gcp-ce-instance-disk-size +name: Disk Size +metric_type: GAUGE +resource_type: inventory.CloudService:google_cloud.ComputeEngine.Instance +query_options: + group_by: + - key: region_code + name: Region + search_key: region_code + reference: + resource_type: inventory.Region + reference_key: region_code + - key: data.compute.az + name: Availability Zone + search_key: data.compute.az + - key: account + name: Project ID + search_key: account + - key: instance_type + name: Instance Type + search_key: instance_type + - key: data.os.os_type + name: OS Type + search_key: data.os.os_type + unwind: + - path: data.disks + fields: + value: + key: data.disks.size + operator: sum +unit: BYTES +namespace_id: ns-gcp-ce-instance +version: '1.0' \ No newline at end of file diff --git a/src/spaceone/inventory/model/bigquery/sql_workspace/data.py b/src/spaceone/inventory/model/bigquery/sql_workspace/data.py index a556ff6..a82cefe 100644 --- a/src/spaceone/inventory/model/bigquery/sql_workspace/data.py +++ b/src/spaceone/inventory/model/bigquery/sql_workspace/data.py @@ -134,6 +134,7 @@ class BigQueryWorkSpace(BaseResource): creation_time = DateTimeType(deserialize_from="creationTime") last_modified_time = DateTimeType(deserialize_from="lastModifiedTime") + stats = DictType(StringType, default={}) def reference(self): return {