maven dependency
<dependency>
<groupId>com.volcengine</groupId>
<artifactId>apminsight-server-sdk-metrics</artifactId>
<version>{latest-version}</version>
</dependency>
see CODE EXAMPLE
MetricClient metricClient = MetricClientBuilder.newBuilder()
.unixDomainSocket(true)
.prefix("your application metric name common prefix")
.maxPacketBytes(8192)
.build();
metricClient.close();
//without tags
metricClient.emitCounter("example_counter_metric");
metricClient.emitCounter("example_counter_metric", 3);
metricClient.emitTimer("example_timer_metric", 200);
metricClient.emitTimer("example_timer_metric", 200, TimeUnit.MILLISECONDS);
metricClient.emitGauge("example_gauge_metric", 100);
//with tags
Map<String, String> tags = new HashMap<>();
tags.put("tagKey", "tagValue");
metricClient.emitCounter("example_counter_metric", tags);
metricClient.emitCounter("example_counter_metric", 3, tags);
metricClient.emitTimer("example_timer_metric", 200, tags);
metricClient.emitTimer("example_timer_metric", 200, TimeUnit.MILLISECONDS, tags);
metricClient.emitGauge("example_gauge_metric", 100, tags);
you can config client with MetricClientBuilder
,there are some config items available in MetricConfig
such as:
prefix
the common prefix of metric nameunixDomainSocket
use unix domain socket to send metric packetsockAddress
domain unix socket addresssocketTimeOutMs
send metric to agent socket timeout in millisecondsmaxPacketBytes
send metric to agent socket max packet bytes limituseMetricPool
whether to use metric object poolmetricPoolMinIdle
metric object pool min idlemetricPoolMaxIdle
metric object pool max idlebyteBufferPoolMinIdle
byte buffer object pool min idlebyteBufferPoolMaxIdle
byte buffer object pool max idlereporterQueueCapacity
reporter buffer queue capacity.metric will be discarded when the capacity is exceeded, you can increase this queue capacity orreporterWorkers
orsenderWorkers
to avoidreporterWorkers
number of reporter queue processor workerssenderSync
send packet sync or asyncsenderWorkers
number of sender queue processor workers ifsenderSync
is falseworkerWaitSleepMs
reporter and sender processor waiting for empty poll