gnocchi-Sampling data storage Flow Analysis (001)--Data storage __ Monitoring alarm

Source: Internet
Author: User

1 data storage

1.1 Add a sample data

Gnocchi--debug measures add-m 2016-04-16t14:33:58@43.1--resource-id 3068f5ec-0d37-419a-929d-0505efaf908c vm_meteric _001 1.2 Rest API processing Interface

Source code is located in: gnocchi/rest/__init__.py Namedmetriccontroller:

In the lookup interface, find the corresponding metric information in the index database based on the name of the incoming meter and resource, and return the data processing method of the metric

classNamedmetriccontroller (rest. Restcontroller):
def__init__ (self, resource_id, Resource_type):
self.resource_id = resource_id
Self.resource_type = Resource_type

@pecan. Expose ()
def_lookup (self, Name, *remainder):
Details = TrueifPecan.request.method = =' Get ' elseFalse
m = Pecan.request.indexer.list_metrics (Details=details,
Name=name,
RESOURCE_ID=SELF.RESOURCE_ID)
ifM:
returnMetriccontroller (M[0]), remainder

Resource = Pecan.request.indexer.get_resource (self.resource_type,self.resource_id)
ifResource
Abort (404, indexer. Nosuchmetric (name))
Else:
Abort (404, indexer. Nosuchresource (self.resource_id))

1.3 Metriccontroller add record post_measures

Source code is located in: gnocchi/rest/__init__.py Meticcontroller:

According to the backend storage type defined by Pecan.request.storage, the corresponding Add_measures interface is called, which is mainly analyzed in local storage file.

@pecan. Expose ()
def post_measures (self):
Self.enforce_metric ("post measures")
params = Deserialize ()
if not Isinstance (params,list):
Abort ( "Invalid input for measures")
if params:
# Gnocchi.storage.file.FileStorage
Pecan.request.storage.add_measures (
Self.metric, Six.moves.map (Measureschema, params))
Pecan.response.status = 202

1.4 add_measures

The parent source of the method is located in the gnocchi/storage/_carbonara.py Carbnonarabasestorage, and the other storage backend realizes the _store_measures () method in Add_measures

def add_measures (self, Metric, measures):
Self._store_measures (Metric, Msgpackutils.dumps (
List (map (tuple, measures)))

1.5 file-driven _store_measures method

The source is located in the gnocchi/storage/file.py Filestorage class:

def _store_measures (self, Metric, data):
Tmpfile = Self._get_tempfile ()

#临时文件路径为/var/lib/gnocchi/tmp
Tmpfile.write (data)
Tmpfile.close ()
Path = Self._build_measure_path (metric.id,true)

#该路径为/var/lib/gnocchi/measure/metric.id/+ random uuid+ time stamp
whileTrue:
Try:
Os.rename (tmpfile.name, Path)
Break
Except
OSError asE:
ifE.errno!= errno. Enoent:
Raise
Try
:
Os.mkdir (Self._build_measure_path (metric.id))
exceptOSError asE:
# Note (JD) It ' s possible that another process created the
# path just before us! In the, good for us, let's do
# Nothing then! (For a bug #1475684)
ifE.errno!= errno. Eexist:
Raise

Specifically as follows:



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.