]>
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 | ||
18 | #include <map> | |
19 | #include <set> | |
20 | using namespace std; | |
21 | ||
22 | #include "include/types.h" | |
23 | #include "PaxosService.h" | |
24 | ||
25 | #include "common/LogEntry.h" | |
26 | #include "include/str_map.h" | |
27 | ||
28 | class MMonCommand; | |
29 | class MLog; | |
30 | ||
31 | static const string LOG_META_CHANNEL = "$channel"; | |
32 | ||
33 | namespace ceph { | |
34 | namespace logging { | |
35 | class Graylog; | |
36 | } | |
37 | } | |
38 | ||
39 | class LogMonitor : public PaxosService, | |
40 | public md_config_obs_t { | |
41 | private: | |
42 | multimap<utime_t,LogEntry> pending_log; | |
43 | LogSummary pending_summary, summary; | |
44 | ||
45 | struct log_channel_info { | |
46 | ||
47 | map<string,string> log_to_syslog; | |
48 | map<string,string> syslog_level; | |
49 | map<string,string> syslog_facility; | |
50 | map<string,string> log_file; | |
51 | map<string,string> expanded_log_file; | |
52 | map<string,string> log_file_level; | |
53 | map<string,string> log_to_graylog; | |
54 | map<string,string> log_to_graylog_host; | |
55 | map<string,string> log_to_graylog_port; | |
56 | ||
57 | map<string, shared_ptr<ceph::logging::Graylog>> graylogs; | |
58 | uuid_d fsid; | |
59 | string host; | |
60 | ||
61 | void clear() { | |
62 | log_to_syslog.clear(); | |
63 | syslog_level.clear(); | |
64 | syslog_facility.clear(); | |
65 | log_file.clear(); | |
66 | expanded_log_file.clear(); | |
67 | log_file_level.clear(); | |
68 | log_to_graylog.clear(); | |
69 | log_to_graylog_host.clear(); | |
70 | log_to_graylog_port.clear(); | |
71 | graylogs.clear(); | |
72 | } | |
73 | ||
74 | /** expands $channel meta variable on all maps *EXCEPT* log_file | |
75 | * | |
76 | * We won't expand the log_file map meta variables here because we | |
77 | * intend to do that selectively during get_log_file() | |
78 | */ | |
79 | void expand_channel_meta() { | |
80 | expand_channel_meta(log_to_syslog); | |
81 | expand_channel_meta(syslog_level); | |
82 | expand_channel_meta(syslog_facility); | |
83 | expand_channel_meta(log_file_level); | |
84 | } | |
85 | void expand_channel_meta(map<string,string> &m); | |
86 | string expand_channel_meta(const string &input, | |
87 | const string &change_to); | |
88 | ||
89 | bool do_log_to_syslog(const string &channel); | |
90 | ||
91 | string get_facility(const string &channel) { | |
92 | return get_str_map_key(syslog_facility, channel, | |
93 | &CLOG_CONFIG_DEFAULT_KEY); | |
94 | } | |
95 | ||
96 | string get_level(const string &channel) { | |
97 | return get_str_map_key(syslog_level, channel, | |
98 | &CLOG_CONFIG_DEFAULT_KEY); | |
99 | } | |
100 | ||
101 | string get_log_file(const string &channel) { | |
102 | generic_dout(25) << __func__ << " for channel '" | |
103 | << channel << "'" << dendl; | |
104 | ||
105 | if (expanded_log_file.count(channel) == 0) { | |
106 | string fname = expand_channel_meta( | |
107 | get_str_map_key(log_file, channel, &CLOG_CONFIG_DEFAULT_KEY), | |
108 | channel); | |
109 | expanded_log_file[channel] = fname; | |
110 | ||
111 | generic_dout(20) << __func__ << " for channel '" | |
112 | << channel << "' expanded to '" | |
113 | << fname << "'" << dendl; | |
114 | } | |
115 | return expanded_log_file[channel]; | |
116 | } | |
117 | ||
118 | string get_log_file_level(const string &channel) { | |
119 | return get_str_map_key(log_file_level, channel, | |
120 | &CLOG_CONFIG_DEFAULT_KEY); | |
121 | } | |
122 | ||
123 | bool do_log_to_graylog(const string &channel) { | |
124 | return (get_str_map_key(log_to_graylog, channel, | |
125 | &CLOG_CONFIG_DEFAULT_KEY) == "true"); | |
126 | } | |
127 | ||
128 | shared_ptr<ceph::logging::Graylog> get_graylog(const string &channel); | |
129 | } channels; | |
130 | ||
131 | void update_log_channels(); | |
132 | ||
133 | void create_initial() override; | |
134 | void update_from_paxos(bool *need_bootstrap) override; | |
135 | void create_pending() override; // prepare a new pending | |
136 | // propose pending update to peers | |
137 | void encode_pending(MonitorDBStore::TransactionRef t) override; | |
138 | void encode_full(MonitorDBStore::TransactionRef t) override; | |
139 | version_t get_trim_to() override; | |
140 | bool preprocess_query(MonOpRequestRef op) override; // true if processed. | |
141 | bool prepare_update(MonOpRequestRef op) override; | |
142 | ||
143 | bool preprocess_log(MonOpRequestRef op); | |
144 | bool prepare_log(MonOpRequestRef op); | |
145 | void _updated_log(MonOpRequestRef op); | |
146 | ||
147 | bool should_propose(double& delay) override; | |
148 | ||
149 | bool should_stash_full() override { | |
150 | // commit a LogSummary on every commit | |
151 | return true; | |
152 | } | |
153 | ||
154 | struct C_Log; | |
155 | ||
156 | bool preprocess_command(MonOpRequestRef op); | |
157 | bool prepare_command(MonOpRequestRef op); | |
158 | ||
159 | bool _create_sub_summary(MLog *mlog, int level); | |
160 | void _create_sub_incremental(MLog *mlog, int level, version_t sv); | |
161 | ||
162 | public: | |
163 | LogMonitor(Monitor *mn, Paxos *p, const string& service_name) | |
164 | : PaxosService(mn, p, service_name) { } | |
165 | ||
166 | void init() override { | |
167 | generic_dout(10) << "LogMonitor::init" << dendl; | |
168 | g_conf->add_observer(this); | |
169 | update_log_channels(); | |
170 | } | |
171 | ||
172 | void tick() override; // check state, take actions | |
173 | ||
174 | void check_subs(); | |
175 | void check_sub(Subscription *s); | |
176 | ||
177 | /** | |
178 | * translate log sub name ('log-info') to integer id | |
179 | * | |
180 | * @param n name | |
181 | * @return id, or -1 if unrecognized | |
182 | */ | |
183 | int sub_name_to_id(const string& n); | |
184 | ||
185 | void on_shutdown() override { | |
186 | g_conf->remove_observer(this); | |
187 | } | |
188 | ||
189 | const char **get_tracked_conf_keys() const override { | |
190 | static const char* KEYS[] = { | |
191 | "mon_cluster_log_to_syslog", | |
192 | "mon_cluster_log_to_syslog_level", | |
193 | "mon_cluster_log_to_syslog_facility", | |
194 | "mon_cluster_log_file", | |
195 | "mon_cluster_log_file_level", | |
196 | "mon_cluster_log_to_graylog", | |
197 | "mon_cluster_log_to_graylog_host", | |
198 | "mon_cluster_log_to_graylog_port", | |
199 | NULL | |
200 | }; | |
201 | return KEYS; | |
202 | } | |
203 | void handle_conf_change(const struct md_config_t *conf, | |
204 | const std::set<std::string> &changed) override; | |
205 | }; | |
206 | #endif |