This repository has been archived by the owner on May 28, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
taotaowill
committed
Jan 5, 2017
1 parent
03cbc71
commit b709442
Showing
26 changed files
with
694 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,6 +75,7 @@ int main(int argc, char* argv[]) | |
while (!s_quit) { | ||
sleep(1); | ||
} | ||
_exit(0); | ||
|
||
return 0; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
// Copyright (c) 2016, Baidu.com, Inc. All Rights Reserved | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
#include "galaxy_memory_subsystem.h" | ||
#include "agent/util/path_tree.h" | ||
#include "protocol/galaxy.pb.h" | ||
#include "protocol/agent.pb.h" | ||
#include "util/input_stream_file.h" | ||
|
||
#include <boost/filesystem/path.hpp> | ||
#include <boost/filesystem/operations.hpp> | ||
#include <iostream> | ||
|
||
namespace baidu { | ||
namespace galaxy { | ||
namespace cgroup { | ||
|
||
GalaxyMemorySubsystem::GalaxyMemorySubsystem() { | ||
} | ||
|
||
GalaxyMemorySubsystem::~GalaxyMemorySubsystem() { | ||
} | ||
|
||
std::string GalaxyMemorySubsystem::Name() { | ||
return "memory"; | ||
} | ||
|
||
|
||
baidu::galaxy::util::ErrorCode GalaxyMemorySubsystem::Collect(boost::shared_ptr<baidu::galaxy::proto::CgroupMetrix> metrix) { | ||
assert(NULL != metrix.get()); | ||
boost::filesystem::path path(Path()); | ||
path.append("memory.usage_in_bytes"); | ||
baidu::galaxy::file::InputStreamFile in(path.string()); | ||
|
||
if (!in.IsOpen()) { | ||
baidu::galaxy::util::ErrorCode ec = in.GetLastError(); | ||
return ERRORCODE(-1, "open file(%s) failed: %s", | ||
path.string().c_str(), | ||
ec.Message().c_str()); | ||
} | ||
|
||
std::string data; | ||
baidu::galaxy::util::ErrorCode ec = in.ReadLine(data); | ||
|
||
if (ec.Code() != 0) { | ||
return ERRORCODE(-1, "read failed: %s", ec.Message().c_str()); | ||
} | ||
|
||
metrix->set_memory_used_in_byte(::atol(data.c_str())); | ||
return ERRORCODE_OK; | ||
} | ||
|
||
baidu::galaxy::util::ErrorCode GalaxyMemorySubsystem::Construct() { | ||
assert(!this->container_id_.empty()); | ||
assert(NULL != this->cgroup_.get()); | ||
std::string path = this->Path(); | ||
boost::system::error_code ec; | ||
|
||
if (!boost::filesystem::exists(path, ec) | ||
&& !baidu::galaxy::file::create_directories(path, ec)) { | ||
return ERRORCODE(-1, "failed in creating file %s: %s", | ||
path.c_str(), | ||
ec.message().c_str()); | ||
} | ||
|
||
boost::filesystem::path memory_limit_path = path; | ||
memory_limit_path.append("memory.limit_in_bytes"); | ||
baidu::galaxy::util::ErrorCode err; | ||
err = baidu::galaxy::cgroup::Attach(memory_limit_path.c_str(), | ||
-1, false); | ||
|
||
if (0 != err.Code()) { | ||
return ERRORCODE(-1, | ||
"attch memory.limit_in_bytes failed: %s", | ||
err.Message().c_str()); | ||
} | ||
|
||
boost::filesystem::path kill_mode_path = path; | ||
kill_mode_path.append("memory.kill_mode"); | ||
err = baidu::galaxy::cgroup::Attach(kill_mode_path.c_str(), | ||
0L, | ||
false); | ||
|
||
if (0 != err.Code()) { | ||
return ERRORCODE(-1, | ||
"attch memory.kill_mode failed: %s", | ||
err.Message().c_str()); | ||
} | ||
|
||
return ERRORCODE_OK; | ||
} | ||
|
||
boost::shared_ptr<Subsystem> GalaxyMemorySubsystem::Clone() { | ||
boost::shared_ptr<Subsystem> ret(new GalaxyMemorySubsystem()); | ||
return ret; | ||
} | ||
|
||
|
||
} //namespace cgroup | ||
} //namespace galaxy | ||
} //namespace baidu |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Copyright (c) 2016, Baidu.com, Inc. All Rights Reserved | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
#pragma once | ||
|
||
#include "subsystem.h" | ||
#include <boost/shared_ptr.hpp> | ||
|
||
namespace baidu { | ||
namespace galaxy { | ||
namespace cgroup { | ||
|
||
class GalaxyMemorySubsystem : public Subsystem { | ||
public: | ||
GalaxyMemorySubsystem(); | ||
~GalaxyMemorySubsystem(); | ||
|
||
boost::shared_ptr<Subsystem> Clone(); | ||
std::string Name(); | ||
baidu::galaxy::util::ErrorCode Construct(); | ||
baidu::galaxy::util::ErrorCode Collect(boost::shared_ptr<baidu::galaxy::proto::CgroupMetrix> metrix); | ||
}; | ||
|
||
} //namespace cgroup | ||
} //namespace galaxy | ||
} //namespace baidu |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.