Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
18928a62
Commit
18928a62
authored
May 01, 2015
by
Dave Syer
Committed by
Andy Wilkinson
May 13, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add sample for Redis metric exporter
parent
a32c530c
Changes
10
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
309 additions
and
0 deletions
+309
-0
pom.xml
spring-boot-samples/pom.xml
+1
-0
README.adoc
...boot-samples/spring-boot-sample-metrics-redis/README.adoc
+24
-0
docker-compose.yml
...mples/spring-boot-sample-metrics-redis/docker-compose.yml
+4
-0
pom.xml
spring-boot-samples/spring-boot-sample-metrics-redis/pom.xml
+48
-0
ExportProperties.java
.../src/main/java/sample/metrics/redis/ExportProperties.java
+43
-0
HelloWorldService.java
...src/main/java/sample/metrics/redis/HelloWorldService.java
+40
-0
SampleController.java
.../src/main/java/sample/metrics/redis/SampleController.java
+58
-0
SampleRedisExportApplication.java
...va/sample/metrics/redis/SampleRedisExportApplication.java
+45
-0
application.properties
...e-metrics-redis/src/main/resources/application.properties
+2
-0
SampleRedisExportApplicationTests.java
...mple/metrics/redis/SampleRedisExportApplicationTests.java
+44
-0
No files found.
spring-boot-samples/pom.xml
View file @
18928a62
...
@@ -52,6 +52,7 @@
...
@@ -52,6 +52,7 @@
<module>
spring-boot-sample-jta-bitronix
</module>
<module>
spring-boot-sample-jta-bitronix
</module>
<module>
spring-boot-sample-jta-jndi
</module>
<module>
spring-boot-sample-jta-jndi
</module>
<module>
spring-boot-sample-liquibase
</module>
<module>
spring-boot-sample-liquibase
</module>
<module>
spring-boot-sample-metrics-redis
</module>
<module>
spring-boot-sample-parent-context
</module>
<module>
spring-boot-sample-parent-context
</module>
<module>
spring-boot-sample-profile
</module>
<module>
spring-boot-sample-profile
</module>
<module>
spring-boot-sample-secure
</module>
<module>
spring-boot-sample-secure
</module>
...
...
spring-boot-samples/spring-boot-sample-metrics-redis/README.adoc
0 → 100644
View file @
18928a62
Spring Boot sample with Redis export for metrics.
Start redis, 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 Redis, e.g.
[source,indent=0]
----
$ redis-cli
127.0.0.1:6379> keys *
1) "keys.spring.metrics"
2) "spring.metrics.counter.status.200.root"
3) "spring.metrics.gauge.response.root"
127.0.0.1:6379> zrange keys.spring.metrics 0 0 WITHSCORES
1) "spring.metrics.counter.status.200.root"
2) "4"
----
spring-boot-samples/spring-boot-sample-metrics-redis/docker-compose.yml
0 → 100644
View file @
18928a62
redis
:
image
:
redis
ports
:
-
"
6379:6379"
spring-boot-samples/spring-boot-sample-metrics-redis/pom.xml
0 → 100644
View file @
18928a62
<?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-redis
</artifactId>
<name>
spring-boot-sample-metrics-redis
</name>
<description>
Spring Boot Metrics Redis 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-redis
</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>
spring-boot-samples/spring-boot-sample-metrics-redis/src/main/java/sample/metrics/redis/ExportProperties.java
0 → 100644
View file @
18928a62
/*
* 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
sample
.
metrics
.
redis
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
@ConfigurationProperties
(
"metrics.export"
)
class
ExportProperties
{
private
String
prefix
=
"spring.metrics"
;
private
String
key
=
"keys.spring.metrics"
;
public
String
getPrefix
()
{
return
this
.
prefix
;
}
public
void
setPrefix
(
String
prefix
)
{
this
.
prefix
=
prefix
;
}
public
String
getKey
()
{
return
this
.
key
;
}
public
void
setKey
(
String
key
)
{
this
.
key
=
key
;
}
}
\ No newline at end of file
spring-boot-samples/spring-boot-sample-metrics-redis/src/main/java/sample/metrics/redis/HelloWorldService.java
0 → 100644
View file @
18928a62
/*
* 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
sample
.
metrics
.
redis
;
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
;
}
}
spring-boot-samples/spring-boot-sample-metrics-redis/src/main/java/sample/metrics/redis/SampleController.java
0 → 100644
View file @
18928a62
/*
* 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
sample
.
metrics
.
redis
;
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
;
}
}
}
spring-boot-samples/spring-boot-sample-metrics-redis/src/main/java/sample/metrics/redis/SampleRedisExportApplication.java
0 → 100644
View file @
18928a62
/*
* 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
sample
.
metrics
.
redis
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.actuate.metrics.repository.redis.RedisMetricRepository
;
import
org.springframework.boot.actuate.metrics.writer.MetricWriter
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.data.redis.connection.RedisConnectionFactory
;
@SpringBootApplication
@EnableConfigurationProperties
(
ExportProperties
.
class
)
public
class
SampleRedisExportApplication
{
@Autowired
private
ExportProperties
export
;
public
static
void
main
(
String
[]
args
)
throws
Exception
{
SpringApplication
.
run
(
SampleRedisExportApplication
.
class
,
args
);
}
@Bean
public
MetricWriter
redisMetricWriter
(
RedisConnectionFactory
connectionFactory
)
{
return
new
RedisMetricRepository
(
connectionFactory
,
this
.
export
.
getPrefix
(),
this
.
export
.
getKey
());
}
}
spring-boot-samples/spring-boot-sample-metrics-redis/src/main/resources/application.properties
0 → 100644
View file @
18928a62
service.name
:
Phil
metrics.export.prefix
:
${spring.application.name:application}:${random.value:0000}
\ No newline at end of file
spring-boot-samples/spring-boot-sample-metrics-redis/src/test/java/sample/metrics/redis/SampleRedisExportApplicationTests.java
0 → 100644
View file @
18928a62
/*
* 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
sample
.
metrics
.
redis
;
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 SampleRedisExportApplication}.
*
* @author Dave Syer
*/
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@SpringApplicationConfiguration
(
classes
=
SampleRedisExportApplication
.
class
)
@WebAppConfiguration
@IntegrationTest
(
"server.port=0"
)
@DirtiesContext
public
class
SampleRedisExportApplicationTests
{
@Test
public
void
contextLoads
()
{
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment