RRDtool 系列连载-6 :如何从 RRD 数据库中提取数据 - RRDtool - 阿勃的 blog
- 格式:doc
- 大小:15.95 KB
- 文档页数:13
接口数据的提取方法和步骤
接口数据的提取方法和步骤大致如下:
1. 确定接口:首先确定需要提取数据的接口,可以是网络API
接口、文件接口或其他类型接口。
2. 确定数据格式:根据接口文档或接口返回的数据结构,确定数据的格式,例如JSON、XML等。
3. 发送请求:使用适当的工具或编程语言,发送请求到接口,并获取返回的数据。
4. 解析数据:根据数据的格式,解析接口返回的数据,将数据转换为可操作的数据结构。
5. 提取数据:按需求提取所需要的数据,可以使用字符串处理、正则表达式、数据过滤等方法,将所需数据从原始数据中提取出来。
6. 处理数据:对提取到的数据进行必要的处理,例如数据清洗、数据转换等。
7. 存储数据:根据需求将提取到的数据进行存储,可以存储到数据库、文件或其他媒体。
8. 数据分析或展示:根据需要进行数据分析或展示,可以使用数据分析工具、可视化工具等。
需要注意的是,每个接口的数据提取方法和步骤可能会有所不同,需要根据具体情况进行调整。
另外,提取接口数据时也要注意接口的安全性和合法性,遵守相关的法律和规定。
extract函数用法如何使用extract函数。
提取函数是在计算机编程中广泛使用的一种功能。
它可以帮助我们从给定的数据集中提取特定的信息。
在本文中,我们将探讨提取函数的使用方法,并展示如何使用不同编程语言中的提取函数。
什么是提取函数?提取函数是一种用于从大量数据中提取有用信息的功能。
它可以根据特定的条件来搜索和匹配数据,并将匹配的结果返回给用户。
提取函数可以用于提取文本中的关键字、提取数据集中的特定列或行、从网页中提取链接等。
在不同的编程语言中,提取函数通常具有不同的名称和语法。
在接下来的部分中,我们将逐步介绍提取函数的使用方法。
使用Python中的提取函数在Python中,我们可以使用正则表达式(re库)进行数据提取。
正则表达式是一种强大的工具,可以用于根据模式匹配的方式搜索和替换字符串。
以下是使用Python中的提取函数的一般步骤:1.导入re库:在Python中使用re库之前,我们需要先导入它。
可以使用以下代码行导入re库:import re2.创建正则表达式模式:在使用提取函数之前,我们需要创建一个正则表达式模式,该模式将根据我们的需求来搜索和匹配数据。
例如,如果我们想从给定的文本中提取所有的Email地址,我们可以使用以下正则表达式模式:pattern = r'\b[A-Za-z0-9._+-]+@[A-Za-z0-9.-]+\.[A-Z a-z]{2,7}\b'3.使用re.findall()函数:使用re.findall()函数,我们可以在给定的文本中查找与模式匹配的所有项,并将它们作为列表返回。
以下是使用re.findall()函数从文本中提取所有的Email地址的示例代码:text = "Please contact us at info@example for further assistance" emails = re.findall(pattern, text)4.打印提取的结果:最后一步是打印提取函数的结果。
Package‘rerddapXtracto’October18,2023Type PackageTitle Extracts Environmental Data from'ERDDAP'Web ServicesVersion1.1.7Date2023-10-18Description Contains three functions that accessenvironmental data from any'ERDDAP'data web service.The rxtracto()function extracts data along a trajectory for a given``radius''around the point.Therxtracto_3D()function extracts data in a box.The rxtractogon()functionextracts data in a polygon.All of those three function use the'rerddap'packageto extract the data,and should work with any'ERDDAP'server.There are also two functions,plotBBox()and plotTrack()that use the'plotdap'package to simplify the creation of maps of the data.URL https:///rmendels/rerddapXtractoBugReports https:///rmendels/rerddapXtracto/issuesDepends R(>=4.0.0)License CC0Imports abind,dplyr,ggplot2,httr,maps,methods,ncdf4,parsedate,plotdap(>=0.0.5),readr,rerddap(>=0.8.0),sf,sp,stats,utilsSuggests cmocean,gganimate,knitr,mapdata,rmarkdownRoxygenNote7.2.3Encoding UTF-8LazyData TRUEVignetteBuilder knitrNeedsCompilation noAuthor Roy Mendelssohn[aut,cre],Marie Auger-Methe[ctb]Maintainer Roy Mendelssohn<************************>Repository CRANDate/Publication2023-10-1817:40:02UTC12Marlintag38606 R topics documented:dataInfo (2)Marlintag38606 (2)mbnms (3)MBsst (4)plotBBox (4)plotTrack (5)rxtracto (7)rxtractogon (9)rxtracto_3D (11)swchl (12)tidy_grid (13)Index14 dataInfo dataInfo DataDescriptionpre-Download of’rerddap’info needed for examples so can run within CRAN Time limitsUsagedataInfoFormatAn object of class info of length3.Detailsobtained using dataInfo<-rerddap::info(’erdHadISST’)Marlintag38606Marlin Tag DataDescriptionTelemetry data of a blue marlin tagged in the Pacific Ocean in2003UsageMarlintag38606mbnms3 FormatA data frame with152obs.of7variables:date time of observation given as YYYY-MM-DDlon longitude of observationlat latitude of observationlowLon low error on longitudehigLon high error on longitudelowLat low error on latitudehigLat high error on latitudeSourceDr.Mike Musyl,Pelagic Research Group LLCmbnms MBNMS BoundariesDescriptionA dataset containing the latitudes and longitudes of a polygon that define boundaries of the Mon-terey Bay National Marine Sanctuary.UsagembnmsFormatA data frame with6666obs.of2variables:Longitude Longitudes of a boundary polygonLatitude Latitudes of a boundary polygonSourcehttps:///library/imast_gis.html4plotBBox MBsst MBsst DataDescriptionpre-Download of Pacific West Coast SST fro use in‘plotBBox()‘example can run within CRAN Time limitsUsageMBsstFormatAn object of class list(inherits from rxtracto3D)of length6.Detailsobtained using the‘rxtracto_3D()‘command dataInfo<-rerddap::info(’erdMBsstd1day’)parame-ter<-’sst’xcoord<-c(230,230.1)ycoord<-c(33,33.1)tcoord<-c(’2006-01-15’,’2006-01-15’) zcoord<-c(0.,0.)MBsst<-rxtracto_3D(dataInfo,parameter,xcoord=xcoord,ycoord=ycoord, tcoord=tcoord,zcoord=zcoord)plotBBox plot result of’rxtracto_3D’DescriptionplotBBox is a function to plot the results from’rxtracto_3D’()’and’rxtractogon()’UsageplotBBox(resp,plotColor="viridis",time=NA,myFunc=NA,mapData=NULL,crs=NULL,animate=FALSE,cumulative=FALSE,name=NA,maxpixels=10000)Argumentsresp data frame returned from’rxtracto_3D’()’or’rxtractogon()’plotColor the color to use in plot from’cmocean’time a function to map multi-time to one,or else identity for animationmyFunc function of one argument to transform the datamapData map data from’maps’or’mapdata’,must be of class’map’crs valid crs stringanimate if multiple times,if TRUE will animate the mapscumulative makes cumulative animation of dataname name for colorbar labelmaxpixels maximum number of pixels to use in making the map-controls resolution Valuea’plotdap’plotExamples##example code to download data for plotBBox##dataInfo<-rerddap::info( erdMBsstd1day )##parameter<- sst##xcoord<-c(230,230.1)##ycoord<-c(33,33.1)##tcoord<-c( 2006-01-15 , 2006-01-15 )##zcoord<-c(0.,0.)##MBsst<-rxtracto_3D(dataInfo,parameter,xcoord=xcoord,ycoord=ycoord,##tcoord=tcoord,zcoord=zcoord)####low resolution selected to keep time to render down#suppressWarnings(p<-plotBBox(MBsst,maxpixels=50))plotTrack plot result of’rxtracto’DescriptionplotTrack is a function to plot the results from’rxtracto()’UsageplotTrack(resp,xcoord,ycoord,tcoord,plotColor="viridis",myFunc=NA,mapData=NULL,crs=NULL,animate=FALSE,cumulative=FALSE,name=NA,shape=20,size=0.5)Argumentsresp data frame returned from’rxtracto()’xcoord passed to’rxtracto()’ycoord passed to’rxtracto()’tcoord passed to’rxtracto()’plotColor the color to use in plot from’cmocean’myFunc function of one argument to transform the datamapData map data from’maps’or’mapdata’,must be of class’map’crs valid crs stringanimate if multiple times,if TRUE will animate the mapscumulative makes cumulative animation of dataname name for colorbar labelshape shape to use to mark tracksize size of shape to use to mark trackValuea’plotdap’plotExamples##example data download for plotTrack##tagData<-Marlintag38606##xpos<-tagData$lon[1:20]##ypos<-tagData$lat[1:20]##tpos<-tagData$date[1:20]##zpos<-rep(0.,length(xpos))##example data download for plotTrack##swchlInfo<-rerddap::info( erdSWchla8day )##scwchl<-rxtracto(swchlInfo,parameter= chlorophyll ,xcoord=xpos,##ycoord=ypos,tcoord=tpos,zcoord=zpos,xlen=.2,ylen=.2) ###suppressWarnings(p<-plotTrack(swchl,xpos,ypos,tpos,plotColor= algae ))rxtracto Extract environmental data along a trajectory from an’ERDDAP’server using’rerddap’.Descriptionrxtracto_new uses the R program’rerddap’to extract environmental data from an’ERDDAP’server along a(x,y,z,time)trajectory.Usagerxtracto(dataInfo,parameter=NULL,xcoord=NULL,ycoord=NULL,zcoord=NULL,tcoord=NULL,xlen=0,ylen=0,zlen=0,xName="longitude",yName="latitude",zName="altitude",tName="time",interp=NULL,verbose=FALSE,progress_bar=FALSE)ArgumentsdataInfo-the return from an’rerddap::info’call to an’ERDDAP’serverparameter-character string containing the name of the parameter to extractxcoord-a real array with the x-coordinates of the trajectory(if longitude in#’decimal degrees East,either0-360or-180to180)ycoord-a real array with the y-coordinate of the trajectory(if latitude in decimal de-grees N;-90to90)zcoord-a real array with the z-coordinate of the trajectory(usually altitude or depth) tcoord-a character array with the times of the trajectory in"YYYY-MM-DD"-for now restricted to be time.xlen-real array defining the longitude box around the given point(xlen/2around the point)ylen-real array defining the latitude box around the given point(ylen/2around the point)zlen-real array defining the depth or altitude box around the given point(zlen/2 around the point)xName-character string with name of the xcoord in the’ERDDAP’dataset(default "longitude")yName-character string with name of the ycoord in the’ERDDAP’dataset(default "latitude")zName-character string with name of the zcoord in the’ERDDAP’dataset(default "altitude")tName-character string with name of the tcoord in the’ERDDAP’dataset(default "time")interp-array(size2)of character strings-c(interpolation type,neighborhood)Uses the new ERDDAP interpoation option to get values See Vignette for details De-fault is Null,do not use the interpolation optionverbose-logical variable(default FALSE)if the the URL request should be verbose progress_bar-logical variable(default FALSE)should a progress bar be displayedValueIf success a dataframe containing:•column1=mean of data within search radius•column2=standard deviation of data within search radius•column3=number of points found within search radius•column4=time of returned value•column5=min longitude of call(decimal degrees)•column6=max longitude of call(decimal degrees)•column7=min latitude of call(decimal degrees)•column8=max latitude of call(decimal degrees)•column9=requested time in tag•column10=median of data within search radius•column11=median absolute deviation of data within search radiuselse an error stringExamples##toy example to show use##but keep execution time down###dataInfo<-rerddap::info( erdHadISST )##parameter<- sstxcoord<-c(-130.5)ycoord<-c(40.5)tcoord<-c( 2006-01-16 )#extract<-rxtracto(dataInfo,parameter=parameter,xcoord=xcoord,#ycoord=ycoord,tcoord=tcoord#)####bathymetry example##2-D example getting bathymetrydataInfo<-rerddap::info( etopo360 )parameter<- altitude#extract<-rxtracto(dataInfo,parameter,xcoord=xcoord,ycoord=ycoord)rxtractogon Extract environmental data in a polygon using’ERDDAP’and’rerd-dap’.Descriptionrxtractogon uses the R program’rerddap’to extract environmental data from an’ERDDAP’server in a polygon through time.Usagerxtractogon(dataInfo,parameter,xcoord=NULL,ycoord=NULL,zcoord=NULL,tcoord=NULL,xName="longitude",yName="latitude",zName="altitude",tName="time",verbose=FALSE,cache_remove=TRUE)ArgumentsdataInfo-the return from an’rerddap:info’call to an’ERDDAP’serverparameter-character string containing the name of the parameter to extractxcoord-array giving longitudes(in decimal degrees East,either0-360or-180to180) of polygonycoord-array giving latitudes(in decimal degrees N;-90to90)of polygonzcoord-a real number with the z-coordinate(usually altitude or depth)tcoord-2-array of minimum and maximum times as’YYYY-MM-DD’xName-character string with name of the xcoord in the’ERDDAP’dataset(default "longitude")yName-character string with name of the ycoord in the’ERDDAP’dataset(default "latitude")zName-character string with name of the zcoord in the’ERDDAP’dataset(default "altitude")tName-character string with name of the tcoord in the’ERDDAP’dataset(default "time")verbose-logical variable(default FALSE)if the the URL request should be verbose cache_remove-logical variable(default TRUE)whether to delete’rerddap’cacheValueIf successful a structure with data and dimensions•extract$data-the masked data array dimensioned(lon,lat,time)•extract$varname-the name of the parameter extracted•extract$datasetname-ERDDAP dataset name•extract$longitude-the longitudes on some scale as request•extract$latitude-the latitudes always going south to north•extract$time-the times of the extractselse an error stringDetailsrxtractogon extracts the data from the smallest bounding box that contains the polygon,and then uses the function"point.in.polygon"from the"sp"package to mask out the areas outside of the polygon.rxtractogon only works with datasets defined on a latitude and longitude grid.Examples##toy example to show use##and keep execution time low#dataInfo<-rerddap::info( erdHadISST )parameter<- ssttcoord<-c("2016-06-15")xcoord<-mbnms$Longitude[1:3]ycoord<-mbnms$Latitude[1:3]#sanctSST<-rxtractogon(dataInfo,parameter=parameter,xcoord=xcoord,#ycoord=ycoord,tcoord=tcoord)###MBMS bathymetry examplexcoord<-mbnms$Longitudeycoord<-mbnms$LatitudedataInfo<-rerddap::info( etopo180 )parameter= altitudexName<- longitudeyName<- latitude#bathy<-rxtractogon(dataInfo,parameter=parameter,xcoord=xcoord,ycoord=ycoord)rxtracto_3D11rxtracto_3D Extract environmental data in a3-dimensional box from an’ERDDAP’server using’rerddap’.Descriptionrxtracto_3D uses the R program’rerddap’to extract environmental data from an’ERDDAP’server in an(x,y,z,time)bounding box.The same call could be made directly in rerddap,but function is maintained as it is used in the polygon routine.Usagerxtracto_3D(dataInfo,parameter=NULL,xcoord=NULL,ycoord=NULL,zcoord=NULL,tcoord=NULL,xName="longitude",yName="latitude",zName="altitude",tName="time",verbose=FALSE,cache_remove=TRUE)ArgumentsdataInfo-the return from an’rerddap:info’call to an’ERDDAP’serverparameter-character string containing the name of the parameter to extractxcoord-a real array with the x-coordinates of the trajectory(if longitude in#’decimal degrees East,either0-360or-180to180)ycoord-a real array with the y-coordinate of the trajectory(if latitude in decimal de-grees N;-90to90)zcoord-a real array with the z-coordinate(usually altitude or depth)tcoord-a character array with the times of the trajectory in"YYYY-MM-DD"-for now restricted to be time.xName-character string with name of the xcoord in the’ERDDAP’dataset(default "longitude")yName-character string with name of the ycoord in the’ERDDAP’dataset(default "latitude")zName-character string with name of the zcoord in the’ERDDAP’dataset(default "altitude")12swchltName-character string with name of the tcoord in the’ERDDAP’dataset(default "time")verbose-logical variable(default FALSE)if the the URL request should be verbose cache_remove-logical variable(default TRUE)whether to delete’rerddap’cacheValueIf successful a structure with data and dimensions:•extract$data-the data array dimensioned(lon,lat,time)•extract$varname-the name of the parameter extracted•extract$datasetname-ERDDAP dataset name•extract$longitude-the longitudes on some scale as request•extract$latitude-the latitudes always going south to north•extract$time-the times of the extractselse an error stringExamples##toy example to show use##and keep execution time low###dataInfo<-rerddap::info( erdHadISST )parameter<- sstxcoord<-c(-130.5,-130.5)ycoord<-c(40.5,40.5)tcoord<-c( 2006-01-16 , 2006-01-16 )#extract<-rxtracto_3D(dataInfo,parameter,xcoord=xcoord,ycoord=ycoord,#tcoord=tcoord)##bathymetry example##2-D example getting bathymetrydataInfo<-rerddap::info( etopo360 )parameter<- altitude#extract<-rxtracto_3D(dataInfo,parameter,xcoord=xcoord,ycoord=ycoord)swchl swchl DataDescriptionpre-Download of Pacific West Coast SST fro use in‘plotTrack()‘example can run within CRAN Time limitsUsageswchltidy_grid13FormatAn object of class list(inherits from rxtractoTrack)of length13.Detailsobtained using the‘rxtracto()‘command tagData<-Marlintag38606xpos<-tagData$lon[1:20] ypos<-tagData$lat[1:20]tpos<-tagData$date[1:20]tpos<-tagData$date[1:20]zpos<-rep(0., length(xpos))swchlInfo<-rerddap::info(’erdSWchla8day’)swchl<-rxtracto(swchlInfo,parameter =’chlorophyll’,xcoord=xpos,ycoord=ypos,tcoord=tpos,zcoord=zpos,xlen=.2,ylen=.2) tidy_grid convert result of’rxtracto_3D’or’rxtractogon’to tidy long-formatDescriptiontidy_grid is a function to convert result of’rxtracto_3D’or’rxtractogon’to"tidy"long-formatUsagetidy_grid(response)Argumentsresponse data frame returned from’rxtracto_3D’()’or’rxtractogon()’Valuea dataframe in long-formatExamplesMBsst_tidy<-tidy_grid(MBsst)Index∗datasetsdataInfo,2Marlintag38606,2mbnms,3MBsst,4swchl,12dataInfo,2Marlintag38606,2mbnms,3MBsst,4plotBBox,4plotTrack,5rxtracto,7rxtracto_3D,11rxtractogon,9swchl,12tidy_grid,1314。
RRDtool 的前期规划RRDtool 的前期规划相对多一点,因为RRDtool 很多东西需要自己设定。
除了上述MRTG 考虑的几点之外,我一般还考虑以下几点:A)是一个RRD 文件中包括多个监测对象(DS),还是分成多个RRD 文件?RRDtool 提供了tune 操作,可以增加监测对象或者删除RRD 文件中的某个对象,而且绘图时也可以指定要画的是那个对象,这点看个人喜欢而定。
B)如何统计取得的数据:MRTG 是固定的,5分钟、20分钟、2小时、1天。
RRDtool 则可以自己设置C)如何保存/统计这些数据:这是和MRTG 不同的地方。
MRTG log 的建立和维护是自动的,RRDtool 的数据存放则需要自己定义。
但我们可以参照MRTG 的方式:每日统计图(5分钟平均):600 个,大约2天的时间每周统计图(20分钟平均):600 个,大约8天的时间每月统计图(2小时平均):600 个,50 天的时间每年统计图(1天平均):730 个,2年的时间D 要以什么方式绘图:MRTG 只有曲线(LINE)和方块(AREA)两种;RRDtool 除了这两种外,还有一种是STACK 方式。
就是在前一个曲线或者方块的基础上绘图图,而不是直接从X 轴开始绘图。
这样绘制出来的图比较清晰,不会出现交叉的现象,但此时Y 轴的值等于当前对象的值加上前一个绘图对象的值。
例如前一个对象(cpu 的系统进程利用率)的值是10,采用的是AREA 方式绘图。
当前对象(cpu 的用户级进程的利用率)是5,采用的是STACK 方式,则―cpu的用户级进程利用率‖对应的Y轴刻度是10+5=15;所以如果不加说明,别人可能会误解。
三)实际例子A)搞清楚究竟想要监测什么对象:监测本地主机的网络流量。
包括eth0 和lo 接口的流量。
B)想要以什么方法来取得数据:sar 也可以统计网卡接口的流量。
但这里我们用SNMP ,访问ifInOctets 和ifOutOctets 。
数据抓取是数据处理的重要环节,它是指从各种数据源中提取所需数据的过程。
对于许多数据处理任务来说,数据抓取是关键的第一步,而且数据抓取的质量和效率对后续的数据处理和分析工作有着重要影响。
本文将从数据抓取的目的、方法和技巧等方面进行探讨。
一、数据抓取的目的数据抓取的目的是为了获取所需的数据,供后续的数据处理和分析使用。
在进行数据抓取之前,我们需要明确所需数据的来源和类型,以及数据的格式和结构。
有了明确的目标,我们才能有针对性地进行数据抓取,找到正确的数据源和适合的抓取方法。
二、数据抓取的方法数据抓取的方法有多种,常见的包括爬虫、API接口、数据库查询等。
其中,爬虫是一种常用的数据抓取方法,它通过模拟浏览器行为,访问网页并提取网页内容中的数据。
爬虫的基本原理是通过发送HTTP请求获取网页内容,然后通过解析网页内容提取所需的数据。
在进行爬虫抓取时,我们需要选择合适的爬虫框架和工具。
常用的爬虫框架包括Scrapy、BeautifulSoup等,它们提供了丰富的功能和工具,方便我们进行数据抓取和处理。
在选择框架和工具时,需要考虑需求的复杂度、数据的规模和实时性等因素。
除了爬虫之外,API接口也是常用的数据抓取方法。
很多网站和服务提供了API接口,通过调用API接口可以方便地获取所需数据。
使用API接口进行数据抓取的好处是可以获得结构化的数据,减少数据清洗和处理的工作量。
但是在使用API接口时,我们需要了解接口的调用方式和限制条件,以及可能产生的费用等情况。
数据库查询是另一种常见的数据抓取方法,它适用于数据存储在数据库中的情况。
通过编写查询语句,我们可以从数据库中提取所需的数据。
数据库查询的好处是可以高效地获取大量数据,同时可以进行复杂的数据过滤和排序操作。
但是需要注意的是,在进行数据库查询时,我们需要了解数据库的结构和查询语言,以及有关权限和性能的考虑。
三、数据抓取的技巧数据抓取的效果和效率往往依赖于一些技巧和经验。
数据透析表中的数据导入和导出方法在数据分析和处理的过程中,数据导入和导出是非常重要的环节。
数据透析表中的数据导入和导出方法是确保数据准确性和保密性的关键步骤。
本文将介绍如何有效地导入和导出数据,以及如何保护数据的安全性。
一、数据导入方法在数据透析表中,数据导入是将外部数据导入到表中的操作。
以下是几种常见的数据导入方法:1. 手工输入数据手工输入数据是最常见的数据导入方法。
通过在透析表中逐个单元格输入数据,可以确保数据的准确性。
然而,这种方法对于大量数据来说非常耗时且容易出错。
2. 复制和粘贴数据复制和粘贴数据是一种比手工输入更快速的方法。
首先,在外部数据源中选择需要导入的数据,然后将其复制到剪贴板中。
接下来,将数据粘贴到透析表的相应单元格中。
这种方法适用于少量数据的导入,但对于大规模数据来说仍然不够高效。
3. 导入外部文件将外部文件导入到透析表中是处理大规模数据的最佳选择。
常见的外部文件包括CSV(逗号分隔值)文件、Excel文件和文本文件。
透析表软件通常提供了导入选项,使用户能够选择相应的文件并将其导入到表中。
这种方法可以节省大量时间并减少错误的发生。
二、数据导出方法数据导出是将透析表中的数据导出到外部文件或其他应用程序的过程。
1. 导出为外部文件透析表软件通常提供了将数据导出为常见文件格式的选项,如CSV、Excel和文本文件。
用户只需选择所需的数据范围和导出格式,即可将数据保存到外部文件中。
这样,用户可以方便地与其他应用程序共享数据,如电子邮件、数据库软件等。
2. 复制和粘贴数据类似于数据导入方法中的复制和粘贴数据,用户可以将透析表中的数据复制到剪贴板中,然后粘贴到其他应用程序中。
这种方法适用于少量数据的导出,但对于大量数据来说不够高效。
三、数据安全性保护保护数据的安全性是非常重要的,特别是涉及敏感信息的数据透析表。
以下是几种保护数据安全性的方法:1. 密码保护透析表软件通常提供了密码保护的选项,用户可以设置一个密码来限制对透析表的访问。
RRDtool系列连载-5:查询RRD数据库信息-RRDtool-阿勃的blogRRDtool 系列连载-5 :查询 RRD 数据库信息一)前言可能你已经颇不亟待的想知道如何往RRD 文件插入数据、如何绘图了吧?hoho,先别急,在你做这些事情之前,最好先思考以下几个问题:A)如果给你一个RRD 文件,你能知道它的第一次/最后一次 update 的时间是在什么时候吗?B)如果你很久之前建立了一个 RRD 文件,现在因为工作原因需要对该 RRD 文件进行一些修改。
不过遗憾的是,你已经不记得得当初设置的具体选项和参数了,这时候该怎么办呢?这两个问题就对应今天要讲的两个操作:first/last 、info 。
first 就是用于查看该 RRD 文件中某个 RRA 的第一个数据是在什么时候插入的(或者说第一次更新);last 就是查看该 RRD 文件的最近一次更新;info就是查看 rrd 文件的结构信息。
下面就以实际例子来看一下该怎么用这三个命令:二)如何查询一个 RRD 文件的结构信息[Copy to clipboard][ - ]CODE:[root@dns1 bob]# rrdtool info eth0.rrd (由于输出信息较多,截取了一部分)filename = "eth0.rrd"rrd_version = "0003"step = 300 # RRDtool 希望每5分钟收到一个数据last_update = 1163862985 # 这是最近一次更新的 timestamp 。
可以用 date 转换为具体的时间ds[eth0_in].type = "COUNTER" # 有一个名为eth0_in 的 DS,DST是 COUNTERds[eth0_in].minimal_heartbeat = 600 # hearbeat 时间是600 秒ds[eth0_in].min = 0.0000000000e+00 # eth0_in 的最小值是 0 (bytes)ds[eth0_in].max = 1.2500000000e+07 # eth0_in 的最大值是 1250000000 (bytes)ds[eth0_in].last_ds = "UNKN"ds[eth0_in].value = 0.0000000000e+00ds[eth0_in].unknown_sec = 85ds[eth0_out].type = "COUNTER"ds[eth0_out].minimal_heartbeat = 600ds[eth0_out].min = 0.0000000000e+00ds[eth0_out].max = 1.2500000000e+07ds[eth0_out].last_ds = "UNKN"ds[eth0_out].value = 0.0000000000e+00ds[eth0_out].unknown_sec = 85rra[0].cf = "AVERAGE" # 第一个 RRA 的编号是0,不是1。
RRDtool是什么在Linux如何使用RRDtool是指Round Robin Database工具,即环状数据库。
从功能上说,RRDtool可用于数据存储+数据展示。
著名的网络流量绘图软件MRTG和集群监控系统Ganglia都使用的RRDtool,那么在Linux上要如何使用RRDtool呢?下面小编就给大家介绍下Linux使用RRDtool的方法,一起来学习下吧。
一、简介数据存储方面,RRDtool采用“Round Robin”模式存储数据。
所谓“Round Robin”是一种存储数据的方式,使用固定大小的空间来存储数据,并有指针指向最新的数据的位置。
我们可以把用于存储数据的数据库空间看成一个圆,上面有很多刻度,这些刻度所在的位置就代表用于存储数据的地方。
所谓指针,可以认为是从圆心指向这些刻度的一条线。
指针会随着数据的读写自动移动。
要注意的是,这个圆没有起点和终点,所以指针可以一直移动,而不担心到达终点后无法继续写入的问题。
在一段时间后,当所有的空间都存满数据,就又从头开始存放。
这样整个存储空间的大小就是一个固定的数值。
RRDtool所使用数据库文件的后缀名是“.rrd”。
数据展示方面,RRDtool可以看作是一个强大的绘图引擎。
下图是其官网上的一张效果图,我们大致了解RRDtool的绘图能力。
二、基本语法RRDtool的使用分为三个部分,建库、更新数据、绘图(具体使用shell命令)。
因此,我们也分上述三个部分介绍基本语法。
1、建库为表述清晰,这里将建库命令写成分段形式,实际应用时应写成一串。
rrdtool create cpu.rrd # 数据库名称--start $(date -d ‘1 days ago’ +%s) # 开始时间--step 15 # 更新数据时间间隔DS:cpu_user:GAUGE:120:0:NaN # DS:cpu_user,相当于变量名;后面的是DST:GAUGE,相当于数据类型;后面120是heartbeat,是最大没有数据的间隔;后面两个NaN分别是最小值、最大值限制。
RRDTool 中文手册-简易入门一、简介RRDtool是由Tobias Oetiker 编写并由全球各地的许多人贡献的工具。
本篇文档的作者是Alex van den Bogaerdt主要是帮助你理解RRDtool是什么,它能够帮助你作些什么。
RRDtool的文档对于有些人来说过于技术化。
本教程帮助你理解RRDtool的基本概念。
它为你自学RRDtool的文档做好准备。
本文档还重点介绍了网络统计方面的知识。
1、RRDtool是什么东西?RRDtool是指Round Robin Database 工具(环状数据库)。
Roundrobin是一种处理定量数据、以及当前元素指针的技术。
想象一个周边标有点的圆环--这些点就是时间存储的位置。
从圆心画一条到圆周的某个点的箭头--这就是指针。
就像我们在一个圆环上一样,没有起点和终点,你可以一直往下走下去。
过来一段时间,所有可用的位置都会被用过,该循环过程会自动重用原来的位置。
这样,数据集不会增大,并且不需要维护。
RRDtool处理RRD数据库。
它用向RRD数据库存储数据、从RRD数据库中提取数据。
2、RRD中可以存放什么样的数据?可以适合时间序列的数据。
就是说你必须能够在时间的几个点上度量某些值,并提供这些信息给RRDtool。
如果你能够做到这一点,RRDtool就能够存储它们。
这些数值必须是数字,但是不一定要是整数,在与MRTG合用时。
(下一节会给出更详细的介绍)。
下面的例子是关于SNMP的,SNMP是简单网络过来协议的缩写。
简单是指协议简单--并不表示管理或监视网络简单。
读完本篇文档后,你应当能够对人们谈论的SNMP的东西有更多的理解。
现在,只要知道SNMP可以用来查询设备中保持的计数器的值就可以了。
我们要存放到RRD数据库中的正是这些计数器中的数值。
3、RRDtool可以用来干什么?RRDtool源自MRTG(多路由器流量绘图器)。
MRTG是有一个大学连接到互联网链路的使用率的小脚本开始的。
RRDtool 系列连载-6 :如何从RRD 数据库中提取数据-RRDtool - 阿勃的blogRRDtool 系列连载-6 :如何从RRD 数据库中提取数据一)前言RRD 是Round Robin Database 的意思,那么是否可以象普通的数据库进行查询操作呢?答案是可以的。
fetch 就是用来做这种事情的工具。
当然fetch 不能和select 语句相比,它只是根据用户指定的时间,从合适的RRA 中取出数据,并加以格式化。
不过和MRTG 相比,已经好很多了,至少你不用取看该死的log 文件。
实际上,fetch 操作其实可以不学,因为RRDtool 会自动帮你选好数据。
但你如何确定RRDtool 取的数据就是你想要的呢?或者说你如何证明RRDtool 绘制出来的图是正确的呢?废话少说,下面开始正文二)fetch 操作的语法[Copy to clipboard] [ - ] CODE:rrdtool fetch filename CF [--resolution|-r resolution][--start|-s start] [--end|-e end]其中--start、--end、-r 都是可选的。
RRDtool 默认的--end 是now ,--start 是end-1day ,也就是1天前。
CF 可以是AVERAGE、MAX、MIN、LAST ,当然必须建库时有该CF 类型的RRA 才可以查,否则会报错。
三)fetch 如何取数据在确定了时间范围后,RRDtool 会从多个RRA 中挑选最佳的那个RRA 的数据。
至于什么是“最佳”,则从两个方面考虑:A)第一是该RRA 的数据要尽可能的覆盖所请求的时间范围。
如何计算一个RRA 的覆盖时间呢?以eth0.rrd 的第一个RRA 为例,有600 个记录,每个记录相隔300秒,则总的时间覆盖范围是180000 秒≈2天,所以如果–-start 和-–end 规定的时间范围大于2天,则RRDtool 不会从该RRA 中取数据。
B)第二是resolution 的要求。
还是上面的例子,如果是要画3天的数据,从时间覆盖范围上来讲,第2、3、4 个RRA 都符合要求。
那究竟挑选那个RRA 的数据呢?如果fetch 中有指定–r 选项,则挑选resolution 等于–r 指定的值那个RRA 的数据。
如果没有–r 选项,则从第一个合适的RRA 中取数据。
C)fetch 如果不加–-start、--end、-r ,则默认输出resolution 最小的那个RRA 的数据。
就像下面的例子1一样。
四)实际例子实例一:默认情况[Copy to clipboard] [ - ] CODE:[root@dns1 bob]# rrdtool fetch eth0.rrd AVERAGE |moreeth0_ineth0_out1164467700: 1.1337243905e+019.6323712631e-021164468000: 1.7896453039e+01 0.0000000000e+00 1164468300: 1.8469136234e+01 1.2215723119e+00 。
(中间省略)1164553800: 6.9634610564e+01 4.9644415243e+011164554100: nan nan[Copy to clipboard] [ - ]CODE:[root@dns1 bob]# date (当前时间)日11月26 23:11:12 CST 2006[root@dns1 bob]# date -d '1970-1-1 1164554100 sec utc' (最后一个记录的时间)日11月26 23:15:00 CST 2006[root@dns1 bob]#[root@dns1 bob]# date -d '1970-1-1 1164467700 sec utc' (第一个记录的时间)六11月25 23:15:00 CST 2006[root@dns1 bob]#fetch 输出的第一列是timestamp ,表示后面的数据是在什么时间收到的。
”:” 后面就是DS的值。
fetch 不能指定只取那个DS 的数据,只能一次性取出全部DS 的值。
可以看到,eth0.rrd 有两个DS :eth0_in 和eth0_out ,每个DS 的值用空格进行分隔,一律采用科学记数法的格式。
如果fetch 不指定–-start 和-–end ,则默认取从当前时刻算起,往前1天的数据(289个记录)。
因为现在是23:11 ,还不到23:15,所以最后一个记录的值是NaN (Not a Number),也就是UNKNOWN 的意思。
可以看到,两个记录之间的时间间隔是300。
实例二:使用--start 和--end 指定时间范围[Copy to clipboard] [ - ]CODE:[root@dns1 bob]# rrdtool fetch eth0.rrd AVERAGE --start 1164467700 --end 1164553800 |moreeth0_ineth0_out1164468000: 1.7896453039e+010.0000000000e+001164468300: 1.8469136234e+01 1.2215723119e+001164468600: 1.5988336199e+01 1.4417769382e-01。
(中间省略很多)1164553800: 6.9634610564e+01 4.9644415243e+011164554100: 1.7481962958e+02 2.3086574912e+02[root@dns1 bob]#可以看到第一个记录和最后一个记录都比–-start 和–-end 晚了300秒。
实例三:使用AT风格的时间[Copy to clipboard] [ - ][root@dns1 bob]# rrdtool fetch eth0.rrd AVERAGE --start end-1day --end 1164553800 |moreeth0_ineth0_out1164467700: 1.1337243905e+019.6323712631e-021164468000: 1.7896453039e+01 0.0000000000e+00。
(中间省略很多)1164554100: 1.7481962958e+02 2.3086574912e+02[root@dns1 bob]#注意--start 的值是end-1day ,这就是AT风格的时间。
end 就是--end 中给出的1164553800 。
具体的时间范围是表示起始时间从1164553800 往前1天。
可以看到,现在第一个记录和实例二相比,提前了300秒。
和例2中的–start 一致了。
所以能够用AT风格的时间的时候还是用AT 风格的时间比较方便。
可以省去计算的麻烦,别人也比较容易看。
实例四:提取指定resolution 的数据[Copy to clipboard] [ - ][root@dns1 bob]# rrdtool fetch eth0.rrd AVERAGE --start 1164467700 --end start+1day -r 1200 |moreeth0_ineth0_out1164468000: 1.7899370295e+013.8782610300e+001164469200: 2.0828335735e+01 3.4166666667e-011164470400: 1.4581351504e+01 3.5000000000e-02。
(中间省略很多)1164554400: 9.4367707174e+01 9.4866775629e+01[root@dns1 bob]可以看到,现在记录两两之间的时间间隔变成了1200 了。
输出的行数为(86400/1200)+1=73 (72+1)。
实例五:如果指定一个不存在的resolution 呢?[Copy to clipboard] [ - ]CODE:[root@dns1 bob]# rrdtool fetch eth0.rrd AVERAGE --start1164467700 --end start+1day -r 1000 |moreeth0_ineth0_out1164468000: 1.7899370295e+013.8782610300e+001164469200: 2.0828335735e+01 3.4166666667e-01 。
(中间省略很多)1164554400: 9.4367707174e+01 9.4866775629e+01[root@dns1 bob]#我们指定的resolution 是1000 ,但并没有那个RRA 的resolution 为1000,所以RRDtool 挑选了第一个合适的resolution ,也就是1200 的那个RRA 的数据作为结果输出。
注意,RRDtool 只会挑选resolution 比–r 指定的值相等或者更高的RRA ,不会挑选比–r 指定的值小的RRA 。
例如在该例子中,RRDtool 就不会挑选resolution=300 的第一个RRA 。
为什么呢?各位可以自己根据第三部分“fetch 如何提取数据”的两个准则考虑一下实例六:再来看一个–r 的例子如果我不想指定–-start 或者–end ,就想看resolution 为1200 呢?[Copy to clipboard] [ - ]CODE:[root@dns1 bob]# rrdtool fetch eth0.rrd AVERAGE -r 1200eth0_ineth0_out1164470400: 1.4581351504e+013.5000000000e-021164471600: 1.9312781373e+01 3.5000000000e-02 。