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 a collector generator script #28

Merged
merged 1 commit into from
Sep 25, 2016
Merged

Add a collector generator script #28

merged 1 commit into from
Sep 25, 2016

Conversation

carlpett
Copy link
Collaborator

There is a fair amount of boilerplate involved in creating a new collector, so I've attempted to automate that part. This PR adds a script which queries a WMI class to pull its member list, and then creates a skeleton collector implementation.

One potential improvement would be if we could get the CounterType from the WMI query as well, then it would be possible to make a better guess on what type of metric should be exposed. Right now it is hardcoded to GaugeValue.

It doesn't really fix #12, but it at least removes some of the tedium...

@martinlindhe
Copy link
Collaborator

martinlindhe commented Sep 24, 2016

very cool! I been meaning to learn "go generate", looks like i should study your impl. :)

minor nitpick comment, otherwise lets merge and continue improve upon.

} | ConvertTo-Json
$outFileName = "..\..\collector\$CollectorName.go".ToLower()
$input | .\collector-generator.exe | Out-File -NoClobber -Encoding UTF8 $outFileName
go fmt $outFileName
Copy link
Collaborator

Choose a reason for hiding this comment

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

nitpick: text files should end with a new line

)
{{ end }}
return nil, nil
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

nitpick: text files should end with a new line

@carlpett
Copy link
Collaborator Author

Actually, this doesn't use go generate, should probably look into that... This just uses the text/template package

@martinlindhe
Copy link
Collaborator

martinlindhe commented Sep 24, 2016

You're right of course. I commented before properly reading the code.
I think using go generate is basically doing what you do, plus add special // go:generate xxx comments in your code, to invoke it. There's a blog about it here: https://blog.golang.org/generate

@carlpett
Copy link
Collaborator Author

I had heard about it but it didn't cross my mind when doing this. I'll check it out some day, it is probably a better solution

@carlpett
Copy link
Collaborator Author

Fixed and squashed!

@martinlindhe martinlindhe merged commit 497ee65 into master Sep 25, 2016
@martinlindhe
Copy link
Collaborator

great work!

@martinlindhe martinlindhe deleted the generator-tool branch September 27, 2016 09:01
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.

Automatically convert WMI metrics to prometheus
2 participants