]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
2 | // vim: ts=8 sw=2 smarttab | |
3 | /* | |
4 | * Ceph - scalable distributed file system | |
5 | * | |
6 | * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net> | |
7 | * | |
8 | * This is free software; you can redistribute it and/or | |
9 | * modify it under the terms of the GNU Lesser General Public | |
10 | * License version 2.1, as published by the Free Software | |
11 | * Foundation. See file COPYING. | |
12 | * | |
13 | */ | |
14 | ||
15 | #ifndef CEPH_LOGMONITOR_H | |
16 | #define CEPH_LOGMONITOR_H | |
17 | ||
33c7a0ef | 18 | #include <atomic> |
7c673cae FG |
19 | #include <map> |
20 | #include <set> | |
7c673cae | 21 | |
20effc67 TL |
22 | #include <fmt/format.h> |
23 | #include <fmt/ostream.h> | |
24 | ||
7c673cae FG |
25 | #include "include/types.h" |
26 | #include "PaxosService.h" | |
27 | ||
11fdf7f2 | 28 | #include "common/config_fwd.h" |
7c673cae FG |
29 | #include "common/LogEntry.h" |
30 | #include "include/str_map.h" | |
31 | ||
7c673cae FG |
32 | class MLog; |
33 | ||
f67539c2 | 34 | static const std::string LOG_META_CHANNEL = "$channel"; |
7c673cae FG |
35 | |
36 | namespace ceph { | |
37 | namespace logging { | |
38 | class Graylog; | |
20effc67 | 39 | class JournaldClusterLogger; |
7c673cae FG |
40 | } |
41 | } | |
42 | ||
43 | class LogMonitor : public PaxosService, | |
44 | public md_config_obs_t { | |
45 | private: | |
f67539c2 | 46 | std::multimap<utime_t,LogEntry> pending_log; |
20effc67 TL |
47 | unordered_set<LogEntryKey> pending_keys; |
48 | ||
49 | LogSummary summary; | |
50 | ||
51 | version_t external_log_to = 0; | |
52 | std::map<std::string, int> channel_fds; | |
53 | ||
1e59de90 | 54 | fmt::memory_buffer log_buffer; |
33c7a0ef | 55 | std::atomic<bool> log_rotated = false; |
7c673cae FG |
56 | |
57 | struct log_channel_info { | |
58 | ||
f67539c2 TL |
59 | std::map<std::string,std::string> log_to_syslog; |
60 | std::map<std::string,std::string> syslog_level; | |
61 | std::map<std::string,std::string> syslog_facility; | |
62 | std::map<std::string,std::string> log_file; | |
63 | std::map<std::string,std::string> expanded_log_file; | |
64 | std::map<std::string,std::string> log_file_level; | |
65 | std::map<std::string,std::string> log_to_graylog; | |
66 | std::map<std::string,std::string> log_to_graylog_host; | |
67 | std::map<std::string,std::string> log_to_graylog_port; | |
20effc67 | 68 | std::map<std::string,std::string> log_to_journald; |
f67539c2 TL |
69 | |
70 | std::map<std::string, std::shared_ptr<ceph::logging::Graylog>> graylogs; | |
20effc67 | 71 | std::unique_ptr<ceph::logging::JournaldClusterLogger> journald; |
7c673cae | 72 | uuid_d fsid; |
f67539c2 | 73 | std::string host; |
7c673cae | 74 | |
20effc67 TL |
75 | log_channel_info(); |
76 | ~log_channel_info(); | |
77 | ||
78 | void clear(); | |
7c673cae FG |
79 | |
80 | /** expands $channel meta variable on all maps *EXCEPT* log_file | |
81 | * | |
82 | * We won't expand the log_file map meta variables here because we | |
83 | * intend to do that selectively during get_log_file() | |
84 | */ | |
85 | void expand_channel_meta() { | |
86 | expand_channel_meta(log_to_syslog); | |
87 | expand_channel_meta(syslog_level); | |
88 | expand_channel_meta(syslog_facility); | |
89 | expand_channel_meta(log_file_level); | |
90 | } | |
f67539c2 TL |
91 | void expand_channel_meta(std::map<std::string,std::string> &m); |
92 | std::string expand_channel_meta(const std::string &input, | |
93 | const std::string &change_to); | |
7c673cae | 94 | |
f67539c2 | 95 | bool do_log_to_syslog(const std::string &channel); |
7c673cae | 96 | |
f67539c2 | 97 | std::string get_facility(const std::string &channel) { |
7c673cae FG |
98 | return get_str_map_key(syslog_facility, channel, |
99 | &CLOG_CONFIG_DEFAULT_KEY); | |
100 | } | |
101 | ||
f67539c2 | 102 | std::string get_level(const std::string &channel) { |
7c673cae FG |
103 | return get_str_map_key(syslog_level, channel, |
104 | &CLOG_CONFIG_DEFAULT_KEY); | |
105 | } | |
106 | ||
f67539c2 | 107 | std::string get_log_file(const std::string &channel); |
7c673cae | 108 | |
f67539c2 | 109 | std::string get_log_file_level(const std::string &channel) { |
7c673cae FG |
110 | return get_str_map_key(log_file_level, channel, |
111 | &CLOG_CONFIG_DEFAULT_KEY); | |
112 | } | |
113 | ||
f67539c2 | 114 | bool do_log_to_graylog(const std::string &channel) { |
7c673cae FG |
115 | return (get_str_map_key(log_to_graylog, channel, |
116 | &CLOG_CONFIG_DEFAULT_KEY) == "true"); | |
117 | } | |
118 | ||
f67539c2 | 119 | std::shared_ptr<ceph::logging::Graylog> get_graylog(const std::string &channel); |
20effc67 TL |
120 | |
121 | bool do_log_to_journald(const std::string &channel) { | |
122 | return (get_str_map_key(log_to_journald, channel, | |
123 | &CLOG_CONFIG_DEFAULT_KEY) == "true"); | |
124 | } | |
125 | ||
126 | ceph::logging::JournaldClusterLogger &get_journald(); | |
7c673cae FG |
127 | } channels; |
128 | ||
129 | void update_log_channels(); | |
130 | ||
131 | void create_initial() override; | |
132 | void update_from_paxos(bool *need_bootstrap) override; | |
133 | void create_pending() override; // prepare a new pending | |
134 | // propose pending update to peers | |
20effc67 | 135 | void generate_logentry_key(const std::string& channel, version_t v, std::string *out); |
7c673cae FG |
136 | void encode_pending(MonitorDBStore::TransactionRef t) override; |
137 | void encode_full(MonitorDBStore::TransactionRef t) override; | |
11fdf7f2 | 138 | version_t get_trim_to() const override; |
7c673cae FG |
139 | bool preprocess_query(MonOpRequestRef op) override; // true if processed. |
140 | bool prepare_update(MonOpRequestRef op) override; | |
141 | ||
142 | bool preprocess_log(MonOpRequestRef op); | |
143 | bool prepare_log(MonOpRequestRef op); | |
144 | void _updated_log(MonOpRequestRef op); | |
145 | ||
146 | bool should_propose(double& delay) override; | |
147 | ||
20effc67 | 148 | bool should_stash_full() override; |
7c673cae FG |
149 | |
150 | struct C_Log; | |
151 | ||
152 | bool preprocess_command(MonOpRequestRef op); | |
153 | bool prepare_command(MonOpRequestRef op); | |
154 | ||
7c673cae FG |
155 | void _create_sub_incremental(MLog *mlog, int level, version_t sv); |
156 | ||
157 | public: | |
f67539c2 | 158 | LogMonitor(Monitor &mn, Paxos &p, const std::string& service_name) |
7c673cae FG |
159 | : PaxosService(mn, p, service_name) { } |
160 | ||
161 | void init() override { | |
162 | generic_dout(10) << "LogMonitor::init" << dendl; | |
11fdf7f2 | 163 | g_conf().add_observer(this); |
7c673cae FG |
164 | update_log_channels(); |
165 | } | |
166 | ||
167 | void tick() override; // check state, take actions | |
168 | ||
1e59de90 | 169 | void dump_info(Formatter *f); |
7c673cae FG |
170 | void check_subs(); |
171 | void check_sub(Subscription *s); | |
172 | ||
33c7a0ef TL |
173 | void reopen_logs() { |
174 | this->log_rotated.store(true); | |
175 | } | |
20effc67 TL |
176 | void log_external_close_fds(); |
177 | void log_external(const LogEntry& le); | |
178 | void log_external_backlog(); | |
179 | ||
7c673cae FG |
180 | /** |
181 | * translate log sub name ('log-info') to integer id | |
182 | * | |
183 | * @param n name | |
184 | * @return id, or -1 if unrecognized | |
185 | */ | |
f67539c2 | 186 | int sub_name_to_id(const std::string& n); |
7c673cae FG |
187 | |
188 | void on_shutdown() override { | |
11fdf7f2 | 189 | g_conf().remove_observer(this); |
7c673cae FG |
190 | } |
191 | ||
192 | const char **get_tracked_conf_keys() const override { | |
193 | static const char* KEYS[] = { | |
194 | "mon_cluster_log_to_syslog", | |
195 | "mon_cluster_log_to_syslog_level", | |
196 | "mon_cluster_log_to_syslog_facility", | |
197 | "mon_cluster_log_file", | |
198 | "mon_cluster_log_file_level", | |
199 | "mon_cluster_log_to_graylog", | |
200 | "mon_cluster_log_to_graylog_host", | |
201 | "mon_cluster_log_to_graylog_port", | |
20effc67 | 202 | "mon_cluster_log_to_journald", |
7c673cae FG |
203 | NULL |
204 | }; | |
205 | return KEYS; | |
206 | } | |
11fdf7f2 | 207 | void handle_conf_change(const ConfigProxy& conf, |
7c673cae FG |
208 | const std::set<std::string> &changed) override; |
209 | }; | |
210 | #endif |