i would like to show you a new community beat i created. It's called Perfmonbeat and it is a beat to collect perfomance counters from windows. It's yet very basic and there is a lot more to do ( exception handling, configs, naming of outputs, ...). But i want to discuss with you if it goes in the right direction and if there is a need for such a beat.
I definitely like the idea of collecting perf data through the PDH API.
It looks like this would work nicely as a MetricSet in Metricbeat. Instead of using the beat generator there is a metricset generator that creates a standalone beat using Metricbeat as a framework. Then you would have a MetricSet that could be later integrated into Metricbeat or be used as a plugin.
I didn't review the code since it's a work in progress. But one thing you should consider doing is generating code for the methods you need in the PDH API (here's a place where we do that in gosigar). It uses the mksyscall_windows tool from Go.
And if you require constants from header files you can do some generation there too. You would create a defs_windows.go file that contains cgo code then run a generator to build another go file. See defs_windows.go.
This makes the code a little cleaner and means that you don't need to use cgo for your builds which then allows for easier cross-compiles.
Hi @andrewkroh, many thanks for that detailed answer!! Especially for that part with cgo!! Really exciting stuff I also think it is better to create this as a MetricSet. I just wanted to start with coding. I create a new metricset an come back if i'm done.
Hi @andrewkroh, i have create a new repo to build a MetricSet instead of a beat. Now i'm try to configure config settings for that metricset. Assume the following structure i created
Should that command be present in all def files? defs_windows_amd64.go, defs_windows_386.go. Is it necessary to create these 386, amd64 files or is it better to copy the output from the cgo command into defs_windows.go and just have this file? There is also one thing more i created a wrapper pdh_windows.go like you say.
//go:generate go run $GOROOT/src/syscall/mksyscall_windows.go -output pdh_windows.go pdh.go
// Windows API calls
//sys _PdhOpenQuery(dataSource *string, userData int, query *syscall.Handle) (err int) = pdh.PdhOpenQuery
//sys _PdhAddCounter(query syscall.Handle, counterPath string, userData int, counter *syscall.Handle) (err int) = pdh.PdhAddCounter
//sys _PdhCollectQueryData(query syscall.Handle) (err int) = pdh.PdhCollectQueryData
//sys _PdhGetFormattedCounterValue(counter syscall.Handle, format int, counterType int, value PdhCounterValue) (err int) = pdh.GetFormattedCounterValue
This all works fine, except in the output file there is an import statement "golang.org/x/sys/windows". which is used by modpdh = windows.NewLazySystemDLL("pdh.dll"). should i use syscall instead and then modpdh = syscall.NewLazyDLL("pdh.dll")??
defs_windows.go is the source file for generating defs_windows_amd64.go and defs_windows_386.go. All three files should be committed to your repo. defs_windows.go will not be used by go build so it needs to have the build tag so that the compiler ignore it. Doing this allows us to build without needing cgo. cgo is only needed if we have to change defs_windows.go and need to regenerate defs_windows_amd64.go and defs_windows_386.go.
What "output" file? The code generated by mksyscall_windows.go should have imports for syscall and not windows.
It looks like it does have logic for the golang.org/x/sys/windows package. https://golang.org/src/syscall/mksyscall_windows.go#L741 I didn't examine the logic, but I would prefer functions in the syscall package over golang.org/x/sys/windows if you have a choice (just to reduce the external deps). But if there's a function in the windows package that makes life easier use it.
Ok, i will use the syscall package. Here are the new metricset i have created (ignore the name of the beat). There is only that error with unexpteced NUL in defs_windows_amd64.go. Maybe you have some time to look over. I can't see whats wrong with this file
Ohh, got it. This error throws if you are in the wrong folder. I tried go build in maddin2016/pdhbeat instead of maddin2016\pdhbeat\module\windows. How can i test if the new metricset is working? Do i have to build the whole metricbeat?
go build in GitHub - martinscholz83/pdhbeat will produce pdhbeat.exe that you can use. If you uncomment this line you can use the the normal metricbeat modules too (the configuration will all be namespaced under pdhbeat instead of metricbeat).
Check defs_windows.go for bad characters. Run gofmt on it and gofmt on the output files too. I'm seeing bad encoding.
Hi @andrewkroh, if you had the time can try to run this metricbeat on a windows machine. I had to do some fixing of types and add some errors. But basically it is running.
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.