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

Cache and expire metrics for prometheus output #2016

Merged
merged 5 commits into from
Nov 15, 2016

Conversation

ragalie
Copy link
Contributor

@ragalie ragalie commented Nov 8, 2016

Required for all PRs:

  • CHANGELOG.md updated (we recommend not updating this until the PR has been approved by a maintainer)
  • Sign CLA (if not already signed)
  • README.md updated (if adding a new plugin)

This implements the solution we discussed in #1775

type PrometheusClient struct {
Listen string
Listen string
ExpirationInterval int64 `toml:"expiration_interval"`
Copy link
Contributor

Choose a reason for hiding this comment

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

change this type to internal.Duration, that way it can reprepsented like expiration_interval = "10s"

Copy link
Contributor

Choose a reason for hiding this comment

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

you'll need to import github.com/influxdata/telegraf/internal

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

@@ -171,7 +174,12 @@ func (p *PrometheusClient) Write(metrics []telegraf.Metric) error {
"key: %s, labels: %v,\nerr: %s\n",
mname, l, err.Error())
}
p.metrics[desc.String()] = metric

metricWithTime := &MetricWithExpiration{
Copy link
Contributor

Choose a reason for hiding this comment

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

don't declare a tmp var for metricWithTime, just do p.metrics[desc.String()] = &MetricWithExpiration{ ....

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

@sparrc sparrc added this to the 1.2.0 milestone Nov 9, 2016
@sparrc sparrc added the bug unexpected problem or unintended behavior label Nov 9, 2016

sync.Mutex
}

var sampleConfig = `
## Address to listen on
# listen = ":9126"

## Interval to expire metrics and not deliver to prometheus, 0 == no expiration
# expiration_interval = 0
Copy link
Contributor

Choose a reason for hiding this comment

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

I would say this should default to "60s", since the current behavior of the plugin is to expire metrics.

Copy link
Contributor

Choose a reason for hiding this comment

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

you'll also need to set the value in the struct that gets returned in the init() function

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this is what you're looking for here, let me know if I did it wrong

@ragalie
Copy link
Contributor Author

ragalie commented Nov 14, 2016

@sparrc I updated the changelog on this; is there anything else you'd like me to do?

@sparrc
Copy link
Contributor

sparrc commented Nov 15, 2016

looks good but the changelog update is in the wrong section, you should rebase and put it into release 1.2

@jdoupe
Copy link
Contributor

jdoupe commented Jun 21, 2017

Running 1.2.1 and still seeing same behavior (as detailed in #1775).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug unexpected problem or unintended behavior
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants