]> git.proxmox.com Git - ceph.git/blame - ceph/src/include/util.h
update sources to v12.2.1
[ceph.git] / ceph / src / include / util.h
CommitLineData
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) 2012 Inktank Storage, Inc.
7 * Copyright (C) 2014 Red Hat <contact@redhat.com>
8 *
9 * This is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License version 2.1, as published by the Free Software
12 * Foundation. See file COPYING.
13 */
14#ifndef CEPH_UTIL_H
15#define CEPH_UTIL_H
16
17#include "common/Formatter.h"
18#include "include/types.h"
19
20int64_t unit_to_bytesize(string val, ostream *pss);
21
181888fb
FG
22std::string bytes2str(uint64_t count);
23
7c673cae
FG
24struct ceph_data_stats
25{
26 uint64_t byte_total;
27 uint64_t byte_used;
28 uint64_t byte_avail;
29 int avail_percent;
30
31 ceph_data_stats() :
32 byte_total(0),
33 byte_used(0),
34 byte_avail(0),
35 avail_percent(0)
36 { }
37
38 void dump(Formatter *f) const {
39 assert(f != NULL);
40 f->dump_int("total", byte_total);
41 f->dump_int("used", byte_used);
42 f->dump_int("avail", byte_avail);
43 f->dump_int("avail_percent", avail_percent);
44 }
45
46 void encode(bufferlist &bl) const {
47 ENCODE_START(1, 1, bl);
48 ::encode(byte_total, bl);
49 ::encode(byte_used, bl);
50 ::encode(byte_avail, bl);
51 ::encode(avail_percent, bl);
52 ENCODE_FINISH(bl);
53 }
54
55 void decode(bufferlist::iterator &p) {
56 DECODE_START(1, p);
57 ::decode(byte_total, p);
58 ::decode(byte_used, p);
59 ::decode(byte_avail, p);
60 ::decode(avail_percent, p);
61 DECODE_FINISH(p);
62 }
63
64 static void generate_test_instances(list<ceph_data_stats*>& ls) {
65 ls.push_back(new ceph_data_stats);
66 ls.push_back(new ceph_data_stats);
67 ls.back()->byte_total = 1024*1024;
68 ls.back()->byte_used = 512*1024;
69 ls.back()->byte_avail = 512*1024;
70 ls.back()->avail_percent = 50;
71 }
72};
73typedef struct ceph_data_stats ceph_data_stats_t;
74WRITE_CLASS_ENCODER(ceph_data_stats)
75
76int get_fs_stats(ceph_data_stats_t &stats, const char *path);
77
78/// collect info from @p uname(2), @p /proc/meminfo and @p /proc/cpuinfo
79void collect_sys_info(map<string, string> *m, CephContext *cct);
80
81/// dump service ids grouped by their host to the specified formatter
82/// @param f formatter for the output
83/// @param services a map from hostname to a list of service id hosted by this host
84/// @param type the service type of given @p services, for example @p osd or @p mon.
85void dump_services(Formatter* f, const map<string, list<int> >& services, const char* type);
86
87string cleanbin(bufferlist &bl, bool &b64);
88string cleanbin(string &str);
89#endif /* CEPH_UTIL_H */