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{0, 0, 0, 0};
35
41 static size_t countDirectoryEntries(const std::string &path);
42
43 protected:
48 static long int getMemoryUsage();
49
54 static long int getPageFaults();
55
60 double getCpuUsage();
61
66 std::pair<size_t, size_t> getDiskIO();
67
72 static size_t getThreadCount();
73
78 static size_t getFileDescriptorCount();
79
83 void update();
84
88 void threadRunner() noexcept;
89
90 public:
96 ProcessMetrics(std::shared_ptr<std::atomic_flag> checkFlag, const std::shared_ptr<prometheus::Registry> &reg);
97
99 ProcessMetrics(const ProcessMetrics & /*unused*/) = delete;
100
102 ProcessMetrics(ProcessMetrics && /*unused*/) = delete;
103
105 ProcessMetrics &operator=(ProcessMetrics /*unused*/) = delete;
106
108 ProcessMetrics &operator=(ProcessMetrics && /*unused*/) = delete;
109
114};
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.