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
21 #include "include/types.h"
22 #include "PaxosService.h"
24 #include "common/config_fwd.h"
25 #include "common/LogEntry.h"
26 #include "include/str_map.h"
30 static const string LOG_META_CHANNEL
= "$channel";
38 class LogMonitor
: public PaxosService
,
39 public md_config_obs_t
{
41 multimap
<utime_t
,LogEntry
> pending_log
;
42 LogSummary pending_summary
, summary
;
44 struct log_channel_info
{
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
;
56 map
<string
, shared_ptr
<ceph::logging::Graylog
>> graylogs
;
61 log_to_syslog
.clear();
63 syslog_facility
.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();
73 /** expands $channel meta variable on all maps *EXCEPT* log_file
75 * We won't expand the log_file map meta variables here because we
76 * intend to do that selectively during get_log_file()
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
);
84 void expand_channel_meta(map
<string
,string
> &m
);
85 string
expand_channel_meta(const string
&input
,
86 const string
&change_to
);
88 bool do_log_to_syslog(const string
&channel
);
90 string
get_facility(const string
&channel
) {
91 return get_str_map_key(syslog_facility
, channel
,
92 &CLOG_CONFIG_DEFAULT_KEY
);
95 string
get_level(const string
&channel
) {
96 return get_str_map_key(syslog_level
, channel
,
97 &CLOG_CONFIG_DEFAULT_KEY
);
100 string
get_log_file(const string
&channel
) {
101 generic_dout(25) << __func__
<< " for channel '"
102 << channel
<< "'" << dendl
;
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
),
108 expanded_log_file
[channel
] = fname
;
110 generic_dout(20) << __func__
<< " for channel '"
111 << channel
<< "' expanded to '"
112 << fname
<< "'" << dendl
;
114 return expanded_log_file
[channel
];
117 string
get_log_file_level(const string
&channel
) {
118 return get_str_map_key(log_file_level
, channel
,
119 &CLOG_CONFIG_DEFAULT_KEY
);
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");
127 shared_ptr
<ceph::logging::Graylog
> get_graylog(const string
&channel
);
130 void update_log_channels();
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
;
138 version_t
get_trim_to() const override
;
139 bool preprocess_query(MonOpRequestRef op
) override
; // true if processed.
140 bool prepare_update(MonOpRequestRef op
) override
;
142 bool preprocess_log(MonOpRequestRef op
);
143 bool prepare_log(MonOpRequestRef op
);
144 void _updated_log(MonOpRequestRef op
);
146 bool should_propose(double& delay
) override
;
148 bool should_stash_full() override
{
149 // commit a LogSummary on every commit
155 bool preprocess_command(MonOpRequestRef op
);
156 bool prepare_command(MonOpRequestRef op
);
158 void _create_sub_incremental(MLog
*mlog
, int level
, version_t sv
);
161 LogMonitor(Monitor
*mn
, Paxos
*p
, const string
& service_name
)
162 : PaxosService(mn
, p
, service_name
) { }
164 void init() override
{
165 generic_dout(10) << "LogMonitor::init" << dendl
;
166 g_conf().add_observer(this);
167 update_log_channels();
170 void tick() override
; // check state, take actions
173 void check_sub(Subscription
*s
);
176 * translate log sub name ('log-info') to integer id
179 * @return id, or -1 if unrecognized
181 int sub_name_to_id(const string
& n
);
183 void on_shutdown() override
{
184 g_conf().remove_observer(this);
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",
201 void handle_conf_change(const ConfigProxy
& conf
,
202 const std::set
<std::string
> &changed
) override
;