]>
Commit | Line | Data |
---|---|---|
9f95a23c TL |
1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
2 | // vim: ts=8 sw=2 smarttab | |
3 | ||
4 | #include "crimson/admin/osd_admin.h" | |
5 | #include <string> | |
6 | #include <string_view> | |
7 | ||
8 | #include <fmt/format.h> | |
9 | #include <seastar/core/do_with.hh> | |
10 | #include <seastar/core/future.hh> | |
11 | #include <seastar/core/thread.hh> | |
f67539c2 | 12 | #include <seastar/core/scollectd_api.hh> |
9f95a23c TL |
13 | |
14 | #include "common/config.h" | |
15 | #include "crimson/admin/admin_socket.h" | |
16 | #include "crimson/common/log.h" | |
17 | #include "crimson/osd/exceptions.h" | |
18 | #include "crimson/osd/osd.h" | |
19 | ||
20 | using crimson::osd::OSD; | |
21 | using namespace crimson::common; | |
22 | ||
9f95a23c TL |
23 | namespace crimson::admin { |
24 | ||
25 | using crimson::common::local_conf; | |
26 | ||
27 | template <class Hook, class... Args> | |
28 | std::unique_ptr<AdminSocketHook> make_asok_hook(Args&&... args) | |
29 | { | |
30 | return std::make_unique<Hook>(std::forward<Args>(args)...); | |
31 | } | |
32 | ||
9f95a23c TL |
33 | /** |
34 | * An OSD admin hook: OSD status | |
35 | */ | |
f67539c2 | 36 | class OsdStatusHook : public AdminSocketHook { |
9f95a23c | 37 | public: |
f67539c2 TL |
38 | explicit OsdStatusHook(const crimson::osd::OSD& osd) : |
39 | AdminSocketHook{"status", "", "OSD status"}, | |
9f95a23c TL |
40 | osd(osd) |
41 | {} | |
f67539c2 TL |
42 | seastar::future<tell_result_t> call(const cmdmap_t&, |
43 | std::string_view format, | |
44 | ceph::bufferlist&& input) const final | |
9f95a23c | 45 | { |
f67539c2 | 46 | unique_ptr<Formatter> f{Formatter::create(format, "json-pretty", "json-pretty")}; |
9f95a23c | 47 | f->open_object_section("status"); |
f67539c2 | 48 | osd.dump_status(f.get()); |
9f95a23c | 49 | f->close_section(); |
f67539c2 | 50 | return seastar::make_ready_future<tell_result_t>(std::move(f)); |
9f95a23c TL |
51 | } |
52 | private: | |
f67539c2 | 53 | const crimson::osd::OSD& osd; |
9f95a23c TL |
54 | }; |
55 | template std::unique_ptr<AdminSocketHook> | |
f67539c2 | 56 | make_asok_hook<OsdStatusHook>(const crimson::osd::OSD& osd); |
9f95a23c TL |
57 | |
58 | /** | |
59 | * An OSD admin hook: send beacon | |
60 | */ | |
f67539c2 | 61 | class SendBeaconHook : public AdminSocketHook { |
9f95a23c TL |
62 | public: |
63 | explicit SendBeaconHook(crimson::osd::OSD& osd) : | |
f67539c2 TL |
64 | AdminSocketHook{"send_beacon", |
65 | "", | |
66 | "send OSD beacon to mon immediately"}, | |
67 | osd(osd) | |
9f95a23c | 68 | {} |
f67539c2 TL |
69 | seastar::future<tell_result_t> call(const cmdmap_t&, |
70 | std::string_view format, | |
71 | ceph::bufferlist&& input) const final | |
9f95a23c TL |
72 | { |
73 | return osd.send_beacon().then([] { | |
74 | return seastar::make_ready_future<tell_result_t>(); | |
75 | }); | |
76 | } | |
77 | private: | |
78 | crimson::osd::OSD& osd; | |
79 | }; | |
80 | template std::unique_ptr<AdminSocketHook> | |
81 | make_asok_hook<SendBeaconHook>(crimson::osd::OSD& osd); | |
82 | ||
83 | /** | |
f67539c2 | 84 | * send the latest pg stats to mgr |
9f95a23c | 85 | */ |
f67539c2 | 86 | class FlushPgStatsHook : public AdminSocketHook { |
9f95a23c | 87 | public: |
f67539c2 TL |
88 | explicit FlushPgStatsHook(crimson::osd::OSD& osd) : |
89 | AdminSocketHook("flush_pg_stats", | |
90 | "", | |
91 | "flush pg stats"), | |
92 | osd{osd} | |
9f95a23c | 93 | {} |
f67539c2 TL |
94 | seastar::future<tell_result_t> call(const cmdmap_t&, |
95 | std::string_view format, | |
96 | ceph::bufferlist&& input) const final | |
9f95a23c | 97 | { |
f67539c2 TL |
98 | uint64_t seq = osd.send_pg_stats(); |
99 | unique_ptr<Formatter> f{Formatter::create(format, "json-pretty", "json-pretty")}; | |
100 | f->dump_unsigned("stat_seq", seq); | |
101 | return seastar::make_ready_future<tell_result_t>(std::move(f)); | |
9f95a23c | 102 | } |
9f95a23c | 103 | |
f67539c2 TL |
104 | private: |
105 | crimson::osd::OSD& osd; | |
9f95a23c | 106 | }; |
f67539c2 | 107 | template std::unique_ptr<AdminSocketHook> make_asok_hook<FlushPgStatsHook>(crimson::osd::OSD& osd); |
9f95a23c | 108 | |
f67539c2 TL |
109 | /// dump the history of PGs' peering state |
110 | class DumpPGStateHistory final: public AdminSocketHook { | |
9f95a23c | 111 | public: |
f67539c2 TL |
112 | explicit DumpPGStateHistory(const crimson::osd::OSD &osd) : |
113 | AdminSocketHook{"dump_pgstate_history", | |
114 | "", | |
115 | "dump history of PGs' peering state"}, | |
116 | osd{osd} | |
9f95a23c | 117 | {} |
f67539c2 TL |
118 | seastar::future<tell_result_t> call(const cmdmap_t&, |
119 | std::string_view format, | |
120 | ceph::bufferlist&& input) const final | |
9f95a23c | 121 | { |
f67539c2 TL |
122 | std::unique_ptr<Formatter> f{Formatter::create(format, |
123 | "json-pretty", | |
124 | "json-pretty")}; | |
125 | f->open_object_section("pgstate_history"); | |
126 | osd.dump_pg_state_history(f.get()); | |
127 | f->close_section(); | |
128 | return seastar::make_ready_future<tell_result_t>(std::move(f)); | |
9f95a23c | 129 | } |
f67539c2 TL |
130 | private: |
131 | const crimson::osd::OSD& osd; | |
9f95a23c | 132 | }; |
f67539c2 | 133 | template std::unique_ptr<AdminSocketHook> make_asok_hook<DumpPGStateHistory>(const crimson::osd::OSD& osd); |
9f95a23c TL |
134 | |
135 | /** | |
136 | * A CephContext admin hook: calling assert (if allowed by | |
137 | * 'debug_asok_assert_abort') | |
138 | */ | |
f67539c2 | 139 | class AssertAlwaysHook : public AdminSocketHook { |
9f95a23c TL |
140 | public: |
141 | AssertAlwaysHook() : | |
f67539c2 TL |
142 | AdminSocketHook{"assert", |
143 | "", | |
144 | "asserts"} | |
9f95a23c | 145 | {} |
f67539c2 TL |
146 | seastar::future<tell_result_t> call(const cmdmap_t&, |
147 | std::string_view format, | |
148 | ceph::bufferlist&& input) const final | |
9f95a23c TL |
149 | { |
150 | if (local_conf().get_val<bool>("debug_asok_assert_abort")) { | |
151 | ceph_assert_always(0); | |
152 | return seastar::make_ready_future<tell_result_t>(); | |
153 | } else { | |
154 | return seastar::make_ready_future<tell_result_t>( | |
155 | tell_result_t{-EPERM, "configuration set to disallow asok assert"}); | |
156 | } | |
157 | } | |
158 | }; | |
159 | template std::unique_ptr<AdminSocketHook> make_asok_hook<AssertAlwaysHook>(); | |
160 | ||
f67539c2 TL |
161 | /** |
162 | * A Seastar admin hook: fetching the values of configured metrics | |
163 | */ | |
164 | class SeastarMetricsHook : public AdminSocketHook { | |
165 | public: | |
166 | SeastarMetricsHook() : | |
167 | AdminSocketHook("perf dump_seastar", | |
168 | "", | |
169 | "dump current configured seastar metrics and their values") | |
170 | {} | |
171 | seastar::future<tell_result_t> call(const cmdmap_t& cmdmap, | |
172 | std::string_view format, | |
173 | ceph::bufferlist&& input) const final | |
174 | { | |
175 | std::unique_ptr<Formatter> f{Formatter::create(format, "json-pretty", "json-pretty")}; | |
176 | f->open_object_section("perf_dump_seastar"); | |
177 | for (const auto& mf : seastar::scollectd::get_value_map()) { | |
178 | for (const auto& m : mf.second) { | |
179 | if (m.second && m.second->is_enabled()) { | |
180 | auto& metric_function = m.second->get_function(); | |
181 | f->dump_float(m.second->get_id().full_name(), metric_function().d()); | |
182 | } | |
183 | } | |
184 | } | |
185 | f->close_section(); | |
186 | return seastar::make_ready_future<tell_result_t>(std::move(f)); | |
187 | } | |
188 | }; | |
189 | template std::unique_ptr<AdminSocketHook> make_asok_hook<SeastarMetricsHook>(); | |
190 | ||
9f95a23c | 191 | } // namespace crimson::admin |