]>
Commit | Line | Data |
---|---|---|
eafe8130 TL |
1 | #include <algorithm> |
2 | #include <iostream> | |
3 | #include <fstream> | |
4 | #include <string> | |
5 | #include <numeric> | |
6 | #include <regex> | |
7 | #include <cmath> | |
8 | #include <system_error> | |
9 | ||
10 | using namespace std; | |
11 | ||
12 | int main(int argc, char **argv) | |
13 | { | |
14 | cout << "Mon RSS Usage Test" << endl; | |
15 | ||
16 | if (argc != 2) { | |
17 | cout << "Syntax: " | |
18 | << "ceph_test_mon_rss_usage <mon-memory-target-bytes>" | |
19 | << endl; | |
20 | exit(EINVAL); | |
21 | } | |
22 | ||
23 | unsigned long maxallowed = stoul(argv[1], nullptr, 10); | |
24 | // Set max allowed RSS usage to be 125% of mon-memory-target | |
25 | maxallowed *= 1.25; | |
26 | ||
27 | string target_directory("/var/log/ceph/"); | |
28 | string filePath = target_directory + "ceph-mon-rss-usage.log"; | |
29 | ifstream buffer(filePath.c_str()); | |
30 | string line; | |
31 | vector<unsigned long> results; | |
32 | while(getline(buffer, line) && !line.empty()) { | |
33 | string rssUsage; | |
34 | size_t pos = line.find(':'); | |
35 | if (pos != string::npos) { | |
36 | rssUsage = line.substr(0, pos); | |
37 | } | |
38 | if (!rssUsage.empty()) { | |
39 | results.push_back(stoul(rssUsage)); | |
40 | } | |
41 | } | |
42 | ||
43 | buffer.close(); | |
44 | if (results.empty()) { | |
45 | cout << "Error: No grep results found!" << endl; | |
46 | exit(ENOENT); | |
47 | } | |
48 | ||
49 | auto maxe = *(max_element(results.begin(), results.end())); | |
50 | cout << "Stats for mon RSS Memory Usage:" << endl; | |
51 | cout << "Parsed " << results.size() << " entries." << endl; | |
52 | cout << "Max: " << maxe << endl; | |
53 | cout << "Min: " << *(min_element(results.begin(), results.end())) << endl; | |
54 | auto sum = accumulate(results.begin(), results.end(), | |
55 | static_cast<unsigned long long>(0)); | |
56 | auto mean = sum / results.size(); | |
57 | cout << "Mean average: " << mean << endl; | |
58 | vector<unsigned long> diff(results.size()); | |
59 | transform(results.begin(), results.end(), diff.begin(), | |
60 | [mean](unsigned long x) { return x - mean; }); | |
61 | auto sump = inner_product(diff.begin(), diff.end(), diff.begin(), 0.0); | |
62 | auto stdev = sqrt(sump / results.size()); | |
63 | cout << fixed << "Standard deviation: " << stdev << endl; | |
64 | ||
65 | if (maxe > maxallowed) { | |
66 | cout << "Error: Mon RSS memory usage exceeds maximum allowed!" << endl; | |
67 | exit(ENOMEM); | |
68 | } | |
69 | ||
70 | cout << "Completed successfully" << endl; | |
71 | return 0; | |
72 | } |