简介

  Graphite 是一个数据绘图工具,安装完成之后需要喂它数据,就可以根据你的需要将数据生成制定的格式(绘图、json、xml等),还可以和Nagios结合完成报警功能。具体的数据采集工具是由第三方工具完成。
  Graphite 支持的第三方工具很多,Bucky, collectd, Collectl, Charcoal, Diamond, Ganglia, Host sFlow, statsd, Tasseo 等等。本文第三方工具使用的elasticsearch的filter/metrics插件。

graphite安装

服务器环境为10.10.10.60 centos7
1.安装epel源并安装相关开发包

rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
yum -y install httpd gcc gcc-c++ git pycairo mod_wsgi
yum -y install python-pip python-devel blas-devel lapack-devel libffi-devel

2.下载并安装graphite

cd /usr/local/src/graphite
git clone https://github.com/graphite-project/graphite-web.git
git clone https://github.com/graphite-project/carbon.git
#检测安装依赖
pip install -r /usr/local/src/graphite/graphite-web/requirements.txt

若当前安装环境缺少相关组件,则会提示。例如我本机提示缺少django-tagging django等,我们可以通过pip安装:

pip install django-tagging
pip install 'Django==1.8'

注意:安装python相关组件要根据python版本进行,我本机为Python 2.7.5,但是安装django1.9和1.7后graphite启动报错,后来改成1.8才正常。

#安装carbon和graphite-web
cd /usr/local/src/graphite/carbon/
python setup.py installcd /usr/local/src/graphite/graphite-web/
python setup.py install
#默认安装到/opt/graphite/

3.生成配置文件

 cp /opt/graphite/conf/carbon.conf.example /opt/graphite/conf/carbon.confcp /opt/graphite/conf/storage-schemas.conf.example /opt/graphite/conf/storage-schemas.confcp /opt/graphite/conf/storage-aggregation.conf.example /opt/graphite/conf/storage-aggregation.confcp /opt/graphite/conf/relay-rules.conf.example /opt/graphite/conf/relay-rules.confcp /opt/graphite/webapp/graphite/local_settings.py.example /opt/graphite/webapp/graphite/local_settings.pycp /opt/graphite/conf/graphite.wsgi.example /opt/graphite/conf/graphite.wsgi#生成apache配置文件cp /opt/graphite/examples/example-graphite-vhost.conf /etc/httpd/conf.d/graphite.conf#配置启动脚本cp /usr/local/src/graphite/carbon/distro/redhat/init.d/carbon-* /etc/init.d/chmod +x /etc/init.d/carbon-*

4.配置graphite
graphite默认使用sqlit作为本地数据库,当然也可以使用mysql数据库。我们需要为graphite-webapp导入静态文件并且设置相关权限

cd /opt/graphite
PYTHONPATH=/opt/graphite/webapp/ django-admin.py syncdb --settings=graphite.settings
PYTHONPATH=/opt/graphite/webapp/ django-admin.py collectstatic --settings=graphite.settings

**注意:**django1.9不支持syncdb参数,需要使用migrate参数

chown -R apache:apache /opt/graphite/storage/
chown -R apache:apache /opt/graphite/static/
chown -R apache:apache /opt/graphite/webapp/

5.配置apache

<IfModule !wsgi_module.c>LoadModule wsgi_module modules/mod_wsgi.so
</IfModule># XXX You need to set this up!
# Read http://code.google.com/p/modwsgi/wiki/ConfigurationDirectives#WSGISocketPrefix
# For example, create a directory /var/run/wsgi and use that.
WSGISocketPrefix run/wsgi<VirtualHost *:80>ServerName graphiteDocumentRoot "/opt/graphite/webapp"ErrorLog /opt/graphite/storage/log/webapp/error.logCustomLog /opt/graphite/storage/log/webapp/access.log common# I've found that an equal number of processes & threads tends# to show the best performance for Graphite (ymmv).WSGIDaemonProcess graphite processes=5 threads=5 display-name='%{GROUP}' inactivity-timeout=120WSGIProcessGroup graphiteWSGIApplicationGroup %{GLOBAL}WSGIImportScript /opt/graphite/conf/graphite.wsgi process-group=graphite application-group=%{GLOBAL}# XXX You will need to create this file! There is a graphite.wsgi.example# file in this directory that you can safely use, just copy it to graphite.wgsiWSGIScriptAlias / /opt/graphite/conf/graphite.wsgi# XXX To serve static files, either:# * Install the whitenoise Python package (pip install whitenoise)# * Collect static files in a directory by running:#     django-admin.py collectstatic --noinput --settings=graphite.settings#   And set an alias to serve static files with Apache:Alias /static/ /opt/graphite/static/<Directory /opt/graphite/static>#       Order allow,deny#       Allow from allRequire all granted</Directory>######################### URL-prefixed install ########################## If using URL_PREFIX in local_settings for URL-prefixed install (that is not located at "/"))# your WSGIScriptAlias line should look like the following (e.g. URL_PREFX="/graphite"# WSGIScriptAlias /graphite /srv/graphite-web/conf/graphite.wsgi/graphite# Alias /graphite/static /opt/graphite/webapp/content#  <Location "/graphite/static/">#        SetHandler None# </Location># XXX In order for the django admin site media to work you# must change @DJANGO_ROOT@ to be the path to your django# installation, which is probably something like:# /usr/lib/python2.6/site-packages/djangoAlias /media/ "@DJANGO_ROOT@/contrib/admin/media/"# The graphite.wsgi file has to be accessible by apache. It won't# be visible to clients because of the DocumentRoot though.<Directory /opt/graphite/conf/><IfVersion < 2.4>Order deny,allowAllow from all</IfVersion><IfVersion >= 2.4>Require all granted</IfVersion></Directory></VirtualHost>

注意:
(1).默认情况下,apache访问限制Alias目录,因此我们需要在配置文件中对static目录进行更改:

        Alias /static/ /opt/graphite/static/<Directory /opt/graphite/static>Require all granted</Directory>

(2).apache版本不同,授权方式也不同,例如:

        Alias /static/ /opt/graphite/static/<Directory /opt/graphite/static>Order allow,denyAllow from allRequire all grantedRequire all granted</Directory>

(3).若登录后发现css,js等静态内容无法显示,或日志返回403错误,则需要注意“Alias /static/ /opt/graphite/static/”最后的/是否存在。

6.启动graphite

service start carbon-cache
systemctl start httpd

7.登录10.10.10.60

由于没有数据输入,因此没有数据显示

实验

需求:在此我们通过ELKstack的logstash组件中的filter/metrics来采集nginx的日志,来检测访问日志中503每分钟的频率,若频率过高则表示nginx有异常访问。

1.编辑logstash配置文件

cd /usr/local/logstash/etc
vim reponse_503.confinput {file {path => "/data/nginx/logs/access.log"type => "nginx-access"start_position => "beginning"sincedb_path => "/usr/local/logstash/sincedb"}
}
filter {if [type] == "nginx-access" {grok {patterns_dir => "/usr/local/logstash/patterns"match => {"message" => "%{NGINXACCESS}"}}date {match => [ "timestamp" , "dd/MMM/YYYY:HH:mm:ss Z" ]}metrics {meter => [ "http_%{status}" ]add_tag => "metric"}}
}
output {if "metric" in [tags] {graphite {host => "10.10.10.60"metrics => [ "218-http_503.rate_1m", "%{[http_503][rate_1m]}" ]}}}

2.运行logstash

/usr/local/logstash/bin/logstash -f reponse_503.conf
Default settings used: Filter workers: 4
Logstash startup completed

3.登录graphite就可以看出相关的数据曲线了

总结

  由于nagios不支持filter/metrics,因此我们在提供graphite进行画图。当然ELKstack支持很多组件,如果我们日常使用的nagios监控,我们也可以通过使用其他组件来配合nagios使用。

metrics和graphite监控相关推荐

  1. Graphite监控上手指南

    主要讨论内容 在本文中我们将会谈及如下用于创建Graphite监控系统的主题: Carbon和Whisper简介 Whisper存储模式和聚合 Graphite Web应用 前提条件 首先,我们需要能 ...

  2. 使用graphite和cabot搭建监控服务

    说起监控,我们一般会首先想到zabbix,nagios,ganglia等等.但是对于非ops开发人员而言,这些东西,多多少少让人感到陌生.所以本文将从一个服务端开发人员的视角,介绍如何通过graphi ...

  3. spark 监控--WebUi、Metrics System(转载)

    转载自:https://www.cnblogs.com/barrenlake/p/4364644.html Spark 监控相关的部分有WebUi 及 Metrics System; WebUi用于展 ...

  4. Kubernetes 【监控】1. Metrics Server、Aggregator APIServer和Prometheus监控体系

    文章目录 1. 背景 2. 简介 3. 监控对象类型 4. Metrics Server简介 5. Metrics Server部署 5.1 下载并解压Metrics-Server 5.2 修改Met ...

  5. Spark源码阅读02-Spark核心原理之监控管理

    监控管理 监控管理 UI监控 实时UI监控 历史UI监控 Metrics 输入源(Metrics Source)介绍 输出方式(Metrics Sink)介绍 TEST 监控管理 Spark提供了UI ...

  6. Spring Boot2.x-14 使用Prometheus + Grafana 实现可视化的监控

    文章目录 环境信息 Prometheus 组件 下载 & 安装 通过指定配置文件prometheus.yml启动Prometheus 查看采集到的性能指标 查看prometheus规则 查看监 ...

  7. Prometheus监控kubernetes

    Prometheus监控 kubernetes 咱们的目标通过Prometheus监控Kubernetes集群. 1.使用ConfigMaps管理Prometheus的配置文件 创建prometheu ...

  8. prometheus监控mysql慢查询_使用Grafana+Prometheus监控mysql服务性能

    prometheus(也叫普罗米修斯)官网: grafana官网: 特征 普罗米修斯的主要特点是: 具有由度量名称和键/值对标识的时间序列数据的 一个 来利用这一维度 不依赖分布式存储; 单个服务器节 ...

  9. 广告业务系统 之 数据中转站 —— “日志中心-实时服务监控”

    文章目录 广告业务系统 之 数据中转站 -- "日志中心-实时服务监控" 日志中心 实时服务监控 -- 前链路日志分析 日志收敛手段 -- "手术开口" 基于 ...

最新文章

  1. 项目需求|10~15万|自动上料系统—将物料通过机械手臂挂在挂钩上
  2. python使用正则表达式删除字符串中的其它字符只保留数字和字母
  3. 游戏中常用的寻路算法的分享(4)处理移动中的障碍物
  4. c++成员运算符的重载
  5. 网站时间显示——基于Date
  6. CSS animation 与 transition 有何区别?
  7. ifen.os x pe.dmg天翼云_3.3K屏显纵览天下 11代酷睿横行职场 华硕灵耀X纵横值得选择...
  8. PASCAL-VOC2012数据集(vocdevkit、Vocbenchmark_release)详细介绍
  9. egret性能优化总结
  10. android 时钟动态图标,安卓 8.1 Launcher3实现动态指针时钟功能
  11. 还记不住Spring Bean的生命周期?看这篇你就知道方法了!
  12. 网传固态硬盘因为TRIM指令一经删除无法恢复是以讹传讹
  13. 编程人员的不二之选 LEGION Y9000X正式发布
  14. 写计算机老师的一封信200,写给老师的一封信200个字
  15. 香港伦敦金交易平台排行榜(2022最新版)
  16. 【打卡】医学搜索Query相关性判断学习赛
  17. 联通光猫 nat转发 - 虚拟主机设置
  18. chrome审查元素功能
  19. android项目大全,总有你所需的
  20. 我是如何用单机实现亿级规模题库去重的?

热门文章

  1. 利用JS来设计夜场的倒计时以及进入页面
  2. 这是一篇有温度的NLP秋招面经
  3. JAVA浮点数转人民币读法_算法--java实现将数字转换成人民币大写(迅雷面试题)...
  4. 腾讯X5浏览器简单使用
  5. 2021_RecSys_Together is Better: Hybrid Recommendations Combining Graph Embeddings and Contextualized
  6. 【minimal problem】资料整理
  7. 表达式计算: 分析与设计
  8. 从零开始:微信小程序新手入门宝典
  9. C语言逻辑类型与运算
  10. 【随机过程】随机过程第一章 随机过程的基本概念