Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add table gcp_compute_instance_metric_cpu_utilization_hourly. closes #253 #255

Merged
merged 9 commits into from
Jun 30, 2021
41 changes: 41 additions & 0 deletions docs/tables/gcp_compute_instance_metric_cpu_utilization_hourly.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Table: gcp_compute_instance_metric_cpu_utilization_hourly

GCloud Monitoring Metrics provide data about the performance of your systems. The `gcp_compute_instance_metric_cpu_utilization_hourly` table provides metric statistics at 60 minute intervals for the most recent 5 days.


## Examples

### Basic info

```sql
select
instance_id,
timestamp,
minimum,
maximum,
average,
sample_count
from
gcp_compute_instance_metric_cpu_utilization_hourly
order by
instance_id,
timestamp;
```

### CPU Over 80% average

```sql
select
instance_id,
timestamp,
round(minimum::numeric,2) as min_cpu,
round(maximum::numeric,2) as max_cpu,
round(average::numeric,2) as avg_cpu,
sample_count
from
gcp_compute_instance_metric_cpu_utilization_hourly
where average > 80
order by
instance_id,
timestamp;
```
121 changes: 61 additions & 60 deletions gcp/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,66 +28,67 @@ func Plugin(ctx context.Context) *plugin.Plugin {
Schema: ConfigSchema,
},
TableMap: map[string]*plugin.Table{
"gcp_audit_policy": tableGcpAuditPolicy(ctx),
"gcp_bigquery_dataset": tableGcpBigQueryDataset(ctx),
"gcp_bigquery_table": tableGcpBigqueryTable(ctx),
"gcp_bigtable_instance": tableGcpBigtableInstance(ctx),
"gcp_cloudfunctions_function": tableGcpCloudfunctionFunction(ctx),
"gcp_compute_address": tableGcpComputeAddress(ctx),
"gcp_compute_backend_bucket": tableGcpComputeBackendBucket(ctx),
"gcp_compute_backend_service": tableGcpComputeBackendService(ctx),
"gcp_compute_disk": tableGcpComputeDisk(ctx),
"gcp_compute_firewall": tableGcpComputeFirewall(ctx),
"gcp_compute_forwarding_rule": tableGcpComputeForwardingRule(ctx),
"gcp_compute_global_address": tableGcpComputeGlobalAddress(ctx),
"gcp_compute_global_forwarding_rule": tableGcpComputeGlobalForwardingRule(ctx),
"gcp_compute_image": tableGcpComputeImage(ctx),
"gcp_compute_instance": tableGcpComputeInstance(ctx),
"gcp_compute_instance_template": tableGcpComputeInstanceTemplate(ctx),
"gcp_compute_network": tableGcpComputeNetwork(ctx),
"gcp_compute_node_group": tableGcpComputeNodeGroup(ctx),
"gcp_compute_node_template": tableGcpComputeNodeTemplate(ctx),
"gcp_compute_project_metadata": tableGcpComputeProjectMetadata(ctx),
"gcp_compute_region": tableGcpComputeRegion(ctx),
"gcp_compute_resource_policy": tableGcpComputeResourcePolicy(ctx),
"gcp_compute_router": tableGcpComputeRouter(ctx),
"gcp_compute_snapshot": tableGcpComputeSnapshot(ctx),
"gcp_compute_ssl_policy": tableGcpComputeSslPolicy(ctx),
"gcp_compute_subnetwork": tableGcpComputeSubnetwork(ctx),
"gcp_compute_target_https_proxy": tableGcpComputeTargetHttpsProxy(ctx),
"gcp_compute_target_pool": tableGcpComputeTargetPool(ctx),
"gcp_compute_target_ssl_proxy": tableGcpComputeTargetSslProxy(ctx),
"gcp_compute_target_vpn_gateway": tableGcpComputeTargetVpnGateway(ctx),
"gcp_compute_url_map": tableGcpComputeURLMap(ctx),
"gcp_compute_vpn_tunnel": tableGcpComputeVpnTunnel(ctx),
"gcp_compute_zone": tableGcpComputeZone(ctx),
"gcp_dns_managed_zone": tableGcpDnsManagedZone(ctx),
"gcp_dns_policy": tableDnsPolicy(ctx),
"gcp_dns_record_set": tableDnsRecordSet(ctx),
"gcp_iam_policy": tableGcpIAMPolicy(ctx),
"gcp_iam_role": tableGcpIamRole(ctx),
"gcp_kms_key": tableGcpKmsKey(ctx),
"gcp_kms_key_ring": tableGcpKmsKeyRing(ctx),
"gcp_logging_bucket": tableGcpLoggingBucket(ctx),
"gcp_logging_exclusion": tableGcpLoggingExclusion(ctx),
"gcp_logging_metric": tableGcpLoggingMetric(ctx),
"gcp_logging_sink": tableGcpLoggingSink(ctx),
"gcp_monitoring_alert_policy": tableGcpMonitoringAlert(ctx),
"gcp_monitoring_group": tableGcpMonitoringGroup(ctx),
"gcp_monitoring_notification_channel": tableGcpMonitoringNotificationChannel(ctx),
"gcp_project_organization_policy": tableGcpProjectOrganizationPolicy(ctx),
"gcp_project": tableGcpProject(ctx),
"gcp_project_service": tableGcpProjectService(ctx),
"gcp_pubsub_snapshot": tableGcpPubSubSnapshot(ctx),
"gcp_pubsub_subscription": tableGcpPubSubSubscription(ctx),
"gcp_pubsub_topic": tableGcpPubSubTopic(ctx),
"gcp_service_account": tableGcpServiceAccount(ctx),
"gcp_service_account_key": tableGcpServiceAccountKey(ctx),
"gcp_sql_backup": tableGcpSQLBackup(ctx),
"gcp_sql_database": tableGcpSQLDatabase(ctx),
"gcp_sql_database_connections_daily": tableGcpSQLDatabaseConnectionsMetricDaily(ctx),
"gcp_sql_database_instance": tableGcpSQLDatabaseInstance(ctx),
"gcp_storage_bucket": tableGcpStorageBucket(ctx),
"gcp_audit_policy": tableGcpAuditPolicy(ctx),
"gcp_bigquery_dataset": tableGcpBigQueryDataset(ctx),
"gcp_bigquery_table": tableGcpBigqueryTable(ctx),
"gcp_bigtable_instance": tableGcpBigtableInstance(ctx),
"gcp_cloudfunctions_function": tableGcpCloudfunctionFunction(ctx),
"gcp_compute_address": tableGcpComputeAddress(ctx),
"gcp_compute_backend_bucket": tableGcpComputeBackendBucket(ctx),
"gcp_compute_backend_service": tableGcpComputeBackendService(ctx),
"gcp_compute_disk": tableGcpComputeDisk(ctx),
"gcp_compute_firewall": tableGcpComputeFirewall(ctx),
"gcp_compute_forwarding_rule": tableGcpComputeForwardingRule(ctx),
"gcp_compute_global_address": tableGcpComputeGlobalAddress(ctx),
"gcp_compute_global_forwarding_rule": tableGcpComputeGlobalForwardingRule(ctx),
"gcp_compute_image": tableGcpComputeImage(ctx),
"gcp_compute_instance": tableGcpComputeInstance(ctx),
"gcp_compute_instance_metric_cpu_utilization_hourly": tableComputeInstanceCpuUtilizationMetricHourly(ctx),
"gcp_compute_instance_template": tableGcpComputeInstanceTemplate(ctx),
"gcp_compute_network": tableGcpComputeNetwork(ctx),
"gcp_compute_node_group": tableGcpComputeNodeGroup(ctx),
"gcp_compute_node_template": tableGcpComputeNodeTemplate(ctx),
"gcp_compute_project_metadata": tableGcpComputeProjectMetadata(ctx),
"gcp_compute_region": tableGcpComputeRegion(ctx),
"gcp_compute_resource_policy": tableGcpComputeResourcePolicy(ctx),
"gcp_compute_router": tableGcpComputeRouter(ctx),
"gcp_compute_snapshot": tableGcpComputeSnapshot(ctx),
"gcp_compute_ssl_policy": tableGcpComputeSslPolicy(ctx),
"gcp_compute_subnetwork": tableGcpComputeSubnetwork(ctx),
"gcp_compute_target_https_proxy": tableGcpComputeTargetHttpsProxy(ctx),
"gcp_compute_target_pool": tableGcpComputeTargetPool(ctx),
"gcp_compute_target_ssl_proxy": tableGcpComputeTargetSslProxy(ctx),
"gcp_compute_target_vpn_gateway": tableGcpComputeTargetVpnGateway(ctx),
"gcp_compute_url_map": tableGcpComputeURLMap(ctx),
"gcp_compute_vpn_tunnel": tableGcpComputeVpnTunnel(ctx),
"gcp_compute_zone": tableGcpComputeZone(ctx),
"gcp_dns_managed_zone": tableGcpDnsManagedZone(ctx),
"gcp_dns_policy": tableDnsPolicy(ctx),
"gcp_dns_record_set": tableDnsRecordSet(ctx),
"gcp_iam_policy": tableGcpIAMPolicy(ctx),
"gcp_iam_role": tableGcpIamRole(ctx),
"gcp_kms_key": tableGcpKmsKey(ctx),
"gcp_kms_key_ring": tableGcpKmsKeyRing(ctx),
"gcp_logging_bucket": tableGcpLoggingBucket(ctx),
"gcp_logging_exclusion": tableGcpLoggingExclusion(ctx),
"gcp_logging_metric": tableGcpLoggingMetric(ctx),
"gcp_logging_sink": tableGcpLoggingSink(ctx),
"gcp_monitoring_alert_policy": tableGcpMonitoringAlert(ctx),
"gcp_monitoring_group": tableGcpMonitoringGroup(ctx),
"gcp_monitoring_notification_channel": tableGcpMonitoringNotificationChannel(ctx),
"gcp_project_organization_policy": tableGcpProjectOrganizationPolicy(ctx),
"gcp_project": tableGcpProject(ctx),
"gcp_project_service": tableGcpProjectService(ctx),
"gcp_pubsub_snapshot": tableGcpPubSubSnapshot(ctx),
"gcp_pubsub_subscription": tableGcpPubSubSubscription(ctx),
"gcp_pubsub_topic": tableGcpPubSubTopic(ctx),
"gcp_service_account": tableGcpServiceAccount(ctx),
"gcp_service_account_key": tableGcpServiceAccountKey(ctx),
"gcp_sql_backup": tableGcpSQLBackup(ctx),
"gcp_sql_database": tableGcpSQLDatabase(ctx),
"gcp_sql_database_connections_daily": tableGcpSQLDatabaseConnectionsMetricDaily(ctx),
"gcp_sql_database_instance": tableGcpSQLDatabaseInstance(ctx),
"gcp_storage_bucket": tableGcpStorageBucket(ctx),
/*
https://github.com/turbot/steampipe/issues/108
"gcp_compute_route": tableGcpComputeRoute(ctx),
Expand Down
41 changes: 41 additions & 0 deletions gcp/table_gcp_compute_instance_metric_cpu_utilization_hourly.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package gcp

import (
"context"

"github.com/turbot/steampipe-plugin-sdk/grpc/proto"
"github.com/turbot/steampipe-plugin-sdk/plugin"
"github.com/turbot/steampipe-plugin-sdk/plugin/transform"
"google.golang.org/api/compute/v1"
)

//// TABLE DEFINITION

func tableComputeInstanceCpuUtilizationMetricHourly(_ context.Context) *plugin.Table {
return &plugin.Table{
Name: "gcp_compute_instance_metric_cpu_utilization_hourly",
Description: "GCP Compute Instance Hourly CPU Utilization",
List: &plugin.ListConfig{
ParentHydrate: listComputeInstances,
Hydrate: listComputeInstanceMetricCpuUtilizationHourly,
},
Columns: monitoringMetricColumns([]*plugin.Column{
{
Name: "instance_id",
Description: "The Compute Instance name.",
Type: proto.ColumnType_STRING,
Transform: transform.FromField("DimensionValue"),
},
}),
}
}

//// LIST FUNCTION

func listComputeInstanceMetricCpuUtilizationHourly(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) {
instanceInfo := h.Item.(*compute.Instance)

dimensionValue := "\"" + instanceInfo.Name + "\""

return listMonitorMetricStatistics(ctx, d, "HOURLY", "\"compute.googleapis.com/instance/cpu/utilization\"", "metric.labels.instance_name = ", dimensionValue, instanceInfo.Name)
}