最小的监视工具
minitor的Python项目详细描述
小型车
最小的监控系统
它是做什么的?
minitor接受一个yaml配置文件,其中包含一组要运行的命令和一组要在这些命令失败时执行的警报。它的设计尽可能简单,并依赖于其他命令行工具来执行检查和发出警报。
但为什么呢?
我正在运行一些小型服务,发现sensu、consul、nagios等对我的用例来说都太复杂了。
那我该怎么用呢?
运行
使用以下命令安装和执行:
pip install minitor
minitor
如果是本地开发,您可以使用:
make run
它将读取config.yml
的内容并开始循环。您还可以直接运行它,并通过--config
参数提供一个新的配置文件。
码头工人
您可以直接从Docker中提取此存储库:
docker pull iamthefij/minitor
Docker映像使用从sample-config.yml
复制的默认config.yml
。这对你没有任何帮助,所以当你运行docker映像时,你应该提供你自己的config.yml
文件:
docker run -v $PWD/config.yml:/app/config.yml iamthefij/minitor
配置
在这个repo中,您可以以sample-config.yml
文件为例进行探索,但一般结构如下。应该注意的是,环境变量插值是在加载yaml文件时发生的。
全局配置是:
key | value |
---|---|
^{ | Maximum frequency to run checks for each monitor |
^{ | List of all monitors. Detailed description below |
^{ | List of all alerts. Detailed description below |
监视器
所有监视器都应列在monitors
下。
每个监视器允许以下配置:
key | value |
---|---|
^{ | Name of the monitor running. This will show up in messages and logs. |
^{ | Specifies the command that should be executed, either in exec or shell form. This command's exit value will determine whether the check is successful |
^{ | A list of Alerts to be triggered when the monitor is in a "down" state |
^{ | A list of Alerts to be triggered when the monitor moves to an "up" state |
^{ | The interval at which this monitor should be checked. This must be greater than the global ^{ |
^{ | Allows specifying the number of failed checks before an alert should be triggered |
^{ | Allows specifying how often an alert should be retriggered. There are a few magic numbers here. Defaults to ^{ |
警报
警报作为在{{CD11}}下键入的对象存在。他们的钥匙应该是警报的名字。这在alert_down
和alert_up
中的监视器设置中使用。
每个警报允许以下配置:
key | value |
---|---|
^{ | Specifies the command that should be executed, either in exec or shell form. This is the command that will be run when the alert is executed. This can be templated with environment variables or the variables shown in the table below |
此外,在执行警报时,它们将通过python的format函数传递,该函数带有监控器某些属性的参数。可以使用python格式语法引用以下特定于监视器的变量:
token | value |
---|---|
^{ | Number of times this monitor has alerted |
^{ | The exception message that was raised |
^{ | The total number of sequential failed checks for this monitor |
^{ | The last returned value from the check command to either stderr or stdout |
^{ | The ISO datetime of the last successful check |
^{ | The name of the monitor that failed and triggered the alert |
指标
从v0.3.0开始,minitor支持导出Prometheus的度量。普罗米修斯是一个开源工具,用于从不同来源读取和查询度量。结合另一个工具Grafana,它允许构建图表和仪表板。您也可以选择只使用minitor来记录检查结果,而不是使用grafana进行警报。
也可以使用metrics端点来监视minitor本身!这允许在不同的服务器上设置多个minitor实例,并让它们相互监视,以便您可以检测到minitor中断。
要使用度量运行minitor,请使用--metrics
(或-m
)标志。默认情况下,度量值将在端口8080
上提供,但可以使用--metrics-port
(或-p
)覆盖它
minitor --metrics
# or
minitor --metrics --metrics-port 3000
贡献
无论您是想提交修补程序还是告诉我我弄坏了什么,都可以通过github镜像进行贡献,我可以将prs合并回源存储库。
一级回购:https://git.iamthefij.com/iamthefij/minitor.git
Github镜像:https://github.com/IamTheFij/minitor.git