prometheus-community / node-exporter-textfile-collector-scripts

Scripts for node-exporter's textfile collector
Apache License 2.0
488 stars 185 forks source link

use a better heuristic for the apt update last run time #184

Closed anarcat closed 10 months ago

anarcat commented 10 months ago

As reported in #182, pkgcache.bin gets updated on more than just apt update. In particular, it gets modified when a package is installed, upgraded or removed.

So let's fallback on a better heuristic, which is the APT::Periodic timestamp. This should give us a much more precise and deliberate status.

We also fallback to the lists directory, which gets updated when new mirror lists gets moved into place. This does run the risk of staying silently unchanged if there's no change on mirrors but (a) that's rather infrequent and (b) we might actually want to warn on that anyway.

Closes: #183

anarcat commented 10 months ago

@julian-klode could you review this? I think it covers the comments you made in #182...

jcharaoui commented 10 months ago

If APT::Periodic is used at some point, and then disabled, wouldn't this report a false metric if apt is updated in another manner?

anarcat commented 10 months ago

On 2023-10-17 07:50:27, Jerome Charaoui wrote:

If APT::Periodic is used at some point, and then disabled, wouldn't this report a false metric if apt is updated in another manner?

If it's disabled, the code won't check that timestamp file, unless I got this wrong.

jcharaoui commented 10 months ago

On 2023-10-17 07:50:27, Jerome Charaoui wrote: If APT::Periodic is used at some point, and then disabled, wouldn't this report a false metric if apt is updated in another manner? If it's disabled, the code won't check that timestamp file, unless I got this wrong.

Right, my bad!

julian-klode commented 10 months ago

I think you want to use get_b or what it's called in the config object that returns a boolean so that it parses everything correctly.

anarcat commented 10 months ago

I think you want to use get_b or what it's called in the config object that returns a boolean so that it parses everything correctly.

It's a boolean? That wasn't quite clear to me, reading the documentation... I thought it could be a time delta (e.g. 1d) as well, which is why I compare against "0", as a string.

anarcat commented 10 months ago

@julian-klode you mean find_b()?

julian-klode commented 10 months ago

Yes indeed, find_b sorry. Wasn't on my laptop so didn't look it up :)

anarcat commented 10 months ago

thanks, fixed.