Toggle navigation
Toggle navigation
This project
Loading...
Sign in
홍길동
/
onos
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
tom
2014-10-01 17:26:27 -0700
Browse Files
Options
Browse Files
Download
Plain Diff
Commit
ebe6a51739e5b41cdea91a1564f7cf9ea66c7061
ebe6a517
2 parents
53af33b4
390abbcb
Merge remote-tracking branch 'origin/master'
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
463 additions
and
0 deletions
features/features.xml
utils/misc/pom.xml
utils/misc/src/main/java/org/onlab/metrics/MetricsComponent.java
utils/misc/src/main/java/org/onlab/metrics/MetricsComponentRegistry.java
utils/misc/src/main/java/org/onlab/metrics/MetricsFeature.java
utils/misc/src/main/java/org/onlab/metrics/MetricsManager.java
utils/misc/src/main/java/org/onlab/metrics/MetricsService.java
utils/misc/src/main/java/org/onlab/metrics/package-info.java
features/features.xml
View file @
ebe6a51
...
...
@@ -11,6 +11,7 @@
<bundle>
mvn:io.netty/netty/3.9.2.Final
</bundle>
<bundle>
mvn:com.hazelcast/hazelcast/3.3
</bundle>
<bundle>
mvn:com.codahale.metrics/metrics-core/3.0.2
</bundle>
<bundle>
mvn:com.eclipsesource.minimal-json/minimal-json/0.9.1
</bundle>
<bundle>
mvn:com.esotericsoftware.kryo/kryo/2.24.0
</bundle>
...
...
utils/misc/pom.xml
View file @
ebe6a51
...
...
@@ -55,6 +55,11 @@
<groupId>
org.objenesis
</groupId>
<artifactId>
objenesis
</artifactId>
</dependency>
<dependency>
<groupId>
com.codahale.metrics
</groupId>
<artifactId>
metrics-core
</artifactId>
<version>
3.0.2
</version>
</dependency>
</dependencies>
</project>
...
...
utils/misc/src/main/java/org/onlab/metrics/MetricsComponent.java
0 → 100644
View file @
ebe6a51
package
org
.
onlab
.
metrics
;
import
java.util.concurrent.ConcurrentHashMap
;
import
java.util.concurrent.ConcurrentMap
;
/**
* Components to register for metrics.
*/
public
class
MetricsComponent
implements
MetricsComponentRegistry
{
private
final
String
name
;
/**
* Registry to hold the Features defined in this Component.
*/
private
final
ConcurrentMap
<
String
,
MetricsFeature
>
featuresRegistry
=
new
ConcurrentHashMap
<>();
/**
* Constructs a component from a name.
*
* @param newName name of the component
*/
MetricsComponent
(
final
String
newName
)
{
name
=
newName
;
}
@Override
public
String
getName
()
{
return
name
;
}
@Override
public
MetricsFeature
registerFeature
(
final
String
featureName
)
{
MetricsFeature
feature
=
featuresRegistry
.
get
(
featureName
);
if
(
feature
==
null
)
{
final
MetricsFeature
createdFeature
=
new
MetricsFeature
(
featureName
);
feature
=
featuresRegistry
.
putIfAbsent
(
featureName
,
createdFeature
);
if
(
feature
==
null
)
{
feature
=
createdFeature
;
}
}
return
feature
;
}
}
utils/misc/src/main/java/org/onlab/metrics/MetricsComponentRegistry.java
0 → 100644
View file @
ebe6a51
package
org
.
onlab
.
metrics
;
/**
* Registry Entry for Metrics Components.
*/
public
interface
MetricsComponentRegistry
{
String
getName
();
MetricsFeature
registerFeature
(
String
featureName
);
}
utils/misc/src/main/java/org/onlab/metrics/MetricsFeature.java
0 → 100644
View file @
ebe6a51
package
org
.
onlab
.
metrics
;
/**
* Features to tag metrics.
*/
public
class
MetricsFeature
{
private
final
String
name
;
/**
* Constructs a Feature from a name.
*
* @param newName name of the Feature
*/
MetricsFeature
(
final
String
newName
)
{
name
=
newName
;
}
public
String
getName
()
{
return
name
;
}
}
utils/misc/src/main/java/org/onlab/metrics/MetricsManager.java
0 → 100644
View file @
ebe6a51
package
org
.
onlab
.
metrics
;
import
java.util.Map
;
import
java.util.concurrent.ConcurrentHashMap
;
import
java.util.concurrent.ConcurrentMap
;
import
com.codahale.metrics.Counter
;
import
com.codahale.metrics.Gauge
;
import
com.codahale.metrics.Histogram
;
import
com.codahale.metrics.Meter
;
import
com.codahale.metrics.Metric
;
import
com.codahale.metrics.MetricFilter
;
import
com.codahale.metrics.MetricRegistry
;
import
com.codahale.metrics.Timer
;
/**
* This class holds the Metrics registry for ONOS.
* All metrics (Counter, Histogram, Timer, Meter, Gauge) use a hierarchical
* string-based naming scheme: COMPONENT.FEATURE.NAME.
* Example: "Topology.Counters.TopologyUpdates".
* The COMPONENT and FEATURE names have to be registered in advance before
* a metric can be created. Example:
* <pre>
* <code>
* private final MetricsManager.MetricsComponent COMPONENT =
* MetricsManager.registerComponent("Topology");
* private final MetricsManager.MetricsFeature FEATURE =
* COMPONENT.registerFeature("Counters");
* private final Counter counterTopologyUpdates =
* MetricsManager.createCounter(COMPONENT, FEATURE, "TopologyUpdates");
* </code>
* </pre>
* Gauges are slightly different because they are not created directly in
* this class, but are allocated by the caller and passed in for registration:
* <pre>
* <code>
* private final Gauge<Long> gauge =
* new {@literal Gauge<Long>}() {
* {@literal @}Override
* public Long getValue() {
* return gaugeValue;
* }
* };
* MetricsManager.registerMetric(COMPONENT, FEATURE, GAUGE_NAME, gauge);
* </code>
* </pre>
*/
public
final
class
MetricsManager
implements
MetricsService
{
/**
* Registry to hold the Components defined in the system.
*/
private
ConcurrentMap
<
String
,
MetricsComponent
>
componentsRegistry
=
new
ConcurrentHashMap
<>();
/**
* Registry for the Metrics objects created in the system.
*/
private
final
MetricRegistry
metricsRegistry
=
new
MetricRegistry
();
/**
* Hide constructor. The only way to get the registry is through the
* singleton getter.
*/
private
MetricsManager
()
{}
/**
* Registers a component.
*
* @param name name of the Component to register
* @return MetricsComponent object that can be used to create Metrics.
*/
public
MetricsComponent
registerComponent
(
final
String
name
)
{
MetricsComponent
component
=
componentsRegistry
.
get
(
name
);
if
(
component
==
null
)
{
final
MetricsComponent
createdComponent
=
new
MetricsComponent
(
name
);
component
=
componentsRegistry
.
putIfAbsent
(
name
,
createdComponent
);
if
(
component
==
null
)
{
component
=
createdComponent
;
}
}
return
component
;
}
/**
* Generates a name for a Metric from its component and feature.
*
* @param component component the metric is defined in
* @param feature feature the metric is defined in
* @param metricName local name of the metric
*
* @return full name of the metric
*/
public
String
generateName
(
final
MetricsComponent
component
,
final
MetricsFeature
feature
,
final
String
metricName
)
{
return
MetricRegistry
.
name
(
component
.
getName
(),
feature
.
getName
(),
metricName
);
}
/**
* Creates a Counter metric.
*
* @param component component the Counter is defined in
* @param feature feature the Counter is defined in
* @param metricName local name of the metric
* @return the created Counter Meteric
*/
public
Counter
createCounter
(
final
MetricsComponent
component
,
final
MetricsFeature
feature
,
final
String
metricName
)
{
final
String
name
=
generateName
(
component
,
feature
,
metricName
);
return
metricsRegistry
.
counter
(
name
);
}
/**
* Creates a Histogram metric.
*
* @param component component the Histogram is defined in
* @param feature feature the Histogram is defined in
* @param metricName local name of the metric
* @return the created Histogram Metric
*/
public
Histogram
createHistogram
(
final
MetricsComponent
component
,
final
MetricsFeature
feature
,
final
String
metricName
)
{
final
String
name
=
generateName
(
component
,
feature
,
metricName
);
return
metricsRegistry
.
histogram
(
name
);
}
/**
* Creates a Timer metric.
*
* @param component component the Timer is defined in
* @param feature feature the Timeer is defined in
* @param metricName local name of the metric
* @return the created Timer Metric
*/
public
Timer
createTimer
(
final
MetricsComponent
component
,
final
MetricsFeature
feature
,
final
String
metricName
)
{
final
String
name
=
generateName
(
component
,
feature
,
metricName
);
return
metricsRegistry
.
timer
(
name
);
}
/**
* Creates a Meter metric.
*
* @param component component the Meter is defined in
* @param feature feature the Meter is defined in
* @param metricName local name of the metric
* @return the created Meter Metric
*/
public
Meter
createMeter
(
final
MetricsComponent
component
,
final
MetricsFeature
feature
,
final
String
metricName
)
{
final
String
name
=
generateName
(
component
,
feature
,
metricName
);
return
metricsRegistry
.
meter
(
name
);
}
/**
* Registers an already created Metric. This is used for situation where a
* caller needs to allocate its own Metric, but still register it with the
* system.
*
* @param <T> Metric type
* @param component component the Metric is defined in
* @param feature feature the Metric is defined in
* @param metricName local name of the metric
* @param metric Metric to register
* @return the registered Metric
*/
public
<
T
extends
Metric
>
T
registerMetric
(
final
MetricsComponent
component
,
final
MetricsFeature
feature
,
final
String
metricName
,
final
T
metric
)
{
final
String
name
=
generateName
(
component
,
feature
,
metricName
);
metricsRegistry
.
register
(
name
,
metric
);
return
metric
;
}
/**
* Fetches the existing Timers.
*
* @param filter filter to use to select Timers
* @return a map of the Timers that match the filter, with the key as the
* name String to the Timer.
*/
public
Map
<
String
,
Timer
>
getTimers
(
final
MetricFilter
filter
)
{
return
metricsRegistry
.
getTimers
(
filter
);
}
/**
* Fetches the existing Gauges.
*
* @param filter filter to use to select Gauges
* @return a map of the Gauges that match the filter, with the key as the
* name String to the Gauge.
*/
@SuppressWarnings
(
"rawtypes"
)
public
Map
<
String
,
Gauge
>
getGauges
(
final
MetricFilter
filter
)
{
return
metricsRegistry
.
getGauges
(
filter
);
}
/**
* Fetches the existing Counters.
*
* @param filter filter to use to select Counters
* @return a map of the Counters that match the filter, with the key as the
* name String to the Counter.
*/
public
Map
<
String
,
Counter
>
getCounters
(
final
MetricFilter
filter
)
{
return
metricsRegistry
.
getCounters
(
filter
);
}
/**
* Fetches the existing Meters.
*
* @param filter filter to use to select Meters
* @return a map of the Meters that match the filter, with the key as the
* name String to the Meter.
*/
public
Map
<
String
,
Meter
>
getMeters
(
final
MetricFilter
filter
)
{
return
metricsRegistry
.
getMeters
(
filter
);
}
/**
* Fetches the existing Histograms.
*
* @param filter filter to use to select Histograms
* @return a map of the Histograms that match the filter, with the key as the
* name String to the Histogram.
*/
public
Map
<
String
,
Histogram
>
getHistograms
(
final
MetricFilter
filter
)
{
return
metricsRegistry
.
getHistograms
(
filter
);
}
/**
* Removes all Metrics that match a given filter.
*
* @param filter filter to use to select the Metrics to remove.
*/
public
void
removeMatching
(
final
MetricFilter
filter
)
{
metricsRegistry
.
removeMatching
(
filter
);
}
}
utils/misc/src/main/java/org/onlab/metrics/MetricsService.java
0 → 100644
View file @
ebe6a51
package
org
.
onlab
.
metrics
;
import
java.util.Map
;
import
com.codahale.metrics.Counter
;
import
com.codahale.metrics.Gauge
;
import
com.codahale.metrics.Histogram
;
import
com.codahale.metrics.Meter
;
import
com.codahale.metrics.Metric
;
import
com.codahale.metrics.MetricFilter
;
import
com.codahale.metrics.Timer
;
/**
* Metrics Service to collect metrics.
*/
interface
MetricsService
{
/**
* Registers a component.
*
* @param name name of the Component to register
* @return MetricsComponent object that can be used to create Metrics.
*/
MetricsComponent
registerComponent
(
String
name
);
/**
* Creates a Counter metric.
*
* @param component component the Counter is defined in
* @param feature feature the Counter is defined in
* @param metricName local name of the metric
* @return the created Counter Meteric
*/
Counter
createCounter
(
MetricsComponent
component
,
MetricsFeature
feature
,
String
metricName
);
/**
* Creates a Histogram metric.
*
* @param component component the Histogram is defined in
* @param feature feature the Histogram is defined in
* @param metricName local name of the metric
* @return the created Histogram Metric
*/
Histogram
createHistogram
(
MetricsComponent
component
,
MetricsFeature
feature
,
String
metricName
);
/**
* Creates a Timer metric.
*
* @param component component the Timer is defined in
* @param feature feature the Timer is defined in
* @param metricName local name of the metric
* @return the created Timer Metric
*/
Timer
createTimer
(
MetricsComponent
component
,
MetricsFeature
feature
,
String
metricName
);
/**
* Registers an already created Metric. This is used for situation where a
* caller needs to allocate its own Metric, but still register it with the
* system.
*
* @param <T> Metric type
* @param component component the Metric is defined in
* @param feature feature the Metric is defined in
* @param metricName local name of the metric
* @param metric Metric to register
* @return the registered Metric
*/
<
T
extends
Metric
>
T
registerMetric
(
MetricsComponent
component
,
MetricsFeature
feature
,
String
metricName
,
T
metric
);
/**
* Fetches the existing Timers.
*
* @param filter filter to use to select Timers
* @return a map of the Timers that match the filter, with the key as the
* name String to the Timer.
*/
Map
<
String
,
Timer
>
getTimers
(
MetricFilter
filter
);
/**
* Fetches the existing Gauges.
*
* @param filter filter to use to select Gauges
* @return a map of the Gauges that match the filter, with the key as the
* name String to the Gauge.
*/
Map
<
String
,
Gauge
>
getGauges
(
MetricFilter
filter
);
/**
* Fetches the existing Counters.
*
* @param filter filter to use to select Counters
* @return a map of the Counters that match the filter, with the key as the
* name String to the Counter.
*/
Map
<
String
,
Counter
>
getCounters
(
MetricFilter
filter
);
/**
* Fetches the existing Meters.
*
* @param filter filter to use to select Meters
* @return a map of the Meters that match the filter, with the key as the
* name String to the Meter.
*/
Map
<
String
,
Meter
>
getMeters
(
MetricFilter
filter
);
/**
* Fetches the existing Histograms.
*
* @param filter filter to use to select Histograms
* @return a map of the Histograms that match the filter, with the key as the
* name String to the Histogram.
*/
Map
<
String
,
Histogram
>
getHistograms
(
MetricFilter
filter
);
/**
* Removes all Metrics that match a given filter.
*
* @param filter filter to use to select the Metrics to remove.
*/
void
removeMatching
(
MetricFilter
filter
);
}
utils/misc/src/main/java/org/onlab/metrics/package-info.java
0 → 100644
View file @
ebe6a51
/**
* Misc utils for various performance metrics.
*/
package
org
.
onlab
.
metrics
;
Please
register
or
login
to post a comment