Skip to content
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
115 changes: 115 additions & 0 deletions monitor_dashboards.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
package linodego

import (
"context"
"encoding/json"
"time"

"github.com/linode/linodego/internal/parseabletime"
)

// MonitorDashboard represents an ACLP Dashboard object
type MonitorDashboard struct {
ID int `json:"id"`
Type DashboardType `json:"type"`
ServiceType ServiceType `json:"service_type"`
Label string `json:"label"`
Created *time.Time `json:"-"`
Updated *time.Time `json:"-"`
Widgets []DashboardWidget `json:"widgets"`
}

// enum object for serviceType
type ServiceType string

const (
ServiceTypeLinode ServiceType = "linode"
ServiceTypeLKE ServiceType = "lke"
ServiceTypeDBaaS ServiceType = "dbaas"
ServiceTypeACLB ServiceType = "aclb"
ServiceTypeNodeBalancer ServiceType = "nodebalancer"
ServiceTypeObjectStorage ServiceType = "objectstorage"
ServiceTypeVPC ServiceType = "vpc"
ServiceTypeFirewallService ServiceType = "firewall"
)

// enum object for DashboardType
type DashboardType string

const (
DashboardTypeStandard DashboardType = "standard"
DashboardTypeCustom DashboardType = "custom"
)

// DashboardWidget represents an ACLP DashboardWidget object
type DashboardWidget struct {
Metric string `json:"metric"`
Unit string `json:"unit"`
Label string `json:"label"`
Color string `json:"color"`
Size int `json:"size"`
ChartType ChartType `json:"chart_type"`
YLabel string `json:"y_label"`
AggregateFunction AggregateFunction `json:"aggregate_function"`
}

// Enum object for AggregateFunction
type AggregateFunction string

const (
AggregateFunctionMin AggregateFunction = "min"
AggregateFunctionMax AggregateFunction = "max"
AggregateFunctionAvg AggregateFunction = "avg"
AggregateFunctionSum AggregateFunction = "sum"
AggregateFunctionRate AggregateFunction = "rate"
AggregateFunctionIncrease AggregateFunction = "increase"
AggregateFunctionCount AggregateFunction = "count"
AggregateFunctionLast AggregateFunction = "last"
)

// Enum object for Chart type
type ChartType string

const (
ChartTypeLine ChartType = "line"
ChartTypeArea ChartType = "area"
)

// ListMonitorDashboards lists all the ACLP Monitor Dashboards
func (c *Client) ListMonitorDashboards(ctx context.Context, opts *ListOptions) ([]MonitorDashboard, error) {
return getPaginatedResults[MonitorDashboard](ctx, c, "monitor/dashboards", opts)
}

// GetMonitorDashboard gets an ACLP Monitor Dashboard for a given dashboardID
func (c *Client) GetMonitorDashboard(ctx context.Context, dashboardID int) (*MonitorDashboard, error) {
e := formatAPIPath("monitor/dashboards/%d", dashboardID)
return doGETRequest[MonitorDashboard](ctx, c, e)
}

// ListMonitorDashboardsByServiceType lists ACLP Monitor Dashboards for a given serviceType
func (c *Client) ListMonitorDashboardsByServiceType(ctx context.Context, serviceType string, opts *ListOptions) ([]MonitorDashboard, error) {
e := formatAPIPath("monitor/services/%s/dashboards", serviceType)
return getPaginatedResults[MonitorDashboard](ctx, c, e, opts)
}

// UnmarshalJSON implements the json.Unmarshaler interface
func (i *MonitorDashboard) UnmarshalJSON(b []byte) error {
type Mask MonitorDashboard

p := struct {
*Mask
Created *parseabletime.ParseableTime `json:"created"`
Updated *parseabletime.ParseableTime `json:"updated"`
}{
Mask: (*Mask)(i),
}

if err := json.Unmarshal(b, &p); err != nil {
return err
}

i.Created = (*time.Time)(p.Created)
i.Updated = (*time.Time)(p.Updated)

return nil
}
61 changes: 61 additions & 0 deletions monitor_metrics_definitions.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package linodego

import (
"context"
)

// MonitorMetricsDefinition represents an ACLP MetricsDefinition object
type MonitorMetricsDefinition struct {
AvailableAggregateFunctions []AggregateFunction `json:"available_aggregate_functions"`
Dimensions []MonitorDimension `json:"dimensions"`
IsAlertable bool `json:"is_alertable"`
Label string `json:"label"`
Metric string `json:"metric"`
MetricType MetricType `json:"metric_type"`
ScrapeInterval string `json:"scrape_interval"`
Unit MetricUnit `json:"unit"`
}

// Enum object for MetricType
type MetricType string

const (
MetricTypeCounter MetricType = "counter"
MetricTypeHistogram MetricType = "histogram"
MetricTypeGauge MetricType = "gauge"
MetricTypeSummary MetricType = "summary"
)

// Enum object for Unit
type MetricUnit string

const (
MetricUnitCount MetricUnit = "count"
MetricUnitPercent MetricUnit = "percent"
MetricUnitByte MetricUnit = "byte"
MetricUnitSecond MetricUnit = "second"
MetricUnitBitsPerSecond MetricUnit = "bits_per_second"
MetricUnitMillisecond MetricUnit = "millisecond"
MetricUnitKB MetricUnit = "KB"
MetricUnitMB MetricUnit = "MB"
MetricUnitGB MetricUnit = "GB"
MetricUnitRate MetricUnit = "rate"
MetricUnitBytesPerSecond MetricUnit = "bytes_per_second"
MetricUnitPercentile MetricUnit = "percentile"
MetricUnitRatio MetricUnit = "ratio"
MetricUnitOpsPerSecond MetricUnit = "ops_per_second"
MetricUnitIops MetricUnit = "iops"
)

// MonitorDimension represents an ACLP MonitorDimension object
type MonitorDimension struct {
DimensionLabel string `json:"dimension_label"`
Label string `json:"label"`
Values []string `json:"values"`
}

// ListMonitorMetricsDefinitionByServiceType lists metric definitions
func (c *Client) ListMonitorMetricsDefinitionByServiceType(ctx context.Context, serviceType string, opts *ListOptions) ([]MonitorMetricsDefinition, error) {
e := formatAPIPath("monitor/services/%s/metric-definitions", serviceType)
return getPaginatedResults[MonitorMetricsDefinition](ctx, c, e, opts)
}
22 changes: 22 additions & 0 deletions monitor_services.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package linodego

import (
"context"
)

// MonitorService represents a MonitorService object
type MonitorService struct {
Label string `json:"label"`
ServiceType string `json:"service_type"`
}

// ListMonitorServices lists all the registered ACLP MonitorServices
func (c *Client) ListMonitorServices(ctx context.Context, opts *ListOptions) ([]MonitorService, error) {
return getPaginatedResults[MonitorService](ctx, c, "monitor/services", opts)
}

// ListMonitorServiceByType lists monitor services by a given service_type
func (c *Client) ListMonitorServiceByType(ctx context.Context, serviceType string, opts *ListOptions) ([]MonitorService, error) {
e := formatAPIPath("monitor/services/%s", serviceType)
return getPaginatedResults[MonitorService](ctx, c, e, opts)
}
21 changes: 21 additions & 0 deletions monitor_services_create_token.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package linodego

import (
"context"
)

// MonitorServiceToken represents a MonitorServiceToken object
type MonitorServiceToken struct {
Token string `json:"token"`
}

// Create token options
type MonitorTokenCreateOptions struct {
EntityIDs []int `json:"entity_ids"`
}

// CreateMonitorServiceTokenForServiceType to create token for a given serviceType
func (c *Client) CreateMonitorServiceTokenForServiceType(ctx context.Context, serviceType string, opts MonitorTokenCreateOptions) (*MonitorServiceToken, error) {
e := formatAPIPath("monitor/services/%s/token", serviceType)
return doPOSTRequest[MonitorServiceToken](ctx, c, e, opts)
}
3 changes: 2 additions & 1 deletion regions.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ const (
CapabilityBlockStorageMigrations string = "Block Storage Migrations"
CapabilityCloudFirewall string = "Cloud Firewall"
CapabilityDBAAS string = "Managed Databases"
CapabilityDiskEncryption string = "LA Disk Encryption"
CapabilityDiskEncryption string = "Disk Encryption"
CapabilityEdgePlans string = "Edge Plans"
CapabilityGPU string = "GPU Linodes"
CapabilityKubernetesEnterprise string = "Kubernetes Enterprise"
CapabilityLADiskEncryption string = "LA Disk Encryption"
CapabilityLKE string = "Kubernetes"
CapabilityLKEControlPlaneACL string = "LKE Network Access Control List (IP ACL)"
CapabilityLinodes string = "Linodes"
Expand Down
Loading
Loading