]>
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) 2013 Inktank, Inc | |
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 | #include <sstream> | |
16 | #include <stdlib.h> | |
17 | #include <limits.h> | |
18 | ||
19 | // #include <boost/intrusive_ptr.hpp> | |
20 | // Because intusive_ptr clobbers our assert... | |
21 | #include "include/assert.h" | |
22 | ||
23 | #include "mon/Monitor.h" | |
24 | #include "mon/HealthService.h" | |
25 | #include "mon/HealthMonitor.h" | |
26 | #include "mon/DataHealthService.h" | |
27 | ||
28 | #include "messages/MMonHealth.h" | |
29 | #include "common/Formatter.h" | |
30 | // #include "common/config.h" | |
31 | ||
32 | #define dout_subsys ceph_subsys_mon | |
33 | #undef dout_prefix | |
34 | #define dout_prefix _prefix(_dout, mon, this) | |
35 | static ostream& _prefix(std::ostream *_dout, const Monitor *mon, | |
36 | const HealthMonitor *hmon) { | |
37 | return *_dout << "mon." << mon->name << "@" << mon->rank | |
38 | << "(" << mon->get_state_name() << ")." << hmon->get_name() | |
39 | << "(" << hmon->get_epoch() << ") "; | |
40 | } | |
41 | ||
42 | void HealthMonitor::init() | |
43 | { | |
44 | dout(10) << __func__ << dendl; | |
45 | assert(services.empty()); | |
46 | services[HealthService::SERVICE_HEALTH_DATA] = new DataHealthService(mon); | |
47 | ||
48 | for (map<int,HealthService*>::iterator it = services.begin(); | |
49 | it != services.end(); | |
50 | ++it) { | |
51 | it->second->init(); | |
52 | } | |
53 | } | |
54 | ||
55 | bool HealthMonitor::service_dispatch(MonOpRequestRef op) | |
56 | { | |
57 | assert(op->get_req()->get_type() == MSG_MON_HEALTH); | |
58 | MMonHealth *hm = static_cast<MMonHealth*>(op->get_req()); | |
59 | int service_type = hm->get_service_type(); | |
60 | if (services.count(service_type) == 0) { | |
61 | dout(1) << __func__ << " service type " << service_type | |
62 | << " not registered -- drop message!" << dendl; | |
63 | return false; | |
64 | } | |
65 | return services[service_type]->service_dispatch(op); | |
66 | } | |
67 | ||
68 | void HealthMonitor::start_epoch() { | |
69 | epoch_t epoch = get_epoch(); | |
70 | for (map<int,HealthService*>::iterator it = services.begin(); | |
71 | it != services.end(); ++it) { | |
72 | it->second->start(epoch); | |
73 | } | |
74 | } | |
75 | ||
76 | void HealthMonitor::finish_epoch() { | |
77 | generic_dout(20) << "HealthMonitor::finish_epoch()" << dendl; | |
78 | for (map<int,HealthService*>::iterator it = services.begin(); | |
79 | it != services.end(); ++it) { | |
80 | assert(it->second != NULL); | |
81 | it->second->finish(); | |
82 | } | |
83 | } | |
84 | ||
85 | void HealthMonitor::service_shutdown() | |
86 | { | |
87 | dout(0) << "HealthMonitor::service_shutdown " | |
88 | << services.size() << " services" << dendl; | |
89 | for (map<int,HealthService*>::iterator it = services.begin(); | |
90 | it != services.end(); | |
91 | ++it) { | |
92 | it->second->shutdown(); | |
93 | delete it->second; | |
94 | } | |
95 | services.clear(); | |
96 | } | |
97 | ||
98 | void HealthMonitor::get_health(Formatter *f, | |
99 | list<pair<health_status_t,string> >& summary, | |
100 | list<pair<health_status_t,string> > *detail) | |
101 | { | |
102 | if (f) { | |
103 | f->open_object_section("health"); | |
104 | f->open_array_section("health_services"); | |
105 | } | |
106 | ||
107 | for (map<int,HealthService*>::iterator it = services.begin(); | |
108 | it != services.end(); | |
109 | ++it) { | |
110 | it->second->get_health(f, summary, detail); | |
111 | } | |
112 | ||
113 | if (f) { | |
114 | f->close_section(); // health_services | |
115 | f->close_section(); // health | |
116 | } | |
117 | } | |
118 |