From 49415b23424208799f8155f85e68da0a83ea04d4 Mon Sep 17 00:00:00 2001 From: Denis Vaksman Date: Thu, 15 Aug 2024 18:15:19 +0300 Subject: [PATCH] Send `kphp_version` StatsHouse metric as count (not value) metric (#1066) --- runtime/php_assert.cpp | 2 ++ runtime/php_assert.h | 2 ++ server/php-engine.cpp | 1 + server/php-master.cpp | 4 ++-- server/statshouse/statshouse-manager.cpp | 3 ++- 5 files changed, 9 insertions(+), 3 deletions(-) diff --git a/runtime/php_assert.cpp b/runtime/php_assert.cpp index 80decabd90..a41b6d1a8b 100644 --- a/runtime/php_assert.cpp +++ b/runtime/php_assert.cpp @@ -32,6 +32,8 @@ #include "server/php-engine-vars.h" const char *engine_tag = "["; +long long engine_tag_number = 0; + const char *engine_pid = "] "; int php_disable_warnings = 0; diff --git a/runtime/php_assert.h b/runtime/php_assert.h index 0532199bac..e35ded1eef 100644 --- a/runtime/php_assert.h +++ b/runtime/php_assert.h @@ -16,6 +16,8 @@ extern int die_on_fail; extern const char *engine_tag; +extern long long engine_tag_number; + extern const char *engine_pid; extern int php_disable_warnings; diff --git a/server/php-engine.cpp b/server/php-engine.cpp index 61d1ce3bf1..1dc11ca64f 100644 --- a/server/php-engine.cpp +++ b/server/php-engine.cpp @@ -1834,6 +1834,7 @@ int main_args_handler(int i, const char *long_option) { } case 'E': { read_engine_tag(optarg); + engine_tag_number = atoll(engine_tag); return 0; } case 'm': { diff --git a/server/php-master.cpp b/server/php-master.cpp index 80d5d851c0..611c647c8c 100644 --- a/server/php-master.cpp +++ b/server/php-master.cpp @@ -959,7 +959,7 @@ std::string php_master_prepare_stats(bool add_worker_pids) { oss << "uptime\t" << get_uptime() << "\n"; if (engine_tag) { // engine_tag may be ended with "[" - oss << "kphp_version\t" << atoll(engine_tag) << "\n"; + oss << "kphp_version\t" << engine_tag_number << "\n"; } const auto &config = vk::singleton::get(); if (!config.get_environment().empty()) { @@ -1105,7 +1105,7 @@ static long long int instance_cache_memory_swaps_fail = 0; STATS_PROVIDER_TAGGED(kphp_stats, 100, stats_tag_kphp_server) { if (engine_tag) { - stats->add_gauge_stat("kphp_version", atoll(engine_tag)); + stats->add_gauge_stat("kphp_version", engine_tag_number); } stats->add_gauge_stat("uptime", get_uptime()); diff --git a/server/statshouse/statshouse-manager.cpp b/server/statshouse/statshouse-manager.cpp index 9af11021d0..78b492ebb5 100644 --- a/server/statshouse/statshouse-manager.cpp +++ b/server/statshouse/statshouse-manager.cpp @@ -5,6 +5,7 @@ #include "server/statshouse/statshouse-manager.h" #include +#include #include "common/precise-time.h" #include "common/resolver.h" @@ -181,7 +182,7 @@ void StatsHouseManager::add_common_master_stats(const workers_stats_t &workers_s double cpu_s_usage, double cpu_u_usage, long long int instance_cache_memory_swaps_ok, long long int instance_cache_memory_swaps_fail) { if (engine_tag) { - client.metric("kphp_version").write_value(atoll(engine_tag)); + client.metric("kphp_version").tag(std::to_string(engine_tag_number)).write_count(1); } client.metric("kphp_uptime").write_value(get_uptime());