Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Publish runtime metric in seconds #5893

Merged
merged 7 commits into from
Aug 11, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 44 additions & 12 deletions src/v/redpanda/application.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
#include "redpanda/admin_server.h"
#include "resource_mgmt/io_priority.h"
#include "rpc/simple_protocol.h"
#include "ssx/metrics.h"
#include "storage/backlog_controller.h"
#include "storage/chunk_cache.h"
#include "storage/compaction_controller.h"
Expand Down Expand Up @@ -317,23 +316,56 @@ void application::initialize(
}

void application::setup_metrics() {
if (!config::shard_local_cfg().disable_public_metrics()) {
seastar::metrics::replicate_metric_families(
seastar::metrics::default_handle(),
{{"scheduler_runtime_ms", ssx::metrics::public_metrics_handle},
{"io_queue_total_read_ops", ssx::metrics::public_metrics_handle},
{"io_queue_total_write_ops", ssx::metrics::public_metrics_handle},
{"memory_allocated_memory", ssx::metrics::public_metrics_handle},
{"memory_free_memory", ssx::metrics::public_metrics_handle}})
.get();
}
setup_internal_metrics();
setup_public_metrics();
}

if (config::shard_local_cfg().disable_metrics()) {
void application::setup_public_metrics() {
namespace sm = ss::metrics;

if (config::shard_local_cfg().disable_public_metrics()) {
return;
}

seastar::metrics::replicate_metric_families(
seastar::metrics::default_handle(),
{{"scheduler_runtime_ms", ssx::metrics::public_metrics_handle},
{"io_queue_total_read_ops", ssx::metrics::public_metrics_handle},
{"io_queue_total_write_ops", ssx::metrics::public_metrics_handle},
{"memory_allocated_memory", ssx::metrics::public_metrics_handle},
{"memory_free_memory", ssx::metrics::public_metrics_handle}})
.get();

_public_metrics.add_group(
"application",
{
sm::make_gauge(
"uptime_seconds_total",
[] {
return std::chrono::duration<double>(ss::engine().uptime())
.count();
},
sm::description("Redpanda uptime in seconds"))
.aggregate({sm::shard_label}),
sm::make_gauge(
"busy_seconds_total",
[] {
return std::chrono::duration<double>(
ss::engine().total_busy_time())
.count();
},
sm::description("Total CPU busy time in seconds"))
.aggregate({sm::shard_label}),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's worth keeping the shards here

Copy link
Contributor Author

@VladLazar VladLazar Aug 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These metrics are only reported from one shard. That's why I aggregated. Just drops the label basically.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

curl -s  localhost:19644/metrics | grep  cpu_busy_ms
# HELP vectorized_reactor_cpu_busy_ms Total cpu busy time in milliseconds
# TYPE vectorized_reactor_cpu_busy_ms counter
vectorized_reactor_cpu_busy_ms{shard="0"} 6268
vectorized_reactor_cpu_busy_ms{shard="1"} 5003

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, you mean this probe is only on one shard? Can you register a metric for each shard?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. I've confused myself. It's reported from one shard because it's only registered on one shard. We should probably register it on all shards. This means that's probably not the right place for the "busy_time" metric. Let me have a think.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can invoke_on, or submit_to, or create a sharded<probe> and .invoke_on_all, or move it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know. Just feels a bit unnatural to do it there.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw. Do we want the uptime for every shard? It would probably be redundant. Busy time for each shard makes sense though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, that's how it is:

curl -s localhost:19644/metrics | grep uptime
# HELP vectorized_application_uptime Redpanda uptime in milliseconds
# TYPE vectorized_application_uptime gauge
vectorized_application_uptime{shard="0"} 24680.000000

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. I wrapped the metric_groups object into a ss::sharded. uptime is only reported from the home shard, while busy is reported from all shards.

});
}

void application::setup_internal_metrics() {
namespace sm = ss::metrics;

if (config::shard_local_cfg().disable_metrics()) {
return;
}

// build info
auto version_label = sm::label("version");
auto revision_label = sm::label("revision");
Expand Down
5 changes: 5 additions & 0 deletions src/v/redpanda/application.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "resource_mgmt/smp_groups.h"
#include "rpc/fwd.h"
#include "seastarx.h"
#include "ssx/metrics.h"
#include "storage/fwd.h"
#include "v8_engine/fwd.h"

Expand Down Expand Up @@ -149,6 +150,8 @@ class application {
}

void setup_metrics();
void setup_public_metrics();
void setup_internal_metrics();
std::unique_ptr<ss::app_template> _app;
bool _redpanda_enabled{true};
cluster::config_manager::preload_result _config_preload;
Expand Down Expand Up @@ -176,6 +179,8 @@ class application {
ss::sharded<archival::upload_controller> _archival_upload_controller;

ss::metrics::metric_groups _metrics;
ss::metrics::metric_groups _public_metrics{
ssx::metrics::public_metrics_handle};
std::unique_ptr<kafka::rm_group_proxy_impl> _rm_group_proxy;
// run these first on destruction
deferred_actions _deferred;
Expand Down