SWC-DB  v0.5.12 C++ documentations
SWC-DB© (Super Wide Column Database) - High Performance Scalable Database (https://github.com/kashirin-alex/swc-db)
Shell_Statistics.cc
Go to the documentation of this file.
1 /*
2  * SWC-DB© Copyright since 2019 Alex Kashirin <kashirin.alex@gmail.com>
3  * License details at <https://github.com/kashirin-alex/swc-db/#license>
4  */
5 
6 
8 
13 #include <iomanip>
14 
15 
16 
17 
18 namespace SWC { namespace Utils { namespace shell {
19 
20 
22  "host", "group", "role", "id", "component", "part", "type"
23 };
24 
25 
27  : Interface("\033[32mSWC-DB(\033[36mstatistics\033[32m)\033[33m> \033[00m",
28  "/tmp/.swc-cli-statistics-history",
29  CLI::STATISTICS),
30  with_broker(Env::Config::settings()->get_bool("with-broker")),
31  clients(
32  (with_broker
33  ? client::Clients::make(
34  *Env::Config::settings(),
35  Comm::IoContext::make("Statistics", 8),
36  nullptr // std::make_shared<client::BrokerContext>()
37  )
38  : client::Clients::make(
39  *Env::Config::settings(),
40  Comm::IoContext::make("Statistics", 8),
41  nullptr, // std::make_shared<client::ManagerContext>()
42  nullptr // std::make_shared<client::RangerContext>()
43  )
44  )->init()
45  ),
46  m_message(),
47  m_stat_names(default_stat_names),
48  m_read_groups(), m_definitions() {
49 
50  add_option(
51  "show",
52  {"show last='DURATION' since='DATETIME' agg='DURATION'",
53  " host='STRING' group='STRING' role='STRING' id='STRING'",
54  " component='STRING' part='STRING' type='STRING' metric='STRING'",
55  " AND .. ;",
56  " -> show last=30day group=swcdb role=rgr component=fs part=broker;",
57  " # show Fs-Broker stats on Ranger for the last 30 days",
58  " -> show since='2021/05/01 00:00:00' component='cpu';",
59  " # show CPU on all roles having CPU metrics since May of 2021",
60  "* STRING: string-type definition is optional",
61  "* DURATION: in Decimal[week|day|hour|minute] (4week)",
62  "* DATETIME: in format YYYY/MM/DD HH:mm:ss or seconds-timestamp",
63  "* 'last=': The Duration set or NONE default to 7day",
64  "* 'since=': The Datetime set or NONE for since (now-'last'|ever)",
65  "* 'agg=': The Duration for aggregations or NONE into-single entry",
66  "* AND: Another metrics group"
67  },
68  [this](std::string& cmd) { return read(cmd, true); },
69  "(?i)^show(.*|$)"
70  );
71  add_option(
72  "list metrics",
73  {"list metrics host='STRING' group='STRING' role='STRING' id='STRING'",
74  " component='STRING' part='STRING' type='STRING' AND .. ;",
75  " -> list metrics;",
76  " # List all metrics definitions"
77  },
78  [this](std::string& cmd) { return read(cmd, false); },
79  "(?i)^list metrics(.*|$)"
80  );
81  add_option(
82  "truncate",
83  {"truncate last='DURATION' since='DATETIME' agg='DURATION'",
84  " host='STRING' group='STRING' role='STRING' id='STRING'",
85  " component='STRING' part='STRING'",
86  " type='STRING' AND ..;",
87  " -> truncate;",
88  " # Truncate all metrics"
89  },
90  [this](std::string& cmd) { return read(cmd, true); },
91  "(?i)^truncate(.*|$)"
92  );
93  add_option(
94  "set stat-names",
95  {"set stat-names F1,F2, .. or 'swcdb-default';",
96  "* swcdb-default: host,group,role,id,component,part,type"},
97  [this](std::string& cmd) { return read(cmd, false); },
98  "(?i)^set stat-names(.*|$)"
99  );
100  add_option(
101  "list stat-names",
102  {"list stat-names;"},
103  [this](std::string&) {
104  SWC_PRINT << "stat-names: ";
105  for(auto it=m_stat_names.cbegin(); it != m_stat_names.cend();) {
106  SWC_LOG_OSTREAM << '"' << *it << '"';
107  if(++it != m_stat_names.cend())
108  SWC_LOG_OSTREAM<< ", ";
109  }
111  return true;
112  },
113  "(?i)^list stat-names(.*|$)"
114  );
115 
116  SWC_ASSERT(!with_broker || clients->brokers.has_endpoints());
117 }
118 
120  clients->stop();
121 }
122 
123 void Statistics::ReadGroup::print(std::ostream& out,
124  const Statistics* ptr) const {
125  if(last)
126  out << "last=" << last << "s ";
127  if(since)
128  out << "since=" << since << "s ";
129  if(agg)
130  out << "agg=" << agg << "s ";
131  for(size_t i=0; i < key.size(); ++i) {
132  if(!key[i].empty())
133  key[i].print(out << ' ' << ptr->m_stat_names[i]);
134  }
135  if(!metric.empty())
136  out << " metric=" << metric << ' ';
137 }
138 
139 
140 bool Statistics::read(std::string& cmd, bool extended) {
141  m_read_groups.clear();
142  m_message.clear();
143  err = Error::OK;
144 
145  uint8_t func = 0;
146  client::SQL::Reader parser(cmd, m_message);
147  while(parser.remain && !err) {
148  if(parser.found_space())
149  continue;
150 
151  if(parser.found_token("list metrics", 12)) {
152  func = 1;
153  break;
154  }
155  if(parser.found_token("show", 4)) {
156  func = 2;
157  break;
158  }
159  if(parser.found_token("truncate", 8)) {
160  func = 3;
161  break;
162  }
163  if(parser.found_token("set stat-names", 14)) {
164  parser.seek_space();
165  if(parser.found_token("swcdb-default", 13)) {
167  return true;
168  }
170  std::string buf;
171  while(parser.remain && !err) {
172  parser.seek_space();
173  parser.read(buf, ",");
174  if(!buf.empty())
175  tmp.emplace_back(std::move(buf));
176  parser.seek_space();
177  if(!parser.found_char(','))
178  break;
179  }
180  if(!tmp.empty()) {
181  m_stat_names = std::move(tmp);
182  return true;
183  }
185  return error("Empty stat names list");
186  }
187  bool token_cmd = false;
188  parser.expect_token("list metrics|show|truncate", 1, token_cmd);
189  err = parser.err;
190  return error(m_message);
191  }
192 
193  auto group = &m_read_groups.emplace_back();
194  group->key.resize(m_stat_names.size());
195  bool ok = false;
196  while(parser.remain && !err) {
197  if(parser.found_space())
198  continue;
199  if(extended) {
200  if(parser.found_token("last", 4)) {
201  parser.seek_space();
202  parser.expect_eq();
203  bool was_set;
204  parser.read_duration_secs(group->last, was_set, " ");
205  ok = true;
206  continue;
207  }
208  if(parser.found_token("since", 5)) {
209  parser.seek_space();
210  parser.expect_eq();
211  std::string buf;
212  parser.read(buf, " ");
213  group->since = Time::parse_ns(err, buf);
214  if(err)
215  parser.error_msg(Error::SQL_PARSE_ERROR, "Bad datetime format");
216  else
217  group->since /= 1000000000;
218  ok = true;
219  continue;
220  }
221  if(parser.found_token("agg", 3)) {
222  parser.seek_space();
223  parser.expect_eq();
224  bool was_set;
225  uint64_t agg;
226  parser.read_duration_secs(agg, was_set, " ");
227  if(was_set)
228  group->agg = agg;
229  ok = true;
230  continue;
231  }
232  if(parser.found_token("metric", 6)) {
233  parser.seek_space();
234  parser.expect_eq();
235  parser.read(group->metric, " ");
236  ok = true;
237  continue;
238  }
239  }
240 
241  bool found = false;
242  std::string buf;
243  parser.read(buf, " =");
244  if(!buf.empty()) for(size_t i=0; i < m_stat_names.size(); ++i) {
246  buf.c_str(), m_stat_names[i].c_str(), m_stat_names[i].size())) {
247  parser.seek_space();
248  parser.expect_eq();
249  parser.read(group->key[i], " ");
250  found = ok = true;
251  break;
252  }
253  }
254  if(found)
255  continue;
256 
257  if(!Condition::str_case_eq(buf.c_str(), "and", 3))
258  break;
259  if(!ok) {
261  m_message = "Empty Metrics-Group";
262  break;
263  }
264  group = &m_read_groups.emplace_back();
265  group->key.resize(m_stat_names.size());
266  ok = false;
267  }
268 
269  if(!ok && m_read_groups.size() > 1) {
271  m_message = "Empty Metrics-Group";
272  }
273  if(err || (err = parser.err))
274  return error(m_message);
275 
276  for(auto& g : m_read_groups) {
277  auto it = g.key.begin();
278  auto it_set = g.key.cbegin();
279  for(; it != g.key.cend(); ++it) {
280  if(!it->empty()) {
281  it->comp = Condition::EQ;
282  it_set = it;
283  continue;
284  }
285  it->comp = Condition::FIP;
286  }
287  if(it == g.key.cbegin()) {
288  g.key.clear();
289  } else if(it_set != g.key.cend() &&
290  ++it_set != g.key.cend() &&
291  ++it_set != g.key.cend()) {
292  g.key.erase(it_set, g.key.cend());
293  }
294  }
295 
296  switch(func) {
297  case 1:
298  return list_metrics();
299  case 2:
300  return show();
301  case 3:
302  return truncate();
303  default:
304  if(!err)
306  }
307  return error(m_message);
308 }
309 
310 
311 
313  : property(), metrics() {
314  property.set(cell.key, Condition::Comp::EQ);
315  property[0].clear();
316  property[0].comp = Condition::Comp::GE;
317 
318  StaticBuffer v;
319  cell.get_value(v, false);
320  const uint8_t* ptr = v.base;
321  size_t remain = v.size;
322 
324  Core::Vector<int64_t> aggregations;
325  Core::Vector<int64_t> relations;
328 
329  while(remain) {
330  switch(DB::Cell::Serial::Value::read_type(&ptr, &remain)) {
332  DB::Cell::Serial::Value::Field_LIST_INT64 value(&ptr, &remain, false);
333  if(value.fid == 0)
334  value.convert_to(ids);
335  else if(value.fid == 3)
336  value.convert_to(aggregations);
337  else if(value.fid == 4)
338  value.convert_to(relations);
339  break;
340  }
342  DB::Cell::Serial::Value::Field_LIST_BYTES value(&ptr, &remain, false);
343  if(value.fid == 1)
344  value.convert_to(names);
345  else if(value.fid == 2)
346  value.convert_to(labels);
347  break;
348  }
349  default:
350  break;
351  }
352  }
353  metrics.resize(ids.size());
354 
355  for(size_t i =0; i < ids.size(); ++i) {
356  metrics[i].id = ids[i];
357  metrics[i].relation = i < relations.size() ? relations[i] : 0;
358  metrics[i].agg = i < aggregations.size() ? aggregations[i] : 0;
359  if(i < names.size())
360  metrics[i].name = std::move(names[i]);
361  else
362  metrics[i].name = std::to_string(ids[i]);
363  if(i < labels.size())
364  metrics[i].label = std::move(labels[i]);
365  else
366  metrics[i].label = metrics[i].name;
367  }
368 
369  std::sort(
370  metrics.begin(), metrics.end(),
371  [](const MetricDefinition& a, const MetricDefinition& b) {
372  return a.id < b.id;
373  });
374 }
375 
376 bool Statistics::StatsDefinition::has_metric(const std::string& name,
377  uint24_t fid,
378  size_t& i)
379  const noexcept {
380  for(i=0; i < metrics.size(); ++i) {
381  if(metrics[i].id == fid) {
382  if(!name.empty() && (metrics[i].name.empty() ||
383  !Condition::str_eq(name, metrics[i].name)))
384  return false;
385  return true;
386  }
387  }
388  return false;
389 }
390 
391 void Statistics::StatsDefinition::print(std::ostream& out,
392  const Statistics* ptr,
393  bool only_property) const {
394  out << "# property:";
395  for(size_t i = 1; i < property.size(); ++i) {
396  out << ' ';
397  if(i <= ptr->m_stat_names.size())
398  out << ptr->m_stat_names[i-1];
399  else
400  out << "F" << i;
401  out << '=' << property[i];
402  }
403  if(only_property)
404  return;
405 
406  size_t len_relation = 8;
407  size_t len_id = 2;
408  size_t len_name = 6;
409  size_t len_label = 5;
410  for(auto& metric : metrics) {
411  if(len_name < metric.name.length())
412  len_name = metric.name.length();
413  if(len_label < metric.label.length())
414  len_label = metric.label.length();
415  size_t tmp = std::to_string(uint32_t(metric.id)).length();
416  if(len_id < tmp)
417  len_id = tmp;
418  tmp = std::to_string(uint32_t(metric.relation)).length();
419  if(len_relation < tmp)
420  len_relation = tmp;
421  }
422  len_relation += 3;
423  len_id += 3;
424  len_name += 3;
425  len_label += 3;
426 
427  out << '\n';
428  out << std::left << std::setw(3) << " "
429  << std::left << std::setw(len_name) << "Metric"
430  << std::left << std::setw(len_id) << "ID"
431  << std::left << std::setw(len_label) << "Label"
432  << std::left << std::setw(len_relation) << "Relation"
433  << std::left << "Aggregation";
434  out << std::endl;
435  for(auto& metric : metrics) {
436  out << std::left << std::setw(3) << " "
437  << std::left << std::setw(len_name) << metric.name
438  << std::left << std::setw(len_id) << metric.id
439  << std::left << std::setw(len_label) << metric.label
440  << std::left << std::setw(len_relation) << metric.relation
441  << std::left
443  metric.agg);
444  out << std::endl;
445  }
446 }
447 
448 
449 
451  m_definitions.clear();
452 
453  auto& col = specs.columns.emplace_back(
455 
456  for(auto& g : m_read_groups) {
457  auto& key_intval = col.add(
458  DB::Types::Column::SERIAL)->key_intervals.add();
459  if(!g.key.empty())
460  key_intval.start.copy(g.key);
461  key_intval.start.insert(
462  0,
465  );
466  if(g.key.empty())
467  key_intval.start.add("", Condition::FIP);
468  }
469 
471  clients,
472  [this]
474  DB::Cells::Result cells;
475  for(cid_t cid : _hdlr->get_cids()) {
476  _hdlr->get_cells(cid, cells);
477  m_definitions.reserve(cells.size());
478  for(auto cell : cells) {
479  try {
480  m_definitions.emplace_back(*cell);
481  } catch(...) {
482  SWC_LOG_CURRENT_EXCEPTION("");
483  SWC_PRINT << "";
484  cell->print(SWC_LOG_OSTREAM, DB::Types::Column::SERIAL);
485  SWC_LOG_OSTREAM << SWC_PRINT_CLOSE;
486  }
487 
488  }
489  }
490  },
491  true,
492  nullptr,
496  );
497 
498  hdlr->scan(err, specs);
499  if(!err)
500  hdlr->wait();
501 }
502 
503 // LIST-METRICS
505  DB::Specs::Scan specs;
506  set_definitions(specs);
507 
508  SWC_LOG_OUT(
509  LOG_DEBUG,
510  specs.display(SWC_LOG_OSTREAM << "\n # Definitions ");
511  SWC_LOG_OSTREAM << "# Groups:";
512  for(auto& g : m_read_groups)
513  g.print(SWC_LOG_OSTREAM << "\n\t", this);
514  );
515  if(err)
516  return error(m_message);
517 
518  SWC_PRINT << "";
519  for(auto& stats : m_definitions)
520  stats.print(SWC_LOG_OSTREAM << '\n', this);
522 
523  return true;
524 }
525 
526 
527 
528 void Statistics::Stats::print(std::ostream& out, const ReadGroup& group,
529  Statistics* ptr) const {
530  defined->print(out, ptr, true);
531  out << '\n';
532 
533  size_t len_name = 5;
534  size_t len_value = 5;
535  for(auto& m : defined->metrics) {
536  for(auto& data : values) {
537  if(m.id != data.id)
538  continue;
539  if(len_name < m.name.length())
540  len_name = m.name.length();
541  size_t tmp = std::to_string(
542  data.count ? data.total/data.count : data.total).length();
543  if(data.flag && data.count > 1)
544  tmp += 7;
545  if(len_value < tmp)
546  len_value = tmp;
547  break;
548  }
549  }
550  len_name += 3;
551  len_value += 3;
552 
553  char res[20];
554  std::strftime(res, 20, "%Y/%m/%d %H:%M:%S", std::gmtime(&ts));
555  out << " since " << res;
556  if(group.agg) {
557  time_t tmp = ts + group.agg-1;
558  std::strftime(res, 20, "%Y/%m/%d %H:%M:%S", std::gmtime(&tmp));
559  out << " to " << res;
560  }
561  out << std::endl;
562 
563  out << std::left << std::setw(3) << " "
564  << std::left << std::setw(len_name) << "Metric"
565  << std::left << std::setw(len_value) << "Value"
566  << std::left << "Label";
567  out << std::endl;
568 
569  for(auto& m : defined->metrics) {
570  for(auto& data : values) {
571  if(m.id != data.id)
572  continue;
573  std::string value(
574  std::to_string(data.count ? data.total/data.count : data.total));
575  if(data.flag && data.count > 1)
576  value.append("(!prop)");
577  out << std::left << std::setw(3) << " "
578  << std::left << std::setw(len_name) << m.name
579  << std::left << std::setw(len_value) << value
580  << std::left << m.label;
581  out << std::endl;
582  break;
583  }
584  }
585 }
586 
588  size_t metric_idx, uint24_t field_id,
589  int64_t value) noexcept {
590  size_t idx = 0;
591  bool found = false;
592  for(;idx < values.size(); ++idx) {
593  if((found = values[idx].id == field_id))
594  break;
595  }
596  if(!found) {
597  idx = values.size();
598  values.emplace_back(field_id);
599  }
600  auto& data = values[idx];
601 
602  auto& m = defined->metrics[metric_idx];
603  switch(m.agg) {
605  if(!found || value > data.total)
606  data.total = value;
607  break;
608  }
610  if(!found || value < data.total)
611  data.total = value;
612  break;
613  }
615  /* Proportional Average, such-for Latency Avg or Ev-Bytes */
616  if(!data.flag) {
617  for(auto& stat : *datasp) {
618  if(defined != stat.defined || ts != stat.ts)
619  continue;
620  for(auto& other_m : defined->metrics) {
621  if(other_m.agg !=
623  m.relation != other_m.relation)
624  continue;
625  for(auto& other_v : stat.values) {
626  if(other_v.id == other_m.id) {
627  data.count += other_v.last;
628  data.total += value * other_v.last;
629  return;
630  }
631  }
632  }
633  }
634  data.flag = 1;
635  }
636  [[fallthrough]];
637  }
639  ++data.count;
640  data.total += value;
641  break;
642  }
643  default: {
644  data.total += data.last = value;
645  break;
646  }
647  }
648 }
649 
650 
651 
652 // SHOW
654 
655  DB::Specs::Scan specs_definitions;
656  set_definitions(specs_definitions);
657  if(err)
658  return error(m_message);
659 
660  for(auto& g : m_read_groups) {
662  auto& key_intval = spec.key_intervals.add();
663 
664  bool empty = g.key.empty();
665  if(!empty)
666  key_intval.start.copy(g.key);
667  if(g.since) {
668  key_intval.start.insert(0, std::to_string(g.since), Condition::GE);
669  if(g.last) {
670  key_intval.finish.add(
671  std::to_string(g.since + g.last), Condition::LT);
672  key_intval.finish.add("", Condition::FIP);
673  }
674  } else {
675  int64_t secs = ::time(nullptr);
676  key_intval.start.insert(
677  0,
678  std::to_string(secs - (g.last ? g.last : 7 * 24 * 60 * 60)),
679  Condition::GE);
680  }
681  if(empty && !key_intval.start.empty())
682  key_intval.start.add("", Condition::FIP);
683 
684  SWC_LOG_OUT(
685  LOG_DEBUG,
686  spec.display(SWC_LOG_OSTREAM << "\n # Statistics ");
687  g.print(SWC_LOG_OSTREAM << "# Group:", this);
688  );
689 
690  Core::Vector<Stats> stats_datas;
692  clients,
693  [this, &g, datasp=&stats_datas]
695  DB::Cells::Result cells;
696  if(!err && !(err = _hdlr->state_error)) {
697  auto col = _hdlr->get_columnn(DB::Types::SystemColumn::SYS_CID_STATS);
698  if(!(err = col->error()) && !col->empty())
699  col->get_cells(cells);
700  }
701  if(err) {
702  _hdlr->valid_state.store(false);
703  return;
704  }
705 
706  for(auto cell : cells) {
707  for(auto& defined : m_definitions) {
708  if(defined.property.is_matching_lexic(cell->key)) {
709 
710  time_t ts = (cell->get_timestamp()/1000000000);
711  if(g.agg) {
712  ts /= g.agg;
713  ts *= g.agg;
714  }
715  StaticBuffer v;
716  cell->get_value(v, false);
717  const uint8_t* ptr = v.base;
718  size_t remain = v.size;
719 
720  while(remain) {
721  SWC::DB::Cell::Serial::Value::read_type(&ptr, &remain);
722  if(!remain)
723  break;
724  size_t metric_idx;
725  DB::Cell::Serial::Value::Field_INT64 field(&ptr, &remain);
726  if(!defined.has_metric(g.metric, field.fid, metric_idx))
727  continue;
728 
729  Stats* statsp = nullptr;
730  for(auto& stats : *datasp) {
731  if(stats.defined == &defined &&
732  (!g.agg || (stats.ts + g.agg > ts && stats.ts <= ts))) {
733  statsp = &stats;
734  break;
735  }
736  }
737  (statsp ? statsp : &datasp->emplace_back(&defined, ts))
738  ->add(datasp, metric_idx, field.fid, field.value);
739  }
740  /*
741  SWC_PRINT << "";
742  defined.print(SWC_LOG_OSTREAM << std::endl, this);
743  cell->print(SWC_LOG_OSTREAM << std::endl, DB::Types::Column::SERIAL);
744  SWC_LOG_OSTREAM << SWC_PRINT_CLOSE;
745  */
746  break;
747  }
748  }
749  }
750  },
751  true,
752  nullptr,
756  );
757 
758  hdlr->scan(
759  DB::Types::KeySeq::LEXIC,
761  std::move(spec)
762  );
763  hdlr->wait();
764  if(err || (err = hdlr->state_error))
765  break;
766 
767  SWC_PRINT << "";
768  for(auto& data : stats_datas)
769  data.print(SWC_LOG_OSTREAM << '\n', g, this);
771  }
772 
773  SWC_LOG_OUT(
774  LOG_DEBUG,
775  specs_definitions.display(SWC_LOG_OSTREAM << "\n # Definitions ");
776  SWC_LOG_OSTREAM << "# Groups:";
777  for(auto& g : m_read_groups)
778  g.print(SWC_LOG_OSTREAM << "\n\t", this);
779  );
780  return err ? error(m_message) : true;
781 }
782 
783 
784 
785 // TRUNCATE
787  Core::Atomic<size_t> deleted_count(0);
788 
790  clients,
791  [countp=&deleted_count]
793  if(_hdlr->state_error) {
794  _hdlr->valid_state.store(false);
795  } else {
796  auto col = _hdlr->get_columnn(DB::Types::SystemColumn::SYS_CID_STATS);
797  if(col->error()) {
798  _hdlr->valid_state.store(false);
799  } else if(!col->empty()) {
800  DB::Cells::Result cells;
801  col->get_cells(cells);
802  countp->fetch_add(cells.size());
803  }
804  }
805  },
806  true,
807  nullptr,
808  with_broker
811  );
812 
813  DB::Specs::Scan specs;
814  auto& col = specs.columns.emplace_back(
815  DB::Types::SystemColumn::SYS_CID_STATS, m_read_groups.size());
816  for(auto& g : m_read_groups) {
817  auto& intval = col.add(DB::Types::Column::SERIAL);
818  intval->set_opt__deleting();
819  intval->flags.set_only_keys();
820  auto& key_intval = intval->key_intervals.add();
821 
822  bool empty = g.key.empty();
823  if(!empty)
824  key_intval.start.copy(g.key);
825  if(g.since) {
826  key_intval.start.insert(0, std::to_string(g.since), Condition::GE);
827  if(g.last) {
828  key_intval.finish.add(
829  std::to_string(g.since + g.last), Condition::LT);
830  key_intval.finish.add("", Condition::FIP);
831  }
832  } else {
833  int64_t secs = ::time(nullptr);
834  key_intval.start.insert(
835  0,
836  std::to_string(secs - (g.last ? g.last : 7 * 24 * 60 * 60)),
837  Condition::GE);
838  }
839  if(empty && !key_intval.start.empty())
840  key_intval.start.add("", Condition::FIP);
841  }
842 
843  SWC_LOG_OUT(
844  LOG_DEBUG,
845  specs.display(SWC_LOG_OSTREAM << "\n # ");
846  SWC_LOG_OSTREAM << "# Groups:";
847  for(auto& g : m_read_groups)
848  g.print(SWC_LOG_OSTREAM << "\n\t", this);
849  );
850 
851  hdlr->scan(err, std::move(specs));
852  if(!err) {
853  hdlr->wait();
854  err = hdlr->state_error.load();
855  }
856  SWC_PRINT << " Deleted Cells: " << deleted_count << SWC_PRINT_CLOSE;
857  return err ? error(m_message) : true;
858 }
859 
860 
861 
862 }}} // namespace Utils::shell
SWC::Utils::shell::Statistics::m_read_groups
Core::Vector< ReadGroup > m_read_groups
Definition: Shell_Statistics.h:116
SWC::Error::SQL_PARSE_ERROR
@ SQL_PARSE_ERROR
Definition: Error.h:122
SWC::client::Query::Select::Handlers::Common::make
static SWC_CAN_INLINE Ptr make(const Clients::Ptr &clients, Cb_t &&cb=nullptr, bool rsp_partials=false, const Comm::IoContextPtr &io=nullptr, Clients::Flag executor=Clients::DEFAULT)
Definition: Common.h:26
SWC::Utils::shell::Interface::add_option
void add_option(const char *a_name, Core::Vector< std::string > &&a_desc, OptCall_t &&a_call, const char *a_re)
Definition: Shell.cc:249
SWC::DB::Specs::Scan
Definition: SpecsScan.h:21
SWC::client::Query::Select::Handlers::Common::Ptr
std::shared_ptr< Common > Ptr
Definition: Common.h:22
SWC_LOG_OSTREAM
#define SWC_LOG_OSTREAM
Definition: Logger.h:44
SWC::DB::Specs::Interval::key_intervals
KeyIntervals key_intervals
Definition: SpecsInterval.h:239
SWC::client::SQL::Reader::expect_eq
void expect_eq()
Definition: Reader.cc:82
SWC::Utils::shell::Statistics::m_definitions
Core::Vector< StatsDefinition > m_definitions
Definition: Shell_Statistics.h:117
SWC::Utils::shell::Statistics::set_definitions
void set_definitions(DB::Specs::Scan &specs)
Definition: Shell_Statistics.cc:450
SWC::Utils::shell::Statistics::m_stat_names
Core::Vector< std::string > m_stat_names
Definition: Shell_Statistics.h:115
SWC::DB::Specs::KeyInterval::start
Key start
Definition: SpecsKeyIntervals.h:19
SWC::client::SQL::Reader::expect_token
void expect_token(const char *token, uint8_t token_len, bool &found)
Definition: Reader.cc:122
SWC::Condition::GE
@ GE
Definition: Comparators.h:31
SWC_LOG_OUT
#define SWC_LOG_OUT(pr, _code_)
Definition: Logger.h:178
SWC::Utils::shell::Statistics::~Statistics
virtual ~Statistics()
Definition: Shell_Statistics.cc:119
SWC::Utils::shell::Statistics::MetricDefinition
Definition: Shell_Statistics.h:56
SWC::client::Clients::DEFAULT
@ DEFAULT
Definition: Clients.h:61
data
T data
Definition: BitFieldInt.h:1
SWC::Utils::shell::Statistics::read
bool read(std::string &cmd, bool extended)
Definition: Shell_Statistics.cc:140
SWC::Core::Atomic< size_t >
SWC::Utils::shell::STATISTICS
@ STATISTICS
Definition: Shell.h:34
SWC::Utils::shell::Statistics::ReadGroup::last
uint64_t last
Definition: Shell_Statistics.h:42
SWC::DB::Cell::Serial::Value::Field::fid
uint24_t fid
Definition: CellValueSerialField.h:72
SWC::DB::Types::SystemColumn::SYS_CID_DEFINE_LEXIC
const cid_t SYS_CID_DEFINE_LEXIC
Definition: SystemColumn.h:25
SWC::client::Query::Update::Handlers::Metric::MIN
@ MIN
Definition: Metrics.h:28
SWC::client::SQL::Reader::seek_space
void seek_space()
Definition: Reader.cc:78
SWC::client::SQL::Reader::remain
uint32_t remain
Definition: Reader.h:124
SWC::Utils::shell::Interface::err
int err
Definition: Shell.h:54
SWC::DB::Specs::Key::copy
void copy(const Key &other)
Definition: SpecsKey.cc:40
SWC::Utils::shell::CLI
CLI
Definition: Shell.h:28
SWC::Condition::LT
@ LT
Definition: Comparators.h:34
SWC::Utils::shell::Interface::error
bool error(const std::string &message)
Definition: Shell.cc:345
SWC_PRINT
#define SWC_PRINT
Definition: Logger.h:167
SWC::client::SQL::Reader::read_duration_secs
void read_duration_secs(uint64_t &value, bool &was_set, const char *stop=nullptr)
Definition: Reader.cc:304
SWC_PRINT_CLOSE
#define SWC_PRINT_CLOSE
Definition: Logger.h:171
SWC::DB::Cells::Cell
Definition: Cell.h:92
SWC::DB::Cell::Serial::Value::Field_LIST_BYTES
Definition: CellValueSerialField.h:323
SWC::client::Query::Update::Handlers::Metric::MAX
@ MAX
Definition: Metrics.h:29
SWC::client::SQL::Reader
Definition: Reader.h:28
SWC::Utils::shell::Interface
Definition: Shell.h:41
SWC::DB::Cells::Cell::key
DB::Cell::Key key
Definition: Cell.h:357
SWC::DB::Cells::Result
Definition: Result.h:16
SWC::Utils::shell::Statistics::StatsDefinition::has_metric
bool has_metric(const std::string &name, uint24_t fid, size_t &metric_idx) const noexcept
Definition: Shell_Statistics.cc:376
SWC::Condition::str_eq
bool str_eq(const char *s1, const char *s2) noexcept SWC_ATTRIBS((SWC_ATTRIB_O3))
Definition: Comparators_basic.h:237
SWC::client::SQL::Reader::found_char
bool found_char(const char c)
Definition: Reader.cc:28
SWC::client::Query::Update::Handlers::Metric::AVG
@ AVG
Definition: Metrics.h:30
SWC::Utils::shell::Statistics::Stats::print
void print(std::ostream &out, const ReadGroup &group, Statistics *ptr) const
Definition: Shell_Statistics.cc:528
SWC::Utils::shell::Statistics::ReadGroup::print
void print(std::ostream &out, const Statistics *ptr) const
Definition: Shell_Statistics.cc:123
SWC::Utils::shell::Statistics::clients
client::Clients::Ptr clients
Definition: Shell_Statistics.h:23
SWC::client::SQL::Reader::found_space
bool found_space()
Definition: Reader.cc:37
SWC::Error::OK
@ OK
Definition: Error.h:45
SWC::Core::Vector::empty
constexpr SWC_CAN_INLINE bool empty() const noexcept
Definition: Vector.h:168
SWC::LOG_DEBUG
@ LOG_DEBUG
Definition: Logger.h:36
CellValueSerialFields.h
SWC::Condition::FIP
@ FIP
Definition: Comparators.h:75
SWC::DB::Specs::Scan::columns
Columns columns
Definition: SpecsScan.h:101
SWC::client::SQL::Reader::read
void read(std::string &buf, const char *stop=nullptr, bool keep_escape=false)
Definition: Reader.cc:185
SWC::DB::Specs::KeyIntervals::add
KeyInterval & add()
Definition: SpecsKeyIntervals.cc:28
SWC::Core::Buffer::base
value_type * base
Definition: Buffer.h:131
SWC::DB::Specs::Key::print
void print(std::ostream &out) const
Definition: SpecsKey.cc:105
Metrics.h
SWC
The SWC-DB C++ namespace 'SWC'.
Definition: main.cc:12
SWC::Utils::shell::Statistics::Statistics
Statistics()
Definition: Shell_Statistics.cc:26
SWC::Utils::shell::Statistics::ReadGroup::since
int64_t since
Definition: Shell_Statistics.h:43
SWC::Time::parse_ns
int64_t parse_ns(int &err, const std::string &buf)
Definition: Time.cc:37
SWC::Utils::shell::Statistics::StatsDefinition::metrics
Core::Vector< MetricDefinition > metrics
Definition: Shell_Statistics.h:72
SWC::DB::Cell::Serial::Value::Field_LIST_INT64::convert_to
void convert_to(T &items) const
Definition: CellValueSerialField.h:292
SWC::DB::Specs::Interval::display
void display(std::ostream &out, bool pretty=false, const std::string &offset="") const
Definition: SpecsInterval.cc:351
SWC::Core::Buffer
Definition: Buffer.h:18
SWC::Utils::shell::Statistics::show
bool show()
Definition: Shell_Statistics.cc:653
SWC::Core::Buffer::size
size_t size
Definition: Buffer.h:130
SWC::Condition::EQ
@ EQ
Definition: Comparators.h:32
SWC::DB::Cells::Cell::get_value
Types::Encoder get_value(StaticBuffer &v, bool owner) const
Definition: Cell.cc:77
SWC::client::Query::Update::Handlers::Metric::SUM
@ SUM
Definition: Metrics.h:27
SWC::Utils::shell::default_stat_names
static const Core::Vector< std::string > default_stat_names
Definition: Shell_Statistics.cc:21
SWC::Utils::shell::Statistics::list_metrics
bool list_metrics()
Definition: Shell_Statistics.cc:504
SWC::Utils::shell::Statistics::ReadGroup::agg
uint32_t agg
Definition: Shell_Statistics.h:44
Shell_Statistics.h
SWC::Comm::Resolver::sort
void sort(const Networks &nets, const EndPoints &endpoints, EndPoints &sorted)
Definition: Resolver.cc:243
SWC::Utils::shell::Statistics::Stats::values
Core::Vector< Data > values
Definition: Shell_Statistics.h:111
SWC::client::SQL::Reader::found_token
bool found_token(const char *token, uint8_t token_len)
Definition: Reader.cc:58
SWC::DB::Cell::Serial::Value::Field_LIST_BYTES::convert_to
void convert_to(T &items) const
Definition: CellValueSerialField.h:374
SWC::Utils::shell::Statistics::m_message
std::string m_message
Definition: Shell_Statistics.h:114
SWC::client::Query::Update::Handlers::Metric::AVG_PROP
@ AVG_PROP
Definition: Metrics.h:31
SWC::DB::Cell::Serial::Value::LIST_INT64
@ LIST_INT64
Definition: CellValueSerialField.h:39
SWC::Utils::shell::Statistics::Stats::defined
const StatsDefinition * defined
Definition: Shell_Statistics.h:109
SWC::cid_t
uint64_t cid_t
Definition: Identifiers.h:16
SWC::client::Query::Update::Handlers::Metric::aggregation_to_string
const char *SWC_CONST_FUNC aggregation_to_string(uint8_t agg) noexcept
Definition: Metrics.cc:16
SWC::Utils::shell::Statistics::StatsDefinition::StatsDefinition
StatsDefinition(const DB::Cells::Cell &cell)
Definition: Shell_Statistics.cc:312
SWC::Utils::shell::Statistics::ReadGroup::metric
std::string metric
Definition: Shell_Statistics.h:46
SWC::DB::Cell::Serial::Value::read_type
SWC_CAN_INLINE Type read_type(const uint8_t **bufp, size_t *remainp)
Definition: CellValueSerialField.h:51
SWC::DB::Cell::Serial::Value::Field_LIST_INT64
Definition: CellValueSerialField.h:241
SWC::Core::Vector< std::string >
SWC::Utils::shell::Statistics::Stats::ts
const time_t ts
Definition: Shell_Statistics.h:110
SWC::Utils::shell::Statistics::Stats::add
void add(const Core::Vector< Stats > *datasp, size_t metric_idx, uint24_t field_id, int64_t value) noexcept
Definition: Shell_Statistics.cc:587
SWC::DB::Specs::Interval
Definition: SpecsInterval.h:25
SWC::uint24_t
Core::uint24_t uint24_t
Definition: BitFieldInt.h:401
SWC::client::SQL::Reader::err
int err
Definition: Reader.h:125
SWC::Core::Vector::cend
constexpr SWC_CAN_INLINE const_iterator cend() const noexcept
Definition: Vector.h:232
SWC::client::Clients::BROKER
@ BROKER
Definition: Clients.h:62
SWC::Utils::shell::Statistics::StatsDefinition::print
void print(std::ostream &out, const Statistics *ptr, bool only_property=false) const
Definition: Shell_Statistics.cc:391
SWC::Utils::shell::Statistics::with_broker
const bool with_broker
Definition: Shell_Statistics.h:22
SWC::Utils::shell::Statistics::ReadGroup::key
DB::Specs::Key key
Definition: Shell_Statistics.h:45
SWC::Utils::shell::Statistics
Definition: Shell_Statistics.h:19
SWC::DB::Cell::Serial::Value::LIST_BYTES
@ LIST_BYTES
Definition: CellValueSerialField.h:40
SWC::DB::Types::Column::SERIAL
@ SERIAL
SWC::client::SQL::Reader::error_msg
void error_msg(int error, const std::string &msg)
Definition: Reader.cc:841
SWC_ASSERT
#define SWC_ASSERT(_e_)
Definition: Exception.h:165
SWC::Error::CANCELLED
@ CANCELLED
Definition: Error.h:56
SWC::Core::Vector::cbegin
constexpr SWC_CAN_INLINE const_iterator cbegin() const noexcept
Definition: Vector.h:216
SWC::Core::to_string
SWC_CAN_INLINE std::string to_string(const BitFieldInt< T, SZ > &v)
Definition: BitFieldInt.h:263
Common.h
SWC::Core::Vector::size
constexpr SWC_CAN_INLINE size_type size() const noexcept
Definition: Vector.h:189
SWC::Condition::str_case_eq
bool str_case_eq(const char *s1, const char *s2, size_t count) noexcept SWC_ATTRIBS((SWC_ATTRIB_O3))
Definition: Comparators_basic.h:257
Common.h
SWC::DB::Specs::Scan::display
void display(std::ostream &out, bool pretty=true, std::string offset="") const
Definition: SpecsScan.cc:58
SWC::Core::Vector::emplace_back
SWC_CAN_INLINE reference emplace_back(ArgsT &&... args)
Definition: Vector.h:349
SWC::Utils::shell::Statistics::ReadGroup
Definition: Shell_Statistics.h:41
SWC::DB::Types::SystemColumn::SYS_CID_STATS
const cid_t SYS_CID_STATS
Definition: SystemColumn.h:24
SWC::Utils::shell::Statistics::truncate
bool truncate()
Definition: Shell_Statistics.cc:786