2015-08-11 06:18:00 +08: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-15 04:32:20 +08:00
|
|
|
|
2014-04-22 05:33:32 +08:00
|
|
|
#include <base/command_line.h>
|
2015-11-13 09:52:17 +08:00
|
|
|
#include <base/files/file_path.h>
|
2011-03-01 03:17:43 +08:00
|
|
|
#include <base/logging.h>
|
2015-11-13 09:52:17 +08:00
|
|
|
#include <base/time/time.h>
|
2015-10-14 00:23:34 +08:00
|
|
|
#include <brillo/flag_helper.h>
|
|
|
|
#include <brillo/syslog_logging.h>
|
2010-04-15 04:32:20 +08:00
|
|
|
|
2015-08-05 05:04:51 +08:00
|
|
|
#include "constants.h"
|
2015-12-09 09:46:00 +08:00
|
|
|
#include "uploader/metricsd_service_runner.h"
|
2015-11-13 09:52:17 +08:00
|
|
|
#include "uploader/upload_service.h"
|
2010-04-15 04:32:20 +08:00
|
|
|
|
|
|
|
int main(int argc, char** argv) {
|
2015-11-07 05:25:41 +08:00
|
|
|
DEFINE_bool(foreground, false, "Don't daemonize");
|
2014-10-07 06:15:30 +08:00
|
|
|
|
|
|
|
// Upload the metrics once and exit. (used for testing)
|
2015-11-19 05:46:33 +08:00
|
|
|
DEFINE_bool(uploader_test, false, "run the uploader once and exit");
|
2014-10-07 06:15:30 +08:00
|
|
|
|
|
|
|
// Upload Service flags.
|
2015-11-19 05:46:33 +08:00
|
|
|
DEFINE_int32(upload_interval_secs, 1800,
|
2015-12-16 04:33:01 +08: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-19 05:46:33 +08:00
|
|
|
DEFINE_string(server, metrics::kMetricsServer,
|
2015-12-16 04:33:01 +08:00
|
|
|
"Server to upload the metrics to.");
|
2015-11-26 05:49:12 +08: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 06:15:30 +08:00
|
|
|
|
2015-11-07 05:25:41 +08:00
|
|
|
DEFINE_bool(logtostderr, false, "Log to standard error");
|
|
|
|
DEFINE_bool(logtosyslog, false, "Log to syslog");
|
|
|
|
|
2015-11-13 09:52:17 +08:00
|
|
|
brillo::FlagHelper::Init(argc, argv, "Brillo metrics daemon.");
|
2014-04-22 05:33:32 +08:00
|
|
|
|
2015-11-19 05:46:33 +08:00
|
|
|
int logging_location =
|
|
|
|
(FLAGS_foreground ? brillo::kLogToStderr : brillo::kLogToSyslog);
|
2015-11-07 05:25:41 +08:00
|
|
|
if (FLAGS_logtosyslog)
|
|
|
|
logging_location = brillo::kLogToSyslog;
|
|
|
|
|
|
|
|
if (FLAGS_logtostderr)
|
|
|
|
logging_location = brillo::kLogToStderr;
|
|
|
|
|
2014-04-22 05:33:32 +08:00
|
|
|
// Also log to stderr when not running as daemon.
|
2015-11-07 05:25:41 +08: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-02 05:38:21 +08:00
|
|
|
|
2015-11-07 05:25:41 +08:00
|
|
|
if (!FLAGS_foreground && daemon(0, 0) != 0) {
|
2014-12-02 05:38:21 +08:00
|
|
|
return errno;
|
|
|
|
}
|
|
|
|
|
2015-11-19 05:46:33 +08:00
|
|
|
UploadService upload_service(
|
2015-11-26 05:49:12 +08:00
|
|
|
FLAGS_server, base::TimeDelta::FromSeconds(FLAGS_upload_interval_secs),
|
2015-12-16 04:33:01 +08:00
|
|
|
base::TimeDelta::FromSeconds(FLAGS_disk_persistence_interval_secs),
|
2015-11-26 05:49:12 +08:00
|
|
|
base::FilePath(FLAGS_private_directory),
|
2015-12-09 09:46:00 +08:00
|
|
|
base::FilePath(FLAGS_shared_directory));
|
2014-06-26 05:38:07 +08:00
|
|
|
|
2015-12-09 09:46:00 +08:00
|
|
|
return upload_service.Run();
|
2010-04-15 04:32:20 +08:00
|
|
|
}
|