forked from spring-guides/gs-rest-hateoas
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Arvydas Jonusonis
committed
Mar 27, 2015
1 parent
1d317d2
commit efc6b93
Showing
7 changed files
with
193 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
*.ipr | ||
*.iws | ||
*.iml | ||
target/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package hello; | ||
|
||
import com.codahale.metrics.*; | ||
import com.codahale.metrics.httpclient.HttpClientMetricNameStrategies; | ||
import com.codahale.metrics.jvm.GarbageCollectorMetricSet; | ||
import com.codahale.metrics.jvm.MemoryUsageGaugeSet; | ||
import com.codahale.metrics.jvm.ThreadStatesGaugeSet; | ||
import com.ryantenney.metrics.spring.config.annotation.EnableMetrics; | ||
import com.ryantenney.metrics.spring.config.annotation.MetricsConfigurerAdapter; | ||
import org.apache.http.client.HttpClient; | ||
import org.elasticsearch.metrics.ElasticsearchReporter; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.boot.context.web.SpringBootServletInitializer; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.ComponentScan; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
import javax.management.MBeanServerFactory; | ||
import java.io.IOException; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
/** | ||
* Created by Arvydas on 3/16/15. | ||
*/ | ||
@SpringBootApplication | ||
@Configuration | ||
@EnableMetrics | ||
@ComponentScan | ||
@EnableAutoConfiguration | ||
public class Application extends MetricsConfigurerAdapter { | ||
|
||
static final MetricRegistry metrics = new MetricRegistry(); | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(Application.class, args); | ||
|
||
} | ||
|
||
@Override | ||
public void configureReporters(MetricRegistry metricRegistry) { | ||
|
||
// metricRegistry.registerAll(new GarbageCollectorMetricSet()); | ||
// metricRegistry.registerAll(new MemoryUsageGaugeSet()); | ||
// metricRegistry.registerAll(new ThreadStatesGaugeSet()); | ||
|
||
ConsoleReporter reporter = ConsoleReporter.forRegistry(metrics) | ||
.convertRatesTo(TimeUnit.SECONDS) | ||
.convertDurationsTo(TimeUnit.MILLISECONDS) | ||
.build(); | ||
reporter.start(10, TimeUnit.SECONDS); | ||
|
||
JmxReporter jmxReporter = JmxReporter.forRegistry(metrics).inDomain("net.gogii").build(); | ||
|
||
jmxReporter.start(); | ||
|
||
ElasticsearchReporter esReporter = null; | ||
try { | ||
esReporter = ElasticsearchReporter.forRegistry(metricRegistry) | ||
.hosts("9cn22.lax1.gogii.net:9200") | ||
// .percolationFilter(MetricFilter.ALL) | ||
.index("metricsdemo") | ||
.timeout(10000) | ||
.build(); | ||
esReporter.start(10, TimeUnit.SECONDS); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
} | ||
|
||
@Override | ||
public MetricRegistry getMetricRegistry() { | ||
return metrics; | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package hello; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import org.springframework.hateoas.ResourceSupport; | ||
|
||
/** | ||
* Created by Arvydas on 3/16/15. | ||
*/ | ||
public class Greeting extends ResourceSupport { | ||
|
||
private final String content; | ||
|
||
@JsonCreator | ||
public Greeting(@JsonProperty("content") String content) { | ||
this.content = content; | ||
} | ||
|
||
public String getContent() { | ||
return content; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package hello; | ||
|
||
import com.codahale.metrics.annotation.Gauge; | ||
import com.codahale.metrics.annotation.Metered; | ||
import com.codahale.metrics.annotation.Timed; | ||
import com.ryantenney.metrics.annotation.Counted; | ||
import org.springframework.hateoas.mvc.ControllerLinkBuilder; | ||
import org.springframework.http.HttpEntity; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
|
||
/** | ||
* Created by Arvydas on 3/16/15. | ||
*/ | ||
@Controller | ||
public class GreetingController { | ||
|
||
public static final String TEMPLATE = "Hello, %s"; | ||
|
||
// @Metered | ||
// @Gauge | ||
@Timed | ||
// @Counted(name = "greetingCount") | ||
|
||
@RequestMapping("/greeting") | ||
public HttpEntity<Greeting> greeting( | ||
@RequestParam(value="name", required = false, defaultValue = "World") String name | ||
){ | ||
Greeting greeting = new Greeting(String.format(TEMPLATE, name)); | ||
greeting.add(ControllerLinkBuilder.linkTo(ControllerLinkBuilder.methodOn(GreetingController.class).greeting(name)).withSelfRel()); | ||
return new ResponseEntity<Greeting>(greeting, HttpStatus.OK); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package hello; | ||
|
||
import com.codahale.metrics.ObjectNameFactory; | ||
|
||
import javax.management.MalformedObjectNameException; | ||
import javax.management.ObjectName; | ||
|
||
/** | ||
* Created by Arvydas on 3/24/15. | ||
*/ | ||
public class MyObjectNameFactory implements ObjectNameFactory { | ||
@Override | ||
public ObjectName createName(String type, String domain, String name) { | ||
try { | ||
return new ObjectName(domain + ":" + type + ":" + name); | ||
} catch (MalformedObjectNameException e) { | ||
} | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<%-- | ||
Created by IntelliJ IDEA. | ||
User: Arvydas | ||
Date: 3/16/15 | ||
Time: 3:48 PM | ||
To change this template use File | Settings | File Templates. | ||
--%> | ||
<%@ page contentType="text/html;charset=UTF-8" language="java" %> | ||
<html> | ||
<head> | ||
<title></title> | ||
</head> | ||
<body> | ||
|
||
</body> | ||
</html> |