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_daily closes #225 #256

Merged
merged 5 commits into from
Jun 30, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
40 changes: 40 additions & 0 deletions docs/tables/gcp_compute_instance_metric_cpu_utilization_daily.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Table: gcp_compute_instance_metric_cpu_utilization_daily

GCP Monitoring Metrics provide data about the performance of your systems. The `gcp_compute_instance_metric_cpu_utilization_daily` table provides metric statistics at 24 hour intervals for the most recent 5 days.

ParthaI marked this conversation as resolved.
Show resolved Hide resolved
## Examples

### Basic info

```sql
select
name,
timestamp,
minimum,
maximum,
average,
sample_count
from
gcp_compute_instance_metric_cpu_utilization_daily
order by
name,
timestamp;
```

### CPU Over 80% average

```sql
select
name,
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_daily
where average > 80
order by
name,
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_instance_connections_daily": tableGcpSQLDatabaseInstanceConnectionsMetricDaily(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_daily": tableComputeInstanceCpuUtilizationMetricDaily(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_instance_connections_daily": tableGcpSQLDatabaseInstanceConnectionsMetricDaily(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_daily.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 tableComputeInstanceCpuUtilizationMetricDaily(_ context.Context) *plugin.Table {
return &plugin.Table{
Name: "gcp_compute_instance_metric_cpu_utilization_daily",
Description: "GCP Compute Instance Metrics - CPU Utilization (Daily)",
List: &plugin.ListConfig{
ParentHydrate: listComputeInstances,
Hydrate: listComputeInstanceMetricCpuUtilizationDaily,
},
Columns: monitoringMetricColumns([]*plugin.Column{
{
Name: "name",
Description: "The name of the instance.",
Type: proto.ColumnType_STRING,
Transform: transform.FromField("DimensionValue"),
},
}),
}
}

//// LIST FUNCTION

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

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

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