summaryrefslogtreecommitdiffstats
path: root/src/mon/MgrStatMonitor.h
blob: 7c31f2c13f64f476e136f945e9cfc292e4b8b135 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab

#pragma once

#include "include/Context.h"
#include "PaxosService.h"
#include "mon/PGMap.h"
#include "mgr/ServiceMap.h"

class MgrStatMonitor : public PaxosService {
  // live version
  version_t version = 0;
  PGMapDigest digest;
  ServiceMap service_map;
  std::map<std::string,ProgressEvent> progress_events;

  // pending commit
  PGMapDigest pending_digest;
  health_check_map_t pending_health_checks;
  std::map<std::string,ProgressEvent> pending_progress_events;
  ceph::buffer::list pending_service_map_bl;

public:
  MgrStatMonitor(Monitor &mn, Paxos &p, const std::string& service_name);
  ~MgrStatMonitor() override;

  void init() override {}
  void on_shutdown() override {}

  void create_initial() override;
  void update_from_paxos(bool *need_bootstrap) override;
  void create_pending() override;
  void encode_pending(MonitorDBStore::TransactionRef t) override;
  version_t get_trim_to() const override;

  bool definitely_converted_snapsets() const {
    return digest.definitely_converted_snapsets();
  }

  bool preprocess_query(MonOpRequestRef op) override;
  bool prepare_update(MonOpRequestRef op) override;

  void encode_full(MonitorDBStore::TransactionRef t) override { }

  bool preprocess_report(MonOpRequestRef op);
  bool prepare_report(MonOpRequestRef op);

  bool preprocess_getpoolstats(MonOpRequestRef op);
  bool preprocess_statfs(MonOpRequestRef op);

  void check_sub(Subscription *sub);
  void check_subs();
  void send_digests();

  void on_active() override;
  void tick() override;

  uint64_t get_last_osd_stat_seq(int osd) {
    return digest.get_last_osd_stat_seq(osd);
  }

  void update_logger();

  const ServiceMap& get_service_map() const {
    return service_map;
  }

  const std::map<std::string,ProgressEvent>& get_progress_events() {
    return progress_events;
  }

  // pg stat access
  const pool_stat_t* get_pool_stat(int64_t poolid) const {
    auto i = digest.pg_pool_sum.find(poolid);
    if (i != digest.pg_pool_sum.end()) {
      return &i->second;
    }
    return nullptr;
  }

  const PGMapDigest& get_digest() {
    return digest;
  }

  ceph_statfs get_statfs(OSDMap& osdmap,
			 boost::optional<int64_t> data_pool) const {
    return digest.get_statfs(osdmap, data_pool);
  }

  void print_summary(ceph::Formatter *f, std::ostream *out) const {
    digest.print_summary(f, out);
  }
  void dump_info(ceph::Formatter *f) const {
    digest.dump(f);
    f->dump_object("servicemap", get_service_map());
  }
  void dump_cluster_stats(std::stringstream *ss,
			  ceph::Formatter *f,
			  bool verbose) const {
    digest.dump_cluster_stats(ss, f, verbose);
  }
  void dump_pool_stats(const OSDMap& osdm, std::stringstream *ss, ceph::Formatter *f,
		       bool verbose) const {
    digest.dump_pool_stats_full(osdm, ss, f, verbose);
  }
};