1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
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.
15 #ifndef CEPH_LOGMONITOR_H
16 #define CEPH_LOGMONITOR_H
22 #include "include/types.h"
23 #include "PaxosService.h"
25 #include "common/LogEntry.h"
26 #include "include/str_map.h"
31 static const string LOG_META_CHANNEL
= "$channel";
39 class LogMonitor
: public PaxosService
,
40 public md_config_obs_t
{
42 multimap
<utime_t
,LogEntry
> pending_log
;
43 LogSummary pending_summary
, summary
;
45 struct log_channel_info
{
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
;
57 map
<string
, shared_ptr
<ceph::logging::Graylog
>> graylogs
;
62 log_to_syslog
.clear();
64 syslog_facility
.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();
74 /** expands $channel meta variable on all maps *EXCEPT* log_file
76 * We won't expand the log_file map meta variables here because we
77 * intend to do that selectively during get_log_file()
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
);
85 void expand_channel_meta(map
<string
,string
> &m
);
86 string
expand_channel_meta(const string
&input
,
87 const string
&change_to
);
89 bool do_log_to_syslog(const string
&channel
);
91 string
get_facility(const string
&channel
) {
92 return get_str_map_key(syslog_facility
, channel
,
93 &CLOG_CONFIG_DEFAULT_KEY
);
96 string
get_level(const string
&channel
) {
97 return get_str_map_key(syslog_level
, channel
,
98 &CLOG_CONFIG_DEFAULT_KEY
);
101 string
get_log_file(const string
&channel
) {
102 generic_dout(25) << __func__
<< " for channel '"
103 << channel
<< "'" << dendl
;
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
),
109 expanded_log_file
[channel
] = fname
;
111 generic_dout(20) << __func__
<< " for channel '"
112 << channel
<< "' expanded to '"
113 << fname
<< "'" << dendl
;
115 return expanded_log_file
[channel
];
118 string
get_log_file_level(const string
&channel
) {
119 return get_str_map_key(log_file_level
, channel
,
120 &CLOG_CONFIG_DEFAULT_KEY
);
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");
128 shared_ptr
<ceph::logging::Graylog
> get_graylog(const string
&channel
);
131 void update_log_channels();
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
;
143 bool preprocess_log(MonOpRequestRef op
);
144 bool prepare_log(MonOpRequestRef op
);
145 void _updated_log(MonOpRequestRef op
);
147 bool should_propose(double& delay
) override
;
149 bool should_stash_full() override
{
150 // commit a LogSummary on every commit
156 bool preprocess_command(MonOpRequestRef op
);
157 bool prepare_command(MonOpRequestRef op
);
159 bool _create_sub_summary(MLog
*mlog
, int level
);
160 void _create_sub_incremental(MLog
*mlog
, int level
, version_t sv
);
163 LogMonitor(Monitor
*mn
, Paxos
*p
, const string
& service_name
)
164 : PaxosService(mn
, p
, service_name
) { }
166 void init() override
{
167 generic_dout(10) << "LogMonitor::init" << dendl
;
168 g_conf
->add_observer(this);
169 update_log_channels();
172 void tick() override
; // check state, take actions
175 void check_sub(Subscription
*s
);
178 * translate log sub name ('log-info') to integer id
181 * @return id, or -1 if unrecognized
183 int sub_name_to_id(const string
& n
);
185 void on_shutdown() override
{
186 g_conf
->remove_observer(this);
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",
203 void handle_conf_change(const struct md_config_t
*conf
,
204 const std::set
<std::string
> &changed
) override
;