Skip to content

Latest commit

 

History

History
401 lines (300 loc) · 19.1 KB

README.md

File metadata and controls

401 lines (300 loc) · 19.1 KB

Metrics

(Metrics)

Overview

Available Operations

ListMetrics

List metrics seen within a time period

Example Usage

package main

import(
	"os"
	swosdkgo "github.com/solarwinds/swo-sdk-go"
	"github.com/solarwinds/swo-sdk-go/models/operations"
	"context"
	"log"
)

func main() {
    s := swosdkgo.New(
        swosdkgo.WithSecurity(os.Getenv("SWO_API_TOKEN")),
    )

    ctx := context.Background()
    res, err := s.Metrics.ListMetrics(ctx, operations.ListMetricsRequest{})
    if err != nil {
        log.Fatal(err)
    }
    if res.Object != nil {
                for {
            // handle items
        
            res, err = res.Next()
        
            if err != nil {
                // handle error
            }
        
            if res == nil {
                break
            }
        }
        
    }
}

Parameters

Parameter Type Required Description
ctx context.Context ✔️ The context to use for the request.
request operations.ListMetricsRequest ✔️ The request object to use for the request.
opts []operations.Option The options for this request.

Response

*operations.ListMetricsResponse, error

Errors

Error Type Status Code Content Type
apierrors.APIError 4XX, 5XX */*

CreateCompositeMetric

Create a composite metric given a PromQL query

Example Usage

package main

import(
	"os"
	swosdkgo "github.com/solarwinds/swo-sdk-go"
	"github.com/solarwinds/swo-sdk-go/models/components"
	"context"
	"log"
)

func main() {
    s := swosdkgo.New(
        swosdkgo.WithSecurity(os.Getenv("SWO_API_TOKEN")),
    )

    ctx := context.Background()
    res, err := s.Metrics.CreateCompositeMetric(ctx, components.CompositeMetric{
        Name: "composite.custom.system.disk.io.rate",
        DisplayName: "Disk IO rate",
        Description: "Disk bytes transferred per second",
        Formula: "rate(system.disk.io[5m])",
        Units: "bytes/s",
    })
    if err != nil {
        log.Fatal(err)
    }
    if res.CompositeMetric != nil {
        // handle response
    }
}

Parameters

Parameter Type Required Description
ctx context.Context ✔️ The context to use for the request.
request components.CompositeMetric ✔️ The request object to use for the request.
opts []operations.Option The options for this request.

Response

*operations.CreateCompositeMetricResponse, error

Errors

Error Type Status Code Content Type
apierrors.CreateCompositeMetricResponseBody 400 application/json
apierrors.CreateCompositeMetricMetricsResponseBody 403 application/json
apierrors.APIError 4XX, 5XX */*

GetMetricByName

Get info about a metric

Example Usage

package main

import(
	"os"
	swosdkgo "github.com/solarwinds/swo-sdk-go"
	"github.com/solarwinds/swo-sdk-go/models/operations"
	"context"
	"log"
)

func main() {
    s := swosdkgo.New(
        swosdkgo.WithSecurity(os.Getenv("SWO_API_TOKEN")),
    )

    ctx := context.Background()
    res, err := s.Metrics.GetMetricByName(ctx, operations.GetMetricByNameRequest{
        Name: "<value>",
    })
    if err != nil {
        log.Fatal(err)
    }
    if res.CommonMetricInfo != nil {
                for {
            // handle items
        
            res, err = res.Next()
        
            if err != nil {
                // handle error
            }
        
            if res == nil {
                break
            }
        }
        
    }
}

Parameters

Parameter Type Required Description
ctx context.Context ✔️ The context to use for the request.
request operations.GetMetricByNameRequest ✔️ The request object to use for the request.
opts []operations.Option The options for this request.

Response

*operations.GetMetricByNameResponse, error

Errors

Error Type Status Code Content Type
apierrors.APIError 4XX, 5XX */*

ListMetricAttributes

List all attribute names defined for the given metric

Example Usage

package main

import(
	"os"
	swosdkgo "github.com/solarwinds/swo-sdk-go"
	"github.com/solarwinds/swo-sdk-go/models/operations"
	"context"
	"log"
)

func main() {
    s := swosdkgo.New(
        swosdkgo.WithSecurity(os.Getenv("SWO_API_TOKEN")),
    )

    ctx := context.Background()
    res, err := s.Metrics.ListMetricAttributes(ctx, operations.ListMetricAttributesRequest{
        Name: "<value>",
    })
    if err != nil {
        log.Fatal(err)
    }
    if res.Object != nil {
                for {
            // handle items
        
            res, err = res.Next()
        
            if err != nil {
                // handle error
            }
        
            if res == nil {
                break
            }
        }
        
    }
}

Parameters

Parameter Type Required Description
ctx context.Context ✔️ The context to use for the request.
request operations.ListMetricAttributesRequest ✔️ The request object to use for the request.
opts []operations.Option The options for this request.

Response

*operations.ListMetricAttributesResponse, error

Errors

Error Type Status Code Content Type
apierrors.APIError 4XX, 5XX */*

ListMetricAttributeValues

List values of a metric's attribute

Example Usage

package main

import(
	"os"
	swosdkgo "github.com/solarwinds/swo-sdk-go"
	"github.com/solarwinds/swo-sdk-go/models/operations"
	"context"
	"log"
)

func main() {
    s := swosdkgo.New(
        swosdkgo.WithSecurity(os.Getenv("SWO_API_TOKEN")),
    )

    ctx := context.Background()
    res, err := s.Metrics.ListMetricAttributeValues(ctx, operations.ListMetricAttributeValuesRequest{
        Name: "<value>",
        AttributeName: "<value>",
    })
    if err != nil {
        log.Fatal(err)
    }
    if res.Object != nil {
                for {
            // handle items
        
            res, err = res.Next()
        
            if err != nil {
                // handle error
            }
        
            if res == nil {
                break
            }
        }
        
    }
}

Parameters

Parameter Type Required Description
ctx context.Context ✔️ The context to use for the request.
request operations.ListMetricAttributeValuesRequest ✔️ The request object to use for the request.
opts []operations.Option The options for this request.

Response

*operations.ListMetricAttributeValuesResponse, error

Errors

Error Type Status Code Content Type
apierrors.APIError 4XX, 5XX */*

ListMetricMeasurements

List metric measurement values, grouped by attributes, filtered by the filter

Example Usage

package main

import(
	"os"
	swosdkgo "github.com/solarwinds/swo-sdk-go"
	"github.com/solarwinds/swo-sdk-go/models/operations"
	"context"
	"log"
)

func main() {
    s := swosdkgo.New(
        swosdkgo.WithSecurity(os.Getenv("SWO_API_TOKEN")),
    )

    ctx := context.Background()
    res, err := s.Metrics.ListMetricMeasurements(ctx, operations.ListMetricMeasurementsRequest{
        Name: "<value>",
    })
    if err != nil {
        log.Fatal(err)
    }
    if res.Object != nil {
                for {
            // handle items
        
            res, err = res.Next()
        
            if err != nil {
                // handle error
            }
        
            if res == nil {
                break
            }
        }
        
    }
}

Parameters

Parameter Type Required Description
ctx context.Context ✔️ The context to use for the request.
request operations.ListMetricMeasurementsRequest ✔️ The request object to use for the request.
opts []operations.Option The options for this request.

Response

*operations.ListMetricMeasurementsResponse, error

Errors

Error Type Status Code Content Type
apierrors.APIError 4XX, 5XX */*