新钛云服 祝祥 原创
Monasca 是一个多租户监控即服务工具,可以帮助IT团队分析日志数据并设置告警和通知。
OpenStack环境中的监控需求是巨大,多样且高度复杂的。Monasca的项目任务是提供一种多租户,高度可扩展,高性能和容错的监控即服务解决方案。
Monasca为高级监控提供了可扩展的平台,运营商和租户均可使用该平台来获取有关其基础架构和应用的运行状态。
Monasca使用REST API进行高速的日志处理和查询。它集成了流告警引擎,通知引擎和聚合引擎。
您可以使用Monasca实现的用例非常多样。Monasca遵循微服务架构,其中几个服务分布在多个存储库中。每个模块旨在为整个监控解决方案提供离散服务,并且可以根据运营商/客户的需求进行部署。
下图概述了Monasca的指标管道以及所涉及组件的交互。
核心组件除了直接向API发送请求之外,还可以使用以下工具与Monasca进行交互:
Libraries:
Grafana集成:
Monasca使用多种第三方技术:
monasca的所有组件都可以安装在一个节点上,例如openstack控制器节点上,也可以将其部署在多节点上。本文中,将在我的openstack集群中创建的新VM中安装monasca-api,该VM具有关联的浮动ip。Monasca-agent已安装在控制器节点上。代理节点通过浮动ip将指标发布到api节点。它们在同一子网中。
1、安装我们需要的软件包和工具
apt-get install -y git
apt-get install openjdk-7-jre-headless python-pip python-dev
2、安装mysql数据库
如果您在openstack控制器节点中安装了monasca-api,则可以跳过安装,将已安装的msyql用于openstack服务。
apt-get install -y mysql-server
创建monasca数据库架构,在此处下载mon.sql( https://raw.githubusercontent.com/stackforge/cookbook-monasca-schema/master/files/default/mysql/mon.sql)
mysql -uroot -ppassword < mon_mysql.sql
3、安装Zookeeper 安装Zookeeper并重新启动它。我使用本地主机接口,并且只有一个Zookeeper,因此默认配置文件不需要配置。
apt-get install -y zookeeper zookeeperd zookeeper-bin
service zookeeper restart
4、安装和配置kafka
wget http://apache.mirrors.tds.net/kafka/0.8.1.1/kafka_2.9.2-0.8.1.1.tgz
mv kafka_2.9.2-0.8.1.1.tgz /opt
cd /opt
tar zxf kafka_2.9.2-0.8.1.1.tgz
ln -s /opt/kafka_2.9.2-0.8.1.1/ /opt/kafka
ln -s /opt/kafka/config /etc/kafka
创建kafka系统用户,kafka服务将以该用户身份启动。
useradd kafka -U -r在/etc/init/kafka.conf
中创建kafka启动脚本,将以下内容复制 到/etc/init/kafka.conf中并保存。
description "Kafka"
start on runlevel [2345]
stop on runlevel [!2345]
respawn
limit nofile 32768 32768
# If zookeeper is running on this box also give it time to start up properly
pre-start script
if [ -e /etc/init.d/zookeeper ]; then
/etc/init.d/zookeeper restart
fi
end script
# Rather than using setuid/setgid sudo is used because the pre-start task must run as root
exec sudo -Hu kafka -g kafka KAFKA_HEAP_OPTS="-Xmx1G -Xms1G" JMX_PORT=9997 /opt/kafka/bin/kafka-server-start.sh /etc/kafka/server.properties
配置kafka,vim /etc/kafka/server.properties,确保配置了以下内容:
host.name=localhost
advertised.host.name=localhost
log.dirs=/var/kafka
创建 kafka log目录
mkdir /var/kafka
mkdir /var/log/kafka
chown -R kafka. /var/kafka/
chown -R kafka. /var/log/kafka/启动kafka服务service kafka start下一步就是创建 kafka topics/opt/kafka/bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 64 --topic metrics
/opt/kafka/bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 12 --topic events
/opt/kafka/bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 12 --topic raw-events
/opt/kafka/bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 12 --topic transformed-events
/opt/kafka/bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 12 --topic stream-definitions
/opt/kafka/bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 12 --topic transform-definitions
/opt/kafka/bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 12 --topic alarm-state-transitions
/opt/kafka/bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 12 --topic alarm-notifications
/opt/kafka/bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 12 --topic stream-notifications
/opt/kafka/bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 3 --topic retry-notifications
5、安装和配置 influxdb
curl -sL https://repos.influxdata.com/influxdb.key | apt-key add -
echo "deb https://repos.influxdata.com/ubuntu trusty stable" > /etc/apt/sources.list.d/influxdb.list
apt-get update
apt-get install -y apt-transport-https
apt-get install -y influxdb
service influxdb start
创建 influxdb database, user, password, retention policy, 同时修改密码。
influx
CREATE DATAbase mon
CREATE USER monasca WITH PASSWORD 'tyun'
CREATE RETENTION POLICY persister_all ON mon DURATION 90d REPLICATION 1 DEFAULT
exit
6、安装与配置 storm
wget http://apache.mirrors.tds.net/storm/apache-storm-0.9.6/apache-storm-0.9.6.tar.gz
mkdir /opt/storm
cp apache-storm-0.9.6.tar.gz /opt/storm/
cd /opt/storm/
tar xzf apache-storm-0.9.6.tar.gz
ln -s /opt/storm/apache-storm-0.9.6 /opt/storm/current
useradd storm -U -r
mkdir /var/storm
mkdir /var/log/storm
chown -R storm. /var/storm
/ chown -R storm. /var/log/storm/
修改storm.yaml, vim current/storm/conf/storm.yaml
### base
java.library.path: "/usr/local/lib:/opt/local/lib:/usr/lib"
storm.local.dir: "/var/storm"
### zookeeper.*
storm.zookeeper.servers:
- "localhost"
storm.zookeeper.port: 2181
storm.zookeeper.retry.interval: 5000
storm.zookeeper.retry.times: 29
storm.zookeeper.root: "/storm"
storm.zookeeper.session.timeout: 30000
### supervisor.* configs are for node supervisors
supervisor.slots.ports:
- 6701
- 6702
- 6703
- 6704
supervisor.childopts: "-Xmx1024m"
### worker.* configs are for task workers
worker.childopts: "-Xmx1280m -XX:+UseConcMarkSweepGC -Dcom.sun.management.jmxremote"
### nimbus.* configs are for the masteri
nimbus.host: "localhost"
nimbus.thrift.port: 6627
mbus.childopts: "-Xmx1024m"
### ui.* configs are for the master
ui.host: 127.0.0.1
ui.port: 8078
ui.childopts: "-Xmx768m"
### drpc.* configs
### transactional.* configs
transactional.zookeeper.servers:
- "localhost" transactional.zookeeper.port: 2181
transactional.zookeeper.root: "/storm-transactional"
### topology.* configs are for specific executing storms
topology.acker.executors: 1
topology.debug: false
logviewer.port: 8077
logviewer.childopts: "-Xmx128m"
创建storm supervisor 启动脚本,vim /etc/init/storm-supervisor.conf
# Startup script for Storm Supervisor
description "Storm Supervisor daemon"
start on runlevel [2345]
console log
respawn
kill timeout 240
respawn limit 25 5
setgid storm
setuid storm
chdir /opt/storm/current
exec /opt/storm/current/bin/storm supervisor
创建Storm nimbus 启动脚本。vim /etc/init/storm-nimbus.conf
# Startup script for Storm Nimbus
description "Storm Nimbus
daemon" start on runlevel [2345]
console log
respawn
kill timeout 240
respawn limit 25 5
setgid storm
setuid storm
chdir /opt/storm/current
exec /opt/storm/current/bin/storm nimbus
启动supervisor 与 nimbus
service storm-supervisor start service storm-nimbus start
7、安装monasca api python软件包
一些monasca组件同时提供python和java代码,主要是我选择python代码进行部署。
pip install monasca-common
pip install gunicorn
pip install greenlet # Required for both
pip install eventlet # For eventlet workers
pip install gevent # For gevent workers
pip install monasca-api pip install influxdb
vim /etc/monasca/api-config.ini,将主机修改为您的IP地址
[DEFAULT] name = monasca_api [pipeline:main]
# Add validator in the pipeline so the metrics messages can be validated. pipeline = auth keystonecontext api [app:api] paste.app_factory = monasca_api.api.server:launch [filter:auth] paste.filter_factory = keystonemiddleware.auth_token:filter_factory [filter:keystonecontext] paste.filter_factory = monasca_api.middleware.keystone_context_filter:filter_factory [server:main] use = egg:gunicorn#main host = 192.168.2.23 port = 8082 workers = 1 proc_name = monasca_api
vim /etc/monasca/api-config.conf,修改以下内容
[DEFAULT]
# logging, make sure that the user under whom the server runs has permission
# to write to the directory.
log_file = monasca-api.log
log_dir = /var/log/monasca/api/
debug=False
region = RegionOne
[security]
# The roles that are allowed full access to the API.
default_authorized_roles = admin, user, domainuser, domainadmin, monasca-user
# The roles that are allowed to only POST metrics to the API. This role would be used by the Monasca Agent. agent_authorized_roles = admin
# The roles that are allowed to only GET metrics from the API. read_only_authorized_roles = admin
# The roles that are allowed to access the API on behalf of another tenant. # For example, a service can POST metrics to another tenant if they are a member of the "delegate" role. delegate_authorized_roles = admin [kafka]
# The endpoint to the kafka server uri = localhost:9092 [influxdb] # only needed if Influxdb database is used for backend.
# The IP address of the InfluxDB service. ip_address = localhost # The port number that the InfluxDB service is listening on. port = 8086
# The username to authenticate with. user = monasca
# The password to authenticate with. password = tyun # The name of the InfluxDB database to use. database_name = mon
[database]
url = "mysql+pymysql://monasca:tyun@127.0.0.1/mon"
[keystone_authtoken]
identity_uri =
http://192.168.1.11:35357
auth_uri = http://192.168.1.11:5000
admin_password = tyun admin_user = monasca
admin_tenant_name = service
cafile =
certfile =
keyfile =
insecure = false
注释掉[mysql]部分,其他部分保持默认。
创建monasca系统用户并进入目录
useradd monasca -U -r mkdir /var/log/monasca mkdir /var/log/monasca/api chown -R monasca. /var/log/monasca/
在openstack控制器节点上,创建monasca用户密码,为租户服务中的用户monasca分配管理员角色。
openstack user create --domain default --password tyun monasca
openstack role add --project service --user monasca admin
openstack service create --name monasca --description "Monasca monitoring service" monitoring
create endpoint
openstack endpoint create --region RegionOne monasca public http://192.168.1.143:8082/v2.0
openstack endpoint create --region RegionOne monasca internal http://192.168.1.143:8082/v2.0
openstack endpoint create --region RegionOne monasca admin http://192.168.1.143:8082/v2.0
192.168.1.143是我的api虚拟机地址的浮动IP,请将其更改为您的IP。创建monasca api启动脚本,vim /etc/init/monasca-api.conf
# Startup script for the Monasca API
description "Monasca API Python app"
start on runlevel [2345]
console log
respawn
setgid monasca
setuid monasca
exec /usr/local/bin/gunicorn -n monasca-api -k eventlet --worker-connections=2000 --backlog=1000 --paste /etc/monasca/api-config.ini
8、安装monasca-persister
创建monasca-persister
启动脚本vim /etc/init/monasca-persister.conf
# Startup script for the Monasca Persister
description "Monasca Persister Python app"
start on runlevel [2345]
console log
respawn
setgid monasca
setuid monasca
exec /usr/bin/java -Dfile.encoding=UTF-8 -cp /opt/monasca/monasca-persister.jar monasca.persister.PersisterApplication server /etc/monasca/persister-config.yml启动monasca-persisterservice monasca-persister start
9、安装monasca-notificatoin
pip install --upgrade monasca-notification apt-get install sendmail
将notification.yaml复制到/etc/monasca/
创建启动脚本,vim /etc/init/monasca-notification.conf
# Startup script for the monasca_notification
description "Monasca Notification daemon"
start on runlevel [2345]
console log
respawn
setgid monasca
setuid monasca
exec /usr/bin/python /usr/local/bin/monasca-notification
启动通知服务service monasca-notification start
10、安装monasca-thresh
复制monasca-thresh到/etc/init.d/
复制monasca-thresh.jar到/opt/monasca-thresh/
复制thresh-config.yml到/etc/monasca /并修改主机以及数据库信息
启动monasca-thresh
service monasca-thresh start
11、安装monasca-agent
在openstack控制器节点上安装monasca-agent,以便它可以监控openstack服务进程。
sudo pip install --upgrade monasca-agent
设置monasca-agent,将用户域ID和项目域ID更改为默认值。
monasca-setup -u monasca -p tyun --user_domain_id e25e0413a70c41449d2ccc2578deb1e4 --project_domain_id e25e0413a70c41449d2ccc2578deb1e4 --user monasca --project_name service -s monitoring --keystone_url http://192.168.1.11:35357/v3 --monasca_url http://192.168.1.143:8082/v2.0 --config_dir /etc/monasca/agent --log_dir /var/log/monasca/agent --overwrite
加载认证脚本admin-rc.sh,然后运行monasca metric-list。
DevStack安装运行Monasca DevStack至少需要一台具有10GB RAM的主机。
可在此处找到安装和运行Devstack的说明:
https://docs.openstack.org/devstack/latest/
要在DevStack中运行Monasca,请执行以下三个步骤。
- 克隆DevStack代码库。
git clone https://git.openstack.org/openstack-dev/devstack
- 将以下内容添加到devstack目录根目录中的DevStack local.conf文件中。如果local.conf不存在,则可能需要创建它。
# BEGIN DEVSTACK LOCAL.CONF ConTENTS
[[local|localrc]]
DATAbase_PASSWORD=secretdatabase
RABBIT_PASSWORD=secretrabbit
ADMIN_PASSWORD=secretadmin
SERVICE_PASSWORD=secretservice
SERVICE_TOKEN=111222333444
LOGFILE=$DEST/logs/stack.sh.log
LOGDIR=$DEST/logs
LOG_COLOR=False
# The following two variables allow switching between Java and Python for the implementations
# of the Monasca API and the Monasca Persister. If these variables are not set, then the
# default is to install the Python implementations of both the Monasca API and the Monasca Persister.
# Uncomment one of the following two lines to choose Java or Python for the Monasca API.
MONASCA_API_IMPLEMENTATION_LANG=${MONASCA_API_IMPLEMENTATION_LANG:-java}
# MONASCA_API_IMPLEMENTATION_LANG=${MONASCA_API_IMPLEMENTATION_LANG:-python}
# Uncomment of the following two lines to choose Java or Python for the Monasca Pesister.
MONASCA_PERSISTER_IMPLEMENTATION_LANG=${MONASCA_PERSISTER_IMPLEMENTATION_LANG:-java}
# MONASCA_PERSISTER_IMPLEMENTATION_LANG=${MONASCA_PERSISTER_IMPLEMENTATION_LANG:-python}
# Uncomment one of the following two lines to choose either InfluxDB or Vertica.
# default "influxdb" is selected as metric DB
MONASCA_METRICS_DB=${MONASCA_METRICS_DB:-influxdb}
# MONASCA_METRICS_DB=${MONASCA_METRICS_DB:-vertica}
# This line will enable all of Monasca.
enable_plugin monasca-api https://git.openstack.org/openstack/monasca-api
# END DEVSTACK LOCAL.CONF CONTENTS
- 从devstack目录的根目录运行“ ./stack.sh”。
如果要使用最少的OpenStack组件运行Monasca,可以将以下两行添加到local.conf文件中。
disable_all_services
enable_service rabbit mysql key
如果您还希望安装Tempest测试,请添加 tempest
enable_service rabbit mysql key tempest
要启用Horizon和Monasca UI,请添加 horizon
enable_service rabbit mysql key horizon tempest使用Vagrant
Vagrant可用于使用Vagrantfile部署运行有Devstack和Monasca的VM。安装Vagrant后,只需在../monasca-api/devstack目录中运行vagrant up命令。
要在devstack安装中使用本地代码库,请将更改提交到本地存储库的master分支,然后在配置文件中修改与要使用的本地存储库相对应的变量file://my/local/repo/location。要使用monasca-api repo的本地实例,请将更改enable_plugin monasca-api https://git.openstack.org/openstack/monasca-api为enable_plugin monasca-api file://my/repo/is/here。这两个设置仅在重建devstack VM时生效。
- 使用Vagrant将Vertica启用为Metrics DBMonasca支持同时使用InfluxDB和Vertica来存储指标和告警状态历史记录。默认情况下,在DevStack环境中启用InfluxDB。Vertica是Hewlett Packard Enterprise的商业数据库。可以下载免费的Community Edition(CE)安装程序,要启用Vertica,请执行以下操作:注册并下载Vertica Debian安装程序https://my.vertica.com/download/vertica/community-edition/,并将其放在您的主目录中。不幸的是,DevStack安装程序没有可以自动使用的URL,因此必须单独下载该URL,并将其放置在安装程序运行时可以找到它的位置。安装程序假定此位置是您的主目录。使用Vagrant时,您的主目录通常将以“ /vagrant_home”挂载在VM内。修改local.conf中MONASCA_METRICS_DB变量,配置Vertica的支持,如下所示:MONASCA_METRICS_DB=${MONASCA_METRICS_DB:-vertica}
- 使用PostgreSQL或MySQLMonasca支持使用PostgreSQL和MySQL,因此该devstack插件也支持。启用postgresql或mysql。要使用MySQL设置环境,请使用:enable_service mysql另外,对于PostgreSQL,请使用:enable_service postgresql
- 使用ORM支持ORM支持可以通过MONASCA_DATAbase_USE_ORM变量来控制。但是,如果启用了PostgreSQL(也称为数据库后端),则将强制提供ORM支持enable_service postgresql
- 加强Apache镜像如果由于某种原因APACHE_MIRROR而无法使用,则可以通过以下方式强制执行:APACHE_MIRROR=http://www-us.apache.org/dist/
- 使用WSGIMonasca-api可以使用uwsgi和gunicorn与Apache一起部署。默认情况下,monasca-api在uwsgi下运行。如果您想使用Gunicorn,请确保其中devstack/local.conf包含:MONASCA_API_USE_MOD_WSGI=False
安装完成Monasca Dashboard Plugin后,可以通过web控制台进行查看以及管理相应的监控与告警。
在操作控制台的“Monitoring”栏,单击“Launch Monitoring Dashboard“,这将打开在管理节点上运行的专用OpenStack Horizon门户。
在该面板中,您可以:
监控信息存储在两个数据库中(Vertica/influxdb与mysql)。备份监控数据时,将同时备份两个数据库。看到
- 在操作控制台中,通过从主菜单中选择Monitoring Dashboard来打开监控UI 。
- 单击Launch Monitoring Dashboard。将打开管理设备上OpenStack Horizon中的“Monitoring”仪表板。
- 使用您在首次安装过程中为操作控制台设置的用户名和密码登录。
- 查看告警。您可以在屏幕上过滤结果。点击告警左侧导航看到报警的所有服务和设备。在每行右侧的“操作”菜单上,可以单击“Graph metrics”以查看告警明细,并且可以显示告警的历史记录和告警定义。您还可以在该告警的图形顶部看到指标名称。点击OpenStack服务名称以查看服务告警。单击服务器名称以查看有关设备的告警。
- 单击左侧导航中的”Alarm Definitions “以查看和编辑已启用的告警的类型。注意:请勿更改或删除任何默认告警定义。但是,您可以添加新的告警定义。
- 您可以更改告警的名称,表达式和其他详细信息。
- 如果收到过多或不足的告警,则可能需要提高或降低告警阈值。
- 有关编写告警表达式的信息。
- 可选:单击Dashboard。OpenStack仪表板(Grafana)打开。从该仪表板中,您可以看到OpenStack服务的运行状况以及每个节点的CPU和数据库使用情况的图形表示。单击图形标题(例如,CPU),然后单击“编辑”。更改功能以查看图中的其他类型的信息。
- 可选:单击Monasca Health。将打开“ Monasca服务仪表板”。在此仪表板上,您可以看到Monasca服务运行状况的图形表示。
Monasca作为Openstack的monitoring-as-a-service组件,目前社区和网上的资料还是比较少。本文通过作者的实践,记录了Monasca相关的安装和配置以及使用的方法,
Monasca是一个可以实现IAAS到PAAS的高扩展,高性能的监控系统,其体系架构决定了它能够轻松驾驭大集群,高负载的监控。当前我们已经逐步摈弃了ceilometer+gnocchi+aodh的组合,全面转向Monasca。当前监控的不仅仅是云主机,云网络,同时也监控着我们Openstack集群内部的Kubernetns集群,数据库集群,对象存储等PAAS软件。
参考:


