Repo-Init
 
Loading...
Searching...
No Matches
ProcessMetrics.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <prometheus/gauge.h>
4#include <prometheus/registry.h>
5
6#include <thread>
7
8#include <sys/times.h>
9
15 private:
16 std::atomic_flag _shouldStop{false};
17 std::unique_ptr<std::thread> _thread;
18 std::shared_ptr<std::atomic_flag> _checkFlag;
19
20 prometheus::Gauge *_pInitTime;
21 prometheus::Gauge *_pCurrentTime;
22 prometheus::Gauge *_pMemory;
23 prometheus::Gauge *_pPageFaults;
24 prometheus::Gauge *_pCpuUsage;
25 prometheus::Gauge *_pDiskRead;
26 prometheus::Gauge *_pDiskWrite;
27 prometheus::Gauge *_pThreadCount;
28 prometheus::Gauge *_pFileDescriptorCount;
29
30 size_t _oldReadBytes{0};
31 size_t _oldWriteBytes{0};
32
33 clock_t _oldCpuTime{0};
34 struct tms _oldCpu {
35 0, 0, 0, 0
36 };
37
43 static size_t countDirectoryEntries(const std::string &path);
44
45 protected:
50 static long int getMemoryUsage();
51
56 static long int getPageFaults();
57
62 double getCpuUsage();
63
68 std::pair<size_t, size_t> getDiskIO();
69
74 static size_t getThreadCount();
75
80 static size_t getFileDescriptorCount();
81
85 void update();
86
90 void threadRunner() noexcept;
91
92 public:
98 ProcessMetrics(std::shared_ptr<std::atomic_flag> checkFlag, const std::shared_ptr<prometheus::Registry> &reg);
99
101 ProcessMetrics(const ProcessMetrics & /*unused*/) = delete;
102
104 ProcessMetrics(ProcessMetrics && /*unused*/) = delete;
105
107 ProcessMetrics &operator=(ProcessMetrics /*unused*/) = delete;
108
110 ProcessMetrics &operator=(ProcessMetrics && /*unused*/) = delete;
111
116};
prometheus::Gauge * _pMemory
Pointer to the memory usage gauge.
clock_t _oldCpuTime
Variable to store the old CPU time.
prometheus::Gauge * _pInitTime
Pointer to initialization time gauge.
prometheus::Gauge * _pCurrentTime
Pointer to the current time gauge.
size_t _oldWriteBytes
Variable to store the old write bytes.
std::atomic_flag _shouldStop
Flag to stop monitoring.
prometheus::Gauge * _pCpuUsage
Pointer to the CPU usage gauge.
void threadRunner() noexcept
prometheus::Gauge * _pPageFaults
Pointer to the page faults gauge.
prometheus::Gauge * _pFileDescriptorCount
Pointer to the file descriptor count gauge.
std::pair< size_t, size_t > getDiskIO()
prometheus::Gauge * _pDiskRead
Pointer to the disk read gauge.
size_t _oldReadBytes
Variable to store the old read bytes.
prometheus::Gauge * _pThreadCount
Pointer to the thread count gauge.
static size_t countDirectoryEntries(const std::string &path)
static long int getMemoryUsage()
std::shared_ptr< std::atomic_flag > _checkFlag
Runtime check flag.
std::unique_ptr< std::thread > _thread
Thread handler.
static size_t getThreadCount()
static long int getPageFaults()
static size_t getFileDescriptorCount()
prometheus::Gauge * _pDiskWrite
Pointer to the disk write gauge.
Structure to store the old CPU times.