Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ set(EXAMPLES
examples/6-Increment.cxx
examples/7-InternalBenchamrk.cxx
examples/8-DbFiller.cxx
examples/9-ProcessMonitoring.cxx
examples/10-Buffering.cxx
)

Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,12 @@ This feature provides basic performance status of the process. Note that is runs
```cpp
enableProcessMonitoring([interval in seconds]);
```

As an alternative, without a need of a new thread, user can manually trigger:
```
pushProcessMonitoringMetrics()
```

Following metrics are generated every time interval:
CPU measurements:
+ **cpuUsedPercentage** - percentage of a core usage (kernel + user mode) over time interval
Expand Down
17 changes: 17 additions & 0 deletions examples/9-ProcessMonitoring.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
///
/// \file 9-ProcessMonitoring.cxx
/// \author Adam Wegrzynek <adam.wegrzynek@cern.ch>
///

#include "Monitoring/MonitoringFactory.h"

using namespace o2::monitoring;

int main()
{
auto monitoring = MonitoringFactory::Get("influxdb-stdout://");
for (int i = 0; i < 5; i++) {
monitoring->pushProcessMonitoringMetrics();
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
}
}
6 changes: 2 additions & 4 deletions include/Monitoring/Monitoring.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,8 @@ class Monitoring
/// \param value tag value
void addGlobalTag(tags::Key key, tags::Value value);

/// Returns a metric which will be periodically sent to backends
/// \param name metric name
/// \return periodically send metric
//ComplexMetric& getAutoPushMetric(std::string name, unsigned int interval = 1);
/// Allows user to push process monitoring metrics without having separate thread
void pushProcessMonitoringMetrics();

private:
/// Sends multiple (not related to each other) metrics
Expand Down
5 changes: 1 addition & 4 deletions include/Monitoring/ProcessMonitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ class ProcessMonitor

static std::vector<std::string> getAvailableMetricsNames();
std::vector<Metric> getPerformanceMetrics();
std::vector<Metric> makeLastMeasurementAndGetMetrics();

public:
/// Prepares externam software commands (ps)
ProcessMonitor();

Expand All @@ -73,7 +73,6 @@ class ProcessMonitor
/// Retrievs total memory size from /proc/meminfo
void setTotalMemory();

private:
static constexpr const char* metricsNames[] = {"memoryUsagePercentage", "virtualMemorySize", "residentSetSize",
"cpuUsedPercentage", "involuntaryContextSwitches", "voluntaryContextSwitches", "cpuUsedAbsolute",
"averageResidentSetSize", "averageVirtualMemorySize", "averageCpuUsedPercentage",
Expand Down Expand Up @@ -108,8 +107,6 @@ class ProcessMonitor

/// Retrieves CPU usage (%) and number of context switches during the interval
std::vector<Metric> getCpuAndContexts();

std::vector<Metric> makeLastMeasurementAndGetMetrics();
};

} // namespace monitoring
Expand Down
5 changes: 5 additions & 0 deletions src/Monitoring.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,11 @@ void Monitoring::send(Metric&& metric, DerivedMetricMode mode)
transmit(std::move(metric));
}

void Monitoring::pushProcessMonitoringMetrics()
{
transmit(mProcessMonitor->getPerformanceMetrics());
}

inline bool Monitoring::matchVerbosity(Verbosity backend, Verbosity metric)
{
return (static_cast<std::underlying_type<Verbosity>::type>(backend) >= static_cast<std::underlying_type<Verbosity>::type>(metric));
Expand Down
3 changes: 1 addition & 2 deletions src/ProcessMonitor.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@ namespace monitoring
ProcessMonitor::ProcessMonitor()
{
mPid = static_cast<unsigned int>(::getpid());
mTimeLastRun = std::chrono::high_resolution_clock::now();
getrusage(RUSAGE_SELF, &mPreviousGetrUsage);
#ifdef O2_MONITORING_OS_LINUX
setTotalMemory();
#endif
init();
}

void ProcessMonitor::init()
Expand Down