Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add device last connected metrics #1515

Merged
merged 5 commits into from
Sep 27, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 1 addition & 12 deletions internal/cache/devices.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,8 @@ import (
"sync"
"time"

"github.com/edgexfoundry/device-sdk-go/v3/internal/container"

bootstrapContainer "github.com/edgexfoundry/go-mod-bootstrap/v3/bootstrap/container"
"github.com/edgexfoundry/go-mod-bootstrap/v3/di"
"github.com/edgexfoundry/go-mod-core-contracts/v3/common"
"github.com/edgexfoundry/go-mod-core-contracts/v3/errors"
"github.com/edgexfoundry/go-mod-core-contracts/v3/models"

Expand Down Expand Up @@ -72,13 +69,9 @@ func newDeviceCache(devices []models.Device, dic *di.Container) DeviceCache {
func registerMetric(deviceName string, metric interface{}, dic *di.Container) {
metricsManager := bootstrapContainer.MetricsManagerFrom(dic.Get)
lc := bootstrapContainer.LoggingClientFrom(dic.Get)
configuration := container.ConfigurationFrom(dic.Get)
if configuration.Service.EnableNameFieldEscape {
deviceName = common.URLEncode(deviceName)
}
registeredName := strings.Replace(lastConnectedPrefix, deviceNameText, deviceName, 1)

err := metricsManager.Register(registeredName, metric, map[string]string{"device": deviceName})
err := metricsManager.Register(registeredName, metric, nil)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tag is still needed. This allows for filtering on a dashboard such as Grafana.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, tag added back. Thanks.

if err != nil {
lc.Warnf("Unable to register %s metric. Metric will not be reported : %s", registeredName, err.Error())
} else {
Expand All @@ -88,10 +81,6 @@ func registerMetric(deviceName string, metric interface{}, dic *di.Container) {

func unregisterMetric(deviceName string, dic *di.Container) {
metricsManager := bootstrapContainer.MetricsManagerFrom(dic.Get)
configuration := container.ConfigurationFrom(dic.Get)
if configuration.Service.EnableNameFieldEscape {
deviceName = common.URLEncode(deviceName)
}
registeredName := strings.Replace(lastConnectedPrefix, deviceNameText, deviceName, 1)

metricsManager.Unregister(registeredName)
Expand Down