summaryrefslogtreecommitdiffstats
path: root/src/mgr/OSDPerfMetricTypes.cc
blob: bce95e0ae3889730ca6c1ab9d5d5c9dbbc5d175a (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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab

#include "mgr/OSDPerfMetricTypes.h"

#include <ostream>

using ceph::bufferlist;

std::ostream& operator<<(std::ostream& os,
                         const OSDPerfMetricSubKeyDescriptor &d) {
  switch(d.type) {
  case OSDPerfMetricSubKeyType::CLIENT_ID:
    os << "client_id";
    break;
  case OSDPerfMetricSubKeyType::CLIENT_ADDRESS:
    os << "client_address";
    break;
  case OSDPerfMetricSubKeyType::POOL_ID:
    os << "pool_id";
    break;
  case OSDPerfMetricSubKeyType::NAMESPACE:
    os << "namespace";
    break;
  case OSDPerfMetricSubKeyType::OSD_ID:
    os << "osd_id";
    break;
  case OSDPerfMetricSubKeyType::PG_ID:
    os << "pg_id";
    break;
  case OSDPerfMetricSubKeyType::OBJECT_NAME:
    os << "object_name";
    break;
  case OSDPerfMetricSubKeyType::SNAP_ID:
    os << "snap_id";
    break;
  default:
    os << "unknown (" << static_cast<int>(d.type) << ")";
  }
  return os << "~/" << d.regex_str << "/";
}

void PerformanceCounterDescriptor::pack_counter(const PerformanceCounter &c,
                                                bufferlist *bl) const {
  using ceph::encode;
  encode(c.first, *bl);
  switch(type) {
  case PerformanceCounterType::OPS:
  case PerformanceCounterType::WRITE_OPS:
  case PerformanceCounterType::READ_OPS:
  case PerformanceCounterType::BYTES:
  case PerformanceCounterType::WRITE_BYTES:
  case PerformanceCounterType::READ_BYTES:
    break;
  case PerformanceCounterType::LATENCY:
  case PerformanceCounterType::WRITE_LATENCY:
  case PerformanceCounterType::READ_LATENCY:
    encode(c.second, *bl);
    break;
  default:
    ceph_abort_msg("unknown counter type");
  }
}

void PerformanceCounterDescriptor::unpack_counter(
    bufferlist::const_iterator& bl, PerformanceCounter *c) const {
  using ceph::decode;
  decode(c->first, bl);
  switch(type) {
  case PerformanceCounterType::OPS:
  case PerformanceCounterType::WRITE_OPS:
  case PerformanceCounterType::READ_OPS:
  case PerformanceCounterType::BYTES:
  case PerformanceCounterType::WRITE_BYTES:
  case PerformanceCounterType::READ_BYTES:
    break;
  case PerformanceCounterType::LATENCY:
  case PerformanceCounterType::WRITE_LATENCY:
  case PerformanceCounterType::READ_LATENCY:
    decode(c->second, bl);
    break;
  default:
    ceph_abort_msg("unknown counter type");
  }
}

std::ostream& operator<<(std::ostream& os,
                         const PerformanceCounterDescriptor &d) {
  switch(d.type) {
  case PerformanceCounterType::OPS:
    return os << "ops";
  case PerformanceCounterType::WRITE_OPS:
    return os << "write ops";
  case PerformanceCounterType::READ_OPS:
    return os << "read ops";
  case PerformanceCounterType::BYTES:
    return os << "bytes";
  case PerformanceCounterType::WRITE_BYTES:
    return os << "write bytes";
  case PerformanceCounterType::READ_BYTES:
    return os << "read bytes";
  case PerformanceCounterType::LATENCY:
    return os << "latency";
  case PerformanceCounterType::WRITE_LATENCY:
    return os << "write latency";
  case PerformanceCounterType::READ_LATENCY:
    return os << "read latency";
  default:
    return os << "unknown (" << static_cast<int>(d.type) << ")";
  }
}

std::ostream& operator<<(std::ostream& os, const OSDPerfMetricLimit &limit) {
  return os << "{order_by=" << limit.order_by << ", max_count="
            << limit.max_count << "}";
}

void OSDPerfMetricQuery::pack_counters(const PerformanceCounters &counters,
                                       bufferlist *bl) const {
  auto it = counters.begin();
  for (auto &descriptor : performance_counter_descriptors) {
    if (it == counters.end()) {
      descriptor.pack_counter(PerformanceCounter(), bl);
    } else {
      descriptor.pack_counter(*it, bl);
      it++;
    }
  }
}

std::ostream& operator<<(std::ostream& os, const OSDPerfMetricQuery &query) {
  return os << "{key=" << query.key_descriptor << ", counters="
            << query.performance_counter_descriptors << "}";
}