From: Shachar Sharon Date: Mon, 27 Apr 2026 08:58:10 +0000 (+0300) Subject: s3/smb_prometheus_endpoint: single function to export profile stats X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4e9533575f06a0a414e4274cdd97882e13170429;p=thirdparty%2Fsamba.git s3/smb_prometheus_endpoint: single function to export profile stats Avoid duplicated defines: use 'export_profile_stats' to export both global profile counters and per-share counters. Signed-off-by: Shachar Sharon Reviewed-by: Anoop C S Reviewed-by: Gary Lockyer Autobuild-User(master): Anoop C S Autobuild-Date(master): Thu May 21 06:41:46 UTC 2026 on atb-devel-224 --- diff --git a/source3/utils/smb_prometheus_endpoint.c b/source3/utils/smb_prometheus_endpoint.c index 43d68aafdab..e0b8f5d04a4 100644 --- a/source3/utils/smb_prometheus_endpoint.c +++ b/source3/utils/smb_prometheus_endpoint.c @@ -36,7 +36,8 @@ struct export_state { bool sent_help_smb2_request_failed : 1; }; -static void export_count(const char *name, +static void export_count(const char *svc, + const char *name, const struct smbprofile_stats_count *val, struct export_state *state) { @@ -55,7 +56,8 @@ static void export_count(const char *name, evbuffer_add_printf( state->buf, - "smb_authentications %" PRIu64"\n", + "smb_authentications { share=\"%s\" } %" PRIu64 "\n", + svc ? svc : "", val->count); } @@ -72,12 +74,15 @@ static void export_count(const char *name, evbuffer_add_printf( state->buf, - "smb_authentications_failed %" PRIu64"\n", + "smb_authentications_failed { share=\"%s\" } " + "%" PRIu64 "\n", + svc ? svc : "", val->count); } } -static void export_time(const char *name, +static void export_time(const char *svc, + const char *name, const struct smbprofile_stats_time *val, struct export_state *state) { @@ -98,7 +103,9 @@ static void export_time(const char *name, evbuffer_add_printf( state->buf, - "smb_cpu_seconds_total { mode=\"%s\" } %f\n", + "smb_cpu_seconds_total { share=\"%s\",mode=\"%s\" } " + "%f\n", + svc ? svc : "", mode, ((double)val->time) / 1000000); } @@ -127,7 +134,7 @@ static void export_basic(const char *svc, "smb_smb1_request_total { " "share=\"%s\",operation=\"%s\" } " "%" PRIu64 "\n", - svc, + svc ? svc : "", name + 3, val->count); } @@ -156,7 +163,7 @@ static void export_iobytes_inbytes(const char *svc, "smb_smb2_request_inbytes { " "share=\"%s\",operation=\"%s\" } " "%" PRIu64 "\n", - svc, + svc ? svc : "", name + 5, val->inbytes); } @@ -184,7 +191,7 @@ static void export_iobytes_outbytes(const char *svc, "smb_smb2_request_outbytes { " "share=\"%s\",operation=\"%s\" } " "%" PRIu64 "\n", - svc, + svc ? svc : "", name + 5, val->outbytes); } @@ -217,7 +224,7 @@ static void export_iobytes_buckets(const char *svc, "smb_smb2_request_duration_microseconds_bucket " "{share=\"%s\",operation=\"%s\",le=\"%d000\"} " "%" PRIu64 "\n", - svc, + svc ? svc : "", name + 5, 1 << i, val->buckets[i]); @@ -227,7 +234,7 @@ static void export_iobytes_buckets(const char *svc, "smb_smb2_request_duration_microseconds_bucket " "{share=\"%s\",operation=\"%s\",le=\"+Inf\"} " "%" PRIu64 "\n", - svc, + svc ? svc : "", name + 5, val->buckets[9]); evbuffer_add_printf( @@ -235,7 +242,7 @@ static void export_iobytes_buckets(const char *svc, "smb_smb2_request_duration_microseconds_sum " "{share=\"%s\",operation=\"%s\"} " "%" PRIu64 "\n", - svc, + svc ? svc : "", name + 5, val->time); evbuffer_add_printf( @@ -243,7 +250,7 @@ static void export_iobytes_buckets(const char *svc, "smb_smb2_request_duration_microseconds_count " "{share=\"%s\",operation=\"%s\"} " "%" PRIu64 "\n", - svc, + svc ? svc : "", name + 5, val->count); } @@ -271,155 +278,26 @@ static void export_iobytes_failed(const char *svc, "smb_smb2_request_failed { " "share=\"%s\",operation=\"%s\" } " "%" PRIu64 "\n", - svc, + svc ? svc : "", name + 5, val->failed_count); } } static void export_profile_stats(const struct profile_stats *stats, + const char *svc, struct export_state *state) { #define SMBPROFILE_STATS_START #define SMBPROFILE_STATS_SECTION_START(name, display) -#define SMBPROFILE_STATS_COUNT(name) \ - do { \ - export_count(#name, &stats->values.name##_stats, state); \ - } while (0); -#define SMBPROFILE_STATS_TIME(name) \ - do { \ - export_time(#name, &stats->values.name##_stats, state); \ +#define SMBPROFILE_STATS_COUNT(name) \ + do { \ + export_count(svc, #name, &stats->values.name##_stats, state); \ } while (0); -#define SMBPROFILE_STATS_BASIC(name) \ +#define SMBPROFILE_STATS_TIME(name) \ do { \ - export_basic("", #name, &stats->values.name##_stats, state); \ - } while (0); -#define SMBPROFILE_STATS_BYTES(name) -#define SMBPROFILE_STATS_IOBYTES(name) -#define SMBPROFILE_STATS_SECTION_END -#define SMBPROFILE_STATS_END - SMBPROFILE_STATS_ALL_SECTIONS -#undef SMBPROFILE_STATS_START -#undef SMBPROFILE_STATS_SECTION_START -#undef SMBPROFILE_STATS_COUNT -#undef SMBPROFILE_STATS_TIME -#undef SMBPROFILE_STATS_BASIC -#undef SMBPROFILE_STATS_BYTES -#undef SMBPROFILE_STATS_IOBYTES -#undef SMBPROFILE_STATS_SECTION_END -#undef SMBPROFILE_STATS_END - -#define SMBPROFILE_STATS_START -#define SMBPROFILE_STATS_SECTION_START(name, display) -#define SMBPROFILE_STATS_COUNT(name) -#define SMBPROFILE_STATS_TIME(name) -#define SMBPROFILE_STATS_BASIC(name) -#define SMBPROFILE_STATS_BYTES(name) -#define SMBPROFILE_STATS_IOBYTES(name) \ - do { \ - export_iobytes_inbytes("", \ - #name, \ - &stats->values.name##_stats, \ - state); \ - } while (0); -#define SMBPROFILE_STATS_SECTION_END -#define SMBPROFILE_STATS_END - SMBPROFILE_STATS_ALL_SECTIONS -#undef SMBPROFILE_STATS_START -#undef SMBPROFILE_STATS_SECTION_START -#undef SMBPROFILE_STATS_COUNT -#undef SMBPROFILE_STATS_TIME -#undef SMBPROFILE_STATS_BASIC -#undef SMBPROFILE_STATS_BYTES -#undef SMBPROFILE_STATS_IOBYTES -#undef SMBPROFILE_STATS_SECTION_END -#undef SMBPROFILE_STATS_END - -#define SMBPROFILE_STATS_START -#define SMBPROFILE_STATS_SECTION_START(name, display) -#define SMBPROFILE_STATS_COUNT(name) -#define SMBPROFILE_STATS_TIME(name) -#define SMBPROFILE_STATS_BASIC(name) -#define SMBPROFILE_STATS_BYTES(name) -#define SMBPROFILE_STATS_IOBYTES(name) \ - do { \ - export_iobytes_outbytes("", \ - #name, \ - &stats->values.name##_stats, \ - state); \ + export_time(svc, #name, &stats->values.name##_stats, state); \ } while (0); -#define SMBPROFILE_STATS_SECTION_END -#define SMBPROFILE_STATS_END - SMBPROFILE_STATS_ALL_SECTIONS -#undef SMBPROFILE_STATS_START -#undef SMBPROFILE_STATS_SECTION_START -#undef SMBPROFILE_STATS_COUNT -#undef SMBPROFILE_STATS_TIME -#undef SMBPROFILE_STATS_BASIC -#undef SMBPROFILE_STATS_BYTES -#undef SMBPROFILE_STATS_IOBYTES -#undef SMBPROFILE_STATS_SECTION_END -#undef SMBPROFILE_STATS_END - -#define SMBPROFILE_STATS_START -#define SMBPROFILE_STATS_SECTION_START(name, display) -#define SMBPROFILE_STATS_COUNT(name) -#define SMBPROFILE_STATS_TIME(name) -#define SMBPROFILE_STATS_BASIC(name) -#define SMBPROFILE_STATS_BYTES(name) -#define SMBPROFILE_STATS_IOBYTES(name) \ - do { \ - export_iobytes_buckets("", \ - #name, \ - &stats->values.name##_stats, \ - state); \ - } while (0); -#define SMBPROFILE_STATS_SECTION_END -#define SMBPROFILE_STATS_END - SMBPROFILE_STATS_ALL_SECTIONS -#undef SMBPROFILE_STATS_START -#undef SMBPROFILE_STATS_SECTION_START -#undef SMBPROFILE_STATS_COUNT -#undef SMBPROFILE_STATS_TIME -#undef SMBPROFILE_STATS_BASIC -#undef SMBPROFILE_STATS_BYTES -#undef SMBPROFILE_STATS_IOBYTES -#undef SMBPROFILE_STATS_SECTION_END -#undef SMBPROFILE_STATS_END - -#define SMBPROFILE_STATS_START -#define SMBPROFILE_STATS_SECTION_START(name, display) -#define SMBPROFILE_STATS_COUNT(name) -#define SMBPROFILE_STATS_TIME(name) -#define SMBPROFILE_STATS_BASIC(name) -#define SMBPROFILE_STATS_BYTES(name) -#define SMBPROFILE_STATS_IOBYTES(name) \ - do { \ - export_iobytes_failed("", \ - #name, \ - &stats->values.name##_stats, \ - state); \ - } while (0); -#define SMBPROFILE_STATS_SECTION_END -#define SMBPROFILE_STATS_END - SMBPROFILE_STATS_ALL_SECTIONS -#undef SMBPROFILE_STATS_START -#undef SMBPROFILE_STATS_SECTION_START -#undef SMBPROFILE_STATS_COUNT -#undef SMBPROFILE_STATS_TIME -#undef SMBPROFILE_STATS_BASIC -#undef SMBPROFILE_STATS_BYTES -#undef SMBPROFILE_STATS_IOBYTES -#undef SMBPROFILE_STATS_SECTION_END -#undef SMBPROFILE_STATS_END -} - -static void export_profile_persvc_stats(const struct profile_stats *stats, - const char *svc, - struct export_state *state) -{ -#define SMBPROFILE_STATS_START -#define SMBPROFILE_STATS_SECTION_START(name, display) #define SMBPROFILE_STATS_BASIC(name) \ do { \ export_basic(svc, #name, &stats->values.name##_stats, state); \ @@ -428,7 +306,7 @@ static void export_profile_persvc_stats(const struct profile_stats *stats, #define SMBPROFILE_STATS_IOBYTES(name) #define SMBPROFILE_STATS_SECTION_END #define SMBPROFILE_STATS_END - SMBPROFILE_STATS_PERSVC_SECTIONS + SMBPROFILE_STATS_ALL_SECTIONS #undef SMBPROFILE_STATS_START #undef SMBPROFILE_STATS_SECTION_START #undef SMBPROFILE_STATS_COUNT @@ -480,7 +358,7 @@ static void export_profile_persvc_stats(const struct profile_stats *stats, } while (0); #define SMBPROFILE_STATS_SECTION_END #define SMBPROFILE_STATS_END - SMBPROFILE_STATS_PERSVC_SECTIONS + SMBPROFILE_STATS_ALL_SECTIONS #undef SMBPROFILE_STATS_START #undef SMBPROFILE_STATS_SECTION_START #undef SMBPROFILE_STATS_COUNT @@ -506,7 +384,7 @@ static void export_profile_persvc_stats(const struct profile_stats *stats, } while (0); #define SMBPROFILE_STATS_SECTION_END #define SMBPROFILE_STATS_END - SMBPROFILE_STATS_PERSVC_SECTIONS + SMBPROFILE_STATS_ALL_SECTIONS #undef SMBPROFILE_STATS_START #undef SMBPROFILE_STATS_SECTION_START #undef SMBPROFILE_STATS_COUNT @@ -532,7 +410,7 @@ static void export_profile_persvc_stats(const struct profile_stats *stats, } while (0); #define SMBPROFILE_STATS_SECTION_END #define SMBPROFILE_STATS_END - SMBPROFILE_STATS_PERSVC_SECTIONS + SMBPROFILE_STATS_ALL_SECTIONS #undef SMBPROFILE_STATS_START #undef SMBPROFILE_STATS_SECTION_START #undef SMBPROFILE_STATS_COUNT @@ -563,7 +441,7 @@ static int export_profile_persvc(const char *key, *sep = '\0'; } - export_profile_persvc_stats(stats, svc, state); + export_profile_stats(stats, svc, state); free(svc); return 0; } @@ -651,7 +529,7 @@ static void metrics_handler(struct evhttp_request *req, void *arg) "smb_num_open_files %" PRIu64 "\n", stats.values.num_files_stats.count); - export_profile_stats(&stats, &state); + export_profile_stats(&stats, NULL, &state); /* * Re-open TDB file with read-only mode and iterate-export per-share