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
|
#include <algorithm>
#include <iostream>
#include <fstream>
#include <string>
#include <numeric>
#include <regex>
#include <cmath>
#include <system_error>
using namespace std;
int main(int argc, char **argv)
{
cout << "Mon RSS Usage Test" << endl;
if (argc != 2) {
cout << "Syntax: "
<< "ceph_test_mon_rss_usage <mon-memory-target-bytes>"
<< endl;
exit(EINVAL);
}
unsigned long maxallowed = stoul(argv[1], nullptr, 10);
// Set max allowed RSS usage to be 125% of mon-memory-target
maxallowed *= 1.25;
string target_directory("/var/log/ceph/");
string filePath = target_directory + "ceph-mon-rss-usage.log";
ifstream buffer(filePath.c_str());
string line;
vector<unsigned long> results;
while(getline(buffer, line) && !line.empty()) {
string rssUsage;
size_t pos = line.find(':');
if (pos != string::npos) {
rssUsage = line.substr(0, pos);
}
if (!rssUsage.empty()) {
results.push_back(stoul(rssUsage));
}
}
buffer.close();
if (results.empty()) {
cout << "Error: No grep results found!" << endl;
exit(ENOENT);
}
auto maxe = *(max_element(results.begin(), results.end()));
cout << "Stats for mon RSS Memory Usage:" << endl;
cout << "Parsed " << results.size() << " entries." << endl;
cout << "Max: " << maxe << endl;
cout << "Min: " << *(min_element(results.begin(), results.end())) << endl;
auto sum = accumulate(results.begin(), results.end(),
static_cast<unsigned long long>(0));
auto mean = sum / results.size();
cout << "Mean average: " << mean << endl;
vector<unsigned long> diff(results.size());
transform(results.begin(), results.end(), diff.begin(),
[mean](unsigned long x) { return x - mean; });
auto sump = inner_product(diff.begin(), diff.end(), diff.begin(), 0.0);
auto stdev = sqrt(sump / results.size());
cout << fixed << "Standard deviation: " << stdev << endl;
if (maxe > maxallowed) {
cout << "Error: Mon RSS memory usage exceeds maximum allowed!" << endl;
exit(ENOMEM);
}
cout << "Completed successfully" << endl;
return 0;
}
|