Use graphite to render the collected data into an image.

Source: Internet
Author: User
Tags snmp

Here, I will explain the difference between him and cacti nagios ~ And why should we use him ~

Cacti Uses snmp to capture data. Of course, you can use snmp to execute exec to retrieve the data in the script.

Nagios is used to monitor various Server statuses. Of course, you can also use pnp to draw images.

But why should I use graphite? In fact, it is just a function that shows the received data to the page ~

I think this function is enough ~

Requirements:

Script Execution Efficiency

System log analysis result

Online users

To the quality and delay of each network node

Company developers want to see the number of api calls

Number of calls to a program

Latency statistics for each process

These images can be well drawn, which is more convenient than drawing with rrdtool ~

Http://graphite.readthedocs.org/en/latest/index.html

 

1. Graphite Project Overview

Graphite is an enterprise-level monitoring tool that can run on cheap machine hardware.

Ii. Graphite Functions

Graphite is a drawing tool that displays data graphically. It mainly performs two tasks:

  1. Store time series data
  2. Displays data graphs as needed

Graphite does not collect data. Some tools know how to send data to Graphite. A little code is required, but it is very simple.

Iii. Simple Architecture

Graphite consists of three software components:

  1. Carbon-A Twisted daemon monitors time series data
  2. Whisper-A simple database used to store time series data, designed similar to RRD
  3. Graphite webapp-Django webapp: Uses Cairo to present images as needed
Architecture diagram: 650) this. length = 650; "class =" size-large wp-image-3294 "title =" Graphite High Level "alt =" Graphite High Level "width =" 458 "height =" 600 "style =" margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 13px; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; background-position: initial; background-repeat: initial; "src =" http://www.bkjia.com/uploads/allimg/131227/1U23W126-0.png "/>

Graphite High Level

In this figure, we can see that Carbon first writes data to the Whisper database file, then Graphite Webapp reads the data, and then displays the image. But in fact, this system uses cache. Data may first go to the cache, and then the Webapp reads the data to display the image. This is why the web app graphics can still be displayed in near real-time mode when the host I/O response fails.

Data feed is quite simple, and most of the effort is usually spent on data collection. When you send data points to Carbon, they can draw images in the webapp immediately. Webapp provides several ways to create and display images, including simpleURL APIIn this way, you can easily embed images into other Web pages.

Iv. Effects

Is the effect in the browser:

 

650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131227/1U23S233-1.jpg "/>

Shell example

 
 
  1. ORT=2003 
  2. SERVER=graphite.your.org 
  3. echo "local.random.diceroll 4 `date +%s`" | nc ${SERVER} ${PORT}; 

Python example

 
 
  1. #!/usr/bin/python 
  2. import sys 
  3. import time 
  4. import os 
  5. import platform 
  6. import subprocess 
  7. from socket import socket 
  8.   
  9. CARBON_SERVER = '127.0.0.1' 
  10. CARBON_PORT = 2003 
  11.   
  12. delay = 60 
  13. if len(sys.argv) > 1: 
  14.   delay = int( sys.argv[1] ) 
  15.   
  16. def get_loadavg(): 
  17.   # For more details, "man proc" and "man uptime" 
  18.   if platform.system() == "Linux": 
  19.     return open('/proc/loadavg').read().strip().split()[:3] 
  20.   else: 
  21.     command = "uptime" 
  22.     process = subprocess.Popen(command, stdout=subprocess.PIPE, shell=True) 
  23.     os.waitpid(process.pid, 0) 
  24.     output = process.stdout.read().replace(',', ' ').strip().split() 
  25.     lenlength = len(output) 
  26.     return output[length - 3:length] 
  27.   
  28. sock = socket() 
  29. try: 
  30.   sock.connect( (CARBON_SERVER,CARBON_PORT) ) 
  31. except: 
  32.   print "Couldn't connect to %(server)s on port %(port)d, is carbon-agent.py running?" % { 'server':CARBON_SERVER, 'port':CARBON_PORT } 
  33.   sys.exit(1) 
  34.   
  35. while True: 
  36.   now = int( time.time() ) 
  37.   lines = [] 
  38.   #We're gonna report all three loadavg values 
  39.   loadavg = get_loadavg() 
  40.   lines.append("system.loadavg_1min %s %d" % (loadavg[0],now)) 
  41.   lines.append("system.loadavg_5min %s %d" % (loadavg[1],now)) 
  42.   lines.append("system.loadavg_15min %s %d" % (loadavg[2],now)) 
  43.   message = '\n'.join(lines) + '\n' #all lines must end in a newline 
  44.   print "sending message\n" 
  45.   print '-' * 80 
  46.   print message 
  47.   print 
  48.   sock.sendall(message) 
  49.   time.sleep(delay) 

 

This article is from "Fengyun, it's her ." Blog, please be sure to keep this source http://rfyiamcool.blog.51cto.com/1030776/1184015

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.