MCPcopy Create free account
hub / github.com/apache/mesos / getMetrics

Method getMetrics

src/master/http.cpp:1577–1651  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1575
1576
1577Future<Response> Master::Http::getMetrics(
1578 const mesos::master::Call& call,
1579 const Option<Principal>& principal,
1580 ContentType contentType) const
1581{
1582 CHECK_EQ(mesos::master::Call::GET_METRICS, call.type());
1583 CHECK(call.has_get_metrics());
1584
1585 Option<Duration> timeout;
1586 if (call.get_metrics().has_timeout()) {
1587 timeout = Nanoseconds(call.get_metrics().timeout().nanoseconds());
1588 }
1589
1590 return process::metrics::snapshot(timeout)
1591 .then([contentType](const map<string, double>& metrics) -> Response {
1592 // Serialize the following message:
1593 //
1594 // mesos::master::Response response;
1595 // response.set_type(mesos::master::Response::GET_METRICS);
1596 // mesos::master::Response::GetMetrics* getMetrics = ...;
1597
1598 switch (contentType) {
1599 case ContentType::PROTOBUF: {
1600 string output;
1601 google::protobuf::io::StringOutputStream stream(&output);
1602 google::protobuf::io::CodedOutputStream writer(&stream);
1603
1604 WireFormatLite::WriteEnum(
1605 mesos::v1::master::Response::kTypeFieldNumber,
1606 mesos::v1::master::Response::GET_METRICS,
1607 &writer);
1608
1609 WireFormatLite::WriteBytes(
1610 mesos::v1::master::Response::kGetMetricsFieldNumber,
1611 serializeGetMetrics<mesos::v1::master::Response::GetMetrics>(
1612 metrics),
1613 &writer);
1614
1615 // We must manually trim the unused buffer space since
1616 // we use the string before the coded output stream is
1617 // destructed.
1618 writer.Trim();
1619
1620 return OK(std::move(output), stringify(contentType));
1621 }
1622
1623 case ContentType::JSON: {
1624 string body = jsonify([&](JSON::ObjectWriter* writer) {
1625 const google::protobuf::Descriptor* descriptor =
1626 v1::master::Response::descriptor();
1627
1628 int field;
1629
1630 field = v1::master::Response::kTypeFieldNumber;
1631 writer->field(
1632 descriptor->FindFieldByNumber(field)->name(),
1633 v1::master::Response::Type_Name(
1634 v1::master::Response::GET_METRICS));

Callers

nothing calls this directly

Calls 11

NanosecondsClass · 0.85
snapshotFunction · 0.85
OKClass · 0.85
jsonifyFunction · 0.85
NotAcceptableClass · 0.85
typeMethod · 0.80
fieldMethod · 0.80
stringifyFunction · 0.50
timeoutMethod · 0.45
thenMethod · 0.45
nameMethod · 0.45

Tested by

no test coverage detected