summaryrefslogtreecommitdiffstats
path: root/logd
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2019-12-10 00:54:16 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2019-12-16 23:48:46 +0000
commitc2ea426c8d955ff40873db1e7d06c482ca662e75 (patch)
tree3f1ef7843ca4c984048a4d1cf7ef333b07d9ffb5 /logd
parent6a807615c7ee6364362a9a14d725165e948c5585 (diff)
Drop timestamp.h
Diffstat (limited to 'logd')
-rw-r--r--logd/src/logd/config_subscriber.cpp8
-rw-r--r--logd/src/logd/config_subscriber.h9
-rw-r--r--logd/src/logd/watcher.cpp45
3 files changed, 31 insertions, 31 deletions
diff --git a/logd/src/logd/config_subscriber.cpp b/logd/src/logd/config_subscriber.cpp
index 1e6c9a040d3..3a6af0c54e4 100644
--- a/logd/src/logd/config_subscriber.cpp
+++ b/logd/src/logd/config_subscriber.cpp
@@ -50,7 +50,7 @@ ConfigSubscriber::configure(std::unique_ptr<LogdConfig> cfg)
LOG(config, "bad rotate.size=%d must be positive", newconf.rotate.size);
}
if (newconf.rotate.age > 0) {
- _rotate_age = newconf.rotate.age;
+ _rotate_age = std::chrono::seconds(newconf.rotate.age);
} else {
LOG(config, "bad rotate.age=%d must be positive", newconf.rotate.age);
}
@@ -60,7 +60,7 @@ ConfigSubscriber::configure(std::unique_ptr<LogdConfig> cfg)
LOG(config, "bad remove.totalmegabytes=%d must be positive", newconf.remove.totalmegabytes);
}
if (newconf.remove.age > 0) {
- _remove_age = newconf.remove.age;
+ _remove_age = std::chrono::hours(newconf.remove.age * 24);
} else {
LOG(config, "bad remove.age=%d must be positive", newconf.remove.age);
}
@@ -90,9 +90,9 @@ ConfigSubscriber::ConfigSubscriber(const config::ConfigUri& configUri)
_state_port(0),
_forward_filter(),
_rotate_size(INT_MAX),
- _rotate_age(INT_MAX),
+ _rotate_age(vespalib::duration::max()),
_remove_meg(INT_MAX),
- _remove_age(3650),
+ _remove_age(std::chrono::hours(30*24)),
_use_logserver(true),
_subscriber(configUri.getContext()),
_handle(),
diff --git a/logd/src/logd/config_subscriber.h b/logd/src/logd/config_subscriber.h
index 507952319d6..fcda0ac1e11 100644
--- a/logd/src/logd/config_subscriber.h
+++ b/logd/src/logd/config_subscriber.h
@@ -5,6 +5,7 @@
#include <logd/config-logd.h>
#include <vespa/config/config.h>
#include <vespa/fnet/frt/supervisor.h>
+#include <vespa/vespalib/util/time.h>
namespace logdemon {
@@ -20,9 +21,9 @@ private:
int _state_port;
ForwardMap _forward_filter;
int _rotate_size;
- int _rotate_age;
+ vespalib::duration _rotate_age;
int _remove_meg;
- int _remove_age;
+ vespalib::duration _remove_age;
bool _use_logserver;
config::ConfigSubscriber _subscriber;
config::ConfigHandle<cloud::config::log::LogdConfig>::UP _handle;
@@ -39,9 +40,9 @@ public:
int getStatePort() const { return _state_port; }
int getRotateSize() const { return _rotate_size; }
- int getRotateAge() const { return _rotate_age; }
+ vespalib::duration getRotateAge() const { return _rotate_age; }
int getRemoveMegabytes() const { return _remove_meg; }
- int getRemoveAge() const { return _remove_age; }
+ vespalib::duration getRemoveAge() const { return _remove_age; }
bool need_new_forwarder() const { return _need_new_forwarder; }
std::unique_ptr<Forwarder> make_forwarder(Metrics& metrics);
diff --git a/logd/src/logd/watcher.cpp b/logd/src/logd/watcher.cpp
index 2bb8973f052..00cfb4def16 100644
--- a/logd/src/logd/watcher.cpp
+++ b/logd/src/logd/watcher.cpp
@@ -4,15 +4,15 @@
#include "exceptions.h"
#include "forwarder.h"
#include "watcher.h"
-#include <vespa/log/log.h>
#include <vespa/vespalib/util/sig_catch.h>
-#include <vespa/fastos/timestamp.h>
+#include <vespa/vespalib/util/time.h>
#include <fcntl.h>
#include <glob.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <unistd.h>
+#include <vespa/log/log.h>
LOG_SETUP("");
namespace logdemon {
@@ -164,7 +164,7 @@ Watcher::watchfile()
vespalib::SigCatch catcher;
int sleepcount = 0;
- time_t created = 0;
+ vespalib::system_time created = vespalib::system_time::min();
again:
// XXX should close and/or check _wfd first ?
@@ -175,7 +175,7 @@ Watcher::watchfile()
}
bool rotate = false;
- struct timeval rotStart;
+ vespalib::Timer rotTimer;
off_t offset = 0;
while (1) {
@@ -184,8 +184,8 @@ Watcher::watchfile()
LOG(error, "fstat(%s) failed: %s", filename, strerror(errno));
throw SomethingBad("fstat failed");
}
- if (created == 0) {
- created = sb.st_ctime;
+ if (created == vespalib::system_time::min()) {
+ created = vespalib::system_time(std::chrono::seconds(sb.st_ctime));
}
if (already.valid) {
if (sb.st_dev == already.st_dev &&
@@ -237,19 +237,19 @@ Watcher::watchfile()
already.st_dev = sb.st_dev;
already.st_ino = sb.st_ino;
- time_t now = fastos::time();
+ vespalib::system_time now = vespalib::system_clock::now();
bool wantrotate = (now > created + _confsubscriber.getRotateAge())
|| (sb.st_size > _confsubscriber.getRotateSize());
if (rotate) {
- int rotTime = elapsed(rotStart);
- if (rotTime > 59 || (sb.st_size == offset && rotTime > 4)) {
+ vespalib::duration rotTime = rotTimer.elapsed();
+ if (rotTime > 59s || (sb.st_size == offset && rotTime > 4s)) {
removeOldLogs(filename);
if (sb.st_size != offset) {
- LOG(warning, "logfile rotation incomplete after %d s (dropping %" PRIu64 " bytes)",
- rotTime, static_cast<uint64_t>(sb.st_size - offset));
+ LOG(warning, "logfile rotation incomplete after %2.3f s (dropping %" PRIu64 " bytes)",
+ vespalib::to_s(rotTime), static_cast<uint64_t>(sb.st_size - offset));
} else {
- LOG(debug, "logfile rotation complete after %d s", rotTime);
+ LOG(debug, "logfile rotation complete after %2.3f s", vespalib::to_s(rotTime));
}
created = now;
rotate = false;
@@ -266,13 +266,14 @@ Watcher::watchfile()
goto again;
} else if (wantrotate) {
rotate = true;
- gettimeofday(&rotStart, 0);
- LOG(debug, "preparing to rotate logfile, old logfile size %d, age %d seconds",
- (int)offset, (int)(now-created));
+ rotTimer = vespalib::Timer();
+ LOG(debug, "preparing to rotate logfile, old logfile size %d, age %2.3f seconds",
+ (int)offset, vespalib::to_s(now-created));
char newfn[FILENAME_MAX];
int l = strlen(filename);
strcpy(newfn, filename);
- struct tm *nowtm = gmtime(&now);
+ time_t seconds = vespalib::to_s(now.time_since_epoch());
+ struct tm *nowtm = gmtime(&seconds);
if (strftime(newfn+l, FILENAME_MAX-l-1, "-%Y-%m-%d.%H-%M-%S", nowtm) < 10)
{
LOG(error, "could not strftime");
@@ -351,15 +352,13 @@ Watcher::removeOldLogs(const char *prefix)
continue;
}
if (S_ISREG(sb.st_mode)) {
- if (sb.st_mtime +
- _confsubscriber.getRemoveAge() * 86400 < fastos::time())
- {
- LOG(info, "removing %s, too old (%f days)", fname,
- (double)(fastos::time()-sb.st_mtime)/86400.0);
+ vespalib::system_time mtime = vespalib::system_time(std::chrono::seconds(sb.st_mtime));
+ vespalib::system_time now = vespalib::system_clock::now();
+ if ((mtime + _confsubscriber.getRemoveAge()) < now) {
+ LOG(info, "removing %s, too old (%f days)", fname, vespalib::to_s(now - mtime)/86400.0);
if (unlink(fname) != 0) {
- LOG(warning, "cannot remove %s: %s",
- fname, strerror(errno));
+ LOG(warning, "cannot remove %s: %s", fname, strerror(errno));
}
continue;
}