如何将spring boot metrics导出平均值和绝对值导出到csv

时间:2015-10-06 13:48:32

标签: spring-boot metrics codahale-metrics spring-boot-actuator

我需要将计数器和仪表导出到csv,以便稍后处理它们。通过使用gradle,我获得了codahale指标的罐子3.1.2:

LIKE '%$state%'  group by

对于csv导出,我使用以下代码行创建了一个记者:

let fileManager = NSFileManager.defaultManager()
    // We need just to get the documents folder url
    let documentsUrl = fileManager.URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)[0] as NSURL

    do { let directoryUrls = try NSFileManager.defaultManager().contentsOfDirectoryAtURL(documentsUrl, includingPropertiesForKeys: nil, options: NSDirectoryEnumerationOptions.SkipsSubdirectoryDescendants)
    } catch {
        let directoryUrls = documentsUrl
    }

    let video = AVAsset(URL: directoryUrls)
    let AVThumbnailAsset = AVAssetImageGenerator(asset: video)
    let time = CMTimeMakeWithSeconds(1.0, 1)
    var actualTime : CMTime = CMTimeMake(0, 0)
    let myImage: CGImage
    let convertedImage: UIImage

    do{
        myImage = try AVThumbnailAsset.copyCGImageAtTime(time, actualTime: &actualTime)
        convertedImage = UIImage.init(CGImage: myImage)

    } catch {
        print("This is the Error")
        print(error)
        convertedImage = UIImage(named: "2.35:1")!
    }


  videoThumb.image = convertedImage

我可以看到文件已创建,它们包含时间戳和值(在此示例中,为量表设置了值):

polymer

唯一的问题是文件会重复最后一个值,直到我使用webcomponents覆盖它。在这种情况下,我将标准值设置为References一次,等待几分钟,然后设置新值Angular2 & Polymer

这使得难以解析csv并自己创建平均值或创建直方图,因为我不知道compile('io.dropwizard.metrics:metrics-core:${metricsVersion}' ) compile('io.dropwizard.metrics:metrics-annotations:${metricsVersion}' ) 是否已提交一次或三次。

我看过这些SO帖子,但它们并没有帮助我解决我的问题:

1 个答案:

答案 0 :(得分:1)

所有这一切都是基于我方的误解:Spring Boot提供的指标只允许使用gaugecounters。两者都没有计算平均值。

为了访问我需要的东西,我必须获得对底层Codahale指标注册表的访问权限:

@Autowired
MetricRegistry metricRegistry;

然后我可以在我的代码中启动和停止计时器:

Context timer = metricRegistry.timer("foo").time();
// do whatever needs to be timed
timer.stop();

这些值将由CsvReporter导出到名为timer.foo.csv的文件中,该文件包含以下值:

t,count,max,mean,min,stddev,p50,p75,p95,p98,p99,p999,mean_rate,m1_rate,m5_rate,m15_rate,rate_unit,duration_unit
1446036738,5,18,597084,14,172184,12,832516,2,145484,13,280135,13,445525,18,597084,18,597084,18,597084,18,597084,0,215907,0,494353,0,577132,0,592274,calls/second,milliseconds
1446036798,5,18,597084,14,172184,12,832516,2,145484,13,280135,13,445525,18,597084,18,597084,18,597084,18,597084,0,060092,0,181862,0,472516,0,554077,calls/second,milliseconds
1446036858,5,18,597084,14,172184,12,832516,2,145484,13,280135,13,445525,18,597084,18,597084,18,597084,18,597084,0,034923,0,066903,0,386863,0,518343,calls/second,milliseconds
1446036918,5,18,597084,14,172184,12,832516,2,145484,13,280135,13,445525,18,597084,18,597084,18,597084,18,597084,0,024578,0,024612,0,316737,0,484913,calls/second,milliseconds