【问题标题】:How to notify/alert when the SSH/RDP service is not running in GCE VM当 SSH/RDP 服务未在 GCE VM 中运行时如何通知/警报
【发布时间】:2021-04-23 09:39:03
【问题描述】:

GCP Operation 的套件没有预先构建的指标来监控 GCE VM 中运行的 SSH (Linux) / RDP (Windows) 服务。我也尝试在 GCP Logging 中找到它,但找不到有关在操作系统中运行的服务的任何日志。

还有其他方法可以监控 GCE 虚拟机中 SSH/RDP 服务的运行状况吗?并在未处于运行状态时转发警报。

【问题讨论】:

  • 您可以根据doc为您的用例创建自定义指标
  • @Mahboob 您能否提供更多详细信息,例如任何示例自定义指标
  • this github 帮助您创建自定义指标

标签: google-cloud-platform ssh google-compute-engine stackdriver


【解决方案1】:

我更新了我的答案:

您可以使用 Cloud Logging 监控 SSH 守护程序的状态以及与您的 VM 实例上的连接:

  1. 安装logging agent,它将日志发送到 Cloud Logging(以前称为 Stackdriver):
curl -sSO https://dl.google.com/cloudagents/add-logging-agent-repo.sh
sudo bash add-logging-agent-repo.sh
sudo apt-get update
sudo apt-get install google-fluentd
sudo apt-get install -y google-fluentd-catch-all-config
  1. edit logging agent configuration 位于/etc/google-fluentd/config.d/syslog.conf 收集来自auth.log 的条目,添加:
<source>
  type tail
 
  # Parse the timestamp, but still collect the entire line as 'message'
  format /^(?<message>(?<time>[^ ]*\s*[^ ]* [^ ]*) .*)$/
 
  path /var/log/auth.log
  pos_file /var/lib/google-fluentd/pos/auth.log.pos
  read_from_head false
  tag auth
</source>
  1. 重启google-fluentd以应用更新的配置:
sudo service google-fluentd restart
  1. 转到Cloud Console -> Logging -> Logs Explorer 并查找与 SSH 守护进程相关的事件:

  1. configure alerts;此外,请查看第 3 方示例herehere

您可以使用相同的方法在 Windows 上检查和监控 RDP:

  1. 安装logging agent

  2. edit logging agent configuration 位于C:\Program Files (x86)\Stackdriver\LoggingAgent\fluent.conf

  3. 重启日志代理

  4. 转到Cloud Console -> Logging -> Logs Explorer 并查找与 RDP 服务相关的事件。

  5. configure alerts

编辑

为了使事件不会自动关闭,您可以创建两个指标:
第一个记录终止信号,第二个记录 SSH 启动。
然后,您应该创建一个警报,当第一个高于零且第二个低于 1 时触发。
这样,事件会一直持续到 sshd 再次启动。

【讨论】:

  • 您在回答中的哪个位置显示“如何监控服务是否正在运行”?您的答案仅显示服务的输出,而不是服务状态。
  • @sergiusz ,我创建了一个基于日志的指标,以便在有日志时触发警报 - 云日志中的“停止的 openssh 守护程序”。为了模拟这种行为,停止 SSH 服务并收到警报通知,但随着图表恢复正常值,它会自动解决。但是在 SSH 服务再次启动/运行状态之前不应解决警报。我们如何监控服务状态?
  • @Deena Dhayal您是否通过更新的答案解决了您的问题?
  • @SerhiiRohoza No
  • @Sergiusz Rusiecki,我创建了具有两个条件的警报策略,它应该在满足任何条件时触发。但它会触发警报并自动解决,甚至无需启动 ssh 服务。条件 1 - 违反时:任何 logging.googleapis.com/user/ssh-stop 流高于阈值 0 条件 2 - 违反时:任何 logging.googleapis.com/user/ssh-start 流低于阈值 1
猜你喜欢
  • 1970-01-01
  • 2019-05-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多