-
Notifications
You must be signed in to change notification settings - Fork 23
/
table_gcp_compute_disk_metric_read_ops_hourly.go
50 lines (42 loc) · 1.55 KB
/
table_gcp_compute_disk_metric_read_ops_hourly.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package gcp
import (
"context"
"github.com/turbot/go-kit/types"
"github.com/turbot/steampipe-plugin-sdk/v5/grpc/proto"
"github.com/turbot/steampipe-plugin-sdk/v5/plugin"
"github.com/turbot/steampipe-plugin-sdk/v5/plugin/transform"
"google.golang.org/api/compute/v1"
)
//// TABLE DEFINITION
func tableGcpComputeDiskMetricReadOpsHourly(_ context.Context) *plugin.Table {
return &plugin.Table{
Name: "gcp_compute_disk_metric_read_ops_hourly",
Description: "GCP Compute Disk Metrics - Read Ops (Hourly)",
List: &plugin.ListConfig{
ParentHydrate: listComputeDisk,
Hydrate: listComputeDiskMetricReadOpsHourly,
KeyColumns: plugin.OptionalColumns([]string{"name"}),
},
Columns: monitoringMetricColumns([]*plugin.Column{
{
Name: "name",
Description: "The name of the disk.",
Type: proto.ColumnType_STRING,
Transform: transform.FromField("DimensionValue"),
},
}),
}
}
//// LIST FUNCTION
func listComputeDiskMetricReadOpsHourly(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) {
diskInfo := h.Item.(*compute.Disk)
// Get location
zoneName := getLastPathElement(types.SafeString(diskInfo.Zone))
regionName := getLastPathElement(types.SafeString(diskInfo.Region))
location := zoneName
if zoneName == "" {
location = regionName
}
dimensionValue := "\"" + diskInfo.Name + "\""
return listMonitorMetricStatistics(ctx, d, h, "HOURLY", "\"compute.googleapis.com/instance/disk/read_ops_count\"", "metric.label.device_name = ", dimensionValue, diskInfo.Name, location)
}