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
6b3e79e6
Commit
6b3e79e6
authored
Jan 02, 2014
by
Phillip Webb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish
parent
bd6c672b
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
46 additions
and
41 deletions
+46
-41
SimpleHealthIndicator.java
...gframework/boot/actuate/health/SimpleHealthIndicator.java
+12
-9
Metric.java
...java/org/springframework/boot/actuate/metrics/Metric.java
+15
-26
Exporter.java
...springframework/boot/actuate/metrics/export/Exporter.java
+4
-1
MetricCopyExporter.java
...ework/boot/actuate/metrics/export/MetricCopyExporter.java
+4
-0
PrefixMetricGroupExporter.java
...oot/actuate/metrics/export/PrefixMetricGroupExporter.java
+6
-4
PrefixMetricGroupExporterTests.java
...ctuate/metrics/export/PrefixMetricGroupExporterTests.java
+5
-1
No files found.
spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/SimpleHealthIndicator.java
View file @
6b3e79e6
...
...
@@ -30,6 +30,9 @@ import org.springframework.jdbc.core.JdbcTemplate;
import
org.springframework.util.StringUtils
;
/**
* Simple implementation of {@link HealthIndicator} that returns a status and also
* attempts a simple database test.
*
* @author Dave Syer
*/
public
class
SimpleHealthIndicator
implements
HealthIndicator
<
Map
<
String
,
Object
>>
{
...
...
@@ -53,8 +56,8 @@ public class SimpleHealthIndicator implements HealthIndicator<Map<String, Object
@Override
public
Map
<
String
,
Object
>
health
()
{
LinkedHashMap
<
String
,
Object
>
map
=
new
LinkedHashMap
<
String
,
Object
>();
map
.
put
(
"status"
,
"ok"
);
LinkedHashMap
<
String
,
Object
>
health
=
new
LinkedHashMap
<
String
,
Object
>();
health
.
put
(
"status"
,
"ok"
);
String
product
=
"unknown"
;
if
(
this
.
dataSource
!=
null
)
{
try
{
...
...
@@ -65,25 +68,25 @@ public class SimpleHealthIndicator implements HealthIndicator<Map<String, Object
return
connection
.
getMetaData
().
getDatabaseProductName
();
}
});
map
.
put
(
"database"
,
product
);
health
.
put
(
"database"
,
product
);
}
catch
(
DataAccessException
ex
)
{
map
.
put
(
"status"
,
"error"
);
map
.
put
(
"error"
,
ex
.
getClass
().
getName
()
+
": "
+
ex
.
getMessage
());
health
.
put
(
"status"
,
"error"
);
health
.
put
(
"error"
,
ex
.
getClass
().
getName
()
+
": "
+
ex
.
getMessage
());
}
String
query
=
detectQuery
(
product
);
if
(
StringUtils
.
hasText
(
query
))
{
try
{
map
.
put
(
"hello"
,
health
.
put
(
"hello"
,
this
.
jdbcTemplate
.
queryForObject
(
query
,
String
.
class
));
}
catch
(
Exception
ex
)
{
map
.
put
(
"status"
,
"error"
);
map
.
put
(
"error"
,
ex
.
getClass
().
getName
()
+
": "
+
ex
.
getMessage
());
health
.
put
(
"status"
,
"error"
);
health
.
put
(
"error"
,
ex
.
getClass
().
getName
()
+
": "
+
ex
.
getMessage
());
}
}
}
return
map
;
return
health
;
}
protected
String
detectQuery
(
String
product
)
{
...
...
spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/Metric.java
View file @
6b3e79e6
...
...
@@ -19,6 +19,7 @@ package org.springframework.boot.actuate.metrics;
import
java.util.Date
;
import
org.springframework.util.Assert
;
import
org.springframework.util.ObjectUtils
;
/**
* Immutable class that can be used to hold any arbitrary system measurement value (a
...
...
@@ -33,7 +34,7 @@ public class Metric<T extends Number> {
private
final
T
value
;
private
Date
timestamp
;
private
final
Date
timestamp
;
/**
* Create a new {@link Metric} instance for the current time.
...
...
@@ -104,41 +105,29 @@ public class Metric<T extends Number> {
public
int
hashCode
()
{
final
int
prime
=
31
;
int
result
=
1
;
result
=
prime
*
result
+
((
this
.
name
==
null
)
?
0
:
this
.
name
.
hashCode
());
result
=
prime
*
result
+
((
this
.
timestamp
==
null
)
?
0
:
this
.
timestamp
.
hashCode
());
result
=
prime
*
result
+
((
this
.
value
==
null
)
?
0
:
this
.
value
.
hashCode
());
result
=
prime
*
result
+
ObjectUtils
.
nullSafeHashCode
(
this
.
name
);
result
=
prime
*
result
+
ObjectUtils
.
nullSafeHashCode
(
this
.
timestamp
);
result
=
prime
*
result
+
ObjectUtils
.
nullSafeHashCode
(
this
.
value
);
return
result
;
}
@Override
public
boolean
equals
(
Object
obj
)
{
if
(
this
==
obj
)
if
(
this
==
obj
)
{
return
true
;
if
(
obj
==
null
)
return
false
;
if
(
getClass
()
!=
obj
.
getClass
())
return
false
;
Metric
<?>
other
=
(
Metric
<?>)
obj
;
if
(
this
.
name
==
null
)
{
if
(
other
.
name
!=
null
)
return
false
;
}
else
if
(!
this
.
name
.
equals
(
other
.
name
))
if
(
obj
==
null
)
{
return
false
;
if
(
this
.
timestamp
==
null
)
{
if
(
other
.
timestamp
!=
null
)
return
false
;
}
else
if
(!
this
.
timestamp
.
equals
(
other
.
timestamp
))
return
false
;
if
(
this
.
value
==
null
)
{
if
(
other
.
value
!=
null
)
return
false
;
if
(
obj
instanceof
Metric
)
{
Metric
<?>
other
=
(
Metric
<?>)
obj
;
boolean
rtn
=
true
;
rtn
&=
ObjectUtils
.
nullSafeEquals
(
this
.
name
,
other
.
name
);
rtn
&=
ObjectUtils
.
nullSafeEquals
(
this
.
timestamp
,
other
.
timestamp
);
rtn
&=
ObjectUtils
.
nullSafeEquals
(
this
.
value
,
other
.
value
);
return
rtn
;
}
else
if
(!
this
.
value
.
equals
(
other
.
value
))
return
false
;
return
true
;
return
super
.
equals
(
obj
);
}
}
spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/Exporter.java
View file @
6b3e79e6
...
...
@@ -22,12 +22,15 @@ package org.springframework.boot.actuate.metrics.export;
* across a cluster), so this is the marker interface for those operations. The trigger of
* an export operation might be periodic or even driven, but it remains outside the scope
* of this interface. You might for instance create an instance of an Exporter and trigger
* it using a
<code>@Scheduled</code>
annotation in a Spring ApplicationContext.
* it using a
{@code @Scheduled}
annotation in a Spring ApplicationContext.
*
* @author Dave Syer
*/
public
interface
Exporter
{
/**
* Export metric data.
*/
void
export
();
}
spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/MetricCopyExporter.java
View file @
6b3e79e6
...
...
@@ -23,11 +23,15 @@ import org.springframework.boot.actuate.metrics.reader.MetricReader;
import
org.springframework.boot.actuate.metrics.writer.MetricWriter
;
/**
* {@link Exporter} that "exports" by copying metric data from a source
* {@link MetricReader} to a destination {@link MetricWriter}.
*
* @author Dave Syer
*/
public
class
MetricCopyExporter
extends
AbstractMetricExporter
{
private
final
MetricReader
reader
;
private
final
MetricWriter
writer
;
public
MetricCopyExporter
(
MetricReader
reader
,
MetricWriter
writer
)
{
...
...
spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/PrefixMetricGroupExporter.java
View file @
6b3e79e6
...
...
@@ -31,7 +31,9 @@ import org.springframework.boot.actuate.metrics.writer.MetricWriter;
public
class
PrefixMetricGroupExporter
extends
AbstractMetricExporter
{
private
final
PrefixMetricReader
reader
;
private
final
MetricWriter
writer
;
private
Set
<
String
>
groups
=
new
HashSet
<
String
>();
public
PrefixMetricGroupExporter
(
PrefixMetricReader
reader
,
MetricWriter
writer
)
{
...
...
@@ -53,13 +55,13 @@ public class PrefixMetricGroupExporter extends AbstractMetricExporter {
}
@Override
protected
Iterable
<
Metric
<?>>
next
(
String
group
)
{
return
this
.
reader
.
findAll
(
group
)
;
protected
Iterable
<
String
>
groups
(
)
{
return
this
.
groups
;
}
@Override
protected
Iterable
<
String
>
groups
(
)
{
return
this
.
groups
;
protected
Iterable
<
Metric
<?>>
next
(
String
group
)
{
return
this
.
reader
.
findAll
(
group
)
;
}
@Override
...
...
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/export/PrefixMetricGroupExporterTests.java
View file @
6b3e79e6
...
...
@@ -26,12 +26,16 @@ import org.springframework.boot.actuate.metrics.repository.InMemoryMetricReposit
import
static
org
.
junit
.
Assert
.
assertEquals
;
/**
* Tests for {@link PrefixMetricGroupExporter}.
*
* @author Dave Syer
*/
public
class
PrefixMetricGroupExporterTests
{
private
InMemoryMetricRepository
writer
=
new
InMemoryMetricRepository
();
private
InMemoryMetricRepository
reader
=
new
InMemoryMetricRepository
();
private
InMemoryMetricRepository
writer
=
new
InMemoryMetricRepository
();
private
PrefixMetricGroupExporter
exporter
=
new
PrefixMetricGroupExporter
(
this
.
reader
,
this
.
writer
);
...
...
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