Add samples and tweak metrics reader/writers till they work
This commit is contained in:
committed by
Andy Wilkinson
parent
60a4943520
commit
3fda744522
@@ -943,10 +943,10 @@ Example:
|
||||
[source,java,indent=0]
|
||||
----
|
||||
|
||||
@Value("${spring.application.name:application}.${random.value:0000}")
|
||||
private String prefix = "metrics";
|
||||
@Value("metrics.mysystem.${random.value:0000}.${spring.application.name:application}")
|
||||
private String prefix = "metrics.mysystem";
|
||||
|
||||
@Value("${metrics.key:METRICSKEY}")
|
||||
@Value("${metrics.key:keys.mysystem}")
|
||||
private String key = "METRICSKEY";
|
||||
|
||||
@Bean
|
||||
@@ -955,35 +955,50 @@ MetricWriter metricWriter() {
|
||||
}
|
||||
----
|
||||
|
||||
The prefix is constructed with the application name at the end, so it can easily be used
|
||||
to identify a group of processes with the same logical name later.
|
||||
|
||||
NOTE: it's important to set both the key and the prefix. The key is used for all
|
||||
repository operations, and can be shared by multiple repositories. If multiple
|
||||
repositories share a key (like in the case where you need to aggregate across them), then
|
||||
you normally have a read-only "master" repository that has a short, but identifiable,
|
||||
prefix (like "metrics.mysystem"), and many write-only repositories with prefixes that
|
||||
start with the master prefix (like `metrics.mysystem.*` in the example above). It is
|
||||
efficient to read all the keys from a "master" repository like that, but inefficient to
|
||||
read a subset with a longer prefix (e.g. using one of the writing repositories).
|
||||
|
||||
|
||||
|
||||
[[production-ready-metric-writers-export-to-open-tdsb]]
|
||||
==== Example: Export to Open TSDB
|
||||
If you provide a `@Bean` of type `OpenTsdbHttpMetricWriter` the metrics are exported to
|
||||
http://opentsdb.net/[Open TSDB] for aggregation. The `OpenTsdbHttpMetricWriter` has a
|
||||
`url` property that you need to set to the Open TSDB "/put" endpoint, e.g.
|
||||
`http://localhost:4242/api/put`). It also has a `namingStrategy` that you can customize
|
||||
or configure to make the metrics match the data structure you need on the server. By
|
||||
default it just passes through the metric name as an Open TSDB metric name and adds a tag
|
||||
"prefix" with value "spring.X" where "X" is the object hash of the default naming
|
||||
strategy. Thus, after running the application and generating some metrics (e.g. by pinging
|
||||
the home page) you can inspect the metrics in the TDB UI (http://localhost:4242 by
|
||||
default). Example:
|
||||
|
||||
If you provide a `@Bean` of type `OpenTsdbHttpMetricWriter` the metrics are exported to
|
||||
http://opentsdb.net/[Open TSDB] for aggregation. The `OpenTsdbHttpMetricWriter` has a
|
||||
`url` property that you need to set to the Open TSDB "/put" endpoint, e.g.
|
||||
`http://localhost:4242/api/put`). It also has a `namingStrategy` that you can customize or
|
||||
configure to make the metrics match the data structure you need on the server. By default
|
||||
it just passes through the metric name as an Open TSDB metric name and adds a tag "domain"
|
||||
with value "org.springframework.metrics" and another tag "process" with value equals to
|
||||
the object hash of the naming strategy. Thus, after running the application and generating
|
||||
some metrics (e.g. by pinging the home page) you can inspect the metrics in the TDB UI
|
||||
(http://localhost:4242 by default). Example:
|
||||
|
||||
[source,indent=0]
|
||||
----
|
||||
curl localhost:4242/api/query?start=1h-ago&m=max:counter.status.200.root
|
||||
[
|
||||
{
|
||||
"metric": "counter.status.200.root",
|
||||
"tags": {
|
||||
"prefix": "spring.b968a76"
|
||||
"domain": "org.springframework.metrics",
|
||||
"process": "b968a76"
|
||||
},
|
||||
"aggregateTags": [],
|
||||
"dps": {
|
||||
"1430492872": 2,
|
||||
"1430492875": 6
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
----
|
||||
|
||||
@@ -1057,7 +1072,7 @@ results to the "/metrics" endpoint. Example:
|
||||
@Bean
|
||||
protected MetricReader repository(RedisConnectionFactory connectionFactory) {
|
||||
RedisMetricRepository repository = new RedisMetricRepository(connectionFactory,
|
||||
"metrics", "METRICSKEY");
|
||||
"mysystem", "myorg.keys");
|
||||
return repository;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user