Skip to content

Commit

Permalink
doc: generate metrics should include metrics
Browse files Browse the repository at this point in the history
Created by builtin plugins: Aggregator, Max, and MetricAgent
  • Loading branch information
cgrinds committed Oct 10, 2023
2 parents 6551cef + 0120aee commit 13cf745
Show file tree
Hide file tree
Showing 146 changed files with 2,927 additions and 2,257 deletions.
11 changes: 9 additions & 2 deletions cmd/collectors/commonutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func InvokeRestCall(client *rest.Client, href string, logger *logging.Logger) ([
return result, nil
}

func GetClusterTime(client *rest.Client, returnTimeOut string, logger *logging.Logger) (time.Time, error) {
func GetClusterTime(client *rest.Client, returnTimeOut *int, logger *logging.Logger) (time.Time, error) {
var (
err error
records []gjson.Result
Expand All @@ -72,7 +72,14 @@ func GetClusterTime(client *rest.Client, returnTimeOut string, logger *logging.L
query := "private/cli/cluster/date"
fields := []string{"date"}

href := rest.BuildHref(query, strings.Join(fields, ","), nil, "", "", "1", returnTimeOut, "")
maxRecords := 1

href := rest.NewHrefBuilder().
APIPath(query).
Fields(fields).
MaxRecords(&maxRecords).
ReturnTimeout(returnTimeOut).
Build()

if records, err = rest.Fetch(client, href); err != nil {
return clusterTime, err
Expand Down
22 changes: 18 additions & 4 deletions cmd/collectors/ems/ems.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type Ems struct {
emsProp map[string][]*emsProp // array is used here to handle same ems written with different ops, matches or exports. Example: arw.volume.state ems with op as disabled or dry-run
Filter []string
Fields []string
ReturnTimeOut string
ReturnTimeOut *int
lastFilterTime int64
maxURLSize int
DefaultLabels []string
Expand Down Expand Up @@ -187,7 +187,12 @@ func (e *Ems) InitCache() error {

// default value for ONTAP is 15 sec
if returnTimeout := e.Params.GetChildContentS("return_timeout"); returnTimeout != "" {
e.ReturnTimeOut = returnTimeout
iReturnTimeout, err := strconv.Atoi(returnTimeout)
if err != nil {
e.Logger.Warn().Str("returnTimeout", returnTimeout).Msg("Invalid value of returnTimeout")
} else {
e.ReturnTimeOut = &iReturnTimeout
}
}

// init plugins
Expand Down Expand Up @@ -283,7 +288,11 @@ func (e *Ems) PollInstance() (map[string]*matrix.Matrix, error) {
query := "api/support/ems/messages"
fields := []string{"name"}

href := rest.BuildHref(query, strings.Join(fields, ","), nil, "", "", "", e.ReturnTimeOut, query)
href := rest.NewHrefBuilder().
APIPath(query).
Fields(fields).
ReturnTimeout(e.ReturnTimeOut).
Build()

if records, err = e.GetRestData(href); err != nil {
return nil, err
Expand Down Expand Up @@ -415,7 +424,12 @@ func (e *Ems) getHref(names []string, filter []string) string {
orderByIndexFilter := "order_by=" + "index%20asc"
filter = append(filter, orderByIndexFilter)

href := rest.BuildHref(e.Query, strings.Join(e.Fields, ","), filter, "", "", "", e.ReturnTimeOut, e.Query)
href := rest.NewHrefBuilder().
APIPath(e.Query).
Fields(e.Fields).
Filter(filter).
ReturnTimeout(e.ReturnTimeOut).
Build()
return href
}

Expand Down
8 changes: 6 additions & 2 deletions cmd/collectors/power.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,14 @@ const (
// `system chassis fru show`.
// Chassis FRU information is only available via private CLI
func collectChassisFRU(client *rest.Client, logger *logging.Logger) (map[string]int, error) {
fields := "fru-name,type,status,connected-nodes,num-nodes"
fields := []string{"fru-name", "type", "status", "connected-nodes", "num-nodes"}
query := "api/private/cli/system/chassis/fru"
filter := []string{"type=psu"}
href := rest.BuildHref("", fields, filter, "", "", "", "", query)
href := rest.NewHrefBuilder().
APIPath(query).
Fields(fields).
Filter(filter).
Build()

result, err := rest.Fetch(client, href)
if err != nil {
Expand Down
12 changes: 10 additions & 2 deletions cmd/collectors/rest/plugins/certificate/certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,11 @@ func (my *Certificate) GetAdminVserver() (string, error) {
)

query := "api/private/cli/vserver"
href := rest.BuildHref("", "type", []string{"type=admin"}, "", "", "", "", query)
href := rest.NewHrefBuilder().
APIPath(query).
Fields([]string{"type"}).
Filter([]string{"type=admin"}).
Build()

if result, err = collectors.InvokeRestCall(my.client, href, my.Logger); err != nil {
return "", err
Expand All @@ -208,7 +212,11 @@ func (my *Certificate) GetSecuritySsl(adminSvm string) (string, error) {
)

query := "api/private/cli/security/ssl"
href := rest.BuildHref("", "serial", []string{"vserver=" + adminSvm}, "", "", "", "", query)
href := rest.NewHrefBuilder().
APIPath(query).
Fields([]string{"serial"}).
Filter([]string{"vserver=" + adminSvm}).
Build()

if result, err = collectors.InvokeRestCall(my.client, href, my.Logger); err != nil {
return "", err
Expand Down
60 changes: 48 additions & 12 deletions cmd/collectors/rest/plugins/health/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/netapp/harvest/v2/pkg/matrix"
"github.com/tidwall/gjson"
"strconv"
"strings"
"time"
)

Expand Down Expand Up @@ -446,7 +445,7 @@ func (h *Health) collectSupportAlerts() {
var (
instance *matrix.Instance
)
clusterTime, err := collectors.GetClusterTime(h.client, "", h.Logger)
clusterTime, err := collectors.GetClusterTime(h.client, nil, h.Logger)
if err != nil {
h.Logger.Error().Err(err).Msg("Failed to collect cluster time")
return
Expand Down Expand Up @@ -533,7 +532,11 @@ func (h *Health) getDisks() ([]gjson.Result, error) {

fields := []string{"name", "container_type"}
query := "api/storage/disks"
href := rest.BuildHref(query, strings.Join(fields, ","), []string{"container_type=broken|unassigned"}, "", "", "", "", query)
href := rest.NewHrefBuilder().
APIPath(query).
Fields(fields).
Filter([]string{"container_type=broken|unassigned"}).
Build()

if result, err = collectors.InvokeRestCall(h.client, href, h.Logger); err != nil {
return nil, err
Expand All @@ -549,7 +552,10 @@ func (h *Health) getShelves() ([]gjson.Result, error) {

fields := []string{"error_type", "error_severity", "error_text"}
query := "api/private/cli/storage/shelf"
href := rest.BuildHref(query, strings.Join(fields, ","), nil, "", "", "", "", query)
href := rest.NewHrefBuilder().
APIPath(query).
Fields(fields).
Build()

if result, err = collectors.InvokeRestCall(h.client, href, h.Logger); err != nil {
return nil, err
Expand All @@ -565,7 +571,11 @@ func (h *Health) getNodes() ([]gjson.Result, error) {

fields := []string{"health"}
query := "api/private/cli/node"
href := rest.BuildHref(query, strings.Join(fields, ","), []string{"health=false"}, "", "", "", "", query)
href := rest.NewHrefBuilder().
APIPath(query).
Fields(fields).
Filter([]string{"health=false"}).
Build()

if result, err = collectors.InvokeRestCall(h.client, href, h.Logger); err != nil {
return nil, err
Expand All @@ -580,7 +590,10 @@ func (h *Health) getRansomwareVolumes() ([]gjson.Result, error) {
)

query := "api/storage/volumes"
href := rest.BuildHref(query, "", []string{"anti_ransomware.state=enabled", "anti_ransomware.attack_probability=low|moderate|high"}, "", "", "", "", query)
href := rest.NewHrefBuilder().
APIPath(query).
Filter([]string{"anti_ransomware.state=enabled", "anti_ransomware.attack_probability=low|moderate|high"}).
Build()

if result, err = collectors.InvokeRestCall(h.client, href, h.Logger); err != nil {
return nil, err
Expand All @@ -596,7 +609,11 @@ func (h *Health) getNonCompliantLicense() ([]gjson.Result, error) {

query := "api/cluster/licensing/licenses"
fields := []string{"name,scope,state"}
href := rest.BuildHref(query, strings.Join(fields, ","), []string{"state=noncompliant"}, "", "", "", "", query)
href := rest.NewHrefBuilder().
APIPath(query).
Fields(fields).
Filter([]string{"state=noncompliant"}).
Build()

if result, err = collectors.InvokeRestCall(h.client, href, h.Logger); err != nil {
return nil, err
Expand All @@ -612,7 +629,11 @@ func (h *Health) getMoveFailedVolumes() ([]gjson.Result, error) {

query := "api/storage/volumes"
fields := []string{"uuid,name,movement.state,svm"}
href := rest.BuildHref(query, strings.Join(fields, ","), []string{"movement.state=cutover_wait|failed|cutover_pending"}, "", "", "", "", query)
href := rest.NewHrefBuilder().
APIPath(query).
Fields(fields).
Filter([]string{"movement.state=cutover_wait|failed|cutover_pending"}).
Build()

if result, err = collectors.InvokeRestCall(h.client, href, h.Logger); err != nil {
return nil, err
Expand All @@ -627,7 +648,11 @@ func (h *Health) getNonHomeLIFs() ([]gjson.Result, error) {
)

query := "api/network/ip/interfaces"
href := rest.BuildHref(query, "svm,location", []string{"location.is_home=false"}, "", "", "", "", query)
href := rest.NewHrefBuilder().
APIPath(query).
Fields([]string{"svm", "location"}).
Filter([]string{"location.is_home=false"}).
Build()

if result, err = collectors.InvokeRestCall(h.client, href, h.Logger); err != nil {
return nil, err
Expand All @@ -643,7 +668,11 @@ func (h *Health) getFCPorts() ([]gjson.Result, error) {

fields := []string{"name,node"}
query := "api/network/fc/ports"
href := rest.BuildHref(query, strings.Join(fields, ","), []string{"enabled=true", "state=offlined_by_system"}, "", "", "", "", query)
href := rest.NewHrefBuilder().
APIPath(query).
Fields(fields).
Filter([]string{"enabled=true", "state=offlined_by_system"}).
Build()

if result, err = collectors.InvokeRestCall(h.client, href, h.Logger); err != nil {
return nil, err
Expand All @@ -659,7 +688,11 @@ func (h *Health) getEthernetPorts() ([]gjson.Result, error) {

fields := []string{"name,node"}
query := "api/network/ethernet/ports"
href := rest.BuildHref(query, strings.Join(fields, ","), []string{"enabled=true", "state=down"}, "", "", "", "", query)
href := rest.NewHrefBuilder().
APIPath(query).
Fields(fields).
Filter([]string{"enabled=true", "state=down"}).
Build()

if result, err = collectors.InvokeRestCall(h.client, href, h.Logger); err != nil {
return nil, err
Expand All @@ -673,7 +706,10 @@ func (h *Health) getSupportAlerts(filter []string) ([]gjson.Result, error) {
err error
)
query := "api/private/support/alerts"
href := rest.BuildHref(query, "", filter, "", "", "", "", query)
href := rest.NewHrefBuilder().
APIPath(query).
Filter(filter).
Build()

if result, err = collectors.InvokeRestCall(h.client, href, h.Logger); err != nil {
return nil, err
Expand Down
5 changes: 4 additions & 1 deletion cmd/collectors/rest/plugins/ontaps3service/ontaps3service.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ func (o *OntapS3Service) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matri
data := dataMap[o.Object]

fields := []string{"svm.name", "name", "is_http_enabled", "is_https_enabled", "secure_port", "port"}
href := rest.BuildHref("", strings.Join(fields, ","), nil, "", "", "", "", o.query)
href := rest.NewHrefBuilder().
APIPath(o.query).
Fields(fields).
Build()

if result, err = collectors.InvokeRestCall(o.client, href, o.Logger); err != nil {
return nil, err
Expand Down
6 changes: 5 additions & 1 deletion cmd/collectors/rest/plugins/qtree/qtree.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,11 @@ func (q *Qtree) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matrix, error)
filter = []string{"return_unmatched_nested_array_objects=true", "show_default_records=true", "type=" + strings.Join(q.quotaType[:], "|")}
}

href := rest.BuildHref("", "*", filter, "", "", "", "", q.query)
href := rest.NewHrefBuilder().
APIPath(q.query).
Fields([]string{"*"}).
Filter(filter).
Build()

if result, err = collectors.InvokeRestCall(q.client, href, q.Logger); err != nil {
return nil, err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ func (s *SecurityAccount) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matr
)

data := dataMap[s.Object]
href := rest.BuildHref("", "applications", nil, "", "", "", "", s.query)
href := rest.NewHrefBuilder().
APIPath(s.query).
Fields([]string{"applications"}).
Build()

if result, err = collectors.InvokeRestCall(s.client, href, s.Logger); err != nil {
return nil, err
Expand Down
6 changes: 5 additions & 1 deletion cmd/collectors/rest/plugins/snapmirror/snapmirror.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,11 @@ func (my *SnapMirror) getSVMPeerData(cluster string) error {
my.svmPeerDataMap = make(map[string]Peer)
fields := []string{"name", "peer.svm.name", "peer.cluster.name"}
query := "api/svm/peers"
href := rest.BuildHref("", strings.Join(fields, ","), []string{"peer.cluster.name=!" + cluster}, "", "", "", "", query)
href := rest.NewHrefBuilder().
APIPath(query).
Fields(fields).
Filter([]string{"peer.cluster.name=!" + cluster}).
Build()

result, err := rest.Fetch(my.client, href)
if err != nil {
Expand Down
28 changes: 20 additions & 8 deletions cmd/collectors/rest/plugins/svm/svm.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,11 @@ func (my *SVM) GetKerberosConfig() (map[string]string, error) {

svmKerberosMap = make(map[string]string)
query := "api/protocols/nfs/kerberos/interfaces"
kerberosFields := []string{"svm.name", "enabled"}
href := rest.BuildHref("", strings.Join(kerberosFields, ","), nil, "", "", "", "", query)
fields := []string{"svm.name", "enabled"}
href := rest.NewHrefBuilder().
APIPath(query).
Fields(fields).
Build()

if result, err = collectors.InvokeRestCall(my.client, href, my.Logger); err != nil {
return nil, err
Expand Down Expand Up @@ -240,8 +243,11 @@ func (my *SVM) GetFpolicy() (map[string]Fpolicy, error) {

svmFpolicyMap = make(map[string]Fpolicy)
query := "api/protocols/fpolicy"
fpolicyFields := []string{"svm.name", "policies.enabled", "policies.name"}
href := rest.BuildHref("", strings.Join(fpolicyFields, ","), nil, "", "", "", "", query)
fields := []string{"svm.name", "policies.enabled", "policies.name"}
href := rest.NewHrefBuilder().
APIPath(query).
Fields(fields).
Build()

if result, err = collectors.InvokeRestCall(my.client, href, my.Logger); err != nil {
return nil, err
Expand Down Expand Up @@ -273,8 +279,11 @@ func (my *SVM) GetIscsiServices() (map[string]string, error) {

svmIscsiServiceMap = make(map[string]string)
query := "api/protocols/san/iscsi/services"
iscsiServiceFields := []string{"svm.name", "enabled"}
href := rest.BuildHref("", strings.Join(iscsiServiceFields, ","), nil, "", "", "", "", query)
fields := []string{"svm.name", "enabled"}
href := rest.NewHrefBuilder().
APIPath(query).
Fields(fields).
Build()

if result, err = collectors.InvokeRestCall(my.client, href, my.Logger); err != nil {
return nil, err
Expand Down Expand Up @@ -305,8 +314,11 @@ func (my *SVM) GetIscsiCredentials() (map[string]string, error) {

svmIscsiCredentialMap = make(map[string]string)
query := "api/protocols/san/iscsi/credentials"
iscsiCredentialFields := []string{"svm.name", "authentication_type"}
href := rest.BuildHref("", strings.Join(iscsiCredentialFields, ","), nil, "", "", "", "", query)
fields := []string{"svm.name", "authentication_type"}
href := rest.NewHrefBuilder().
APIPath(query).
Fields(fields).
Build()

if result, err = collectors.InvokeRestCall(my.client, href, my.Logger); err != nil {
return nil, err
Expand Down
9 changes: 6 additions & 3 deletions cmd/collectors/rest/plugins/volume/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/netapp/harvest/v2/pkg/tree/node"
"github.com/tidwall/gjson"
"strconv"
"strings"
"time"
)

Expand Down Expand Up @@ -188,9 +187,13 @@ func (my *Volume) getEncryptedDisks() ([]gjson.Result, error) {
err error
)

diskFields := []string{"aggregates.name", "aggregates.uuid"}
fields := []string{"aggregates.name", "aggregates.uuid"}
query := "api/storage/disks"
href := rest.BuildHref("", strings.Join(diskFields, ","), []string{"protection_mode=!data|full"}, "", "", "", "", query)
href := rest.NewHrefBuilder().
APIPath(query).
Fields(fields).
Filter([]string{"protection_mode=!data|full"}).
Build()

if result, err = collectors.InvokeRestCall(my.client, href, my.Logger); err != nil {
return nil, err
Expand Down
Loading

0 comments on commit 13cf745

Please sign in to comment.