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

Add collection throttling support #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

yvlasenko
Copy link

Allow metric collection throttling to reduce load in case of expensive queries.

Example is queries on systemd_units (osquery-4.7.0) table are pretty expensive.

Copy link
Owner

@zwopir zwopir left a comment

Choose a reason for hiding this comment

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

Hi,

thanks for your PR! makes sense, even if I would solve the problem with a less frequent scrape interval. If you apply the throttling globally and not per query, this doesn't make sense and I prefer adjusting the scrape interval over the possibility of configuring a throttle interval and accepting this PR. However, if you implement the throttling per metric, it might make sense.

I also added some remarks . Also, please document the config option in the README.md

gaugevecs:
# a list of gaugevec definitions
[ - <gaugevec definition> ... ]
Copy link
Owner

Choose a reason for hiding this comment

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

thanks for the cleanup :)

}

// NewOsqueryCollector creates an OsQueryCollector from a given osquery-runner and a set of metric definitions
func NewOsqueryCollector(r *osquery.OsqueryRunner, m model.Metrics) *OsqueryCollector {
func NewOsqueryCollector(r *osquery.OsqueryRunner, m model.Metrics, t string) *OsqueryCollector {
Copy link
Owner

Choose a reason for hiding this comment

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

I'd prefer handling the time.Duration parsing outside the constructor and to pass in a time.Duration. It's not the concern of the constructor to validate the config

"github.com/zwopir/osquery_exporter/model"
"github.com/zwopir/osquery_exporter/osquery"
"osquery_exporter/model"
"osquery_exporter/osquery"
Copy link
Owner

Choose a reason for hiding this comment

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

please keep the github.com/zwopir prefix

Copy link
Author

Choose a reason for hiding this comment

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

Did that to allow build from custom repo/branch, is there any way to keep prefixes while allowing it without having to remove/re-add them? Spent quite some time trying to figure while builds were failing :D

if err != nil {
log.Fatalf("could not parse throttle_interval: %s", err)
}

Copy link
Owner

Choose a reason for hiding this comment

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

see above, should be done outside the constructor.

}(col)
c.throttle.Lock.Lock()
defer c.throttle.Lock.Unlock()
if time.Now().After(c.throttle.LastRun.Add(c.throttle.Interval)) {
Copy link
Owner

Choose a reason for hiding this comment

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

this throttles all metrics, even if just one metric is slow. These should be a throttle state per osquery (based on the same interval for convenience and simplicity of the config).

Copy link
Author

Choose a reason for hiding this comment

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

Agree, was my initial thought but went with easier approach to speed up a bit. Will take another look.

"github.com/zwopir/osquery_exporter/collector"
"github.com/zwopir/osquery_exporter/model"
"github.com/zwopir/osquery_exporter/osquery"
"osquery_exporter/collector"
Copy link
Owner

Choose a reason for hiding this comment

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

dito

@@ -6,7 +6,7 @@ import (
"fmt"
"github.com/prometheus/common/log"
"os/exec"
"github.com/zwopir/osquery_exporter/model"
Copy link
Owner

Choose a reason for hiding this comment

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

dito

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants