Documentation ¶
Index ¶
- Constants
- type AggregationType
- type BatchQueryRequest
- type BatchQueryRequestMethod
- type BatchQueryRequestPath
- type BatchQueryResponse
- type BatchQueryResults
- type BatchRequest
- type BatchResponse
- type Body
- type Column
- type ErrorInfo
- type LocalizableString
- type LogsClient
- func (client *LogsClient) QueryBatch(ctx context.Context, body BatchRequest, options *LogsClientQueryBatchOptions) (LogsClientQueryBatchResponse, error)
- func (client *LogsClient) QueryResource(ctx context.Context, resourceID string, body Body, ...) (LogsClientQueryResourceResponse, error)
- func (client *LogsClient) QueryWorkspace(ctx context.Context, workspaceID string, body Body, ...) (LogsClientQueryWorkspaceResponse, error)
- type LogsClientOptions
- type LogsClientQueryBatchOptions
- type LogsClientQueryBatchResponse
- type LogsClientQueryResourceOptions
- type LogsClientQueryResourceResponse
- type LogsClientQueryWorkspaceOptions
- type LogsClientQueryWorkspaceResponse
- type LogsColumnType
- type LogsQueryOptions
- type MetadataValue
- type Metric
- type MetricAvailability
- type MetricClass
- type MetricDefinition
- type MetricDefinitionCollection
- type MetricNamespace
- type MetricNamespaceCollection
- type MetricNamespaceName
- type MetricUnit
- type MetricValue
- type MetricsClient
- func (client *MetricsClient) NewListDefinitionsPager(resourceURI string, options *MetricsClientListDefinitionsOptions) *runtime.Pager[MetricsClientListDefinitionsResponse]
- func (client *MetricsClient) NewListNamespacesPager(resourceURI string, options *MetricsClientListNamespacesOptions) *runtime.Pager[MetricsClientListNamespacesResponse]
- func (client *MetricsClient) QueryResource(ctx context.Context, resourceURI string, ...) (MetricsClientQueryResourceResponse, error)
- type MetricsClientListDefinitionsOptions
- type MetricsClientListDefinitionsResponse
- type MetricsClientListNamespacesOptions
- type MetricsClientListNamespacesResponse
- type MetricsClientOptions
- type MetricsClientQueryResourceOptions
- type MetricsClientQueryResourceResponse
- type NamespaceClassification
- type Response
- type ResultType
- type Results
- type Row
- type Table
- type TimeInterval
- type TimeSeriesElement
Examples ¶
Constants ¶
const ( ServiceNameLogs cloud.ServiceName = "azqueryLogs" ServiceNameMetrics cloud.ServiceName = "azqueryMetrics" )
Cloud Service Names for Monitor Query Logs and Metrics, used to identify the respective cloud.ServiceConfiguration
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; Unique ID corresponding to each request in the batch CorrelationID *string `json:"id,omitempty"` // REQUIRED; Primary Workspace ID of the query WorkspaceID *string `json:"workspace,omitempty"` // Optional. Headers of the request. Can use prefer header to set server timeout, query statistics and visualization information. // For more information, see // https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/monitor/azquery#readme-increase-wait-time-include-statistics-include-render-visualization 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 NewBatchQueryRequest ¶ added in v0.4.0
func NewBatchQueryRequest(workspaceID string, query string, timespan TimeInterval, correlationID string, options LogsQueryOptions) BatchQueryRequest
NewBatchQueryRequest creates a new BatchQueryRequest.
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"` CorrelationID *string `json:"id,omitempty"` // Dictionary of Headers map[string]*string `json:"headers,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"` // Statistics represented in JSON format. Statistics []byte `json:"statistics,omitempty"` // The results of the query in tabular format. Tables []*Table `json:"tables,omitempty"` // Visualization data in JSON format. Visualization []byte `json:"render,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"` // A list of workspaces to query in addition to the primary workspace. AdditionalWorkspaces []*string `json:"workspaces,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 *TimeInterval `json:"timespan,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 ¶
MarshalJSON implements the json.Marshaller interface for type Body.
func (*Body) UnmarshalJSON ¶
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 ¶
MarshalJSON implements the json.Marshaller interface for type Column.
func (*Column) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaller interface for type Column.
type ErrorInfo ¶
type ErrorInfo struct { // REQUIRED; A machine readable error code. Code string // contains filtered or unexported fields }
ErrorInfo - The code and message for an error.
func (*ErrorInfo) UnmarshalJSON ¶
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 Logs group. Don't use this type directly, use a constructor function instead.
func NewLogsClient ¶
func NewLogsClient(credential azcore.TokenCredential, options *LogsClientOptions) (*LogsClient, error)
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 { //TODO: handle error } client, err := azquery.NewLogsClient(cred, nil) if err != nil { //TODO: handle error } _ = client }
Output:
func (*LogsClient) QueryBatch ¶ added in v0.3.0
func (client *LogsClient) QueryBatch(ctx context.Context, body BatchRequest, options *LogsClientQueryBatchOptions) (LogsClientQueryBatchResponse, error)
QueryBatch - Executes a batch of Analytics queries for data. If the operation fails it returns an *azcore.ResponseError type.
Generated from API version 2022-10-27
- body - The batch request body
- options - LogsClientQueryBatchOptions contains the optional parameters for the LogsClient.QueryBatch method.
Example ¶
package main import ( "context" "fmt" "time" "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" "github.com/Azure/azure-sdk-for-go/sdk/monitor/azquery" ) var logsClient azquery.LogsClient var kustoQuery1 string var kustoQuery2 string var kustoQuery3 string func main() { // `QueryBatch` is an advanced method allowing users to execute multiple log queries in a single request. // For help formatting a `BatchRequest`, please use the method `NewBatchQueryRequest`. workspaceID := "g4d1e129-fb1e-4b0a-b234-250abc987ea65" // example Azure Log Analytics Workspace ID timespan := azquery.NewTimeInterval(time.Date(2022, 12, 25, 0, 0, 0, 0, time.UTC), time.Date(2022, 12, 25, 12, 0, 0, 0, time.UTC)) batchRequest := azquery.BatchRequest{[]*azquery.BatchQueryRequest{ {Body: &azquery.Body{Query: to.Ptr(kustoQuery1), Timespan: to.Ptr(timespan)}, CorrelationID: to.Ptr("1"), WorkspaceID: to.Ptr(workspaceID)}, {Body: &azquery.Body{Query: to.Ptr(kustoQuery2), Timespan: to.Ptr(timespan)}, CorrelationID: to.Ptr("2"), WorkspaceID: to.Ptr(workspaceID)}, {Body: &azquery.Body{Query: to.Ptr(kustoQuery3), Timespan: to.Ptr(timespan)}, CorrelationID: to.Ptr("3"), WorkspaceID: to.Ptr(workspaceID)}, }} res, err := logsClient.QueryBatch(context.TODO(), batchRequest, nil) if err != nil { //TODO: handle error } // `QueryBatch` can return results in any order, usually by time it takes each individual query to complete. // Use the `CorrelationID` field to identify the correct response. responses := res.BatchResponse.Responses fmt.Println("ID's of successful responses:") for _, response := range responses { if response.Body.Error == nil { fmt.Println(*response.CorrelationID) } } }
Output:
func (*LogsClient) QueryResource ¶ added in v1.1.0
func (client *LogsClient) QueryResource(ctx context.Context, resourceID string, body Body, options *LogsClientQueryResourceOptions) (LogsClientQueryResourceResponse, error)
QueryResource - Executes an Analytics query for data in the context of a resource. Here [https://docs.microsoft.com/azure/azure-monitor/logs/api/azure-resource-queries] is an example for using POST with an Analytics query. If the operation fails it returns an *azcore.ResponseError type.
Generated from API version 2022-10-27
- resourceID - The identifier of the resource.
- body - The Analytics query. Learn more about the Analytics query syntax [https://azure.microsoft.com/documentation/articles/app-insights-analytics-reference/]
- options - LogsClientQueryResourceOptions contains the optional parameters for the LogsClient.QueryResource method.
Example ¶
package main import ( "context" "fmt" "time" "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" "github.com/Azure/azure-sdk-for-go/sdk/monitor/azquery" ) var logsClient azquery.LogsClient func main() { // Instead of requiring a Log Analytics workspace, // QueryResource allows users to query logs directly from an Azure resource through a resource ID. // To find the resource ID: // 1. Navigate to your resource's page in the Azure portal. // 2. From the **Overview** blade, select the **JSON View** link. // 3. In the resulting JSON, copy the value of the `id` property. resourceID := "/subscriptions/fajfkx93-c1d8-40ad-9cce-e49c10ca8qe6/resourceGroups/testgroup/providers/Microsoft.Storage/storageAccounts/mystorageacount" // example resource ID res, err := logsClient.QueryResource( context.TODO(), resourceID, azquery.Body{ Query: to.Ptr("StorageBlobLogs | where TimeGenerated > ago(3d)"), // example Kusto query Timespan: to.Ptr(azquery.NewTimeInterval(time.Date(2022, 12, 25, 0, 0, 0, 0, time.UTC), time.Date(2022, 12, 25, 12, 0, 0, 0, time.UTC))), }, nil) if err != nil { //TODO: handle error } if res.Error != nil { //TODO: handle partial error } // Print Rows for _, table := range res.Tables { for _, row := range table.Rows { fmt.Println(row) } } }
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. If the operation fails it returns an *azcore.ResponseError type.
Generated from API version 2022-10-27
- workspaceID - Primary Workspace ID of the query. 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 ¶
package main import ( "context" "fmt" "time" "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" "github.com/Azure/azure-sdk-for-go/sdk/monitor/azquery" ) var logsClient azquery.LogsClient func main() { // QueryWorkspace allows users to query log data. // A workspace ID is required to query logs. To find the workspace ID: // 1. If not already made, create a Log Analytics workspace (https://learn.microsoft.com/azure/azure-monitor/logs/quick-create-workspace). // 2. Navigate to your workspace's page in the Azure portal. // 3. From the **Overview** blade, copy the value of the ***Workspace ID*** property. workspaceID := "g4d1e129-fb1e-4b0a-b234-250abc987ea65" // example Azure Log Analytics Workspace ID res, err := logsClient.QueryWorkspace( context.TODO(), workspaceID, azquery.Body{ Query: to.Ptr("AzureActivity | top 10 by TimeGenerated"), // example Kusto query Timespan: to.Ptr(azquery.NewTimeInterval(time.Date(2022, 12, 25, 0, 0, 0, 0, time.UTC), time.Date(2022, 12, 25, 12, 0, 0, 0, time.UTC))), }, nil) if err != nil { //TODO: handle error } if res.Error != nil { //TODO: handle partial error } // Print Rows for _, table := range res.Tables { for _, row := range table.Rows { fmt.Println(row) } } }
Output:
Example (Second) ¶
// `QueryWorkspace` also has more advanced options, including querying multiple workspaces // and LogsQueryOptions (including statistics and visualization information and increasing default timeout). // 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. workspaceID1 := "g4d1e129-fb1e-4b0a-b234-250abc987ea65" // example Azure Log Analytics Workspace ID workspaceID2 := "h4bc4471-2e8c-4b1c-8f47-12b9a4d5ac71" additionalWorkspaces := []*string{to.Ptr(workspaceID2)} // Advanced query options // Setting Statistics to true returns stats information in Results.Statistics // Setting Visualization to true returns visualization information in Results.Visualization options := &azquery.LogsClientQueryWorkspaceOptions{ Options: &azquery.LogsQueryOptions{ Statistics: to.Ptr(true), Visualization: to.Ptr(true), Wait: to.Ptr(600), }, } res, err := logsClient.QueryWorkspace( context.TODO(), workspaceID1, azquery.Body{ Query: to.Ptr(query), Timespan: to.Ptr(azquery.NewTimeInterval(time.Date(2022, 12, 25, 0, 0, 0, 0, time.UTC), time.Date(2022, 12, 25, 12, 0, 0, 0, time.UTC))), AdditionalWorkspaces: additionalWorkspaces, }, options) if err != nil { //TODO: handle error } if res.Error != nil { //TODO: handle partial error } // Example of converting table data into a slice of structs. // Query results are returned in Table Rows and are of type any. // Type assertion is required to access the underlying value of each index in a Row. var QueryResults []queryResult for _, table := range res.Tables { QueryResults = make([]queryResult, len(table.Rows)) for index, row := range table.Rows { QueryResults[index] = queryResult{ Bool: row[0].(bool), Long: int64(row[1].(float64)), Double: float64(row[2].(float64)), String: row[3].(string), } } } fmt.Println(QueryResults) // Print out Statistics fmt.Printf("Statistics: %s", string(res.Statistics)) // Print out Visualization information fmt.Printf("Visualization: %s", string(res.Visualization))
Output:
type LogsClientOptions ¶
type LogsClientOptions struct {
azcore.ClientOptions
}
LogsClientOptions contains optional settings for LogsClient.
type LogsClientQueryBatchOptions ¶ added in v0.3.0
type LogsClientQueryBatchOptions struct { }
LogsClientQueryBatchOptions contains the optional parameters for the LogsClient.QueryBatch method.
type LogsClientQueryBatchResponse ¶ added in v0.3.0
type LogsClientQueryBatchResponse struct {
BatchResponse
}
LogsClientQueryBatchResponse contains the response from method LogsClient.QueryBatch.
type LogsClientQueryResourceOptions ¶ added in v1.1.0
type LogsClientQueryResourceOptions struct { // Optional. The prefer header to set server timeout, query statistics and visualization information. Options *LogsQueryOptions }
LogsClientQueryResourceOptions contains the optional parameters for the LogsClient.QueryResource method.
type LogsClientQueryResourceResponse ¶ added in v1.1.0
type LogsClientQueryResourceResponse struct {
Results
}
LogsClientQueryResourceResponse contains the response from method LogsClient.QueryResource.
type LogsClientQueryWorkspaceOptions ¶
type LogsClientQueryWorkspaceOptions struct { // Optional. The prefer header to set server timeout, query statistics and visualization information. Options *LogsQueryOptions }
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 LogsQueryOptions ¶ added in v0.4.0
type LogsQueryOptions struct { // Set Statistics to true to get logs query execution statistics, // such as CPU and memory consumption. Defaults to false. Statistics *bool // Set Visualization to true to get visualization // data for logs queries. Defaults to false. Visualization *bool // 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. // Max wait time the service will allow is ten minutes (600 seconds). Wait *int }
LogsQueryOptions sets server timeout, query statistics and visualization information
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 ¶
MarshalJSON implements the json.Marshaller interface for type Metric.
func (*Metric) UnmarshalJSON ¶
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 a constructor function instead.
func NewMetricsClient ¶
func NewMetricsClient(credential azcore.TokenCredential, options *MetricsClientOptions) (*MetricsClient, error)
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 { //TODO: handle error } client, err := azquery.NewMetricsClient(cred, nil) if err != nil { //TODO: handle error } _ = client }
Output:
func (*MetricsClient) NewListDefinitionsPager ¶ added in v0.3.0
func (client *MetricsClient) NewListDefinitionsPager(resourceURI string, options *MetricsClientListDefinitionsOptions) *runtime.Pager[MetricsClientListDefinitionsResponse]
NewListDefinitionsPager - Lists the metric definitions for the resource.
Generated from API version 2018-01-01
- resourceURI - The identifier of the resource.
- options - MetricsClientListDefinitionsOptions contains the optional parameters for the MetricsClient.NewListDefinitionsPager method.
Example ¶
pager := metricsClient.NewListDefinitionsPager(resourceURI, &azquery.MetricsClientListDefinitionsOptions{MetricNamespace: to.Ptr("microsoft.insights/components")}) for pager.More() { nextResult, err := pager.NextPage(context.TODO()) if err != nil { //TODO: handle error } for _, v := range nextResult.Value { // TODO: use page item _ = v } }
Output:
func (*MetricsClient) NewListNamespacesPager ¶ added in v0.3.0
func (client *MetricsClient) NewListNamespacesPager(resourceURI string, options *MetricsClientListNamespacesOptions) *runtime.Pager[MetricsClientListNamespacesResponse]
NewListNamespacesPager - Lists the metric namespaces for the resource.
Generated from API version 2017-12-01-preview
- resourceURI - The identifier of the resource.
- options - MetricsClientListNamespacesOptions contains the optional parameters for the MetricsClient.NewListNamespacesPager method.
Example ¶
pager := metricsClient.NewListNamespacesPager(resourceURI, &azquery.MetricsClientListNamespacesOptions{StartTime: to.Ptr("2020-08-31T15:53:00Z")}) for pager.More() { nextResult, err := pager.NextPage(context.TODO()) if err != nil { //TODO: handle error } for _, v := range nextResult.Value { // TODO: use page item _ = v } }
Output:
func (*MetricsClient) QueryResource ¶
func (client *MetricsClient) QueryResource(ctx context.Context, resourceURI string, options *MetricsClientQueryResourceOptions) (MetricsClientQueryResourceResponse, error)
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 ¶
package main import ( "context" "fmt" "time" "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" "github.com/Azure/azure-sdk-for-go/sdk/monitor/azquery" ) var metricsClient azquery.MetricsClient func main() { // QueryResource is used to query metrics on an Azure resource. // For each requested metric, a set of aggregated values is returned inside the `TimeSeries` collection. // resource ID is required to query metrics. To find the resource ID: // 1. Navigate to your resource's page in the Azure portal. // 2. From the **Overview** blade, select the **JSON View** link. // 3. In the resulting JSON, copy the value of the `id` property. resourceURI := "subscriptions/182c901a-129a-4f5d-86e4-afdsb294590a2/resourceGroups/test-log/providers/microsoft.insights/components/f1-bill/providers/microsoft.insights/metricdefinitions" res, err := metricsClient.QueryResource(context.TODO(), resourceURI, &azquery.MetricsClientQueryResourceOptions{ Timespan: to.Ptr(azquery.NewTimeInterval(time.Date(2022, 12, 25, 0, 0, 0, 0, time.UTC), time.Date(2022, 12, 25, 12, 0, 0, 0, time.UTC))), Interval: to.Ptr("PT1M"), MetricNames: nil, Aggregation: to.SliceOfPtrs(azquery.AggregationTypeAverage, azquery.AggregationTypeCount), 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 { //TODO: handle error } // Print out metric name and the time stamps of each metric data point for _, metric := range res.Value { fmt.Println(*metric.Name.Value) for _, timeSeriesElement := range metric.TimeSeries { for _, metricValue := range timeSeriesElement.Data { fmt.Println(metricValue.TimeStamp) } } } }
Output:
type MetricsClientListDefinitionsOptions ¶ added in v0.3.0
type MetricsClientListDefinitionsOptions struct { // Metric namespace to query metric definitions for. MetricNamespace *string }
MetricsClientListDefinitionsOptions contains the optional parameters for the MetricsClient.NewListDefinitionsPager method.
type MetricsClientListDefinitionsResponse ¶ added in v0.3.0
type MetricsClientListDefinitionsResponse struct {
MetricDefinitionCollection
}
MetricsClientListDefinitionsResponse contains the response from method MetricsClient.NewListDefinitionsPager.
type MetricsClientListNamespacesOptions ¶ added in v0.3.0
type MetricsClientListNamespacesOptions struct { // The ISO 8601 conform Date start time from which to query for metric namespaces. StartTime *string }
MetricsClientListNamespacesOptions contains the optional parameters for the MetricsClient.NewListNamespacesPager method.
type MetricsClientListNamespacesResponse ¶ added in v0.3.0
type MetricsClientListNamespacesResponse struct {
MetricNamespaceCollection
}
MetricsClientListNamespacesResponse contains the response from method MetricsClient.NewListNamespacesPager.
type MetricsClientOptions ¶
type MetricsClientOptions struct {
azcore.ClientOptions
}
MetricsClientOptions contains optional settings for MetricsClient.
type MetricsClientQueryResourceOptions ¶
type MetricsClientQueryResourceOptions struct { // The list of aggregation types to retrieve Aggregation []*AggregationType // 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 *TimeInterval // 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 *TimeInterval `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 ¶
MarshalJSON implements the json.Marshaller interface for type Response.
func (*Response) UnmarshalJSON ¶
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 results of the query in tabular format. Tables []*Table `json:"tables,omitempty"` // The code and message for an error. Error *ErrorInfo `json:"error,omitempty"` // Statistics represented in JSON format. Statistics []byte `json:"statistics,omitempty"` // Visualization data in JSON format. Visualization []byte `json:"render,omitempty"` }
Results - Contains the tables, columns & rows resulting from a query.
func (Results) MarshalJSON ¶
MarshalJSON implements the json.Marshaller interface for type Results.
func (*Results) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaller interface for type Results.
type Row ¶ added in v0.3.0
type Row []any
Row of data in a table, types of data used by service specified in LogsColumnType
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 []Row `json:"rows,omitempty"` }
Table - Contains the columns and rows for one table in a query response.
func (Table) MarshalJSON ¶
MarshalJSON implements the json.Marshaller interface for type Table.
func (*Table) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaller interface for type Table.
type TimeInterval ¶ added in v0.4.0
type TimeInterval string
TimeInterval specifies the time range over which to query. Use NewTimeInterval() for help formatting. Follows the ISO8601 time interval standard with most common format being startISOTime/endISOTime. ISO8601 durations also supported (ex "PT2H" for last two hours). Use UTC for all times.
func NewTimeInterval ¶ added in v0.4.0
func NewTimeInterval(start time.Time, end time.Time) TimeInterval
NewTimeInterval creates a TimeInterval for use in a query. Use UTC for start and end times.
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.