]> git.sesse.net Git - nageru/commitdiff
Expose the start time point instead of the uptime, as per Prometheus recommendations.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Mon, 12 Jun 2017 19:52:09 +0000 (21:52 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Mon, 12 Jun 2017 19:52:09 +0000 (21:52 +0200)
metrics.cpp
metrics.h
mixer.cpp
mixer.h

index 1f3f8a1c18b6478b2c7d5b3956137a3aa67169d9..fd5e54c1c7f48b09d38f64ddd91d84bee4a3b6c0 100644 (file)
@@ -4,13 +4,20 @@
 #include <math.h>
 
 #include <algorithm>
+#include <chrono>
 #include <locale>
 #include <sstream>
 
 using namespace std;
+using namespace std::chrono;
 
 Metrics global_metrics;
 
+double get_timestamp_for_metrics()
+{
+       return duration<double>(system_clock::now().time_since_epoch()).count();
+}
+
 namespace {
 
 string serialize_name(const string &name, const vector<pair<string, string>> &labels)
index a8156587a5f2484da831eda01af26cc0c4742454..bd506a97c6c11dfdbc19247706acae5cb995b497 100644 (file)
--- a/metrics.h
+++ b/metrics.h
 
 class Histogram;
 
+// Prometheus recommends the use of timestamps instead of “time since event”,
+// so you can use this to get the number of seconds since the epoch.
+// Note that this will be wrong if your clock changes, so for non-metric use,
+// you should use std::chrono::steady_clock instead.
+double get_timestamp_for_metrics();
+
 class Metrics {
 public:
        enum Type {
index 24f2a8091c941a8f9338964902be0c988a7a6ba9..400fdd189e3935bb1148e3abc88796abc8c5bb4e 100644 (file)
--- a/mixer.cpp
+++ b/mixer.cpp
@@ -402,9 +402,11 @@ Mixer::Mixer(const QSurfaceFormat &format, unsigned num_cards)
                set_output_card_internal(global_flags.output_card);
        }
 
+       metric_start_time_seconds = get_timestamp_for_metrics();
+
        global_metrics.add("frames_output_total", &metric_frames_output_total);
        global_metrics.add("frames_output_dropped", &metric_frames_output_dropped);
-       global_metrics.add("uptime_seconds", &metric_uptime_seconds);
+       global_metrics.add("start_time_seconds", &metric_start_time_seconds);
        global_metrics.add("memory_used_bytes", &metrics_memory_used_bytes);
        global_metrics.add("metrics_memory_locked_limit_bytes", &metrics_memory_locked_limit_bytes);
 }
@@ -937,7 +939,6 @@ void Mixer::thread_func()
 
                metric_frames_output_total = frame_num;
                metric_frames_output_dropped = stats_dropped_frames;
-               metric_uptime_seconds = elapsed;
 
                if (frame_num % 100 == 0) {
                        printf("%d frames (%d dropped) in %.3f seconds = %.1f fps (%.1f ms/frame)",
diff --git a/mixer.h b/mixer.h
index e2490ede7d9245b43db081f73abc3b975e605e59..8504d5eb4bb9d6a56d8b68dd2ab04464b0bcecfd 100644 (file)
--- a/mixer.h
+++ b/mixer.h
@@ -543,7 +543,7 @@ private:
        // Metrics.
        std::atomic<int64_t> metric_frames_output_total{0};
        std::atomic<int64_t> metric_frames_output_dropped{0};
-       std::atomic<double> metric_uptime_seconds{0.0};
+       std::atomic<double> metric_start_time_seconds{0.0 / 0.0};
        std::atomic<int64_t> metrics_memory_used_bytes{0};
        std::atomic<double> metrics_memory_locked_limit_bytes{0.0 / 0.0};
 };