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
94e891e9
Commit
94e891e9
authored
May 21, 2014
by
Dave Syer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename method count() -> countGroups()
Fixes gh-923
parent
733e12e2
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
168 additions
and
5 deletions
+168
-5
InMemoryMetricRepository.java
.../actuate/metrics/repository/InMemoryMetricRepository.java
+5
-0
MultiMetricRepository.java
...oot/actuate/metrics/repository/MultiMetricRepository.java
+1
-1
RedisMultiMetricRepository.java
.../metrics/repository/redis/RedisMultiMetricRepository.java
+1
-1
MultiMetricRichGaugeReader.java
...boot/actuate/metrics/rich/MultiMetricRichGaugeReader.java
+96
-0
RedisMultiMetricRepositoryTests.java
...ics/repository/redis/RedisMultiMetricRepositoryTests.java
+1
-1
MultiMetricRichGaugeReaderTests.java
...actuate/metrics/rich/MultiMetricRichGaugeReaderTests.java
+62
-0
SpringApplication.java
...main/java/org/springframework/boot/SpringApplication.java
+2
-2
No files found.
spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/repository/InMemoryMetricRepository.java
View file @
94e891e9
...
@@ -88,6 +88,11 @@ public class InMemoryMetricRepository implements MetricRepository, MultiMetricRe
...
@@ -88,6 +88,11 @@ public class InMemoryMetricRepository implements MetricRepository, MultiMetricRe
return
this
.
metrics
.
count
();
return
this
.
metrics
.
count
();
}
}
@Override
public
long
countGroups
()
{
return
this
.
groups
.
size
();
}
@Override
@Override
public
void
reset
(
String
metricName
)
{
public
void
reset
(
String
metricName
)
{
this
.
metrics
.
remove
(
metricName
);
this
.
metrics
.
remove
(
metricName
);
...
...
spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/repository/MultiMetricRepository.java
View file @
94e891e9
...
@@ -52,6 +52,6 @@ public interface MultiMetricRepository extends PrefixMetricReader {
...
@@ -52,6 +52,6 @@ public interface MultiMetricRepository extends PrefixMetricReader {
/**
/**
* @return the number of groups available
* @return the number of groups available
*/
*/
long
count
();
long
count
Groups
();
}
}
spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/repository/redis/RedisMultiMetricRepository.java
View file @
94e891e9
...
@@ -108,7 +108,7 @@ public class RedisMultiMetricRepository implements MultiMetricRepository {
...
@@ -108,7 +108,7 @@ public class RedisMultiMetricRepository implements MultiMetricRepository {
}
}
@Override
@Override
public
long
count
()
{
public
long
count
Groups
()
{
return
this
.
zSetOperations
.
size
();
return
this
.
zSetOperations
.
size
();
}
}
...
...
spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/rich/MultiMetricRichGaugeReader.java
0 → 100644
View file @
94e891e9
/*
* Copyright 2014-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
.
rich
;
import
java.util.ArrayList
;
import
java.util.List
;
import
org.springframework.boot.actuate.metrics.Metric
;
import
org.springframework.boot.actuate.metrics.repository.MultiMetricRepository
;
/**
* A {@link RichGaugeReader} that works by reading metric values from a
* {@link MultiMetricRepository} where the group name is the RichGauge name. The format
* used matches that in he RichGaugeExporter, so this reader can be used on a store that
* has been populated using that exporter.
*
* @author Dave Syer
*
* @since 1.1.0
*/
public
class
MultiMetricRichGaugeReader
implements
RichGaugeReader
{
private
static
final
String
COUNT
=
".count"
;
private
static
final
String
MAX
=
".max"
;
private
static
final
String
MIN
=
".min"
;
private
static
final
String
AVG
=
".avg"
;
private
static
final
String
ALPHA
=
".alpha"
;
private
static
final
String
VAL
=
".val"
;
private
final
MultiMetricRepository
repository
;
public
MultiMetricRichGaugeReader
(
MultiMetricRepository
repository
)
{
this
.
repository
=
repository
;
}
@Override
public
RichGauge
findOne
(
String
name
)
{
Iterable
<
Metric
<?>>
metrics
=
this
.
repository
.
findAll
(
name
);
double
value
=
0
;
double
average
=
0
.;
double
alpha
=
-
1
.;
double
min
=
0
.;
double
max
=
0
.;
long
count
=
0
;
for
(
Metric
<?>
metric
:
metrics
)
{
if
(
metric
.
getName
().
endsWith
(
VAL
))
{
value
=
metric
.
getValue
().
doubleValue
();
}
else
if
(
metric
.
getName
().
endsWith
(
ALPHA
))
{
alpha
=
metric
.
getValue
().
doubleValue
();
}
else
if
(
metric
.
getName
().
endsWith
(
AVG
))
{
average
=
metric
.
getValue
().
doubleValue
();
}
else
if
(
metric
.
getName
().
endsWith
(
MIN
))
{
min
=
metric
.
getValue
().
doubleValue
();
}
else
if
(
metric
.
getName
().
endsWith
(
MAX
))
{
max
=
metric
.
getValue
().
doubleValue
();
}
else
if
(
metric
.
getName
().
endsWith
(
COUNT
))
{
count
=
metric
.
getValue
().
longValue
();
}
}
return
new
RichGauge
(
name
,
value
,
alpha
,
average
,
max
,
min
,
count
);
}
@Override
public
Iterable
<
RichGauge
>
findAll
()
{
List
<
RichGauge
>
result
=
new
ArrayList
<
RichGauge
>();
for
(
String
name
:
this
.
repository
.
groups
())
{
result
.
add
(
findOne
(
name
));
}
return
result
;
}
@Override
public
long
count
()
{
return
this
.
repository
.
countGroups
();
}
}
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/repository/redis/RedisMultiMetricRepositoryTests.java
View file @
94e891e9
...
@@ -78,7 +78,7 @@ public class RedisMultiMetricRepositoryTests {
...
@@ -78,7 +78,7 @@ public class RedisMultiMetricRepositoryTests {
"foo.val"
,
12.3
),
new
Metric
<
Number
>(
"foo.bar"
,
11.3
)));
"foo.val"
,
12.3
),
new
Metric
<
Number
>(
"foo.bar"
,
11.3
)));
this
.
repository
.
save
(
"bar"
,
Arrays
.<
Metric
<?>>
asList
(
new
Metric
<
Number
>(
this
.
repository
.
save
(
"bar"
,
Arrays
.<
Metric
<?>>
asList
(
new
Metric
<
Number
>(
"bar.val"
,
12.3
),
new
Metric
<
Number
>(
"bar.foo"
,
11.3
)));
"bar.val"
,
12.3
),
new
Metric
<
Number
>(
"bar.foo"
,
11.3
)));
assertEquals
(
2
,
this
.
repository
.
count
());
assertEquals
(
2
,
this
.
repository
.
count
Groups
());
}
}
}
}
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/rich/MultiMetricRichGaugeReaderTests.java
0 → 100644
View file @
94e891e9
/*
* 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
org
.
springframework
.
boot
.
actuate
.
metrics
.
rich
;
import
org.junit.Test
;
import
org.springframework.boot.actuate.metrics.Metric
;
import
org.springframework.boot.actuate.metrics.export.RichGaugeExporter
;
import
org.springframework.boot.actuate.metrics.repository.InMemoryMetricRepository
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
/**
* @author Dave Syer
*/
public
class
MultiMetricRichGaugeReaderTests
{
private
InMemoryMetricRepository
repository
=
new
InMemoryMetricRepository
();
private
MultiMetricRichGaugeReader
reader
=
new
MultiMetricRichGaugeReader
(
this
.
repository
);
private
InMemoryRichGaugeRepository
data
=
new
InMemoryRichGaugeRepository
();
private
RichGaugeExporter
exporter
=
new
RichGaugeExporter
(
this
.
data
,
this
.
repository
);
@Test
public
void
countOne
()
{
this
.
data
.
set
(
new
Metric
<
Integer
>(
"foo"
,
1
));
this
.
data
.
set
(
new
Metric
<
Integer
>(
"foo"
,
1
));
this
.
exporter
.
export
();
// Check the exporter worked
assertEquals
(
6
,
this
.
repository
.
count
());
assertEquals
(
1
,
this
.
reader
.
count
());
RichGauge
one
=
this
.
reader
.
findOne
(
"foo"
);
assertNotNull
(
one
);
assertEquals
(
2
,
one
.
getCount
());
}
@Test
public
void
countTwo
()
{
this
.
data
.
set
(
new
Metric
<
Integer
>(
"foo"
,
1
));
this
.
data
.
set
(
new
Metric
<
Integer
>(
"bar"
,
1
));
this
.
exporter
.
export
();
assertEquals
(
2
,
this
.
reader
.
count
());
RichGauge
one
=
this
.
reader
.
findOne
(
"foo"
);
assertNotNull
(
one
);
assertEquals
(
1
,
one
.
getCount
());
}
}
spring-boot/src/main/java/org/springframework/boot/SpringApplication.java
View file @
94e891e9
...
@@ -1014,9 +1014,9 @@ public class SpringApplication {
...
@@ -1014,9 +1014,9 @@ public class SpringApplication {
}
}
}
}
private
static
<
E
>
Set
<
E
>
asUnmodifiableOrderedSet
(
Collection
<
E
>
eleme
me
nts
)
{
private
static
<
E
>
Set
<
E
>
asUnmodifiableOrderedSet
(
Collection
<
E
>
elements
)
{
List
<
E
>
list
=
new
ArrayList
<
E
>();
List
<
E
>
list
=
new
ArrayList
<
E
>();
list
.
addAll
(
eleme
me
nts
);
list
.
addAll
(
elements
);
Collections
.
sort
(
list
,
AnnotationAwareOrderComparator
.
INSTANCE
);
Collections
.
sort
(
list
,
AnnotationAwareOrderComparator
.
INSTANCE
);
return
new
LinkedHashSet
<
E
>(
list
);
return
new
LinkedHashSet
<
E
>(
list
);
}
}
...
...
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