MINOR: stats: add new start time field

Another patch in order to try to reconciliate haproxy stats and
prometheus. Here I'm adding a proper start time field in order to make
proper use of uptime field.
That being done we can move the calculation in `fill_info`

Signed-off-by: William Dauchy <wdauchy@gmail.com>
This commit is contained in:
William Dauchy 2021-01-15 22:41:38 +01:00 committed by Christopher Faulet
parent a8766cfad1
commit defd15685e
3 changed files with 11 additions and 6 deletions

View File

@ -99,7 +99,8 @@ const int promex_global_metrics[INF_TOTAL_FIELDS] = {
[INF_PROCESS_NUM] = INF_UPTIME_SEC, [INF_PROCESS_NUM] = INF_UPTIME_SEC,
[INF_PID] = 0, [INF_PID] = 0,
[INF_UPTIME] = 0, [INF_UPTIME] = 0,
[INF_UPTIME_SEC] = INF_MEMMAX_BYTES, [INF_UPTIME_SEC] = INF_START_TIME_SEC,
[INF_START_TIME_SEC] = INF_MEMMAX_BYTES,
[INF_MEMMAX_BYTES] = INF_POOL_ALLOC_BYTES, [INF_MEMMAX_BYTES] = INF_POOL_ALLOC_BYTES,
[INF_POOL_ALLOC_BYTES] = INF_POOL_USED_BYTES, [INF_POOL_ALLOC_BYTES] = INF_POOL_USED_BYTES,
[INF_POOL_USED_BYTES] = INF_POOL_FAILED, [INF_POOL_USED_BYTES] = INF_POOL_FAILED,
@ -481,7 +482,8 @@ const struct ist promex_inf_metric_names[INF_TOTAL_FIELDS] = {
[INF_PROCESS_NUM] = IST("relative_process_id"), [INF_PROCESS_NUM] = IST("relative_process_id"),
[INF_PID] = IST("pid"), [INF_PID] = IST("pid"),
[INF_UPTIME] = IST("uptime"), [INF_UPTIME] = IST("uptime"),
[INF_UPTIME_SEC] = IST("start_time_seconds"), [INF_UPTIME_SEC] = IST("uptime_seconds"),
[INF_START_TIME_SEC] = IST("start_time_seconds"),
[INF_MEMMAX_BYTES] = IST("max_memory_bytes"), [INF_MEMMAX_BYTES] = IST("max_memory_bytes"),
[INF_POOL_ALLOC_BYTES] = IST("pool_allocated_bytes"), [INF_POOL_ALLOC_BYTES] = IST("pool_allocated_bytes"),
[INF_POOL_USED_BYTES] = IST("pool_used_bytes"), [INF_POOL_USED_BYTES] = IST("pool_used_bytes"),
@ -654,7 +656,8 @@ const struct ist promex_inf_metric_desc[INF_TOTAL_FIELDS] = {
[INF_PROCESS_NUM] = IST("Relative process id, starting at 1."), [INF_PROCESS_NUM] = IST("Relative process id, starting at 1."),
[INF_PID] = IST("HAProxy PID."), [INF_PID] = IST("HAProxy PID."),
[INF_UPTIME] = IST("Uptime in a human readable format."), [INF_UPTIME] = IST("Uptime in a human readable format."),
[INF_UPTIME_SEC] = IST("Start time in seconds."), [INF_UPTIME_SEC] = IST("Uptime in seconds."),
[INF_START_TIME_SEC] = IST("Start time in seconds."),
[INF_MEMMAX_BYTES] = IST("Per-process memory limit (in bytes); 0=unset."), [INF_MEMMAX_BYTES] = IST("Per-process memory limit (in bytes); 0=unset."),
[INF_POOL_ALLOC_BYTES] = IST("Total amount of memory allocated in pools (in bytes)."), [INF_POOL_ALLOC_BYTES] = IST("Total amount of memory allocated in pools (in bytes)."),
[INF_POOL_USED_BYTES] = IST("Total amount of memory used in pools (in bytes)."), [INF_POOL_USED_BYTES] = IST("Total amount of memory used in pools (in bytes)."),
@ -828,6 +831,7 @@ const struct ist promex_inf_metric_labels[INF_TOTAL_FIELDS] = {
[INF_PID] = IST(""), [INF_PID] = IST(""),
[INF_UPTIME] = IST(""), [INF_UPTIME] = IST(""),
[INF_UPTIME_SEC] = IST(""), [INF_UPTIME_SEC] = IST(""),
[INF_START_TIME_SEC] = IST(""),
[INF_MEMMAX_BYTES] = IST(""), [INF_MEMMAX_BYTES] = IST(""),
[INF_POOL_ALLOC_BYTES] = IST(""), [INF_POOL_ALLOC_BYTES] = IST(""),
[INF_POOL_USED_BYTES] = IST(""), [INF_POOL_USED_BYTES] = IST(""),
@ -994,6 +998,7 @@ const struct ist promex_inf_metric_types[INF_TOTAL_FIELDS] = {
[INF_PID] = IST("untyped"), [INF_PID] = IST("untyped"),
[INF_UPTIME] = IST("untyped"), [INF_UPTIME] = IST("untyped"),
[INF_UPTIME_SEC] = IST("gauge"), [INF_UPTIME_SEC] = IST("gauge"),
[INF_START_TIME_SEC] = IST("gauge"),
[INF_MEMMAX_BYTES] = IST("gauge"), [INF_MEMMAX_BYTES] = IST("gauge"),
[INF_POOL_ALLOC_BYTES] = IST("gauge"), [INF_POOL_ALLOC_BYTES] = IST("gauge"),
[INF_POOL_USED_BYTES] = IST("gauge"), [INF_POOL_USED_BYTES] = IST("gauge"),
@ -1333,9 +1338,6 @@ static int promex_dump_global_metrics(struct appctx *appctx, struct htx *htx)
case INF_BUILD_INFO: case INF_BUILD_INFO:
metric = mkf_u32(FN_GAUGE, 1); metric = mkf_u32(FN_GAUGE, 1);
break; break;
case INF_UPTIME_SEC:
metric = mkf_u32(FN_DURATION, start_date.tv_sec);
break;
default: default:
metric = info[appctx->st2]; metric = info[appctx->st2];

View File

@ -327,6 +327,7 @@ enum info_field {
INF_MEMMAX_BYTES, INF_MEMMAX_BYTES,
INF_POOL_ALLOC_BYTES, INF_POOL_ALLOC_BYTES,
INF_POOL_USED_BYTES, INF_POOL_USED_BYTES,
INF_START_TIME_SEC,
/* must always be the last one */ /* must always be the last one */
INF_TOTAL_FIELDS INF_TOTAL_FIELDS

View File

@ -91,6 +91,7 @@ const struct name_desc info_fields[INF_TOTAL_FIELDS] = {
[INF_PID] = { .name = "Pid", .desc = "This worker process identifier for the system" }, [INF_PID] = { .name = "Pid", .desc = "This worker process identifier for the system" },
[INF_UPTIME] = { .name = "Uptime", .desc = "How long ago this worker process was started (days+hours+minutes+seconds)" }, [INF_UPTIME] = { .name = "Uptime", .desc = "How long ago this worker process was started (days+hours+minutes+seconds)" },
[INF_UPTIME_SEC] = { .name = "Uptime_sec", .desc = "How long ago this worker process was started (seconds)" }, [INF_UPTIME_SEC] = { .name = "Uptime_sec", .desc = "How long ago this worker process was started (seconds)" },
[INF_START_TIME_SEC] = { .name = "Start_time_sec", .desc = "Start time in seconds" },
[INF_MEMMAX_MB] = { .name = "Memmax_MB", .desc = "Worker process's hard limit on memory usage in MB (-m on command line)" }, [INF_MEMMAX_MB] = { .name = "Memmax_MB", .desc = "Worker process's hard limit on memory usage in MB (-m on command line)" },
[INF_MEMMAX_BYTES] = { .name = "Memmax_bytes", .desc = "Worker process's hard limit on memory usage in byes (-m on command line)" }, [INF_MEMMAX_BYTES] = { .name = "Memmax_bytes", .desc = "Worker process's hard limit on memory usage in byes (-m on command line)" },
[INF_POOL_ALLOC_MB] = { .name = "PoolAlloc_MB", .desc = "Amount of memory allocated in pools (in MB)" }, [INF_POOL_ALLOC_MB] = { .name = "PoolAlloc_MB", .desc = "Amount of memory allocated in pools (in MB)" },
@ -3851,6 +3852,7 @@ int stats_fill_info(struct field *info, int len)
chunk_appendf(out, "%ud %uh%02um%02us", up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60)); chunk_appendf(out, "%ud %uh%02um%02us", up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60));
info[INF_UPTIME_SEC] = mkf_u32(FN_DURATION, up); info[INF_UPTIME_SEC] = mkf_u32(FN_DURATION, up);
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_MB] = mkf_u32(FO_CONFIG|FN_LIMIT, global.rlimit_memmax);
info[INF_MEMMAX_BYTES] = mkf_u32(FO_CONFIG|FN_LIMIT, global.rlimit_memmax * 1048576L); info[INF_MEMMAX_BYTES] = mkf_u32(FO_CONFIG|FN_LIMIT, global.rlimit_memmax * 1048576L);
info[INF_POOL_ALLOC_MB] = mkf_u32(0, (unsigned)(pool_total_allocated() / 1048576L)); info[INF_POOL_ALLOC_MB] = mkf_u32(0, (unsigned)(pool_total_allocated() / 1048576L));