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 <filesystem>
7#include <thread>
8
9#include <sys/times.h>
10
16 private:
17 std::shared_ptr<std::atomic_flag> _checkFlag;
18
19 prometheus::Gauge *_pInitTime;
20 prometheus::Gauge *_pCurrentTime;
21 prometheus::Gauge *_pMemory;
22 prometheus::Gauge *_pPageFaults;
23 prometheus::Gauge *_pCpuUsage;
24 prometheus::Gauge *_pDiskRead;
25 prometheus::Gauge *_pDiskWrite;
26 prometheus::Gauge *_pThreadCount;
27 prometheus::Gauge *_pFileDescriptorCount;
28
29 size_t _oldReadBytes{0};
30 size_t _oldWriteBytes{0};
31
32 clock_t _oldCpuTime{0};
33 struct tms _oldCpu{
34 .tms_utime = 0, .tms_stime = 0, .tms_cutime = 0, .tms_cstime = 0};
35
36 std::unique_ptr<std::jthread> _thread;
37
43 static size_t countDirectoryEntries(const std::filesystem::path &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
91 void threadRunner(const std::stop_token &stopToken) noexcept;
92
93 public:
99 ProcessMetrics(std::shared_ptr<std::atomic_flag> checkFlag, const std::shared_ptr<prometheus::Registry> &reg);
100
102 ProcessMetrics(const ProcessMetrics & /*unused*/) = delete;
103
105 ProcessMetrics(ProcessMetrics && /*unused*/) = delete;
106
109
111 ProcessMetrics &operator=(ProcessMetrics && /*unused*/) = delete;
112
117};
prometheus::Gauge * _pMemory
Pointer to the memory usage gauge.
ProcessMetrics & operator=(ProcessMetrics)=delete
Copy assignment operator.
std::unique_ptr< std::jthread > _thread
Thread handler.
clock_t _oldCpuTime
Variable to store the old CPU time.
ProcessMetrics(std::shared_ptr< std::atomic_flag > checkFlag, const std::shared_ptr< prometheus::Registry > &reg)
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.
ProcessMetrics & operator=(ProcessMetrics &&)=delete
Move assignment operator.
ProcessMetrics(ProcessMetrics &&)=delete
Move constructor.
prometheus::Gauge * _pCpuUsage
Pointer to the CPU usage gauge.
static size_t countDirectoryEntries(const std::filesystem::path &path)
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 long int getMemoryUsage()
std::shared_ptr< std::atomic_flag > _checkFlag
Runtime check flag.
ProcessMetrics(const ProcessMetrics &)=delete
Copy constructor.
static size_t getThreadCount()
static long int getPageFaults()
void threadRunner(const std::stop_token &stopToken) noexcept
static size_t getFileDescriptorCount()
prometheus::Gauge * _pDiskWrite
Pointer to the disk write gauge.
Structure to store the old CPU times.