[PYTHON] I played with Diamond, a metrics collection tool

Introduction

This is a memo I tried using Diamond, a metrics collection tool. We used the standard Graphite + Grafana as a base for storing and visualizing time-series data.

Time series data storage and visualization

First of all, I will briefly introduce Graphite and Grafana. Graphite provides the following services.

Graphite can be visualized by itself, but it is hard to say that it is sophisticated, so Graphite only provides API, and it seems that the visualization part such as dashboard generation often uses another tool. As this visualization tool, I used Grafana this time.

By using Grafana, you can easily create a stylish dashboard like this, for example.

grafana.png

The following sites will be helpful for Graphite and Grafana. Visualize Chef execution results with Chef Handlers + Graphite Graphite Documentation Memo that I tried using Graphite and Grafana for about an hour Create a dashboard to display Graphite data using Grafana Grafana Official

metrics collection tool, Diamond

What is Diamond

This is the main part of this time.

Diamond Diamond can be broadly divided into two components

The collector is responsible for collecting the data. Just collecting it is not the same as providing the collected data outside of Diamond. The handler handles the collected data. For example, you can write the data obtained by collector to a local file, send it to Graphite (maybe carbon), save it in a MySQL table, skip an alert if there is something wrong, and so on.

Also, Diamond provides a daemon that runs the collector on a regular basis, so you don't have to write your own scheduler.

Diamond's strengths

That said, whether it's a strength or not is subtle, but Diamond has a fairly large number of collectors provided by the community. Diamond/Collectors Various system information, famous places such as apache, nginx, MySQL, PostgreSQL, Redis, MongoDB, DRBD, and relatively maniac metrics such as Openstack Swift are collected.

Move for the time being

Installation

Basically, I will do it while looking here. Even though it is a python main project, I build it using make. Diamond/Usage

For reference, the system information of the installed machine.

-(risuo@ebi)-(0)-
-[9362]% cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=12.10
DISTRIB_CODENAME=quantal
DISTRIB_DESCRIPTION="Ubuntu 12.10"
-(risuo@ebi)-(0)-
-[9369]% uname -a
Linux ebi 3.5.0-23-generic #35-Ubuntu SMP Thu Jan 24 13:05:29 UTC 2013 i686 athlon i686 GNU/Linux

Edit configuration file

First, edit diamond.conf. By default it looks like this Diamond / conf / diamond.conf.example If you install it normally, /etc/diamond/diamond.conf.example will be created, so make a copy with the name diamond.conf in the same directory.

If you want to send data to Graphite, set here first

[[GraphiteHandler]]
### Options for GraphiteHandler

# Graphite server host
host = graphite

# Port to send metrics to
port = 2003

# Socket timeout (seconds)
timeout = 15

# Batch size for metrics
batch = 1

In the host part, write the host of the Graphite server. Set the port number as needed. Graphite must be specified in the handlers in the [server] section, but this is the default, so you don't need to be aware of it for the time being.

As mentioned above, it works for the time being.

sudo /etc/init.d/diamond start
sudo service diamond start

Start the daemon with.

Wait for a while and then look at Grafana's dashboard. It is successful if you can select metrics that look like it has system information. The image below shows metrics related to cpu, diskspace, memory, iostat, load average.

grafana_2.png

Troubleshooting should be done by chewing on /var/log/diamond/diamong.log.

tips

I want to set the interval of acquisition time of metrics

Start by specifying the interval value of conf of various collectors. You can also set global default values in diamond.conf. You can actually embed it in the source code. You can see how to write it by reading the get_default_config method. The following page is detailed. Diamond/Configuration

Write like this (unit is seconds)

interval = 60

I want to set up logger

You can specify the log output format, format, and output destination. You can get a general idea by reading Diamond / Configuration.

I want to set a handler

Specify the handlers you want to enable in the handlers in the [server] section. By default, GraphiteHandler and ArchiveHandler are enabled, but they are specified like this.

handlers = diamond.handler.graphite.GraphiteHandler, diamond.handler.archive.ArchiveHandler

For example, if you want to pickle and send, you need to set GraphitePickleHandler in the [server] section. If you want to save the acquired data in MySQL, specify MySQLHandler.

The community also provides an InfluxdbHandler, a handler that stores in Influxdb. Grafana can also be drawn from Influxdb, so choose the one you like.

The settings for each handler are described in the [handlers] section.

I want to develop a custom collector

You can develop a custom collector by extending diamond.collector.Collector (if you do it normally, make it a derived class). Among the methods that diamond.collector.Collector has, the "publish" related method is the interface between collector and handler. Also, diamond.collector.Collector has an unimplemented "collect" method that allows developers to implement collect in their derived classes. The following page will be helpful. Diamond/CustomCollectors

However, since the amount of information is small with this alone, I think that you should read the implementation of the Collector class if you develop a custom collector. collector.py

For example, the publish method has an argument called precision, which specifies the number of significant digits in metrics. This is 0 by default, that is, it is set to handle only integers. There are quite a lot of situations where you want to handle metrics with float, but it seems that you can not find the solution unless you read the source code.

Similar solution

Sensu and fluentd are images that can do something similar. sensu fluentd

It feels like I've googled it, and sensu seems to be able to do more than just collect metrics. It's cool to be able to create a dashboard that outputs information on each node that contains the sensu client using the sensu API. It seems that this cannot be imitated with Diamond. The following sites will be helpful. About Graphite and Sensu How to build a monitoring system with a high degree of freedom using Sensu Use Fluentd to view CloudWatch metrics in Graphite I tried a combination of InfluxDB and fluentd

Summary / impression

It's easy, but I wrote about Diamond. It's important to keep the data visible, so I think it's a good idea to keep these tools in the future.

Recommended Posts

I played with Diamond, a metrics collection tool
I played with wordcloud!
I made a router config collection tool Config Collecor
I made a fortune with Python.
I played with PyQt5 and Python3
I played with Mecab (morphological analysis)!
I made a daemon with Python
[5th] I tried to make a certain authenticator-like tool with python
[2nd] I tried to make a certain authenticator-like tool with python
[Introduction to StyleGAN] I played with "The Life of a Man" ♬
I tried a tool that imitates Van Gogh's pattern with AI
[4th] I tried to make a certain authenticator-like tool with python
[Introduction to StyleGAN] I played with "A woman transforms into Mayuyu" ♬
[1st] I tried to make a certain authenticator-like tool with python
I played with DragonRuby GTK (Game Toolkit)
I made a tool to automatically browse multiple sites with Selenium (Python)
I made a character counter with Python
I drew a heatmap with seaborn [Python]
[Scikit-learn] I played with the ROC curve
I tried a functional language with Python
[Introduction to Pytorch] I played with sinGAN ♬
What I did with a Python array
I made a Hex map with Python
I made a tool to convert Jupyter py to ipynb with VS Code
I made a life game with Numpy
I made a tool that makes decompression a little easier with CLI (Python3)
I made a stamp generator with GAN
I made a browser automatic stamping tool.
I created a password tool in Python.
I made a roguelike game with Python
I made a simple blackjack with Python
I made a configuration file with Python
I made a WEB application with Django
I made a neuron simulator with Python
I created a tool to correct GPS data with Mapbox Map Matching API (Mapbox Map Matching API)
I made a stamp substitute bot with line
I made a competitive programming glossary with Python
I made a weather forecast bot-like with Python.
I made a GUI application with Python + PyQt5
I made a Twitter fujoshi blocker with Python ①
I want to make a game with Python
[Python] I played with natural language processing ~ transformers ~
I played with Floydhub for the time being
[Python] I made a Youtube Downloader with Tkinter.
I get a UnicodeDecodeError when running with mod_wsgi
I made a simple Bitcoin wallet with pycoin
I made a LINE Bot with Serverless Framework!
I made a tool to compile Hy natively
I made a tool to get new articles
I tried running alembic, a Python migration tool
I made a random number graph with Numpy
I want to write to a file with Python
I tried using a database (sqlite3) with kivy
Create a translation tool with the Translate Toolkit
I made a bin picking game with Python
I made a Mattermost bot with Python (+ Flask)
I made a QR code image with CuteR
I wrote a CLI tool in Go language to view Qiita's tag feed with CLI
I made a Twitter BOT with GAE (python) (with a reference)
I tried to create a table only with Django
I made a household account book bot with LINE Bot