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 all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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;
```
1 change: 1 addition & 0 deletions gcp/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func Plugin(ctx context.Context) *plugin.Plugin {
"gcp_compute_image": tableGcpComputeImage(ctx),
"gcp_compute_instance": tableGcpComputeInstance(ctx),
"gcp_compute_instance_metric_cpu_utilization": tableComputeInstanceCpuUtilizationMetric(ctx),
"gcp_compute_instance_metric_cpu_utilization_daily": tableComputeInstanceCpuUtilizationMetricDaily(ctx),
"gcp_compute_instance_metric_cpu_utilization_hourly": tableComputeInstanceCpuUtilizationMetricHourly(ctx),
"gcp_compute_instance_template": tableGcpComputeInstanceTemplate(ctx),
"gcp_compute_machine_type": tableGcpComputeMachineType(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)
}