azquery

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 8, 2022 License: MIT Imports: 15 Imported by: 17

README

Azure Monitor Query client module for Go

The Azure Monitor Query client library is used to execute read-only queries against Azure Monitor's two data platforms:

  • Logs - Collects and organizes log and performance data from monitored resources. Data from different sources such as platform logs from Azure services, log and performance data from virtual machines agents, and usage and performance data from apps can be consolidated into a single Azure Log Analytics workspace. The various data types can be analyzed together using the [Kusto Query Language][kusto_query_language].
  • Metrics - Collects numeric data from monitored resources into a time series database. Metrics are numerical values that are collected at regular intervals and describe some aspect of a system at a particular time. Metrics are lightweight and capable of supporting near real-time scenarios, making them particularly useful for alerting and fast detection of issues.

NOTE: This library is currently a beta. There may be breaking changes until it reaches semantic version v1.0.0.

Getting started

Install packages

Install azquery and azidentity with go get:

go get github.com/Azure/azure-sdk-for-go/sdk/monitor/azquery
go get github.com/Azure/azure-sdk-for-go/sdk/azidentity

azidentity is used for Azure Active Directory authentication as demonstrated below.

Prerequisites
  • An Azure subscription
  • A supported Go version (the Azure SDK supports the two most recent Go releases)
  • For log queries, a Log Analytics workspace.
  • For metric queries, a Resource URI.
Authentication

This document demonstrates using [azidentity.NewDefaultAzureCredential][default_cred_ref] to authenticate. This credential type works in both local development and production environments. We recommend using a managed identity in production.

Client accepts any azidentity credential. See the azidentity documentation for more information about other credential types.

Create a logs client
import (
	"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
	"github.com/Azure/azure-sdk-for-go/sdk/monitor/azquery"
)

func main() {
	cred, err := azidentity.NewDefaultAzureCredential(nil)
	if err != nil {
		panic(err)
	}

	client := azkeys.NewLogsClient(cred, nil)
}
Create a metrics client
import (
	"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
	"github.com/Azure/azure-sdk-for-go/sdk/monitor/azquery"
)

func main() {
	cred, err := azidentity.NewDefaultAzureCredential(nil)
	if err != nil {
		panic(err)
	}

	client := azkeys.NewMetricsClient(cred, nil)
}
Execute the query

For examples of Logs and Metrics queries, see the Examples section.

Key concepts

Logs query rate limits and throttling

The Log Analytics service applies throttling when the request rate is too high. Limits, such as the maximum number of rows returned, are also applied on the Kusto queries. For more information, see Query API.

If you're executing a batch logs query, a throttled request will return a LogsQueryError object. That object's code value will be ThrottledError.

Metrics data structure

Each set of metric values is a time series with the following characteristics:

  • The time the value was collected
  • The resource associated with the value
  • A namespace that acts like a category for the metric
  • A metric name
  • The value itself
  • Some metrics may have multiple dimensions as described in multi-dimensional metrics. Custom metrics can have up to 10 dimensions.
Timespan

It's best practice to always query with a timespan to prevent excessive queries of the entire logs or metrics data set. Logs uses the ISO8601 Time Interval Standard

The timespan can be the following string formats:

<start>/<end> such as "2007-03-01T13:00:00Z/2008-05-11T15:30:00Z"
<start>/<duration> such as "2007-03-01T13:00:00Z/P1Y2M10DT2H30M"
<duration>/<end> such as "P1Y2M10DT2H30M/2008-05-11T15:30:00Z"
<duration> such as "P1Y2M10DT2H30M" // 1 year, 2 months, 10 days, 2 hours, 20 minutes

Examples

Logs query
client := azquery.NewLogsClient(cred, nil)
timespan := "2022-08-30/2022-08-31"

res, err := client.QueryWorkspace(context.TODO(), workspaceID, azquery.Body{Query: to.Ptr(query), Timespan: to.Ptr(timespan)}, nil)
if err != nil {
	panic(err)
}
_ = res
Logs query body structure
Body
|---Query *string // Kusto Query
|---Timespan *string // ISO8601 Standard Timespan
|---Workspaces []*string //Optional- additional workspaces to query
Logs query result structure
LogsResponse
|---Tables []*Table
	|---Columns []*Column
		|---Name *string
		|---Type *LogsColumnType
	|---Name *string
	|---Rows [][]interface{}
|---Error *ErrorInfo
	|---Code *string
	|---Message *string
	|---AdditionalProperties interface{}
	|---Details []*ErrorDetail
		|---Code *string
		|---Message *string
		|---AdditionalProperties interface{}
		|---Resources []*string
		|---Target *string
		|---Value *string
	|---Innererror *ErrorInfo
|---Render interface{}
|---Statistics interface{}
Batch query
client := azquery.NewLogsClient(cred, nil)
timespan := "2022-08-30/2022-08-31"

batchRequest := azquery.BatchRequest{[]*azquery.BatchQueryRequest{
	{Body: &azquery.Body{Query: to.Ptr(kustoQuery1), Timespan: to.Ptr(timespan)}, ID: to.Ptr("1"), Workspace: to.Ptr(workspaceID)},
	{Body: &azquery.Body{Query: to.Ptr(kustoQuery2), Timespan: to.Ptr(timespan)}, ID: to.Ptr("2"), Workspace: to.Ptr(workspaceID)},
	{Body: &azquery.Body{Query: to.Ptr(kustoQuery3), Timespan: to.Ptr(timespan)}, ID: to.Ptr("3"), Workspace: to.Ptr(workspaceID)},
}}

res, err := client.Batch(context.TODO(), batchRequest, nil)
if err != nil {
	panic(err)
}
_ = res
Batch query request structure
BatchRequest
|---Body *Body
	|---Query *string // Kusto Query
	|---Timespan *string // ISO8601 Standard Timespan
	|---Workspaces []*string // Optional- additional workspaces to query
|---ID *string // unique identifier for each query in batch
|---Workspace *string
|---Headers map[string]*string // Optional- advanced query options in prefer header
|---Method *BatchQueryRequestMethod // Optional- defaults to POST
|---Path *BatchQueryRequestPath // Optional- defaults to /query
Batch query result structure
BatchResponse
|---Responses []*BatchQueryResponse
	|---Body *BatchQueryResults
		|---Error *ErrorInfo
		|---Render interface{}
		|---Statistics interface{}
		|---Tables []*Table
			|---Columns []*Column
				|---Name *string
				|---Type *LogsColumnType
			|---Name *string
			|---Rows [][]interface{}
	|---Headers map[string]*string
	|---ID *string
	|---Status *int32
Advanced logs query
Query multiple workspaces

To run the same query against multiple Log Analytics workspaces, add the additional workspace ID strings to the Workspaces array in the Body struct.

When multiple workspaces are included in the query, the logs in the result table are not grouped according to the workspace from which it was retrieved.

client := azquery.NewLogsClient(cred, nil)
timespan := "2022-08-30/2022-08-31"
additionalWorkspaces := []*string{&workspaceID2, &workspaceID3}

res, err := client.QueryWorkspace(context.TODO(), workspaceID, azquery.Body{Query: to.Ptr(query), Timespan: to.Ptr(timespan), Workspaces: additionalWorkspaces}, nil)
if err != nil {
	panic(err)
}
_ = res
Increase wait time, include statistics, include render (visualization)

By default, the Azure Monitor Query service will run your query for up to three minutes. To increase the default timeout, set wait to desired number of seconds in LogsClientQueryWorkspaceOptions Prefer string. Max wait time the service will allow is ten minutes (600 seconds).

To get logs query execution statistics, such as CPU and memory consumption, set include-statistics to true in LogsClientQueryWorkspaceOptions Prefer string.

To get visualization data for logs queries, set include-render to true in LogsClientQueryWorkspaceOptions Prefer string.

client := azquery.NewLogsClient(cred, nil)
timespan := "2022-08-30/2022-08-31"
prefer := "wait=600,include-statistics=true,include-render=true"
options := &azquery.LogsClientQueryWorkspaceOptions{Prefer: &prefer}

res, err := client.QueryWorkspace(context.TODO(), workspaceID,
	azquery.Body{Query: to.Ptr(query), Timespan: to.Ptr(timespan)}, options)
if err != nil {
	panic(err)
}
_ = res
Metrics query
client := azquery.NewMetricsClient(cred, nil)
res, err := client.QueryResource(context.Background(), resourceURI,
	&azquery.MetricsClientQueryResourceOptions{Timespan: to.Ptr("2017-04-14T02:20:00Z/2017-04-14T04:20:00Z"),
		Interval:        to.Ptr("PT1M"),
		Metricnames:     nil,
		Aggregation:     to.Ptr("Average,count"),
		Top:             to.Ptr[int32](3),
		Orderby:         to.Ptr("Average asc"),
		Filter:          to.Ptr("BlobType eq '*'"),
		ResultType:      nil,
		Metricnamespace: to.Ptr("Microsoft.Storage/storageAccounts/blobServices"),
	})
if err != nil {
	panic(err)
}
_ = res
Metrics result structure
MetricsResults
|---Timespan *string
|---Value []*Metric
	|---ID *string
	|---Name *LocalizableString
	|---Timeseries []*TimeSeriesElement
		|---Data []*MetricValue
			|---TimeStamp *time.Time
			|---Average *float64
			|---Count *float64
			|---Maximum *float64
			|---Minimum *float64
			|---Total *float64
		|---Metadatavalues []*MetadataValue
			|---Name *LocalizableString
			|---Value *string 
	|---Type *string
	|---Unit *MetricUnit
	|---DisplayDescription *string
	|---ErrorCode *string
	|---ErrorMessage *string
|---Cost *int32
|---Interval *string
|---Namespace *string
|---Resourceregion *string

Troubleshooting

Logging

This module uses the logging implementation in azcore. To turn on logging for all Azure SDK modules, set AZURE_SDK_GO_LOGGING to all. By default the logger writes to stderr. Use the azcore/log package to control log output. For example, logging only HTTP request and response events, and printing them to stdout:

import azlog "github.com/Azure/azure-sdk-for-go/sdk/azcore/log"

// Print log events to stdout
azlog.SetListener(func(cls azlog.Event, msg string) {
	fmt.Println(msg)
})

// Includes only requests and responses in credential logs
azlog.SetEvents(azlog.EventRequest, azlog.EventResponse)

Next steps

To learn more about Azure Monitor, see the Azure Monitor service documentation.

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution.

When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information, see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AggregationType

type AggregationType string

AggregationType - the aggregation type of the metric.

const (
	AggregationTypeNone    AggregationType = "None"
	AggregationTypeAverage AggregationType = "Average"
	AggregationTypeCount   AggregationType = "Count"
	AggregationTypeMinimum AggregationType = "Minimum"
	AggregationTypeMaximum AggregationType = "Maximum"
	AggregationTypeTotal   AggregationType = "Total"
)

func PossibleAggregationTypeValues

func PossibleAggregationTypeValues() []AggregationType

PossibleAggregationTypeValues returns the possible values for the AggregationType const type.

type BatchQueryRequest

type BatchQueryRequest struct {
	// REQUIRED; The Analytics query. Learn more about the Analytics query syntax [https://azure.microsoft.com/documentation/articles/app-insights-analytics-reference/]
	Body *Body `json:"body,omitempty"`

	// REQUIRED; The error details.
	ID *string `json:"id,omitempty"`

	// REQUIRED; Workspace Id to be included in the query
	Workspace *string `json:"workspace,omitempty"`

	// Dictionary of
	Headers map[string]*string `json:"headers,omitempty"`

	// The method of a single request in a batch, defaults to POST
	Method *BatchQueryRequestMethod `json:"method,omitempty"`

	// The query path of a single request in a batch, defaults to /query
	Path *BatchQueryRequestPath `json:"path,omitempty"`
}

BatchQueryRequest - An single request in a batch.

func (BatchQueryRequest) MarshalJSON

func (b BatchQueryRequest) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaller interface for type BatchQueryRequest.

func (*BatchQueryRequest) UnmarshalJSON

func (b *BatchQueryRequest) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaller interface for type BatchQueryRequest.

type BatchQueryRequestMethod

type BatchQueryRequestMethod string

BatchQueryRequestMethod - The method of a single request in a batch, defaults to POST

const (
	BatchQueryRequestMethodPOST BatchQueryRequestMethod = "POST"
)

func PossibleBatchQueryRequestMethodValues

func PossibleBatchQueryRequestMethodValues() []BatchQueryRequestMethod

PossibleBatchQueryRequestMethodValues returns the possible values for the BatchQueryRequestMethod const type.

type BatchQueryRequestPath

type BatchQueryRequestPath string

BatchQueryRequestPath - The query path of a single request in a batch, defaults to /query

const (
	BatchQueryRequestPathQuery BatchQueryRequestPath = "/query"
)

func PossibleBatchQueryRequestPathValues

func PossibleBatchQueryRequestPathValues() []BatchQueryRequestPath

PossibleBatchQueryRequestPathValues returns the possible values for the BatchQueryRequestPath const type.

type BatchQueryResponse

type BatchQueryResponse struct {
	// Contains the tables, columns & rows resulting from a query.
	Body *BatchQueryResults `json:"body,omitempty"`

	// Dictionary of
	Headers map[string]*string `json:"headers,omitempty"`
	ID      *string            `json:"id,omitempty"`
	Status  *int32             `json:"status,omitempty"`
}

BatchQueryResponse - Contains the batch query response and the headers, id, and status of the request

func (BatchQueryResponse) MarshalJSON

func (b BatchQueryResponse) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaller interface for type BatchQueryResponse.

func (*BatchQueryResponse) UnmarshalJSON

func (b *BatchQueryResponse) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaller interface for type BatchQueryResponse.

type BatchQueryResults

type BatchQueryResults struct {
	// The code and message for an error.
	Error *ErrorInfo `json:"error,omitempty"`

	// Visualization data in JSON format.
	Render interface{} `json:"render,omitempty"`

	// Statistics represented in JSON format.
	Statistics interface{} `json:"statistics,omitempty"`

	// The list of tables, columns and rows.
	Tables []*Table `json:"tables,omitempty"`
}

BatchQueryResults - Contains the tables, columns & rows resulting from a query.

func (BatchQueryResults) MarshalJSON

func (b BatchQueryResults) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaller interface for type BatchQueryResults.

func (*BatchQueryResults) UnmarshalJSON

func (b *BatchQueryResults) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaller interface for type BatchQueryResults.

type BatchRequest

type BatchRequest struct {
	// REQUIRED; An single request in a batch.
	Requests []*BatchQueryRequest `json:"requests,omitempty"`
}

BatchRequest - An array of requests.

func (BatchRequest) MarshalJSON

func (b BatchRequest) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaller interface for type BatchRequest.

func (*BatchRequest) UnmarshalJSON

func (b *BatchRequest) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaller interface for type BatchRequest.

type BatchResponse

type BatchResponse struct {
	// An array of responses corresponding to each individual request in a batch.
	Responses []*BatchQueryResponse `json:"responses,omitempty"`
}

BatchResponse - Response to a batch query.

func (BatchResponse) MarshalJSON

func (b BatchResponse) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaller interface for type BatchResponse.

func (*BatchResponse) UnmarshalJSON

func (b *BatchResponse) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaller interface for type BatchResponse.

type Body

type Body struct {
	// REQUIRED; The query to execute.
	Query *string `json:"query,omitempty"`

	// Optional. The timespan over which to query data. This is an ISO8601 time period value. This timespan is applied in addition
	// to any that are specified in the query expression.
	Timespan *string `json:"timespan,omitempty"`

	// A list of workspaces that are included in the query.
	Workspaces []*string `json:"workspaces,omitempty"`
}

Body - The Analytics query. Learn more about the Analytics query syntax [https://azure.microsoft.com/documentation/articles/app-insights-analytics-reference/]

func (Body) MarshalJSON

func (b Body) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaller interface for type Body.

func (*Body) UnmarshalJSON

func (b *Body) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaller interface for type Body.

type Column

type Column struct {
	// The name of this column.
	Name *string `json:"name,omitempty"`

	// The data type of this column.
	Type *LogsColumnType `json:"type,omitempty"`
}

Column - A column in a table.

func (Column) MarshalJSON

func (c Column) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaller interface for type Column.

func (*Column) UnmarshalJSON

func (c *Column) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaller interface for type Column.

type ErrorDetail

type ErrorDetail struct {
	// REQUIRED; The error's code.
	Code *string `json:"code,omitempty"`

	// REQUIRED; A human readable error message.
	Message *string `json:"message,omitempty"`

	// Additional properties that can be provided on the error details object
	AdditionalProperties interface{} `json:"additionalProperties,omitempty"`

	// Indicates resources which were responsible for the error.
	Resources []*string `json:"resources,omitempty"`

	// Indicates which property in the request is responsible for the error.
	Target *string `json:"target,omitempty"`

	// Indicates which value in 'target' is responsible for the error.
	Value *string `json:"value,omitempty"`
}

ErrorDetail - Error details.

func (ErrorDetail) MarshalJSON

func (e ErrorDetail) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaller interface for type ErrorDetail.

func (*ErrorDetail) UnmarshalJSON

func (e *ErrorDetail) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaller interface for type ErrorDetail.

type ErrorInfo

type ErrorInfo struct {
	// REQUIRED; A machine readable error code.
	Code *string `json:"code,omitempty"`

	// REQUIRED; A human readable error message.
	Message *string `json:"message,omitempty"`

	// Additional properties that can be provided on the error info object
	AdditionalProperties interface{} `json:"additionalProperties,omitempty"`

	// error details.
	Details []*ErrorDetail `json:"details,omitempty"`

	// Inner error details if they exist.
	Innererror *ErrorInfo `json:"innererror,omitempty"`
}

ErrorInfo - The code and message for an error.

func (ErrorInfo) MarshalJSON

func (e ErrorInfo) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaller interface for type ErrorInfo.

func (*ErrorInfo) UnmarshalJSON

func (e *ErrorInfo) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaller interface for type ErrorInfo.

type LocalizableString

type LocalizableString struct {
	// REQUIRED; the invariant value.
	Value *string `json:"value,omitempty"`

	// the locale specific value.
	LocalizedValue *string `json:"localizedValue,omitempty"`
}

LocalizableString - The localizable string class.

func (LocalizableString) MarshalJSON

func (l LocalizableString) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaller interface for type LocalizableString.

func (*LocalizableString) UnmarshalJSON

func (l *LocalizableString) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaller interface for type LocalizableString.

type LogsClient

type LogsClient struct {
	// contains filtered or unexported fields
}

LogsClient contains the methods for the LogsClient group. Don't use this type directly, use NewLogsClient() instead.

func NewLogsClient

func NewLogsClient(credential azcore.TokenCredential, options *LogsClientOptions) *LogsClient

NewLogsClient creates a client that accesses Azure Monitor logs data.

Example
package main

import (
	"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
	"github.com/Azure/azure-sdk-for-go/sdk/monitor/azquery"
)

func main() {
	cred, err := azidentity.NewDefaultAzureCredential(nil)
	if err != nil {
		panic(err)
	}

	client := azquery.NewLogsClient(cred, nil)
	_ = client
}
Output:

func (*LogsClient) Batch

Batch - Executes a batch of Analytics queries for data. Here [https://dev.loganalytics.io/documentation/Using-the-API] is an example for using POST with an Analytics query. If the operation fails it returns an *azcore.ResponseError type. Generated from API version 2021-05-19_Preview body - The batch request body options - LogsClientBatchOptions contains the optional parameters for the LogsClient.Batch method.

Example
client := azquery.NewLogsClient(cred, nil)
timespan := "2022-08-30/2022-08-31"

batchRequest := azquery.BatchRequest{[]*azquery.BatchQueryRequest{
	{Body: &azquery.Body{Query: to.Ptr(kustoQuery1), Timespan: to.Ptr(timespan)}, ID: to.Ptr("1"), Workspace: to.Ptr(workspaceID)},
	{Body: &azquery.Body{Query: to.Ptr(kustoQuery2), Timespan: to.Ptr(timespan)}, ID: to.Ptr("2"), Workspace: to.Ptr(workspaceID)},
	{Body: &azquery.Body{Query: to.Ptr(kustoQuery3), Timespan: to.Ptr(timespan)}, ID: to.Ptr("3"), Workspace: to.Ptr(workspaceID)},
}}

res, err := client.Batch(context.TODO(), batchRequest, nil)
if err != nil {
	panic(err)
}
_ = res
Output:

func (*LogsClient) QueryWorkspace

func (client *LogsClient) QueryWorkspace(ctx context.Context, workspaceID string, body Body, options *LogsClientQueryWorkspaceOptions) (LogsClientQueryWorkspaceResponse, error)

QueryWorkspace - Executes an Analytics query for data. Here [https://dev.loganalytics.io/documentation/Using-the-API] is an example for using POST with an Analytics query. If the operation fails it returns an *azcore.ResponseError type. Generated from API version 2021-05-19_Preview workspaceID - ID of the workspace. This is Workspace ID from the Properties blade in the Azure portal. body - The Analytics query. Learn more about the Analytics query syntax [https://azure.microsoft.com/documentation/articles/app-insights-analytics-reference/] options - LogsClientQueryWorkspaceOptions contains the optional parameters for the LogsClient.QueryWorkspace method.

Example
client := azquery.NewLogsClient(cred, nil)
timespan := "2022-08-30/2022-08-31"

res, err := client.QueryWorkspace(context.TODO(), workspaceID,
	azquery.Body{Query: to.Ptr(query), Timespan: to.Ptr(timespan)}, nil)
if err != nil {
	panic(err)
}
_ = res
Output:

type LogsClientBatchOptions

type LogsClientBatchOptions struct {
}

LogsClientBatchOptions contains the optional parameters for the LogsClient.Batch method.

type LogsClientBatchResponse

type LogsClientBatchResponse struct {
	BatchResponse
}

LogsClientBatchResponse contains the response from method LogsClient.Batch.

type LogsClientOptions

type LogsClientOptions struct {
	azcore.ClientOptions
}

LogsClientOptions contains optional settings for LogsClient.

type LogsClientQueryWorkspaceOptions

type LogsClientQueryWorkspaceOptions struct {
	// Optional. The prefer header to set server timeout, query statistics and visualization information.
	Prefer *string
}

LogsClientQueryWorkspaceOptions contains the optional parameters for the LogsClient.QueryWorkspace method.

type LogsClientQueryWorkspaceResponse

type LogsClientQueryWorkspaceResponse struct {
	Results
}

LogsClientQueryWorkspaceResponse contains the response from method LogsClient.QueryWorkspace.

type LogsColumnType

type LogsColumnType string

LogsColumnType - The data type of this column.

const (
	LogsColumnTypeBool     LogsColumnType = "bool"
	LogsColumnTypeDatetime LogsColumnType = "datetime"
	LogsColumnTypeDecimal  LogsColumnType = "decimal"
	LogsColumnTypeDynamic  LogsColumnType = "dynamic"
	LogsColumnTypeGUID     LogsColumnType = "guid"
	LogsColumnTypeInt      LogsColumnType = "int"
	LogsColumnTypeLong     LogsColumnType = "long"
	LogsColumnTypeReal     LogsColumnType = "real"
	LogsColumnTypeString   LogsColumnType = "string"
	LogsColumnTypeTimespan LogsColumnType = "timespan"
)

func PossibleLogsColumnTypeValues

func PossibleLogsColumnTypeValues() []LogsColumnType

PossibleLogsColumnTypeValues returns the possible values for the LogsColumnType const type.

type MetadataValue

type MetadataValue struct {
	// the name of the metadata.
	Name *LocalizableString `json:"name,omitempty"`

	// the value of the metadata.
	Value *string `json:"value,omitempty"`
}

MetadataValue - Represents a metric metadata value.

func (MetadataValue) MarshalJSON

func (m MetadataValue) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaller interface for type MetadataValue.

func (*MetadataValue) UnmarshalJSON

func (m *MetadataValue) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaller interface for type MetadataValue.

type Metric

type Metric struct {
	// REQUIRED; the metric Id.
	ID *string `json:"id,omitempty"`

	// REQUIRED; the name and the display name of the metric, i.e. it is localizable string.
	Name *LocalizableString `json:"name,omitempty"`

	// REQUIRED; the time series returned when a data query is performed.
	Timeseries []*TimeSeriesElement `json:"timeseries,omitempty"`

	// REQUIRED; the resource type of the metric resource.
	Type *string `json:"type,omitempty"`

	// REQUIRED; The unit of the metric.
	Unit *MetricUnit `json:"unit,omitempty"`

	// Detailed description of this metric.
	DisplayDescription *string `json:"displayDescription,omitempty"`

	// 'Success' or the error details on query failures for this metric.
	ErrorCode *string `json:"errorCode,omitempty"`

	// Error message encountered querying this specific metric.
	ErrorMessage *string `json:"errorMessage,omitempty"`
}

Metric - The result data of a query.

func (Metric) MarshalJSON

func (m Metric) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaller interface for type Metric.

func (*Metric) UnmarshalJSON

func (m *Metric) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaller interface for type Metric.

type MetricAvailability

type MetricAvailability struct {
	// the retention period for the metric at the specified timegrain. Expressed as a duration 'PT1M', 'P1D', etc.
	Retention *string `json:"retention,omitempty"`

	// the time grain specifies the aggregation interval for the metric. Expressed as a duration 'PT1M', 'P1D', etc.
	TimeGrain *string `json:"timeGrain,omitempty"`
}

MetricAvailability - Metric availability specifies the time grain (aggregation interval or frequency) and the retention period for that time grain.

func (MetricAvailability) MarshalJSON

func (m MetricAvailability) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaller interface for type MetricAvailability.

func (*MetricAvailability) UnmarshalJSON

func (m *MetricAvailability) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaller interface for type MetricAvailability.

type MetricClass

type MetricClass string

MetricClass - The class of the metric.

const (
	MetricClassAvailability MetricClass = "Availability"
	MetricClassErrors       MetricClass = "Errors"
	MetricClassLatency      MetricClass = "Latency"
	MetricClassSaturation   MetricClass = "Saturation"
	MetricClassTransactions MetricClass = "Transactions"
)

func PossibleMetricClassValues

func PossibleMetricClassValues() []MetricClass

PossibleMetricClassValues returns the possible values for the MetricClass const type.

type MetricDefinition

type MetricDefinition struct {
	// Custom category name for this metric.
	Category *string `json:"category,omitempty"`

	// the name and the display name of the dimension, i.e. it is a localizable string.
	Dimensions []*LocalizableString `json:"dimensions,omitempty"`

	// Detailed description of this metric.
	DisplayDescription *string `json:"displayDescription,omitempty"`

	// the resource identifier of the metric definition.
	ID *string `json:"id,omitempty"`

	// Flag to indicate whether the dimension is required.
	IsDimensionRequired *bool `json:"isDimensionRequired,omitempty"`

	// the collection of what aggregation intervals are available to be queried.
	MetricAvailabilities []*MetricAvailability `json:"metricAvailabilities,omitempty"`

	// The class of the metric.
	MetricClass *MetricClass `json:"metricClass,omitempty"`

	// the name and the display name of the metric, i.e. it is a localizable string.
	Name *LocalizableString `json:"name,omitempty"`

	// the namespace the metric belongs to.
	Namespace *string `json:"namespace,omitempty"`

	// the primary aggregation type value defining how to use the values for display.
	PrimaryAggregationType *AggregationType `json:"primaryAggregationType,omitempty"`

	// the resource identifier of the resource that emitted the metric.
	ResourceID *string `json:"resourceId,omitempty"`

	// the collection of what aggregation types are supported.
	SupportedAggregationTypes []*AggregationType `json:"supportedAggregationTypes,omitempty"`

	// The unit of the metric.
	Unit *MetricUnit `json:"unit,omitempty"`
}

MetricDefinition - Metric definition class specifies the metadata for a metric.

func (MetricDefinition) MarshalJSON

func (m MetricDefinition) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaller interface for type MetricDefinition.

func (*MetricDefinition) UnmarshalJSON

func (m *MetricDefinition) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaller interface for type MetricDefinition.

type MetricDefinitionCollection

type MetricDefinitionCollection struct {
	// REQUIRED; the values for the metric definitions.
	Value []*MetricDefinition `json:"value,omitempty"`
}

MetricDefinitionCollection - Represents collection of metric definitions.

func (MetricDefinitionCollection) MarshalJSON

func (m MetricDefinitionCollection) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaller interface for type MetricDefinitionCollection.

func (*MetricDefinitionCollection) UnmarshalJSON

func (m *MetricDefinitionCollection) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaller interface for type MetricDefinitionCollection.

type MetricNamespace

type MetricNamespace struct {
	// Kind of namespace
	Classification *NamespaceClassification `json:"classification,omitempty"`

	// The ID of the metric namespace.
	ID *string `json:"id,omitempty"`

	// The escaped name of the namespace.
	Name *string `json:"name,omitempty"`

	// Properties which include the fully qualified namespace name.
	Properties *MetricNamespaceName `json:"properties,omitempty"`

	// The type of the namespace.
	Type *string `json:"type,omitempty"`
}

MetricNamespace - Metric namespace class specifies the metadata for a metric namespace.

func (MetricNamespace) MarshalJSON

func (m MetricNamespace) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaller interface for type MetricNamespace.

func (*MetricNamespace) UnmarshalJSON

func (m *MetricNamespace) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaller interface for type MetricNamespace.

type MetricNamespaceCollection

type MetricNamespaceCollection struct {
	// REQUIRED; The values for the metric namespaces.
	Value []*MetricNamespace `json:"value,omitempty"`
}

MetricNamespaceCollection - Represents collection of metric namespaces.

func (MetricNamespaceCollection) MarshalJSON

func (m MetricNamespaceCollection) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaller interface for type MetricNamespaceCollection.

func (*MetricNamespaceCollection) UnmarshalJSON

func (m *MetricNamespaceCollection) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaller interface for type MetricNamespaceCollection.

type MetricNamespaceName

type MetricNamespaceName struct {
	// The metric namespace name.
	MetricNamespaceName *string `json:"metricNamespaceName,omitempty"`
}

MetricNamespaceName - The fully qualified metric namespace name.

func (MetricNamespaceName) MarshalJSON

func (m MetricNamespaceName) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaller interface for type MetricNamespaceName.

func (*MetricNamespaceName) UnmarshalJSON

func (m *MetricNamespaceName) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaller interface for type MetricNamespaceName.

type MetricUnit

type MetricUnit string

MetricUnit - The unit of the metric.

const (
	MetricUnitBitsPerSecond  MetricUnit = "BitsPerSecond"
	MetricUnitByteSeconds    MetricUnit = "ByteSeconds"
	MetricUnitBytes          MetricUnit = "Bytes"
	MetricUnitBytesPerSecond MetricUnit = "BytesPerSecond"
	MetricUnitCores          MetricUnit = "Cores"
	MetricUnitCount          MetricUnit = "Count"
	MetricUnitCountPerSecond MetricUnit = "CountPerSecond"
	MetricUnitMilliCores     MetricUnit = "MilliCores"
	MetricUnitMilliSeconds   MetricUnit = "MilliSeconds"
	MetricUnitNanoCores      MetricUnit = "NanoCores"
	MetricUnitPercent        MetricUnit = "Percent"
	MetricUnitSeconds        MetricUnit = "Seconds"
	MetricUnitUnspecified    MetricUnit = "Unspecified"
)

func PossibleMetricUnitValues

func PossibleMetricUnitValues() []MetricUnit

PossibleMetricUnitValues returns the possible values for the MetricUnit const type.

type MetricValue

type MetricValue struct {
	// REQUIRED; the timestamp for the metric value in ISO 8601 format.
	TimeStamp *time.Time `json:"timeStamp,omitempty"`

	// the average value in the time range.
	Average *float64 `json:"average,omitempty"`

	// the number of samples in the time range. Can be used to determine the number of values that contributed to the average
	// value.
	Count *float64 `json:"count,omitempty"`

	// the greatest value in the time range.
	Maximum *float64 `json:"maximum,omitempty"`

	// the least value in the time range.
	Minimum *float64 `json:"minimum,omitempty"`

	// the sum of all of the values in the time range.
	Total *float64 `json:"total,omitempty"`
}

MetricValue - Represents a metric value.

func (MetricValue) MarshalJSON

func (m MetricValue) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaller interface for type MetricValue.

func (*MetricValue) UnmarshalJSON

func (m *MetricValue) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaller interface for type MetricValue.

type MetricsClient

type MetricsClient struct {
	// contains filtered or unexported fields
}

MetricsClient contains the methods for the Metrics group. Don't use this type directly, use NewMetricsClient() instead.

func NewMetricsClient

func NewMetricsClient(credential azcore.TokenCredential, options *MetricsClientOptions) *MetricsClient

NewMetricsClient creates a client that accesses Azure Monitor metrics data.

Example
package main

import (
	"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
	"github.com/Azure/azure-sdk-for-go/sdk/monitor/azquery"
)

func main() {
	cred, err := azidentity.NewDefaultAzureCredential(nil)
	if err != nil {
		panic(err)
	}

	client := azquery.NewMetricsClient(cred, nil)
	_ = client
}
Output:

func (*MetricsClient) NewListMetricDefinitionsPager

func (client *MetricsClient) NewListMetricDefinitionsPager(resourceURI string, options *MetricsClientListMetricDefinitionsOptions) *runtime.Pager[MetricsClientListMetricDefinitionsResponse]

NewListMetricDefinitionsPager - Lists the metric definitions for the resource. Generated from API version 2018-01-01 resourceURI - The identifier of the resource. options - MetricsClientListMetricDefinitionsOptions contains the optional parameters for the MetricsClient.ListMetricDefinitions method.

func (*MetricsClient) NewListMetricNamespacesPager

func (client *MetricsClient) NewListMetricNamespacesPager(resourceURI string, options *MetricsClientListMetricNamespacesOptions) *runtime.Pager[MetricsClientListMetricNamespacesResponse]

NewListMetricNamespacesPager - Lists the metric namespaces for the resource. Generated from API version 2017-12-01-preview resourceURI - The identifier of the resource. options - MetricsClientListMetricNamespacesOptions contains the optional parameters for the MetricsClient.ListMetricNamespaces method.

func (*MetricsClient) QueryResource

QueryResource - Lists the metric values for a resource. If the operation fails it returns an *azcore.ResponseError type. Generated from API version 2018-01-01 resourceURI - The identifier of the resource. options - MetricsClientQueryResourceOptions contains the optional parameters for the MetricsClient.QueryResource method.

Example
client := azquery.NewMetricsClient(cred, nil)
res, err := client.QueryResource(context.Background(), resourceURI,
	&azquery.MetricsClientQueryResourceOptions{Timespan: to.Ptr("2017-04-14T02:20:00Z/2017-04-14T04:20:00Z"),
		Interval:        to.Ptr("PT1M"),
		Metricnames:     nil,
		Aggregation:     to.Ptr("Average,count"),
		Top:             to.Ptr[int32](3),
		Orderby:         to.Ptr("Average asc"),
		Filter:          to.Ptr("BlobType eq '*'"),
		ResultType:      nil,
		Metricnamespace: to.Ptr("Microsoft.Storage/storageAccounts/blobServices"),
	})
if err != nil {
	panic(err)
}
_ = res
Output:

type MetricsClientListMetricDefinitionsOptions

type MetricsClientListMetricDefinitionsOptions struct {
	// Metric namespace to query metric definitions for.
	Metricnamespace *string
}

MetricsClientListMetricDefinitionsOptions contains the optional parameters for the MetricsClient.ListMetricDefinitions method.

type MetricsClientListMetricDefinitionsResponse

type MetricsClientListMetricDefinitionsResponse struct {
	MetricDefinitionCollection
}

MetricsClientListMetricDefinitionsResponse contains the response from method MetricsClient.ListMetricDefinitions.

type MetricsClientListMetricNamespacesOptions

type MetricsClientListMetricNamespacesOptions struct {
	// The ISO 8601 conform Date start time from which to query for metric namespaces.
	StartTime *string
}

MetricsClientListMetricNamespacesOptions contains the optional parameters for the MetricsClient.ListMetricNamespaces method.

type MetricsClientListMetricNamespacesResponse

type MetricsClientListMetricNamespacesResponse struct {
	MetricNamespaceCollection
}

MetricsClientListMetricNamespacesResponse contains the response from method MetricsClient.ListMetricNamespaces.

type MetricsClientOptions

type MetricsClientOptions struct {
	azcore.ClientOptions
}

MetricsClientOptions contains optional settings for MetricsClient.

type MetricsClientQueryResourceOptions

type MetricsClientQueryResourceOptions struct {
	// The list of aggregation types (comma separated) to retrieve.
	Aggregation *string
	// The $filter is used to reduce the set of metric data returned. Example: Metric contains metadata A, B and C. - Return all
	// time series of C where A = a1 and B = b1 or b2 $filter=A eq 'a1' and B eq 'b1'
	// or B eq 'b2' and C eq ” - Invalid variant: $filter=A eq 'a1' and B eq 'b1' and C eq ” or B = 'b2' This is invalid because
	// the logical or operator cannot separate two different metadata names. -
	// Return all time series where A = a1, B = b1 and C = c1: $filter=A eq 'a1' and B eq 'b1' and C eq 'c1' - Return all time
	// series where A = a1 $filter=A eq 'a1' and B eq ” and C eq ”. Special case:
	// When dimension name or dimension value uses round brackets. Eg: When dimension name is dim (test) 1 Instead of using $filter=
	// "dim (test) 1 eq ” " use $filter= "dim %2528test%2529 1 eq ” " When
	// dimension name is dim (test) 3 and dimension value is dim3 (test) val Instead of using $filter= "dim (test) 3 eq 'dim3
	// (test) val' " use $filter= "dim %2528test%2529 3 eq 'dim3 %2528test%2529 val' "
	Filter *string
	// The interval (i.e. timegrain) of the query.
	Interval *string
	// The names of the metrics (comma separated) to retrieve. Special case: If a metricname itself has a comma in it then use
	// %2 to indicate it. Eg: 'Metric,Name1' should be 'Metric%2Name1'
	Metricnames *string
	// Metric namespace to query metric definitions for.
	Metricnamespace *string
	// The aggregation to use for sorting results and the direction of the sort. Only one order can be specified. Examples: sum
	// asc.
	Orderby *string
	// Reduces the set of data collected. The syntax allowed depends on the operation. See the operation's description for details.
	ResultType *ResultType
	// The timespan of the query. It is a string with the following format 'startDateTimeISO/endDateTimeISO'.
	Timespan *string
	// The maximum number of records to retrieve. Valid only if $filter is specified. Defaults to 10.
	Top *int32
}

MetricsClientQueryResourceOptions contains the optional parameters for the MetricsClient.QueryResource method.

type MetricsClientQueryResourceResponse

type MetricsClientQueryResourceResponse struct {
	Response
}

MetricsClientQueryResourceResponse contains the response from method MetricsClient.QueryResource.

type NamespaceClassification

type NamespaceClassification string

NamespaceClassification - Kind of namespace

const (
	NamespaceClassificationCustom   NamespaceClassification = "Custom"
	NamespaceClassificationPlatform NamespaceClassification = "Platform"
	NamespaceClassificationQos      NamespaceClassification = "Qos"
)

func PossibleNamespaceClassificationValues

func PossibleNamespaceClassificationValues() []NamespaceClassification

PossibleNamespaceClassificationValues returns the possible values for the NamespaceClassification const type.

type Response

type Response struct {
	// REQUIRED; The timespan for which the data was retrieved. Its value consists of two datetimes concatenated, separated by
	// '/'. This may be adjusted in the future and returned back from what was originally
	// requested.
	Timespan *string `json:"timespan,omitempty"`

	// REQUIRED; the value of the collection.
	Value []*Metric `json:"value,omitempty"`

	// The integer value representing the relative cost of the query.
	Cost *int32 `json:"cost,omitempty"`

	// The interval (window size) for which the metric data was returned in. This may be adjusted in the future and returned back
	// from what was originally requested. This is not present if a metadata request
	// was made.
	Interval *string `json:"interval,omitempty"`

	// The namespace of the metrics being queried
	Namespace *string `json:"namespace,omitempty"`

	// The region of the resource being queried for metrics.
	Resourceregion *string `json:"resourceregion,omitempty"`
}

Response - The response to a metrics query.

func (Response) MarshalJSON

func (r Response) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaller interface for type Response.

func (*Response) UnmarshalJSON

func (r *Response) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaller interface for type Response.

type ResultType

type ResultType string

ResultType - Reduces the set of data collected. The syntax allowed depends on the operation. See the operation's description for details.

const (
	ResultTypeData     ResultType = "Data"
	ResultTypeMetadata ResultType = "Metadata"
)

func PossibleResultTypeValues

func PossibleResultTypeValues() []ResultType

PossibleResultTypeValues returns the possible values for the ResultType const type.

type Results

type Results struct {
	// REQUIRED; The list of tables, columns and rows.
	Tables []*Table `json:"tables,omitempty"`

	// The code and message for an error.
	Error *ErrorInfo `json:"error,omitempty"`

	// Visualization data in JSON format.
	Render interface{} `json:"render,omitempty"`

	// Statistics represented in JSON format.
	Statistics interface{} `json:"statistics,omitempty"`
}

Results - Contains the tables, columns & rows resulting from a query.

func (Results) MarshalJSON

func (r Results) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaller interface for type Results.

func (*Results) UnmarshalJSON

func (r *Results) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaller interface for type Results.

type Table

type Table struct {
	// REQUIRED; The list of columns in this table.
	Columns []*Column `json:"columns,omitempty"`

	// REQUIRED; The name of the table.
	Name *string `json:"name,omitempty"`

	// REQUIRED; The resulting rows from this query.
	Rows [][]interface{} `json:"rows,omitempty"`
}

Table - Contains the columns and rows for one table in a query response.

func (Table) MarshalJSON

func (t Table) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaller interface for type Table.

func (*Table) UnmarshalJSON

func (t *Table) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaller interface for type Table.

type TimeSeriesElement

type TimeSeriesElement struct {
	// An array of data points representing the metric values. This is only returned if a result type of data is specified.
	Data []*MetricValue `json:"data,omitempty"`

	// the metadata values returned if $filter was specified in the call.
	Metadatavalues []*MetadataValue `json:"metadatavalues,omitempty"`
}

TimeSeriesElement - A time series result type. The discriminator value is always TimeSeries in this case.

func (TimeSeriesElement) MarshalJSON

func (t TimeSeriesElement) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaller interface for type TimeSeriesElement.

func (*TimeSeriesElement) UnmarshalJSON

func (t *TimeSeriesElement) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaller interface for type TimeSeriesElement.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL