| 405 | } |
| 406 | |
| 407 | Status MetricEntity::WriteAsPrometheus(PrometheusWriter* writer) const { |
| 408 | static const string kIdMaster = "kudu.master"; |
| 409 | static const string kIdTabletServer = "kudu.tabletserver"; |
| 410 | |
| 411 | if (strcmp(prototype_->name(), "server") != 0) { |
| 412 | // Only server-level metrics are emitted in Prometheus format as of now, |
| 413 | // non-server metric entities are currently silently skipped. |
| 414 | // |
| 415 | // TODO(KUDU-3563): output tablet-level metrics in Prometheus format as well |
| 416 | return Status::OK(); |
| 417 | } |
| 418 | |
| 419 | // Empty filters result in getting all the metrics for this MetricEntity. |
| 420 | // |
| 421 | // TODO(aserbin): instead of hard-coding, pass MetricFilters as a parameter |
| 422 | MetricFilters filters; |
| 423 | filters.entity_level = "debug"; |
| 424 | |
| 425 | MetricMap metrics; |
| 426 | AttributeMap attrs; |
| 427 | const auto s = GetMetricsAndAttrs(filters, &metrics, &attrs); |
| 428 | if (s.IsNotFound()) { |
| 429 | // Status::NotFound is returned when this entity has been filtered, treat it |
| 430 | // as OK, and skip printing it. |
| 431 | return Status::OK(); |
| 432 | } |
| 433 | RETURN_NOT_OK(s); |
| 434 | |
| 435 | if (id_ == kIdMaster) { |
| 436 | // Prefix all master metrics with 'kudu_master_'. |
| 437 | static const string kMasterPrefix = "kudu_master_"; |
| 438 | WriteMetricsPrometheus(writer, metrics, kMasterPrefix); |
| 439 | return Status::OK(); |
| 440 | } |
| 441 | if (id_ == kIdTabletServer) { |
| 442 | // Prefix all tablet server metrics with 'kudu_tserver_'. |
| 443 | static const string kTabletServerPrefix = "kudu_tserver_"; |
| 444 | WriteMetricsPrometheus(writer, metrics, kTabletServerPrefix); |
| 445 | return Status::OK(); |
| 446 | } |
| 447 | |
| 448 | return Status::NotSupported( |
| 449 | Substitute("$0: unexpected server-level metric entity", id_)); |
| 450 | } |
| 451 | |
| 452 | Status MetricEntity::CollectTo(MergedEntityMetrics* collections, |
| 453 | const MetricFilters& filters, |