Skip to main content
# 通用应用监控框架

@author Danny0

监控应用并将数据保存到influxdb中, 目前已经实现Redis/Mysql/Nginx监控。
[influxdb 官方安装文档](http://docs.influxdata.com/influxdb/v1.2/introduction/installation/)

# 安装

## 源码安装

```
git clone https://github.com/peablog/monflux
python setup.py install
```

## pip安装

```
pip install monflux
```

# 使用

## 基础配置

首先在代码中添加influxdb的连接配置:
```
influx_config = {
"host": "127.0.0.1",
"port": 8086,
"username": "",
"password": "",
"database": ""
}
```

## Redis监控
设置redis连接的配置信息:
```
redis_config = {
"host": "127.0.0.1",
"password": "",
"port":
}
```
引入监控类并实例化:
```
from monflux import RedisMonitor
RedisMonitor(influx_config, redis_config, "redis_load").start()
```
第三个参数是influxdb保存的measurement

注:需要安装python redis客户端库,可通过`pip install redis`安装

## Mysql监控

设置Mysql连接的配置信息:
```
mysql_config = {
"host": "127.0.0.1",
"username": "",
"password": "",
"port": 3306
}
```

引入监控类并实例化:
```
from monflux import MysqlMonitor
MysqlMonitor(influx_config, mysql_config, "mysql_load").start()
```
注:需要安装python mysql客户端库,可通过`pip install mysql-python`安装

## Nginx监控

设置Nginx的配置信息:
```
nginx_config = {
"url": "http://10.110.95.67/nginx_status",
}
```

引入监控类并实例化:
```
from monflux import NginxMonitor
NginxMonitor(influx_config, nginx_config, "nginx_load").start()
```

## 其他
您可以参考Redis或者Nginx的监控实现来写您自己的插件。
具体教程待补充。

# 数据展现

可通过Grafana来展示保存到influxdb中的监控数据。
mysql配置示例:
![](http://img.peablog.com/2017-06-13-14973476197412.jpg)

mysql监控展示效果:
![](http://img.peablog.com/2017-06-13-14973477306458.jpg)

您还可以通过influxdata自家的Chronograf来展示,毕竟是influxdata自家的东西,对influxdb的支持应该要好一些。

# 类似工具
influxdb的开发商influxdata旗下本身已有一款监控工具:Telegraf. 它不仅支持自家的influxdb, 也支持Es、Kafka等其他流行开源工具, 支持的输入插件也非常多。
但它的使用方式是通过配置文件来实现的,部分配置感觉略复杂。

Release files for monflux 0.0.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for monflux 0.0.5
File Size Uploaded
monflux-0.0.5.tar.gz 4.6 kB Details

Release files / monflux-0.0.5.tar.gz

Download URL monflux-0.0.5.tar.gz
Size 4.6 kB
Tags Source
SHA-256 checksum
How to use checksums
4b754c5939f1552b95b8eed69b7e64c1723526d93ea1c2e6fb4a8a7e4a47b0d7
BLAKE2b-256 checksum
How to use checksums
91d49de1e0d1a5c3cf2fe1cc0840db4ac08cb66101bbb6f9dd2f6441a79d861a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.0.5 This release

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page