Add support for metric export to OpenTSDB
parent
18928a62df
commit
60a4943520
@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright 2012-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.actuate.metrics.opentsdb;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
/**
|
||||
* A naming strategy that just passes through the metric name, together with tags from a
|
||||
* set of static values. Open TSDB requires at least one tag, so one is always added for
|
||||
* you: the {@value #PREFIX_KEY} key is added with a unique value "spring.X" where X is an
|
||||
* object hash code ID for this (the naming stategy). In most cases this will be unique
|
||||
* enough to allow aggregation of the underlying metrics in Open TSDB, but normally it is
|
||||
* best to provide your own tags, including a prefix if you know one (overwriting the
|
||||
* default).
|
||||
*
|
||||
* @author Dave Syer
|
||||
*/
|
||||
public class DefaultOpenTsdbNamingStrategy implements OpenTsdbNamingStrategy {
|
||||
|
||||
public static final String PREFIX_KEY = "prefix";
|
||||
|
||||
/**
|
||||
* Tags to apply to every metric. Open TSDB requires at least one tag, so a "prefix"
|
||||
* tag is added for you by default.
|
||||
*/
|
||||
private Map<String, String> tags = new LinkedHashMap<String, String>();
|
||||
|
||||
private Map<String, OpenTsdbName> cache = new HashMap<String, OpenTsdbName>();
|
||||
|
||||
public DefaultOpenTsdbNamingStrategy() {
|
||||
this.tags.put(PREFIX_KEY,
|
||||
"spring." + ObjectUtils.getIdentityHexString(this));
|
||||
}
|
||||
|
||||
public void setTags(Map<String, String> staticTags) {
|
||||
this.tags.putAll(staticTags);
|
||||
}
|
||||
|
||||
@Override
|
||||
public OpenTsdbName getName(String name) {
|
||||
if (this.cache.containsKey(name)) {
|
||||
return this.cache.get(name);
|
||||
}
|
||||
OpenTsdbName value = new OpenTsdbName(name);
|
||||
value.setTags(this.tags);
|
||||
this.cache.put(name, value);
|
||||
return value;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Copyright 2012-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.actuate.metrics.opentsdb;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*/
|
||||
public class OpenTsdbData {
|
||||
|
||||
private OpenTsdbName name;
|
||||
|
||||
private Long timestamp;
|
||||
|
||||
private Number value;
|
||||
|
||||
protected OpenTsdbData() {
|
||||
this.name = new OpenTsdbName();
|
||||
}
|
||||
|
||||
public OpenTsdbData(String metric, Number value) {
|
||||
this(metric, value, System.currentTimeMillis());
|
||||
}
|
||||
|
||||
public OpenTsdbData(String metric, Number value, Long timestamp) {
|
||||
this(new OpenTsdbName(metric), value, timestamp);
|
||||
}
|
||||
|
||||
public OpenTsdbData(OpenTsdbName name, Number value, Long timestamp) {
|
||||
this.name = name;
|
||||
this.value = value;
|
||||
this.timestamp = timestamp;
|
||||
}
|
||||
|
||||
public String getMetric() {
|
||||
return this.name.getMetric();
|
||||
}
|
||||
|
||||
public void setMetric(String metric) {
|
||||
this.name.setMetric(metric);
|
||||
}
|
||||
|
||||
public Long getTimestamp() {
|
||||
return this.timestamp;
|
||||
}
|
||||
|
||||
public void setTimestamp(Long timestamp) {
|
||||
this.timestamp = timestamp;
|
||||
}
|
||||
|
||||
public Number getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
public void setValue(Number value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public Map<String, String> getTags() {
|
||||
return this.name.getTags();
|
||||
}
|
||||
|
||||
public void setTags(Map<String, String> tags) {
|
||||
this.name.setTags(tags);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,143 @@
|
||||
/*
|
||||
* Copyright 2012-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.actuate.metrics.opentsdb;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.boot.actuate.metrics.Metric;
|
||||
import org.springframework.boot.actuate.metrics.writer.Delta;
|
||||
import org.springframework.boot.actuate.metrics.writer.MetricWriter;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
/**
|
||||
* A {@link MetricWriter} for the Open TSDB database (version 2.0), writing metrics to the
|
||||
* HTTP endpoint provided by the server. Data are buffered according to the
|
||||
* {@link #setBufferSize(int) bufferSize} property, and only flushed automatically when
|
||||
* the buffer size is reached. Users should either manually {@link #flush()} after writing
|
||||
* a batch of data if that makes sense, or consider adding a {@link Scheduled
|
||||
* <code>@Scheduled</code>} task to flush periodically.
|
||||
*
|
||||
* @author Dave Syer
|
||||
*/
|
||||
public class OpenTsdbHttpMetricWriter implements MetricWriter {
|
||||
|
||||
private static final Log logger = LogFactory.getLog(OpenTsdbHttpMetricWriter.class);
|
||||
|
||||
private RestTemplate restTemplate = new RestTemplate();
|
||||
|
||||
/**
|
||||
* URL for POSTing data. Defaults to http://localhost:4242/api/put.
|
||||
*/
|
||||
private String url = "http://localhost:4242/api/put";
|
||||
|
||||
/**
|
||||
* Buffer size to fill before posting data to server.
|
||||
*/
|
||||
private int bufferSize = 64;
|
||||
|
||||
/**
|
||||
* The media type to use to serialize and accept responses from the server. Defaults
|
||||
* to "application/json".
|
||||
*/
|
||||
private MediaType mediaType = MediaType.APPLICATION_JSON;
|
||||
|
||||
private List<OpenTsdbData> buffer = new ArrayList<OpenTsdbData>(this.bufferSize);
|
||||
|
||||
private OpenTsdbNamingStrategy namingStrategy = new DefaultOpenTsdbNamingStrategy();
|
||||
|
||||
public RestTemplate getRestTemplate() {
|
||||
return this.restTemplate;
|
||||
}
|
||||
|
||||
public void setRestTemplate(RestTemplate restTemplate) {
|
||||
this.restTemplate = restTemplate;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public void setBufferSize(int bufferSize) {
|
||||
this.bufferSize = bufferSize;
|
||||
}
|
||||
|
||||
public void setMediaType(MediaType mediaType) {
|
||||
this.mediaType = mediaType;
|
||||
}
|
||||
|
||||
public void setNamingStrategy(OpenTsdbNamingStrategy namingStrategy) {
|
||||
this.namingStrategy = namingStrategy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void increment(Delta<?> delta) {
|
||||
throw new UnsupportedOperationException("Counters not supported via increment");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(Metric<?> value) {
|
||||
OpenTsdbData data = new OpenTsdbData(
|
||||
this.namingStrategy.getName(value.getName()), value.getValue(), value
|
||||
.getTimestamp().getTime());
|
||||
this.buffer.add(data);
|
||||
if (this.buffer.size() >= this.bufferSize) {
|
||||
flush();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Flush the buffer without waiting for it to fill any further.
|
||||
*/
|
||||
public void flush() {
|
||||
if (this.buffer.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
List<OpenTsdbData> temp = new ArrayList<OpenTsdbData>();
|
||||
synchronized (this.buffer) {
|
||||
temp.addAll(this.buffer);
|
||||
this.buffer.clear();
|
||||
}
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setAccept(Arrays.asList(this.mediaType));
|
||||
headers.setContentType(this.mediaType);
|
||||
HttpEntity<List<OpenTsdbData>> request = new HttpEntity<List<OpenTsdbData>>(temp,
|
||||
headers);
|
||||
@SuppressWarnings("rawtypes")
|
||||
ResponseEntity<Map> response = this.restTemplate.postForEntity(this.url, request,
|
||||
Map.class);
|
||||
if (!response.getStatusCode().is2xxSuccessful()) {
|
||||
logger.warn("Cannot write metrics (discarded " + temp.size() + " values): "
|
||||
+ response.getBody());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset(String metricName) {
|
||||
set(new Metric<Long>(metricName, 0L));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright 2012-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.actuate.metrics.opentsdb;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*/
|
||||
public class OpenTsdbName {
|
||||
|
||||
private String metric;
|
||||
|
||||
private Map<String, String> tags = new LinkedHashMap<String, String>();
|
||||
|
||||
protected OpenTsdbName() {
|
||||
}
|
||||
|
||||
public OpenTsdbName(String metric) {
|
||||
this.metric = metric;
|
||||
}
|
||||
|
||||
public String getMetric() {
|
||||
return this.metric;
|
||||
}
|
||||
|
||||
public void setMetric(String metric) {
|
||||
this.metric = metric;
|
||||
}
|
||||
|
||||
public Map<String, String> getTags() {
|
||||
return this.tags;
|
||||
}
|
||||
|
||||
public void setTags(Map<String, String> tags) {
|
||||
this.tags.putAll(tags);
|
||||
}
|
||||
|
||||
public void tag(String name, String value) {
|
||||
this.tags.put(name, value);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright 2012-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.actuate.metrics.opentsdb;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*/
|
||||
public interface OpenTsdbNamingStrategy {
|
||||
|
||||
OpenTsdbName getName(String metricName);
|
||||
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright 2012-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Metrics integration with OpenTSDB.
|
||||
*/
|
||||
package org.springframework.boot.actuate.metrics.opentsdb;
|
||||
|
@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright 2012-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.actuate.metrics.writer;
|
||||
|
||||
import java.io.Flushable;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.boot.actuate.metrics.export.MetricCopyExporter;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*/
|
||||
public class WriterUtils {
|
||||
|
||||
private static final Log logger = LogFactory.getLog(MetricCopyExporter.class);
|
||||
|
||||
public static void flush(MetricWriter writer) {
|
||||
if (writer instanceof CompositeMetricWriter) {
|
||||
for (MetricWriter element : (CompositeMetricWriter) writer) {
|
||||
flush(element);
|
||||
}
|
||||
}
|
||||
try {
|
||||
if (ClassUtils.isPresent("java.io.Flushable", null)) {
|
||||
if (writer instanceof Flushable) {
|
||||
((Flushable) writer).flush();
|
||||
return;
|
||||
}
|
||||
}
|
||||
Method method = ReflectionUtils.findMethod(writer.getClass(), "flush");
|
||||
if (method != null) {
|
||||
ReflectionUtils.invokeMethod(method, writer);
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
logger.warn("Could not flush MetricWriter: " + e.getClass() + ": "
|
||||
+ e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
Spring Boot sample with Open TSDB export for metrics.
|
||||
|
||||
Start opentsdb, e.g. with [Docker Compose]()
|
||||
|
||||
[source,indent=0]
|
||||
----
|
||||
$ docker-compose up
|
||||
----
|
||||
|
||||
Run the app and ping the home page (http://localhost:8080) a few times. Go and look at
|
||||
the result in the TDB UI, e.g.
|
||||
|
||||
[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"
|
||||
},
|
||||
"aggregateTags": [],
|
||||
"dps": {
|
||||
"1430492872": 2,
|
||||
"1430492875": 6
|
||||
}
|
||||
}
|
||||
]
|
||||
----
|
@ -0,0 +1,4 @@
|
||||
opentsdb:
|
||||
image: lancope/opentsdb
|
||||
ports:
|
||||
- "4242:4242"
|
@ -0,0 +1,44 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<!-- Your own application should inherit from spring-boot-starter-parent -->
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-samples</artifactId>
|
||||
<version>1.3.0.BUILD-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>spring-boot-sample-metrics-opentsdb</artifactId>
|
||||
<name>spring-boot-sample-metrics-opentsdb</name>
|
||||
<description>Spring Boot Actuator Sample</description>
|
||||
<url>http://projects.spring.io/spring-boot/</url>
|
||||
<organization>
|
||||
<name>Pivotal Software, Inc.</name>
|
||||
<url>http://www.spring.io</url>
|
||||
</organization>
|
||||
<properties>
|
||||
<main.basedir>${basedir}/../..</main.basedir>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright 2012-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package sample.metrics.opentsdb;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@ConfigurationProperties(prefix = "service", ignoreUnknownFields = false)
|
||||
public class HelloWorldService {
|
||||
|
||||
private String name = "World";
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getHelloMessage() {
|
||||
return "Hello " + this.name;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright 2012-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package sample.metrics.opentsdb;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
import org.hibernate.validator.constraints.NotBlank;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Description;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
@Controller
|
||||
@Description("A controller for handling requests for hello messages")
|
||||
public class SampleController {
|
||||
|
||||
@Autowired
|
||||
private HelloWorldService helloWorldService;
|
||||
|
||||
@RequestMapping(value = "/", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public Map<String, String> hello() {
|
||||
return Collections.singletonMap("message",
|
||||
this.helloWorldService.getHelloMessage());
|
||||
}
|
||||
|
||||
protected static class Message {
|
||||
|
||||
@NotBlank(message = "Message value cannot be empty")
|
||||
private String value;
|
||||
|
||||
public String getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright 2012-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package sample.metrics.opentsdb;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.actuate.metrics.opentsdb.DefaultOpenTsdbNamingStrategy;
|
||||
import org.springframework.boot.actuate.metrics.opentsdb.OpenTsdbHttpMetricWriter;
|
||||
import org.springframework.boot.actuate.metrics.opentsdb.OpenTsdbNamingStrategy;
|
||||
import org.springframework.boot.actuate.metrics.writer.MetricWriter;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
||||
@SpringBootApplication
|
||||
public class SampleOpenTsdbExportApplication {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
SpringApplication.run(SampleOpenTsdbExportApplication.class, args);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConfigurationProperties("metrics.export")
|
||||
public MetricWriter openTsdbMetricWriter() {
|
||||
OpenTsdbHttpMetricWriter writer = new OpenTsdbHttpMetricWriter();
|
||||
writer.setNamingStrategy(namingStrategy());
|
||||
return writer;
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConfigurationProperties("metrics.names")
|
||||
public OpenTsdbNamingStrategy namingStrategy() {
|
||||
return new DefaultOpenTsdbNamingStrategy();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1 @@
|
||||
service.name: Phil
|
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright 2012-2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package sample.metrics.opentsdb;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.IntegrationTest;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.web.WebAppConfiguration;
|
||||
|
||||
/**
|
||||
* Basic integration tests for {@link SampleOpenTsdbExportApplication}.
|
||||
*
|
||||
* @author Dave Syer
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringApplicationConfiguration(classes = SampleOpenTsdbExportApplication.class)
|
||||
@WebAppConfiguration
|
||||
@IntegrationTest("server.port=0")
|
||||
@DirtiesContext
|
||||
public class SampleOpenTsdbExportApplicationTests {
|
||||
|
||||
@Test
|
||||
public void contextLoads() {
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue