2015-08-11 00:18:00 +02:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2015 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
2010-04-14 22:32:20 +02:00
|
|
|
|
2014-04-21 23:33:32 +02:00
|
|
|
#include <base/command_line.h>
|
2015-11-13 02:52:17 +01:00
|
|
|
#include <base/files/file_path.h>
|
2011-02-28 20:17:43 +01:00
|
|
|
#include <base/logging.h>
|
2015-11-13 02:52:17 +01:00
|
|
|
#include <base/time/time.h>
|
2015-10-13 18:23:34 +02:00
|
|
|
#include <brillo/flag_helper.h>
|
|
|
|
#include <brillo/syslog_logging.h>
|
2010-04-14 22:32:20 +02:00
|
|
|
|
2015-08-04 23:04:51 +02:00
|
|
|
#include "constants.h"
|
2015-12-09 02:46:00 +01:00
|
|
|
#include "uploader/metricsd_service_runner.h"
|
2015-11-13 02:52:17 +01:00
|
|
|
#include "uploader/upload_service.h"
|
2010-04-14 22:32:20 +02:00
|
|
|
|
|
|
|
int main(int argc, char** argv) {
|
2015-11-06 22:25:41 +01:00
|
|
|
DEFINE_bool(foreground, false, "Don't daemonize");
|
2014-10-07 00:15:30 +02:00
|
|
|
|
|
|
|
// Upload the metrics once and exit. (used for testing)
|
2015-11-18 22:46:33 +01:00
|
|
|
DEFINE_bool(uploader_test, false, "run the uploader once and exit");
|
2014-10-07 00:15:30 +02:00
|
|
|
|
|
|
|
// Upload Service flags.
|
2015-11-18 22:46:33 +01:00
|
|
|
DEFINE_int32(upload_interval_secs, 1800,
|
2015-12-15 21:33:01 +01:00
|
|
|
"Interval at which metricsd uploads the metrics.");
|
|
|
|
DEFINE_int32(disk_persistence_interval_secs, 300,
|
|
|
|
"Interval at which metricsd saves the aggregated metrics to "
|
|
|
|
"disk to avoid losing them if metricsd stops in between "
|
|
|
|
"two uploads.");
|
2015-11-18 22:46:33 +01:00
|
|
|
DEFINE_string(server, metrics::kMetricsServer,
|
2015-12-15 21:33:01 +01:00
|
|
|
"Server to upload the metrics to.");
|
2015-11-25 22:49:12 +01:00
|
|
|
DEFINE_string(private_directory, metrics::kMetricsdDirectory,
|
|
|
|
"Path to the private directory used by metricsd "
|
|
|
|
"(testing only)");
|
|
|
|
DEFINE_string(shared_directory, metrics::kSharedMetricsDirectory,
|
|
|
|
"Path to the shared metrics directory, used by "
|
|
|
|
"metrics_collector, metricsd and all metrics clients "
|
|
|
|
"(testing only)");
|
2014-10-07 00:15:30 +02:00
|
|
|
|
2015-11-06 22:25:41 +01:00
|
|
|
DEFINE_bool(logtostderr, false, "Log to standard error");
|
|
|
|
DEFINE_bool(logtosyslog, false, "Log to syslog");
|
|
|
|
|
2015-11-13 02:52:17 +01:00
|
|
|
brillo::FlagHelper::Init(argc, argv, "Brillo metrics daemon.");
|
2014-04-21 23:33:32 +02:00
|
|
|
|
2015-11-18 22:46:33 +01:00
|
|
|
int logging_location =
|
|
|
|
(FLAGS_foreground ? brillo::kLogToStderr : brillo::kLogToSyslog);
|
2015-11-06 22:25:41 +01:00
|
|
|
if (FLAGS_logtosyslog)
|
|
|
|
logging_location = brillo::kLogToSyslog;
|
|
|
|
|
|
|
|
if (FLAGS_logtostderr)
|
|
|
|
logging_location = brillo::kLogToStderr;
|
|
|
|
|
2014-04-21 23:33:32 +02:00
|
|
|
// Also log to stderr when not running as daemon.
|
2015-11-06 22:25:41 +01:00
|
|
|
brillo::InitLog(logging_location | brillo::kLogHeader);
|
|
|
|
|
|
|
|
if (FLAGS_logtostderr && FLAGS_logtosyslog) {
|
|
|
|
LOG(ERROR) << "only one of --logtosyslog and --logtostderr can be set";
|
|
|
|
return 1;
|
|
|
|
}
|
2014-12-01 22:38:21 +01:00
|
|
|
|
2015-11-06 22:25:41 +01:00
|
|
|
if (!FLAGS_foreground && daemon(0, 0) != 0) {
|
2014-12-01 22:38:21 +01:00
|
|
|
return errno;
|
|
|
|
}
|
|
|
|
|
2015-11-18 22:46:33 +01:00
|
|
|
UploadService upload_service(
|
2015-11-25 22:49:12 +01:00
|
|
|
FLAGS_server, base::TimeDelta::FromSeconds(FLAGS_upload_interval_secs),
|
2015-12-15 21:33:01 +01:00
|
|
|
base::TimeDelta::FromSeconds(FLAGS_disk_persistence_interval_secs),
|
2015-11-25 22:49:12 +01:00
|
|
|
base::FilePath(FLAGS_private_directory),
|
2015-12-09 02:46:00 +01:00
|
|
|
base::FilePath(FLAGS_shared_directory));
|
2014-06-25 23:38:07 +02:00
|
|
|
|
2015-12-09 02:46:00 +01:00
|
|
|
return upload_service.Run();
|
2010-04-14 22:32:20 +02:00
|
|
|
}
|