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 hsperfdata Input Plugin #2058

Closed
wants to merge 3 commits into from
Closed

Conversation

njwhite
Copy link
Contributor

@njwhite njwhite commented Nov 18, 2016

A new version of #2056 (as I can't re-open the PR with my new changes @sparrc?). I've re-written the binary parsing logic (it no longer uses the dependency go-hsperfdata) and so is about 200 lines longer. I've also expanded the test coverage with some interestingly-malformed hsperfdata files and other edge cases.

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)

 For gather data from the shared memory exposed by running processes.
@njwhite
Copy link
Contributor Author

njwhite commented Dec 18, 2016

Could I get a review for this PR? Thanks -

@sparrc
Copy link
Contributor

sparrc commented Dec 19, 2016

@njwhite at the moment we don't have time to fully review all plugin requests we are receiving. This will likely need to become an "external" plugin first (#1717).

I wouldn't expect a full review for a few months.

@njwhite
Copy link
Contributor Author

njwhite commented Dec 19, 2016

Thanks for the update @sparrc!

@njwhite njwhite force-pushed the master branch 2 times, most recently from 7bd350a to f622f80 Compare December 20, 2016 13:05
@njwhite
Copy link
Contributor Author

njwhite commented May 9, 2017

Hi @sparrc - are there any docs on how to make this into an "external" plugin? Or can this PR be merged as an internal plugin? Thanks -

@danielnelson
Copy link
Contributor

@njwhite Sorry, will have to wait awhile more before we have time to review for official inclusion.

@apexlir
Copy link

apexlir commented Jun 18, 2017

Shame, I would like to replace collectd/jmxtrans with telegraf and JVM monitoring is the only thing stopping me from migrating.

@danielnelson
Copy link
Contributor

@apexlir Take a look at the collectd parser used with socket_listener and the jolokia input for JVM monitoring.

@danielnelson danielnelson added feat Improvement on an existing feature such as adding a new setting/mode to an existing plugin and removed feat Improvement on an existing feature such as adding a new setting/mode to an existing plugin plugin request labels Aug 12, 2017
@njwhite njwhite mentioned this pull request Nov 7, 2017
@nashtsai
Copy link

nashtsai commented Nov 9, 2017

it's been almost a year for this PR, is anyone reviewing it?

@coxsim
Copy link

coxsim commented Dec 22, 2017

We have an interest in using a non-JMX means for monitoring the JVM from Telegraf (for a JVM where we're avoiding allocation of additional memory). This looks like a great fit. Is it likely to be included in a future version of Telegraf, or should it be included via the plugin framework?

@g10ck
Copy link

g10ck commented Feb 16, 2018

Hey guys, still waiting this plugin in master. When you will merge it?

@russorat russorat added this to the 1.10 milestone Sep 14, 2018
@russorat russorat modified the milestones: 1.10.0, 1.11.0 Jan 14, 2019
@danielnelson danielnelson modified the milestones: 1.11.0, 1.12.0 May 24, 2019
### Configuration:

```toml
[[inputs.hsperfdata]]
Copy link
Contributor

Choose a reason for hiding this comment

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

Make sure this matches what is in sampleConfig

#
## Use the value for these keys in the hsperfdata as tags, not fields. By
## default everything is a field.
# tags = ["sun.rt.jvmVersion"]
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems this same thing (tags and filter) can be accomplished with the converter processor and metric filtering

## Use an arbitary directory to gather perfdata. This can be useful if you
## want data belonging to a different user.
# directory = "/tmp/hsperfdata_otheruser"
#
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick: Rather than commenting an empty line, leave it empty.

files, err := ioutil.ReadDir(dir)
if err != nil {
// e.g. no such directory or no permissions - just don't record metrics
return retval, nil
Copy link
Contributor

Choose a reason for hiding this comment

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

Just return the error since it get's ignored in Gather (allows for skipping the rest of the logic in gather).

func (n *Hsperfdata) Gather(acc telegraf.Accumulator) error {
files, err := n.GetFiles()
if err != nil {
// the directory doesn't exist - so there aren't any Java processes running
Copy link
Contributor

Choose a reason for hiding this comment

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

This makes sense, but seems too permissive, though returning an error may be too abrasive.

for _, f := range files {
// the hsperfdata files are named after the pid
if _, err := strconv.Atoi(f.Name()); err == nil {
retval[filepath.Join(dir, f.Name())] = f.Name()
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick: i would have done retval[f.Name()] = join(dir,f.Name()) or simply stored a slice of join(dir, f.name()) as the pid can be derived again by using filepath.Base() in the gatherOne function.

return false
}

func (n *Hsperfdata) GatherOne(acc telegraf.Accumulator, file string, pid string) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick: no need to export this function

}
unconvertedTickFields := []tickfield{}

filter, err := regexp.Compile(n.Filter)
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider doing this as a MustCompile in the Init() error function and storing it in the Hsperfdata structure

func (n *Hsperfdata) GetFiles() (map[string]string, error) {
dir := n.Directory
if dir == "" {
// pick a sensible default: /tmp/hsperfdata_<user>
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 almost say put this default directory logic into the init() function and set it to Directory in the Hsperfdata that is set.

@glinton glinton removed the feat Improvement on an existing feature such as adding a new setting/mode to an existing plugin label Jul 29, 2019
@glinton
Copy link
Contributor

glinton commented Jul 29, 2019

Also, @njwhite please update your branch with master to remove the conflicts and refrain from force pushing your branch now that the review has been started, in order to facilitate speedy review updates.
Thanks for this

@njwhite
Copy link
Contributor Author

njwhite commented Jul 30, 2019

Thanks for the review @glinton - however I raised this PR 2 1/2 years ago and now no longer need it. Happy for anyone else to take ownership -

@russorat russorat modified the milestones: 1.12.0, 1.13.0 Aug 5, 2019
@danielnelson
Copy link
Contributor

Let's close the pull request for now and if someone is interested in adopting this plugin please create a new issue first.

@danielnelson danielnelson removed this from the 1.13.0 milestone Nov 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants