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

Bring the textfile collector over from node_exporter #174

Merged

Conversation

poblahblahblah
Copy link
Contributor

This adds a slightly modified textfile collector from the official
node_exporter project.

@poblahblahblah
Copy link
Contributor Author

I am not sure how to test creating and using the MSI installer, so I am fairly confident that it's not correct. Any tips on how to test this locally would be much appreciated and I can follow up with a PR for the README.

)

var (
textFileDirectory = flag.String("collector.textfile.directory", "C:\\Program Files\\prometheus\\textfile_inputs", "Directory to read text files with metrics from.")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is this a sane default?

@@ -27,7 +27,7 @@ type WmiCollector struct {
}

const (
defaultCollectors = "cpu,cs,logical_disk,net,os,service,system"
defaultCollectors = "cpu,cs,logical_disk,net,os,service,system,textfile"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Perhaps we don't want this as a default?

Copy link
Collaborator

@carlpett carlpett left a comment

Choose a reason for hiding this comment

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

Thanks! This has been requested quite a few times, so great work implementing it.
There are a couple of things that I think needs some discussion, but in general, seems good!

)

var (
textFileDirectory = flag.String("collector.textfile.directory", "C:\\Program Files\\prometheus\\textfile_inputs", "Directory to read text files with metrics from.")
Copy link
Collaborator

Choose a reason for hiding this comment

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

We default the installation to C:\Program Files\wmi_exporter so it would be nice to use that, instead of requiring a new directory here.

textFileDirectory = flag.String("collector.textfile.directory", "C:\\Program Files\\prometheus\\textfile_inputs", "Directory to read text files with metrics from.")
textFileAddOnce sync.Once
mtimeDesc = prometheus.NewDesc(
"node_textfile_mtime_seconds",
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think we should be putting metrics inside the node namespace, even ones that are supposed to be compatible? Seems like a dangerous route to go down...
That is, I think this should be wmi_... instead.

buckets, values...,
)
default:
panic("unknown metric type")
Copy link
Collaborator

Choose a reason for hiding this comment

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

I know this probably comes from the node_exporter code, but should we really panic? I don't like the idea of crashing the exporter just because one of the data sources are bad.
I would prefer just logging this, possibly increasing some diagnostic metric, and then continue.

// Export if there were errors.
ch <- prometheus.MustNewConstMetric(
prometheus.NewDesc(
"node_textfile_scrape_error",
Copy link
Collaborator

Choose a reason for hiding this comment

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

As mentioned previously, I don't think this should be in the node namespace.


// Suppress a log message about `nonexistent_path` not existing, this is
// expected and clutters the test output.
log.AddFlags(kingpin.CommandLine)
Copy link
Collaborator

Choose a reason for hiding this comment

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

We haven't switched the wmi_exporter to kingpin for flags yet, so this probably doesn't make sense

path string
out string
}{
{
Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe these files need to exist for the tests to pass?

README.md Outdated
@@ -22,6 +22,7 @@ process | [Win32_PerfRawData_PerfProc_Process](https://msdn.microsoft.com/en-us/
service | [Win32_Service](https://msdn.microsoft.com/en-us/library/aa394418(v=vs.85).aspx) metrics (service states) | &#10003;
system | Win32_PerfRawData_PerfOS_System metrics (system calls) | &#10003;
tcp | [Win32_PerfRawData_Tcpip_TCPv4](https://msdn.microsoft.com/en-us/library/aa394341(v=vs.85).aspx) metrics (tcp connections) |
textfile | Read prometheus metrics from a text file |
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since the collector is added to the defaults further down, it should be marked as such here as well (or not be enabled by default)

@@ -39,6 +40,7 @@ Name | Description
`LISTEN_ADDR` | The IP address to bind to. Defaults to 0.0.0.0
`LISTEN_PORT` | The port to bind to. Defaults to 9182.
`METRICS_PATH` | The path at which to serve metrics. Defaults to `/metrics`
`TEXTFILE_DIR` | As the `--collector.textfile.directory` flag, provide a directory to read text files with metrics from
Copy link
Collaborator

Choose a reason for hiding this comment

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

Currently should just be one -, ie -collector.textfile.directory, since we haven't switched to Kingpin yet

@carlpett
Copy link
Collaborator

There's a compilation failure in the tests, see here: https://ci.appveyor.com/project/martinlindhe/wmi-exporter/build/402/job/2l6kquvy0c8s6ln7.

@poblahblahblah poblahblahblah force-pushed the add-textfile-collector branch from a6975ea to d537631 Compare March 20, 2018 20:59
@carlpett
Copy link
Collaborator

Regarding the MSI, assuming you have compiled the exporter already, you can build it by running ./installer/build.ps1 -PathToExecutable ./wmi_exporter.exe -Version 0.2.99. This will build an msi that goes into ./installer/Output/, and you can test it from there. It should be fairly well-behaved, so just uninstall as usual if something isn't working, and try again.

@poblahblahblah poblahblahblah force-pushed the add-textfile-collector branch from 56def6c to 23ca54b Compare March 20, 2018 22:01
@poblahblahblah
Copy link
Contributor Author

It looks like wmi_exporter and node_exporter are more different than I had assumed when I just cargo culted this over, so the tests were fairly incompatible with wmi_exporter. This is not ideal, but for now I've removed the tests.

@poblahblahblah
Copy link
Contributor Author

The MSI that gets built doesn't work - will troubleshoot that.

@poblahblahblah
Copy link
Contributor Author

I guess the good news is that even if I build the installer from master it still doesn't work, so I am guessing this is a local issue. I'll try to find another wandows computer to test on.

@poblahblahblah
Copy link
Contributor Author

@carlpett it looks like -log.format is not a valid argument for wmi_exporter.exe, which is why my MSI is failing to install.

Here is what the wmi_exporter.wxs file configures the service to use:

"C:\Program Files\wmi_exporter\wmi_exporter.exe" -log.format logger:eventlog?name=wmi_exporter

Here's what happens when I try that command line flag against the compiled exe:

PS C:\Users\Patrick O'Brien\src\go\src\github.com\martinlindhe\wmi_exporter> ./wmi_exporter.exe -log.format logger:eventlog?name=wmi_exporter
2018/03/21 14:26:06 warning: Couldn't open registry to determine IIS version: The system cannot find the file specified.
flag provided but not defined: -log

Any guidance here?

@martinlindhe
Copy link
Collaborator

martinlindhe commented Mar 21, 2018

@poblahblahblah due to powershell parsing arguments with dots in them, you need to specify them like this:

"-log.format"

More info in #96

@poblahblahblah
Copy link
Contributor Author

@martinlindhe I guess my point is I didn't change anything with the wxs file so it looks like any time i build an MSI with that wxs file the MSI installer fails. Are you building the official packages with a different wxs file? I am pretty confused

@pete-leese
Copy link

This is an interesting feature!

Do you have any examples of where this could be used in a Windows world? Cheers Pete

@carlpett
Copy link
Collaborator

@poblahblahblah So sorry for missing this! Due to #169, current master doesn't build working msi:s. I've been pretty busy the last few days, but I'll see if I can fix it today.
If you just want to test your msi, you could make a temporary change which removes the logging flags in the .wxs
Again, apologies for wasting your time on this!

@poblahblahblah poblahblahblah force-pushed the add-textfile-collector branch from 23ca54b to b9607e6 Compare March 22, 2018 17:24
@poblahblahblah
Copy link
Contributor Author

@carlpett no worries!

I've updated the wxs file to work correctly. Everything works and my change looks good.

@poblahblahblah poblahblahblah force-pushed the add-textfile-collector branch 2 times, most recently from 5956389 to 8c66c64 Compare March 22, 2018 17:32
@poblahblahblah
Copy link
Contributor Author

@carlpett Any chance this can get a re-review?

@carlpett
Copy link
Collaborator

@poblahblahblah Yes, of course!
I did a fix for the log-flags in #112, which will also affect this PR a bit (changing the flag declaration syntax), so I would like to merge that first. Sounds ok?

@carlpett carlpett mentioned this pull request Mar 29, 2018

var (
textFileDirectory = flag.String("collector.textfile.directory", "C:\\Program Files\\wmi_exporter\\textfile_inputs", "Directory to read text files with metrics from.")
textFileAddOnce sync.Once
Copy link
Collaborator

Choose a reason for hiding this comment

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

This doesn't seem to be used?

@carlpett
Copy link
Collaborator

@poblahblahblah The flags PR is now merged! You'll need to

  • Change the definition of your flag to use kingpin (and add another - to the flag in the README)
  • Revert the log-flag removal and update with the new flag format in the wxs

I found an (I think) unused variable in my last pass over this, but apart from that, looks good!

This adds a slightly modified textfile collector from the official
node_exporter project.
@poblahblahblah poblahblahblah force-pushed the add-textfile-collector branch from 8c66c64 to aea89f1 Compare April 3, 2018 17:52
@poblahblahblah poblahblahblah force-pushed the add-textfile-collector branch from aea89f1 to 80002f3 Compare April 3, 2018 17:59
@poblahblahblah
Copy link
Contributor Author

poblahblahblah commented Apr 3, 2018

@carlpett ok - I think this is ready to go. Tested locally and everything worked like expected.

edit:

To address your comment about the unused variable - that is there to ensure that the textfile gatherer should only be added to the to the gatherer list once. See prometheus/node_exporter#738

@carlpett
Copy link
Collaborator

carlpett commented Apr 3, 2018

Great!
Regarding the variable - yes, that is the idea, but the piece of code which only adds it once doesn't seem to have come along with the translation? Also, I don't think we have the feature which made node_exporter need that part anyway?

@poblahblahblah
Copy link
Contributor Author

Ah - you are correct. Fix incoming.

@poblahblahblah poblahblahblah force-pushed the add-textfile-collector branch from cf5f1b6 to 51470bf Compare April 3, 2018 18:55
@carlpett
Copy link
Collaborator

carlpett commented Apr 3, 2018

LGTM!

@carlpett carlpett merged commit cf79239 into prometheus-community:master Apr 3, 2018
@carlpett
Copy link
Collaborator

carlpett commented Apr 3, 2018

Thanks @poblahblahblah!

anubhavg-icpl pushed a commit to anubhavg-icpl/windows_exporter that referenced this pull request Sep 22, 2024
…unity#174)

Bring the textfile collector over from node_exporter

This adds a slightly modified textfile collector from the official
node_exporter project.
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.

4 participants