]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: stats: use tv_remain() to precisely compute the uptime
authorWilly Tarreau <w@1wt.eu>
Sat, 8 May 2021 05:40:52 +0000 (07:40 +0200)
committerWilly Tarreau <w@1wt.eu>
Sat, 8 May 2021 08:52:12 +0000 (10:52 +0200)
We'll have to support reporting sub-second uptimes, so let's use the
appropriate function which will automatically adjust the tv_usec field.
In addition to this, it will also report a more accurate uptime thanks
to considering the sub-second part in the result.

src/stats.c

index a352a9bc22bda2b744e4c217256ad6cadd2764a8..4b58f662c65ea9e3e321d904835ee66534c3a559 100644 (file)
@@ -4293,7 +4293,7 @@ static int stats_dump_typed_info_fields(struct buffer *out,
  */
 int stats_fill_info(struct field *info, int len, uint flags)
 {
-       unsigned int up = (now.tv_sec - start_date.tv_sec);
+       struct timeval up;
        struct buffer *out = get_trash_chunk();
 
 #ifdef USE_OPENSSL
@@ -4307,6 +4307,8 @@ int stats_fill_info(struct field *info, int len, uint flags)
        }
 #endif
 
+       tv_remain(&start_date, &now, &up);
+
        if (len < INF_TOTAL_FIELDS)
                return 0;
 
@@ -4324,9 +4326,9 @@ int stats_fill_info(struct field *info, int len, uint flags)
        info[INF_PID]                            = mkf_u32(FO_STATUS, pid);
 
        info[INF_UPTIME]                         = mkf_str(FN_DURATION, chunk_newstr(out));
-       chunk_appendf(out, "%ud %uh%02um%02us", up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60));
+       chunk_appendf(out, "%ud %uh%02um%02us", (uint)up.tv_sec / 86400, ((uint)up.tv_sec % 86400) / 3600, ((uint)up.tv_sec % 3600) / 60, ((uint)up.tv_sec % 60));
 
-       info[INF_UPTIME_SEC]                     = mkf_u32(FN_DURATION, up);
+       info[INF_UPTIME_SEC]                     = mkf_u32(FN_DURATION, up.tv_sec);
        info[INF_START_TIME_SEC]                 = mkf_u32(FN_DURATION, start_date.tv_sec);
        info[INF_MEMMAX_MB]                      = mkf_u32(FO_CONFIG|FN_LIMIT, global.rlimit_memmax);
        info[INF_MEMMAX_BYTES]                   = mkf_u32(FO_CONFIG|FN_LIMIT, global.rlimit_memmax * 1048576L);