Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support host monitor #1890

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Conversation

Abingcbc
Copy link
Collaborator

  1. 打通进程元信息采集链路

TODO:

  1. 支持更多字段
  2. 可观测指标

@Abingcbc Abingcbc force-pushed the host_monitor branch 6 times, most recently from 6150e52 to bfdd9c2 Compare November 19, 2024 06:27
core/common/timer/HostMonitorTimerEvent.cpp Outdated Show resolved Hide resolved
core/models/PipelineEventGroup.h Outdated Show resolved Hide resolved
core/runner/sink/http/HttpSink.cpp Show resolved Hide resolved
core/host_monitor/collector/MockCollector.cpp Outdated Show resolved Hide resolved
core/host_monitor/collector/CollectorManager.cpp Outdated Show resolved Hide resolved
const std::string ProcessorHostMetaNative::sName = "processor_host_meta_native";

bool ProcessorHostMetaNative::Init(const Json::Value& config) {
auto hostType = ToString(getenv(DEFAULT_ENV_KEY_HOST_TYPE.c_str()));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个机制也不合理。应该有个全局的管理中心,各业务方直接读值即可。这个事情日会上提下,讨论下。

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

新pr的实现也是每次再全新获取,跟之前提到的实现也不符合。

core/constants/EntityConstants.cpp Show resolved Hide resolved
core/host_monitor/SystemInformationTools.cpp Show resolved Hide resolved
core/common/FileSystemUtil.h Outdated Show resolved Hide resolved
core/common/StringTools.cpp Outdated Show resolved Hide resolved
core/common/timer/HostMonitorTimerEvent.cpp Outdated Show resolved Hide resolved
core/plugin/input/InputHostMeta.h Outdated Show resolved Hide resolved
core/plugin/input/InputHostMeta.h Outdated Show resolved Hide resolved
core/plugin/input/InputHostMeta.cpp Outdated Show resolved Hide resolved
core/plugin/input/InputHostMeta.cpp Show resolved Hide resolved
core/host_monitor/HostMonitorInputRunner.cpp Outdated Show resolved Hide resolved
core/host_monitor/HostMonitorInputRunner.cpp Outdated Show resolved Hide resolved
core/host_monitor/HostMonitorInputRunner.cpp Outdated Show resolved Hide resolved
Timer& operator=(const Timer&) = delete;
Timer& operator=(Timer&&) = delete;
~Timer() = default;
static Timer* GetInstance() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

改成单例,之前prometheus等使用的地方没有问题?

const std::string ProcessorHostMetaNative::sName = "processor_host_meta_native";

bool ProcessorHostMetaNative::Init(const Json::Value& config) {
auto hostType = ToString(getenv(DEFAULT_ENV_KEY_HOST_TYPE.c_str()));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

新pr的实现也是每次再全新获取,跟之前提到的实现也不符合。

core/runner/sink/http/HttpSink.cpp Show resolved Hide resolved
targetEvent->SetContent("binary", sourceEvent.GetContent(DEFAULT_CONTENT_KEY_PROCESS_BINARY));
targetEvent->SetContent("arguments", sourceEvent.GetContent(DEFAULT_CONTENT_KEY_PROCESS_ARGUMENTS));
targetEvent->SetContent("language", sourceEvent.GetContent(DEFAULT_CONTENT_KEY_PROCESS_LANGUAGE));
targetEvent->SetContent("containerID", sourceEvent.GetContent(DEFAULT_CONTENT_KEY_PROCESS_CONTAINER_ID));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

需要统一到constans里字段。需要避免同一场景一会下划线,一会大小写的问题。

class ProcessCollector : public BaseCollector {
public:
ProcessCollector() : mProcessSilentCount(INT32_FLAG(process_collect_silent_count)) {
mName = "process";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

多处使用的字符串,避免直接使用字符串

}
}

void ProcessCollector::SortProcessByCpu(std::vector<ProcessStatPtr>& processStats, size_t topN) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里面实现并不只是sort还有获取,函数名不匹配


int readCount = 0;
WalkAllProcess(PROCESS_DIR, [&](const std::string& dirName) {
if (++readCount > mProcessSilentCount) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里要看下进程超多时,对timer框架的影响
1、是否影响其他场景
2、单次执行时间大于调度时间的策略


namespace logtail {

const std::string ProcessorHostMetaNative::sName = "processor_host_meta_native";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inner processor存在的必要性是什么?为什么不能collect时直接补充字段

const auto now = steady_clock::now();

// TODO: more accurate cache
auto prev = GetPreProcessStat(pid);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image
mPrevProcessStat 使用场景很局部,都是内部使用,保持统一。


int readCount = 0;
WalkAllProcess(PROCESS_DIR, [&](const std::string& dirName) {
if (++readCount > mProcessSilentCount) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

个数控制是不是也在控制缓存里的?不应该只是控制去直接操作系统交互的吗

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants