Skip to content

Commit

Permalink
Added a global variable for plygins to share metrics
Browse files Browse the repository at this point in the history
WAN-2321 #time 1h
  • Loading branch information
shriyanshk128T committed Sep 1, 2023
1 parent 15d7bf9 commit 85fbee9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
18 changes: 18 additions & 0 deletions plugins/inputs/t128_graphql/t128_graphql.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@ import (
"github.com/Jeffail/gabs"
"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/config"
"github.com/influxdata/telegraf/metric"
"github.com/influxdata/telegraf/plugins/inputs"
)

var T128GraphQLMetrics []telegraf.Metric

const (
//DefaultRequestTimeout is the request timeout if none is configured
DefaultRequestTimeout = 5 * time.Second
Expand Down Expand Up @@ -214,6 +217,21 @@ func (plugin *T128GraphQL) Gather(acc telegraf.Accumulator) error {
processedResponse.Tags,
)
}

//Converting fields to [string]interface{}
fieldsInterface := make(map[string]interface{}, len(plugin.Config.Fields))
for k, v := range plugin.Config.Fields {
fieldsInterface[k] = v
}

//Metric creation for use by other plugins
metric := metric.New(
plugin.CollectorName, // Measurement name
plugin.Config.Tags, // Tags
fieldsInterface, // Fields
time.Now(), // Timestamp
)
T128GraphQLMetrics = append(T128GraphQLMetrics, metric)
return nil
}

Expand Down
4 changes: 3 additions & 1 deletion plugins/inputs/t128_peer_path/t128_peer_path.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ func (plugin *T128PeerPath) Init() error {
RetryIfNotFound: plugin.RetryIfNotFound,
Query: plugin.Query,
}
//fmt.Print(plugin.gqlCollector.endpointNotFound)
err := plugin.gqlCollector.Init()
if err != nil {
return err
Expand All @@ -91,6 +90,9 @@ func (plugin *T128PeerPath) Init() error {
// Gather takes in an accumulator and adds the metrics that the Input gathers
func (plugin *T128PeerPath) Gather(acc telegraf.Accumulator) error {
plugin.gqlCollector.Gather(acc)
for _, metrics := range t128_graphql.T128GraphQLMetrics {

Check failure on line 93 in plugins/inputs/t128_peer_path/t128_peer_path.go

View workflow job for this annotation

GitHub Actions / Continuous Integration

metrics declared but not used
//perform operation
}
return nil
}

Expand Down

0 comments on commit 85fbee9

Please sign in to comment.