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 Bond Interface input plugin #3424

Merged
merged 5 commits into from
Nov 28, 2017

Conversation

ildarsv
Copy link
Contributor

@ildarsv ildarsv commented Nov 3, 2017

Required for all PRs:

  • Signed CLA.
  • Associated README.md updated.
  • Has appropriate unit tests.


// default bond directory path
const (
BOND_PATH = "/proc/net/bonding"
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 call this defaultBondPath because Go naming guidelines, but to match existing style we should only specify the proc location. We can add it to the config as host_proc = "/proc", but we should also load it from the HOST_PROC environment variable.

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

for _, bondName := range bond.BondInterfaces {
file, err := ioutil.ReadFile(bond.BondPath + "/" + bondName)
if err != nil {
acc.AddError(fmt.Errorf("E! error due inspecting '%s' interface: %v", bondName, err))
Copy link
Contributor

Choose a reason for hiding this comment

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

The log level E! will be added by the accumulator, so just "error inspecting '%s' interface: %v", only add a log level if directly using the logger. Check for this throughout pull request.

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

"bond": bondName,
}

lines := strings.Split(rawFile, "\n")
Copy link
Contributor

Choose a reason for hiding this comment

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

Use a bufio.Scanner to avoid EOL encoding issues.

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

if len(stats) < 2 {
continue
}
name := strings.ToLower(strings.Replace(strings.TrimSpace(stats[0]), " ", "_", -1))
Copy link
Contributor

Choose a reason for hiding this comment

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

Why lowercase and replace spaces with underscores?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's too excessive, my bad. Removed.

var slave string
var status int

lines := strings.Split(rawFile, "\n")
Copy link
Contributor

Choose a reason for hiding this comment

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

bufio.Scanner

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

if bond.BondPath == "" {
bond.BondPath = BOND_PATH
}
if len(bond.BondInterfaces) == 0 {
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 cache the bond interfaces, or we won't be able to see new bonds without restarting Telegraf. Return the paths instead of adding them to the struct.

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

## By default, telegraf gather stats for all bond interfaces
## Setting interfaces will restrict the stats to the specified
## bond interfaces.
bond_interfaces = ["bond0", "bond1"]
Copy link
Contributor

Choose a reason for hiding this comment

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

Comment this line out with a single #, so the default will be used.

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

[[inputs.bond]]
## Sets bonding directory path
## If not specified, then default is:
bond_path = "/proc/net/bonding"
Copy link
Contributor

Choose a reason for hiding this comment

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

Comment out since this is default.

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

Down Delay (ms): 0

Slave Interface: eth3
MII Status: down
Copy link
Contributor

Choose a reason for hiding this comment

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

It's also possible for both of the interfaces to be up, right? Maybe we should gather the active slave on the bond master?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, I've added active_slave field. Thanks for the note.

- align README.md
- made host_proc configurable, add loading from env variables
- removed log levels from error messages
- used bufio.Scanner instead of strings.Split
- removed cache of bond interfaces
- gathered active slave for active-backuo mode
@ildarsv
Copy link
Contributor Author

ildarsv commented Nov 19, 2017

Hello @danielnelson ! Thank you for review. I've made some changes and improvements. Please take a look when you have time.

var sampleConfig = `
## Sets 'proc' directory path
## If not specified, then default is /proc
# host_proc = "/proc"
Copy link
Contributor

Choose a reason for hiding this comment

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

Fix indention

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


## Sets 'bonding' directory relative path
## If not specified, then default is /net/bonding
# bond_path = "/net/bonding"
Copy link
Contributor

Choose a reason for hiding this comment

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

Would this ever not be "/net/bonding"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Seems no, would you like me to hardcode this parameter?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, will make the interface simpler which is always a good thing.

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

@danielnelson danielnelson added this to the 1.5.0 milestone Nov 28, 2017
@danielnelson danielnelson merged commit 132fb50 into influxdata:master Nov 28, 2017
@danielnelson
Copy link
Contributor

Merged for 1.5, thanks!

@ildarsv ildarsv deleted the add-bond-input-plugin branch November 29, 2017 05:21
@ildarsv
Copy link
Contributor Author

ildarsv commented Nov 29, 2017

Thank you!
#3390 can be closed now

aromeyer pushed a commit to aromeyer/telegraf that referenced this pull request May 19, 2018
maxunt pushed a commit that referenced this pull request Jun 26, 2018
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