azuremonitormetricsreceiver

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2024 License: MIT Imports: 8 Imported by: 1

README

Azure Monitor Metrics Receiver

An SDK wrapper that uses Azure Monitor SDK. Lets you receive metrics of Azure resources using Azure Monitor API in 3 ways:

  • Resource Target
  • Resource Group Target
  • Subscription Target

Azure Credential

Uses client_id, client_secret and tenant_id for authentication (access token), and subscription_id for accessing Azure resources.

Here how to find each of them:

subscription_id can be found under Overview->Essentials in the Azure portal for your application/service.

client_id and client_secret can be obtained by registering an application under Azure Active Directory.

tenant_id can be found under Azure Active Directory->Properties.

Resource Target

get metrics of a specific resource.

type ResourceTarget struct {
	ResourceID   string
	Metrics      []string
	Aggregations []string
}

ResourceID can be found under Overview->Essentials->JSON View (link) in the Azure portal for your application/service.

Must start with 'resourceGroups/...' ('/subscriptions/xxxxxxxx-xxxx-xxxx-xxx-xxxxxxxxxxxx' must be removed from the beginning of Resource ID property value)

Metrics is an array of the name of the metrics that you want to collect. Pay attention: all metrics should be valid metrics of the resource target.

  • If the array is empty, all available metrics of the resource target will be collected.

Aggregations is an array of the metrics aggregation type value to collect. The available aggregations are:

  • Total
  • Count
  • Average
  • Minimum
  • Maximum
  • If the array is empty, all aggregation types values will be collected for each metric.

Resource Group Target

get metrics of resources under specific resource group, using resource types.

type ResourceGroupTarget struct {
    resourceGroup string
    resources     []*Resource
}

resourceGroup is the name of the resource group.

resources is an array of resources that are under the same resourceGroup.

  • Info about Resource can be found in Subscription Target section.

Subscription Target

get metrics of resources under the subscription, using resource types.

type Resource struct {
    resourceType string
    metrics      []string
    aggregations []string
}

resourceType is the type of resources you want to collect metrics of.

  • Info about metrics and aggregations can be found in Resource Target section.

Documentation

Index

Constants

View Source
const (

	// MetricFieldTimeStamp is timeStamp metric field name.
	MetricFieldTimeStamp = "timeStamp"
	// MetricFieldTotal is total metric field name.
	MetricFieldTotal = "total"
	// MetricFieldAverage is average metric field name.
	MetricFieldAverage = "average"
	// MetricFieldCount is count metric field name.
	MetricFieldCount = "count"
	// MetricFieldMinimum is minimum metric field name.
	MetricFieldMinimum = "minimum"
	// MetricFieldMaximum is maximum metric field name.
	MetricFieldMaximum = "maximum"

	// MetricTagSubscriptionID is subscription ID metric tag name.
	MetricTagSubscriptionID = "subscription_id"
	// MetricTagResourceGroup is resource group metric tag name.
	MetricTagResourceGroup = "resource_group"
	// MetricTagResourceName is resource name metric tag name.
	MetricTagResourceName = "resource_name"
	// MetricTagNamespace is namespace metric tag name.
	MetricTagNamespace = "namespace"
	// MetricTagResourceRegion is resource region metric tag name.
	MetricTagResourceRegion = "resource_region"
	// MetricTagUnit is unit metric tag name.
	MetricTagUnit = "unit"
)
View Source
const (
	// MaxMetricsPerRequest is max metrics per request to Azure Monitor API.
	MaxMetricsPerRequest = 20
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AzureClients

type AzureClients struct {
	Ctx                     context.Context
	ResourcesClient         ResourcesClient
	MetricDefinitionsClient MetricDefinitionsClient
	MetricsClient           MetricsClient
}

AzureClients contains all clients that communicate with Azure Monitor API.

func CreateAzureClients

func CreateAzureClients(subscriptionID string, clientID string, clientSecret string, tenantID string) (*AzureClients, error)

CreateAzureClients creates Azure clients with service principal credentials

func CreateAzureClientsWithCreds added in v1.0.2

func CreateAzureClientsWithCreds(subscriptionID string, credential azcore.TokenCredential) (*AzureClients, error)

CreateAzureClientsWithCreds creates Azure clients with provided TokenCredential

type AzureMonitorMetricsReceiver

type AzureMonitorMetricsReceiver struct {
	Targets      *Targets
	AzureClients *AzureClients
	// contains filtered or unexported fields
}

AzureMonitorMetricsReceiver is the receiver that gets metrics of Azure resources using Azure Monitor API.

func NewAzureMonitorMetricsReceiver

func NewAzureMonitorMetricsReceiver(subscriptionID string, clientID string, clientSecret string, tenantID string, targets *Targets, azureClients *AzureClients) (*AzureMonitorMetricsReceiver, error)

NewAzureMonitorMetricsReceiver lets you create a new receiver.

func (*AzureMonitorMetricsReceiver) CheckResourceTargetsMetricsValidation

func (ammr *AzureMonitorMetricsReceiver) CheckResourceTargetsMetricsValidation() error

CheckResourceTargetsMetricsValidation checks resource targets metrics validation.

func (*AzureMonitorMetricsReceiver) CollectResourceTargetMetrics

func (ammr *AzureMonitorMetricsReceiver) CollectResourceTargetMetrics(target *ResourceTarget) ([]*Metric, []string, error)

CollectResourceTargetMetrics collects metrics of a resource target.

func (*AzureMonitorMetricsReceiver) CreateResourceTargetsFromResourceGroupTargets

func (ammr *AzureMonitorMetricsReceiver) CreateResourceTargetsFromResourceGroupTargets() error

CreateResourceTargetsFromResourceGroupTargets creates resource targets from resource group targets.

func (*AzureMonitorMetricsReceiver) CreateResourceTargetsFromSubscriptionTargets

func (ammr *AzureMonitorMetricsReceiver) CreateResourceTargetsFromSubscriptionTargets() error

CreateResourceTargetsFromSubscriptionTargets creates resource targets from subscription targets.

func (*AzureMonitorMetricsReceiver) SetResourceTargetsAggregations

func (ammr *AzureMonitorMetricsReceiver) SetResourceTargetsAggregations()

SetResourceTargetsAggregations sets resource targets aggregations if their aggregations array is empty.

func (*AzureMonitorMetricsReceiver) SetResourceTargetsMetrics

func (ammr *AzureMonitorMetricsReceiver) SetResourceTargetsMetrics() error

SetResourceTargetsMetrics sets resource targets metrics if their metrics array is empty.

func (*AzureMonitorMetricsReceiver) SplitResourceTargetsMetricsByMinTimeGrain

func (ammr *AzureMonitorMetricsReceiver) SplitResourceTargetsMetricsByMinTimeGrain() error

SplitResourceTargetsMetricsByMinTimeGrain splits resource targets metrics by min time grain.

func (*AzureMonitorMetricsReceiver) SplitResourceTargetsWithMoreThanMaxMetrics

func (ammr *AzureMonitorMetricsReceiver) SplitResourceTargetsWithMoreThanMaxMetrics()

SplitResourceTargetsWithMoreThanMaxMetrics splits resource targets with more than max metrics.

type Metric

type Metric struct {
	Name   string
	Fields map[string]interface{}
	Tags   map[string]string
}

Metric is a metric of an Azure resource using Azure Monitor API.

type MetricDefinitionsClient

MetricDefinitionsClient is an Azure metric definitions client interface.

type MetricsClient

MetricsClient is an Azure metrics client interface.

type Resource

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

Resource describes an Azure resource by resource type.

func NewResource

func NewResource(resourceType string, metrics []string, aggregations []string) *Resource

NewResource lets you create a new resource.

type ResourceGroupTarget

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

ResourceGroupTarget describes an Azure resource group.

func NewResourceGroupTarget

func NewResourceGroupTarget(resourceGroup string, resources []*Resource) *ResourceGroupTarget

NewResourceGroupTarget lets you create a new resource group target.

type ResourceTarget

type ResourceTarget struct {
	ResourceID   string
	Metrics      []string
	Aggregations []string
}

ResourceTarget describes an Azure resource by resource ID.

func NewResourceTarget

func NewResourceTarget(resourceID string, metrics []string, aggregations []string) *ResourceTarget

NewResourceTarget lets you create a new resource target.

type ResourcesClient

ResourcesClient is an Azure resources client interface.

type Targets

type Targets struct {
	ResourceTargets []*ResourceTarget
	// contains filtered or unexported fields
}

Targets contains all targets types.

func NewTargets

func NewTargets(resourceTargets []*ResourceTarget, resourceGroupTargets []*ResourceGroupTarget, subscriptionTargets []*Resource) *Targets

NewTargets lets you create a new targets object.

Jump to

Keyboard shortcuts

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