-
Notifications
You must be signed in to change notification settings - Fork 4.9k
/
storage.go
71 lines (63 loc) · 2.57 KB
/
storage.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
// or more contributor license agreements. Licensed under the Elastic License;
// you may not use this file except in compliance with the Elastic License.
package storage
import (
"fmt"
"github.com/elastic/beats/v7/metricbeat/mb"
"github.com/elastic/beats/v7/x-pack/metricbeat/module/azure"
)
const defaultStorageAccountNamespace = "Microsoft.Storage/storageAccounts"
var (
storageServiceNamespaces = []string{"/blobServices", "/tableServices", "/queueServices", "/fileServices"}
allowedDimensions = []string{"ResponseType", "ApiName"}
)
// init registers the MetricSet with the central registry as soon as the program
// starts. The New function will be called later to instantiate an instance of
// the MetricSet for each host defined in the module's configuration. After the
// MetricSet has been created then Fetch will begin to be called periodically.
func init() {
mb.Registry.MustAddMetricSet("azure", "storage", New)
mb.Registry.MustAddMetricSet("azure", "storage_account", New)
}
// MetricSet holds any configuration or state information. It must implement
// the mb.MetricSet interface. And this is best achieved by embedding
// mb.BaseMetricSet because it implements all of the required mb.MetricSet
// interface methods except for Fetch.
type MetricSet struct {
*azure.MetricSet
}
// New creates a new instance of the MetricSet. New is responsible for unpacking
// any MetricSet specific configuration options if there are any.
func New(base mb.BaseMetricSet) (mb.MetricSet, error) {
ms, err := azure.NewMetricSet(base)
if err != nil {
return nil, err
}
// set default resource type to indicate this is not the generic monitor metricset
ms.Client.Config.DefaultResourceType = defaultStorageAccountNamespace
// if no options are entered we will retrieve all the vm's from the entire subscription
if len(ms.Client.Config.Resources) == 0 {
ms.Client.Config.Resources = []azure.ResourceConfig{
{
Query: fmt.Sprintf("resourceType eq '%s'", defaultStorageAccountNamespace),
},
}
}
for index := range ms.Client.Config.Resources {
// if any resource groups were configured the resource type should be added
if len(ms.Client.Config.Resources[index].Group) > 0 {
ms.Client.Config.Resources[index].Type = defaultStorageAccountNamespace
}
// one metric configuration will be added containing all metrics names
ms.Client.Config.Resources[index].Metrics = []azure.MetricConfig{
{
Name: []string{"*"},
},
}
}
ms.MapMetrics = mapMetrics
return &MetricSet{
MetricSet: ms,
}, nil
}