-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add table gcp_compute_instance_metric_cpu_utilization_hourly. closes #…
- Loading branch information
Showing
3 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
docs/tables/gcp_compute_instance_metric_cpu_utilization_hourly.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Table: gcp_compute_instance_metric_cpu_utilization_hourly | ||
|
||
GCP 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 | ||
name, | ||
timestamp, | ||
minimum, | ||
maximum, | ||
average, | ||
sample_count | ||
from | ||
gcp_compute_instance_metric_cpu_utilization_hourly | ||
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_hourly | ||
where average > 80 | ||
order by | ||
name, | ||
timestamp; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
gcp/table_gcp_compute_instance_metric_cpu_utilization_hourly.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 Metrics - CPU Utilization (Hourly)", | ||
List: &plugin.ListConfig{ | ||
ParentHydrate: listComputeInstances, | ||
Hydrate: listComputeInstanceMetricCpuUtilizationHourly, | ||
}, | ||
Columns: monitoringMetricColumns([]*plugin.Column{ | ||
{ | ||
Name: "name", | ||
Description: "The name of the instance.", | ||
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) | ||
} |