29 _kernel = QSysInfo::kernelType().toLower();
39 if (system(
"which sar > /dev/null 2>&1"))
40 VFS::WARN(
"For linux, the 'sar' command is used for cpuUsage. This command is missing on this system.", 0,
"cpuusage");
42 if (system(
"which bc > /dev/null 2>&1"))
43 VFS::WARN(
"For linux, the 'bc' command is used for cpuUsage. This command is missing on this system.", 0,
"cpuusage");
85 return "data:image/svg+xml;utf8,<svg class=\"menuIcon\" xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 32 32\"><g id=\"vfs\"><path d=\"M3,25.95a1,1,0,0,1-.55-1.84l6.16-4A1,1,0,0,1,9.48,20l5.38,2.11,2.51-9.21A1,1,0,0,1,19,12.47l6.29,6.15L28.68,4.87a1,1,0,1,1,1.94.47L26.85,20.8a1,1,0,0,1-1.67.48l-6.33-6.19L16.5,23.73a1,1,0,0,1-.52.63,1,1,0,0,1-.81,0L9.23,22.07,3.51,25.79A1,1,0,0,1,3,25.95Z\"/><circle fill=\"rgb(27,186,217)\" class=\"iconColor\" cx=\"18.38\" cy=\"13.71\" r=\"1.66\" transform=\"translate(-4.31 17.01) rotate(-45)\"/><circle fill=\"rgb(27,186,217)\" class=\"iconColor\" cx=\"29.65\" cy=\"5.11\" r=\"1.66\" transform=\"translate(5.08 22.46) rotate(-45)\"/><circle fill=\"rgb(27,186,217)\" class=\"iconColor\" cx=\"25.96\" cy=\"20.23\" r=\"1.66\" transform=\"translate(-6.7 24.29) rotate(-45)\"/><circle fill=\"rgb(27,186,217)\" class=\"iconColor\" cx=\"15.78\" cy=\"23.52\" r=\"1.66\" transform=\"translate(-12.01 18.05) rotate(-45)\"/><circle fill=\"rgb(27,186,217)\" class=\"iconColor\" cx=\"2.6\" cy=\"24.95\" r=\"1.66\" transform=\"translate(-16.88 9.14) rotate(-45)\"/><circle fill=\"rgb(27,186,217)\" class=\"iconColor\" cx=\"9.09\" cy=\"21.3\" r=\"1.66\" transform=\"translate(-12.4 12.67) rotate(-45)\"/></g></svg>";
92 a[
"type"] =
"openLayout";
104 r->
_metadata[
"type"] =
"cpuUsage:cpuGraph.js";
128 r->
_data.setObject(d);
143 if (libname ==
"cpuGraph.js")
146 if (libname ==
"cpuGraph.css")
163 QDateTime now = QDateTime::currentDateTime();
164 qint64 t = now.toMSecsSinceEpoch();
196 _cpuSamples << QPair<quint64,double> (t,p);
216 _ramSamples << QPair<quint64,double> (t,p);
237 _reqSamples << QPair<quint64,quint32> (t,s);
239 _req_diff[QString::number(t)] = (qint64) (s+r);
272 QString command =
"";
279 if (which ==
"cpuusage")
281 command =
"sar -u 1 1 | grep verage | perl -pe \"s/\\s+/+/g\" | cut -f 3,5 -d '+' | bc -l";
285 if (which ==
"ramusage")
287 command =
"free -b | grep Mem | perl -pe \"s/\\s+/ /g\" | cut -f 2,4 -d \" \" | perl -pe \"s/\\s+/ \\/ /\" | perl -pe \"s/(.*)/scale=20; 1-1\\/(\\1)/\" | bc -l";
292 if (which ==
"cpuusage")
294 command =
"ps -A -o %cpu | awk '{s+=$1} END {print s}'";
297 if (which ==
"ramusage")
303 command =
"memory_pressure | grep percentage | perl -pe \"s/([^\\d]*)(\\d+)([^\\d]*)/scale=20; \\2 \\/ 100\\n/\" | bc -l";
307 if (!command.isEmpty())
310 process.start(
"bash", QStringList() <<
"-c" << command);
311 process.waitForFinished(5000);
313 QString stdout = process.readAllStandardOutput();
314 QString stderr = process.readAllStandardError();
322 VFS::ERROR( QString(
"Unsupported OS or selector: %1 %2. Can't return command.").arg(
_kernel).arg(which) );
A common base class for all things that want to act like an application or include ACL support.
virtual VFS_request * createRequest(VFS_request::requestType type, QString path, QString user="unknown", QJsonDocument data=QJsonDocument(), QJsonObject metadata=QJsonObject(), bool dontDelete=false)
Create a new VFS_request with this object as _origin.
static QString code(QString nodename, QString libname, QString &error)
Fetch code or any other resource from a node.
void diff(VFS_node *origin, VFS_request *t)
Emit a diff, which will trigger notifySubscribers() for a mounted node.
The base class for all requests between nodes.
static quint32 getSample()
Get the current sample count and clear the counter.
bool _success
if the request was successfully completed
QJsonDocument _data
the request payload
static long _refcount
A reference counter for VFS_request instances, used for debugging to ensure all instances are properl...
QJsonObject _metadata
the request payload
static void ERROR(QString message, int level=0, QString user="server")
Send a message to the VFS::_errors VFS_stream.
static QString uptimeString(bool ms=true)
Get the uptime of this VFS instance as a string.
static void WARN(QString message, int level=0, QString user="server")
Send a message to the VFS::_warnings VFS_stream.
QJsonObject _cpu_diff
The CPU diff.
int _processors
The number of processors available on this machine.
virtual QByteArray icon()
Return the icon.
void getRAMSample(quint64 t)
Get a RAM sample.
QList< QPair< quint64, double > > _ramSamples
The RAM samples recorded.
virtual void metadata(VFS_request *r)
Fetch the metadata of this node.
virtual void initialize()
Start the sample timer.
QJsonObject _req_diff
The VFS_request sample diff.
float _scale
The amount to scale processor values.
void getREQSample(quint64 t)
Take a sample of the current VFS_request::_refcount.
static QString code(QString nodename, QString libname, QString &error)
Fetch code from this node.
QString runCommand(QString which)
Execute a shell command to gather sample data.
QList< QPair< quint64, quint16 > > _reqSamples
The VFS_request count sample recorded.
bool isContainer()
This is always false.
virtual void read(VFS_request *r)
Return the data contents of this node, or if it's a container call ls()
Q_INVOKABLE cpuUsage()
The cpuUsage constructor.
QString _kernel
The kernel string reported by Qt.
QList< QPair< quint64, double > > _cpuSamples
The CPU samples recorded.
void timerEvent(QTimerEvent *event)
Gather the CPU and RAM samples.
void getCPUSample(quint64 t)
Get a CPU sample.
QJsonObject _ram_diff
The RAM diff.
QJsonObject jsonResource(QString resource, bool *ok=nullptr)
Fetch the contents of a Qt resource as a QJsonObject.
QByteArray resourceContents(QString resource, bool *ok=nullptr, bool squashHash=false)
Fetch the contents of a Qt resource file.