【Graphite】使用dropwizard.metrics向Graphite中写入指标项数据
graphite
定时向Graphite中写入指标项数据,指标项模拟个数3000个
使用的类库
官方文档
dropwizard的github地址
Metric官方文档
metrics.dropwizard的GitHub地址
<dependency>
<groupId>io.dropwizard.metrics</groupId>
<artifactId>metrics-core</artifactId>
<version>${dropwizard.metrics.version}</version>
</dependency>
<dependency>
<groupId>io.dropwizard.metrics</groupId>
<artifactId>metrics-graphite</artifactId>
<version>${dropwizard.metrics.version}</version>
</dependency>
核心代码详解
配置Graphite地址
指定Graphite的host和port,默认时,Graphite中的carbon使用2003端口接收数据;
Graphite graphite = new Graphite(new InetSocketAddress("10.144.202.150", 2003));
模拟3000个指标项
每个指标项都有一个uuid,3000个uuid代表3000个不同的指标项
final List<String> uuids = Lists.newArrayList();
{
for (int i = 1000; i < 4000; i++) {
String uuid = "aaa" + i + "";
uuids.add(uuid);
}
}
定义Gauge指标
dropwizard.metrics支持5种指标类型,分别为:
- Gauge
- Counter
- Meter
- Histograms
- Timers
我们这里定义Gauge指标,需要实现Gauge接口;
使用metricValue(uuid)方法模拟每个指标项的当前值
/**
* Gauge指标
*/
class GaugeImp implements Gauge<Float> {
String uuid;
public GaugeImp(String uuid) {
this.uuid = uuid;
}
@Override
public Float getValue() {
return metricValue(uuid);
}
}
/**
* 用于模拟指标值
*
* @param uuid
* @return
*/
private float metricValue(String uuid) {
Random random = new Random();
float value = random.nextFloat();
return value;
}
向Graphite中写入指标项
- 注册一个MetricRegistry:所有的指标项metrics都存在在MetricRegistry中;
- 注册所有需要写入的指标项:这里写入3000个Gauge指标;
- 使用GraphiteReporter实现向Graphite写入数据:A reporter which publishes metric values to a Graphite server.
- 开始定时任务,每隔5s中向Graphite中写入一次数据;
MetricRegistry registry = new MetricRegistry();
// 注册 gauge 指标
for (String uuid : uuids) {
String name = "resource." + uuid + ".size";
registry.register(name, new GaugeImp(uuid));
}
//A reporter which publishes metric values to a Graphite server.
GraphiteReporter reporter = GraphiteReporter.forRegistry(registry)
.prefixedWith("openmetric")
.convertRatesTo(TimeUnit.SECONDS)
.convertDurationsTo(TimeUnit.MILLISECONDS)
.filter(MetricFilter.ALL)
.build(graphite);
// 设置每隔5秒钟,向Graphite中发送一次指标值
reporter.start(5, TimeUnit.SECONDS);
写入结果截图



完整程序
【Graphite】使用dropwizard.metrics向Graphite中写入指标项数据的更多相关文章
- MO拆分计划行程序中写入PRODUCTIONORDERS表数据出现重复导致报错(BUG)20180502
错误提示:ORA-00001: 违反唯一约束条件 (ABPPMGR.C0248833319_6192)ORA-06512: 在 "STG.FP_MO_SPLIT", line 19 ...
- 我们知道写入过程比ZooKeeper集合中的读取过程要贵,因为所有节点都需要在数据库中写入相同的数据。因此,对于平衡的环境拥有较少数量(例如3,5,7)的节点比拥有大量的节点要好。
我们知道写入过程比ZooKeeper集合中的读取过程要贵,因为所有节点都需要在数据库中写入相同的数据.因此,对于平衡的环境拥有较少数量(例如3,5,7)的节点比拥有大量的节点要好. 组件 描述 写入( ...
- Python 使用 xlwings 往 excel中写入一列数据的两种方法
1.准备一个二维列表,然后再range后面不指定任何选项,可以输出该二维列表中数据在一列中显示,如下代码: # -*- coding:utf-8 -*- import xlwings as xw li ...
- 通过java代码往mysql数据库中写入日期相关数据少13个小时
通过show variables like '%time_zone%'; 查看时区: CST 时区 名为 CST 的时区是一个很混乱的时区,有四种含义: 美国中部时间 Central Standard ...
- VS中添加新项 数据选项卡下没有ADO.NET实体数据模型解决方案
第一种:C:\ProgramData下面搜索EFTools找到你vs对应版本的EFTools.msi 先remove 然后再Install 重启电脑再看 第二种:如果意外地删除了 Visual Stu ...
- List<Map>中根据map的同一指标项数据——去重代码
先看网络上,博客经常出现的错误代码: for(ABatchAddCheckVO aBatchAddCheckVO : addList){ dto.put("aac001",aBat ...
- WinForms_ListView中获取选中项数据值
string value = listList.SelectedItems[0].SubItems[1].Text;//获取首行listview的值 string va = listList.Sele ...
- 服务监控 | 彻底搞懂Dropwizard Metrics一篇就够了
Metrics是一个提供服务性能检测工具的Java类库,它提供了功能强大的性能指标工具库用于度量生产环境中的各关键组件性能. 度量类型 Metrics提供了以下几种基本的度量类型: Gauge:用于提 ...
- 通过I2C总线向EEPROM中写入数据,记录开机次数
没买板子之前,用protues画过电路图,实现了通过i2c总线向EEPROM中写入和读出数据. 今天,在自己买的板子上面写关于i2c总线的程序,有个地方忘了延时,调程序的时候很蛋疼.下面说说我对I2c ...
随机推荐
- Sping boot 之 @Value("${xxx}") 注解获取配置文件内容
1.注解方式读取 1-1.@PropertySource配置文件路径设置,在类上添加注解,如果在默认路径下可以不添加该注解. 需要用@PropertySource的有: 例如非application. ...
- MySQL用户管理、常用sql语句、MySQL数据库备份恢复
1.MySQL用户管理 给远程登陆用户授权:grant all on *.* to 'user1'@'127.0.0.1' identified by '123456' (这里的127.0.0.1是指 ...
- python django day 5 database 1
from django.db import models class Blog(models.Model): name = models.CharField(max_length=) tagline ...
- Vue v-text和v-html的区别
v-text和v-html的区别 v-text:会把html的标签输出 v-html:不会把html的标签输出 比如: <template> <div id="app&qu ...
- mysql的utf8与utf8mb4 异同;utf8mb4_unicode_ci 与 utf8mb4_general_ci 如何选择
如图,一般使用如下配置 utf8mb4是4个字节.utf8是3个字节.utf8mb4兼容性更好,占用空间更大. 主要从排序准确性和性能两方面看: 准确性utf8mb4_unicode_ci 是基于标准 ...
- SpringCloud学习
1.SpringCloud的参考博客1 首先主要遇到的问题就是1.写好项目然后放到tomcat或者其他的容器中,然后稍微一点修改就要整个项目重新发布,非常麻烦,这就是微服务出现的契机了 基础知识 PS ...
- 企业库实现AOP的几种方法
1.创建新对象时,分继承基类和继承接口 TargetClass theTarget = PolicyInjection.Create<TargetClass>(parameter1, pa ...
- confluence 新tab 页面打开 kibana short link
confluence 新tab 页面打开 https://confluence.atlassian.com/confkb/how-to-force-links-to-open-in-a-new-win ...
- Android USB Host框架
Android 下的usb框架及功能点:https://blog.csdn.net/tianruxishui/article/details/379029591.Android framework中* ...
- sublime 安装插件出现问题
一. 解决package Install不能安装 If for some reason the console installation instructions do not work for ...