-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
3 changed files
with
199 additions
and
0 deletions.
There are no files selected for viewing
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,112 @@ | ||
--- | ||
title: "Steampipe Table: linode_node_balancer - Query Linode NodeBalancers using SQL" | ||
description: "Allows users to query Linode NodeBalancers, providing detailed information about each NodeBalancer's configurations, status, and specifications." | ||
--- | ||
|
||
# Table: linode_node_balancer - Query Linode NodeBalancers using SQL | ||
|
||
Linode NodeBalancers distribute incoming traffic across multiple Linode instances to ensure high availability and reliability. They are essential for managing and balancing the load on your Linode instances, allowing you to scale applications and services efficiently. | ||
|
||
## Table Usage Guide | ||
|
||
The `linode_node_balancer` table provides insights into each NodeBalancer within the Linode platform. As a system administrator or DevOps engineer, you can explore NodeBalancer-specific details through this table, including configurations, tags, and traffic metrics. Utilize it to gather information about each NodeBalancer, such as its current configuration, traffic handling, and region. | ||
|
||
## Examples | ||
|
||
### Basic info | ||
Retrieve a list of all NodeBalancers in your Linode account to get an overview of your load balancing resources. | ||
|
||
```sql+postgres | ||
select | ||
id, | ||
created, | ||
updated, | ||
label, | ||
hostname | ||
from | ||
linode_node_balancer; | ||
``` | ||
|
||
```sql+sqlite | ||
select | ||
id, | ||
created, | ||
updated, | ||
label, | ||
hostname | ||
from | ||
linode_node_balancer; | ||
``` | ||
|
||
### NodeBalancers by region | ||
Explore which regions have the most NodeBalancers to better allocate resources and manage load distribution. | ||
|
||
```sql+postgres | ||
select | ||
region, | ||
count(*) | ||
from | ||
linode_node_balancer | ||
group by | ||
region; | ||
``` | ||
|
||
```sql+sqlite | ||
select | ||
region, | ||
count(*) | ||
from | ||
linode_node_balancer | ||
group by | ||
region; | ||
``` | ||
|
||
### NodeBalancers created in the last 30 days | ||
List all NodeBalancers that were created in the last 30 days to monitor new infrastructure additions. | ||
|
||
```sql+postgres | ||
select | ||
label, | ||
created, | ||
region | ||
from | ||
linode_node_balancer | ||
where | ||
created >= current_date - interval '30 days'; | ||
``` | ||
|
||
```sql+sqlite | ||
select | ||
label, | ||
created, | ||
region | ||
from | ||
linode_node_balancer | ||
where | ||
created >= date('now', '-30 days'); | ||
``` | ||
|
||
### NodeBalancers by transfer usage | ||
Identify NodeBalancers based on their transfer usage to manage bandwidth and optimize costs. | ||
|
||
```sql+postgres | ||
select | ||
label, | ||
transfer ->> 'in' as transfer_in, | ||
transfer ->> 'out' as transfer_out | ||
from | ||
linode_node_balancer | ||
order by | ||
(transfer ->> 'in')::bigint + (transfer ->> 'out')::bigint desc; | ||
``` | ||
|
||
```sql+sqlite | ||
select | ||
label, | ||
json_extract(transfer, '$.in') as transfer_in, | ||
json_extract(transfer, '$.out') as transfer_out | ||
from | ||
linode_node_balancer | ||
order by | ||
(json_extract(transfer, '$.in')) + (json_extract(transfer, '$.out')) desc; | ||
``` |
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
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,86 @@ | ||
package linode | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/linode/linodego" | ||
"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" | ||
) | ||
|
||
func tableLinodeNodeBalancer(ctx context.Context) *plugin.Table { | ||
return &plugin.Table{ | ||
Name: "linode_node_balancer", | ||
Description: "NodeBalancers that are assigned to this Linode and readable by the requesting User.", | ||
List: &plugin.ListConfig{ | ||
Hydrate: listNodeBalancers, | ||
}, | ||
Columns: commonColumns([]*plugin.Column{ | ||
// Top columns | ||
{Name: "id", Type: proto.ColumnType_INT, Description: "The unique ID of this NodeBalancer."}, | ||
{Name: "created", Type: proto.ColumnType_TIMESTAMP, Description: "When the NodeBalancer was created."}, | ||
{Name: "updated", Type: proto.ColumnType_TIMESTAMP, Description: "When the NodeBalancer was updated."}, | ||
{Name: "label", Type: proto.ColumnType_STRING, Description: "The NodeBalancer's label. These must be unique on your Account."}, | ||
{Name: "region", Type: proto.ColumnType_STRING, Description: "The Region where this NodeBalancer is located. NodeBalancers only support backends in the same Region."}, | ||
{Name: "hostname", Type: proto.ColumnType_STRING, Description: "The NodeBalancer's hostname, ending with .nodebalancer.linode.com."}, | ||
{Name: "ipv4", Type: proto.ColumnType_IPADDR, Description: "The NodeBalancer's public IPv4 address.", Transform: transform.FromField("IPv4")}, | ||
{Name: "ipv6", Type: proto.ColumnType_IPADDR, Description: "The NodeBalancer's public IPv6 address.", Transform: transform.FromField("IPv6")}, | ||
{Name: "client_conn_throttle", Type: proto.ColumnType_INT, Description: "Throttle connections per second (0-20). Set to 0 (zero) to disable throttling."}, | ||
{Name: "transfer", Type: proto.ColumnType_JSON, Description: "Information about the amount of transfer this NodeBalancer has had so far this month."}, | ||
{Name: "tags", Type: proto.ColumnType_JSON, Description: "An array of tags applied to this object. Tags are for organizational purposes only."}, | ||
{Name: "configurations", Hydrate: getNodeBalancersConfiguration, Transform: transform.FromValue(), Type: proto.ColumnType_JSON, Description: "The NodeBalancer configurations."}, | ||
}), | ||
} | ||
} | ||
|
||
//// LIST FUNCTION | ||
|
||
func listNodeBalancers(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateData) (interface{}, error) { | ||
conn, err := connect(ctx, d) | ||
if err != nil { | ||
plugin.Logger(ctx).Error("linode_node_balancer.listNodeBalancers", "connection_error", err) | ||
return nil, err | ||
} | ||
|
||
opts := linodego.ListOptions{} | ||
|
||
items, err := conn.ListNodeBalancers(ctx, &opts) | ||
if err != nil { | ||
plugin.Logger(ctx).Error("linode_node_balancer.listNodeBalancers", "query_error", err, "opts", opts) | ||
return nil, err | ||
} | ||
for _, i := range items { | ||
d.StreamListItem(ctx, i) | ||
|
||
// Context may get cancelled due to manual cancellation or if the limit has been reached | ||
if d.RowsRemaining(ctx) == 0 { | ||
return nil, nil | ||
} | ||
} | ||
return nil, nil | ||
} | ||
|
||
//// HYDRATE FUNCTION | ||
|
||
func getNodeBalancersConfiguration(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) { | ||
nodeBalanccer := h.Item.(linodego.NodeBalancer) | ||
|
||
conn, err := connect(ctx, d) | ||
if err != nil { | ||
plugin.Logger(ctx).Error("linode_node_balancer.getNodeBalancersConfiguration", "connection_error", err) | ||
return nil, err | ||
} | ||
|
||
opts := linodego.ListOptions{} | ||
|
||
items, err := conn.ListNodeBalancerConfigs(ctx, nodeBalanccer.ID, &opts) | ||
if err != nil { | ||
plugin.Logger(ctx).Error("linode_node_balancer.getNodeBalancersConfiguration", "query_error", err, "opts", opts) | ||
return nil, err | ||
} | ||
if len(items) > 0 { | ||
return items, nil | ||
} | ||
return nil, nil | ||
} |