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