Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 (
Linode ServiceType = "linode"
LKE ServiceType = "lke"
DBaaS ServiceType = "dbaas"
ACLB ServiceType = "aclb"
Nodebalancer ServiceType = "nodebalancer"
ObjectStorage ServiceType = "objectstorage"
Vpc ServiceType = "vpc"
FirewallService ServiceType = "firewall"
)

// enum object for DashboardType
type DashboardType string

const (
Standard DashboardType = "standard"
Custom 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 (
Min AggregateFunction = "min"
Max AggregateFunction = "max"
Avg AggregateFunction = "avg"
Sum AggregateFunction = "sum"
Rate AggregateFunction = "rate"
Increase AggregateFunction = "increase"
Count AggregateFunction = "count"
Last AggregateFunction = "last"
)

// Enum object for Chart type
type ChartType string

const (
Line ChartType = "line"
Area 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 Unit `json:"unit"`
}

// Enum object for MetricType
type MetricType string

const (
Counter MetricType = "counter"
Histogram MetricType = "histogram"
Gauge MetricType = "gauge"
Summary MetricType = "summary"
)

// Enum object for Unit
type Unit string

const (
CountUnit Unit = "count"
Percent Unit = "percent"
Byte Unit = "byte"
Second Unit = "second"
BitsPerSecond Unit = "bits_per_second"
Millisecond Unit = "millisecond"
KB Unit = "KB"
MB Unit = "MB"
GB Unit = "GB"
RateUnit Unit = "rate"
BytesPerSecond Unit = "bytes_per_second"
Percentile Unit = "percentile"
Ratio Unit = "ratio"
OpsPerSecond Unit = "ops_per_second"
Iops Unit = "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)
}
Loading