-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDNSPing.cpp
More file actions
64 lines (52 loc) · 1.91 KB
/
Copy pathDNSPing.cpp
File metadata and controls
64 lines (52 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <vector>
#include "Database.hpp"
#include "DNSPing.hpp"
#include "Logger.hpp"
using std::string;
using std::vector;
using namespace te;
using namespace mysqlpp;
DNSPing::DNSPing(const Domain &domain):
domain(domain)
{
}
void DNSPing::update(struct timeval &rtime, unsigned qtime)
{
unsigned long sec = rtime.tv_sec;
debug("Adding timestamp '%lu' for '%s' ", sec, domain.getName().c_str());
char buff[500] = {0};
snprintf(buff, 500, "INSERT INTO pings values (%d, %lu, %u);", domain.getId(), sec, qtime);
vector<Row> results;
Database::getInstance()->runQuery(buff, results);
}
string getTimeString(const time_t &timeT)
{
struct tm *timeTm = localtime(&timeT);
char tmbuf[64];
strftime(tmbuf, sizeof tmbuf, "%Y-%m-%d %H:%M:%S", timeTm);
return string(tmbuf);
}
void DNSPing::printSummary() const
{
string queryStr ("SELECT d.id, d.name, MIN(p.request), MAX(p.request), AVG(p.timetaken), STDDEV(p.timetaken), COUNT(d.id) FROM \
pings AS p,domains AS d WHERE p.id = d.id AND d.name='");
queryStr += domain.getName().c_str();
queryStr += "' GROUP BY p.id";
report("\n\n\t\t|------- Summary for '%s' --------|", domain.getName().c_str());
vector<Row> results;
if(! Database::getInstance()->runQuery(queryStr, results))
{
report ("\t\t No data available !");
}
else
{
string startTime = getTimeString(results[0][2]);
string endTime = getTimeString(results[0][3]);
report ("\t\t First request time :%s", startTime.c_str());
report ("\t\t Last request time :%s", endTime.c_str());
report ("\t\t Average response time :%.3f microseconds", (double)results[0][4]);
report ("\t\t Standard deviation of response time :%.3f microseconds", (double)results[0][5]);
report ("\t\t Number of requests made :%d", (int)results[0][6]);
}
report("\t\t|---------------------|");
}