From: Steinar H. Gunderson Date: Mon, 12 Jun 2017 21:37:18 +0000 (+0200) Subject: Expose a metric for the free disk space (already possible via the normal node exporte... X-Git-Tag: 1.6.1~50 X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=65fda6b2dadac691df6214945e0862551a11bd4c;p=nageru Expose a metric for the free disk space (already possible via the normal node exporter, but with this one, you don't need to hunt for the right filesystem). --- diff --git a/disk_space_estimator.cpp b/disk_space_estimator.cpp index cacc811..a196105 100644 --- a/disk_space_estimator.cpp +++ b/disk_space_estimator.cpp @@ -5,11 +5,13 @@ #include #include +#include "metrics.h" #include "timebase.h" DiskSpaceEstimator::DiskSpaceEstimator(DiskSpaceEstimator::callback_t callback) : callback(callback) { + global_metrics.add("disk_free_bytes", &metric_disk_free_bytes, Metrics::TYPE_GAUGE); } void DiskSpaceEstimator::report_write(const std::string &filename, uint64_t pts) @@ -41,8 +43,10 @@ void DiskSpaceEstimator::report_write(const std::string &filename, uint64_t pts) return; } + off_t free_bytes = off_t(fst.f_bavail) * fst.f_frsize; + metric_disk_free_bytes = free_bytes; + if (!measure_points.empty()) { - off_t free_bytes = off_t(fst.f_bavail) * fst.f_frsize; double bytes_per_second = double(st.st_size - measure_points.front().size) / (pts - measure_points.front().pts) * TIMEBASE; double seconds_left = free_bytes / bytes_per_second; diff --git a/disk_space_estimator.h b/disk_space_estimator.h index 2acd4be..c5b63bf 100644 --- a/disk_space_estimator.h +++ b/disk_space_estimator.h @@ -11,6 +11,7 @@ #include #include +#include #include #include #include @@ -43,6 +44,9 @@ private: off_t size; }; std::deque measure_points; + + // Metrics. + std::atomic metric_disk_free_bytes{-1}; }; extern DiskSpaceEstimator *global_disk_space_estimator;