/[projects]/smsdaemon/plugins/HostStatusPlugin.cpp
ViewVC logotype

Annotation of /smsdaemon/plugins/HostStatusPlugin.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 185 - (hide annotations) (download)
Mon Dec 15 09:10:05 2008 UTC (15 years, 5 months ago) by torben
File size: 1132 byte(s)
Util, a new str_split which operates on whitespace

Make HostStatusPlugin return system memory usage


1 torben 137 #include "HostStatusPlugin.h"
2 torben 149 #include "ISmsTransceiver.h"
3 torben 137 #include "Sms.h"
4 torben 158 #include "Util.h"
5 torben 137
6 torben 185 #include <vector>
7     #include <sstream>
8     #include <iostream>
9 torben 137
10     using namespace std;
11    
12     HostStatusPlugin::HostStatusPlugin()
13     : Plugin("hoststatus", "returns an sms with host server status")
14     {
15     }
16    
17 torben 185 string ParseMemory(string mem)
18     {
19     stringstream out;
20    
21     vector<string> lines = Util::str_split(mem,"\n");
22     vector<string> line2 = Util::str_split( lines[1] );
23     vector<string> line3 = Util::str_split( lines[2] );
24    
25     out << "Mem." << endl;
26     out << "Applications: " << line3[2] << "mb\n" ;
27     out << "Buffers: " << line2[5] << "mb\n" ;
28     out << "Cache: " << line2[6] << "mb\n";
29     out << "Free: " << line2[3] << "mb\n\n";
30    
31     return out.str();
32     }
33    
34 torben 149 void HostStatusPlugin::Execute(ISmsTransceiver& modem, SMS& sms)
35 torben 137 {
36     string message;
37     string out;
38    
39 torben 138 Util::my_system("hostname", &out);
40     message += out;
41    
42 torben 137 Util::my_system("uptime", &out);
43     message += out;
44    
45 torben 185 Util::my_system("free -m",&out);
46     message += ParseMemory(out);
47    
48 torben 137 Util::my_system("df -h | grep dev | awk '{ print $6 \" \" $5}'", &out);
49     message += out;
50    
51 torben 142 modem.SendSms(sms.GetSender(), message, true);
52 torben 137
53     }

  ViewVC Help
Powered by ViewVC 1.1.20