public class PcpMmvWriter extends Object implements PcpWriter
Creates and updates a memory-mapped file suitable for reading by the PCP MMV PMDA. The method
used to 'render' the Java values into the file (converting them to a corresponding PCP Type and
byte array) are determined by TypeHandlers
; some default TypeHandlers are
supplied (see DefaultTypeHandlers.getDefaultMappings()
) but additional ones can be
supplied for a particular Java class (registerType(Class, TypeHandler)
, or on a
metric-by-metric basis.
addMetric(MetricName, Semantics, Unit, Object)
for every metric which will be monitored by the file
start()
to write out the file ready for the MMV agent to read
updateMetric(MetricName, Object)
metrics as new values come to hand
Adding metrics after the file is started will result in an IllegalStateException
, as will
updating metric values before it's started.
This class currently has a few important limitations:
Modifier and Type | Class and Description |
---|---|
static class |
PcpMmvWriter.MmvFlag |
Constructor and Description |
---|
PcpMmvWriter(io.pcp.parfait.dxm.ByteBufferFactory byteBufferFactory,
IdentifierSourceSet identifierSources) |
PcpMmvWriter(io.pcp.parfait.dxm.ByteBufferFactory byteBufferFactory,
IdentifierSourceSet identifierSources,
MmvVersion mmvVersion) |
PcpMmvWriter(File file)
Deprecated.
should pass in an explicit IdentifierSourceSet
|
PcpMmvWriter(File file,
IdentifierSourceSet identifierSources)
Creates a new PcpMmvWriter writing to the underlying file, which will be created + opened as a
memory-mapped file.
|
PcpMmvWriter(File file,
IdentifierSourceSet identifierSources,
MmvVersion mmvVersion)
Creates a new PcpMmvWriter writing to the underlying file, which will be created + opened as a
memory-mapped file.
|
PcpMmvWriter(String name,
IdentifierSourceSet identifierSources)
Creates a new PcpMmvWriter writing to the underlying file, which will be created + opened as a
memory-mapped file.
|
PcpMmvWriter(String name,
IdentifierSourceSet identifierSources,
MmvVersion mmvVersion)
Creates a new PcpMmvWriter writing to the underlying file, which will be created + opened as a
memory-mapped file.
|
Modifier and Type | Method and Description |
---|---|
void |
addMetric(MetricName name,
Semantics semantics,
javax.measure.Unit<?> unit,
Object initialValue)
Adds a new metric to the writer, with an initial default value.
|
<T> void |
addMetric(MetricName name,
Semantics semantics,
javax.measure.Unit<?> unit,
T initialValue,
TypeHandler<T> pcpType)
Adds a new metric to the writer, with an initial default value.
|
static void |
main(String[] args) |
<T> void |
registerType(Class<T> runtimeClass,
TypeHandler<T> handler)
Registers a new
TypeHandler to be used to convert all subsequent values of type
runtimeClass |
void |
reset()
Prepares this object such that it can be restarted by invoking the
PcpWriter.start() method
again. |
void |
setClusterIdentifier(int clusterIdentifier) |
void |
setFlags(Set<PcpMmvWriter.MmvFlag> flags) |
void |
setInstanceDomainHelpText(String instanceDomain,
String shortHelpText,
String longHelpText)
Sets the help text associated with an instance domain.
|
void |
setMetricHelpText(String metricName,
String shortHelpText,
String longHelpText)
Sets the help text associated with a particular metric
|
void |
setPerMetricLock(boolean usePerMetricLock) |
void |
setProcessIdentifier(int pid) |
void |
start()
Starts the Writer, freezing the file format and writing out the metadata and initial values.
|
String |
toString() |
void |
updateMetric(MetricName name,
Object value)
Updates the metric value of the given metric, once the writer has been started
|
@Deprecated public PcpMmvWriter(File file)
IdentifierSourceSet
.PcpMmvWriter(File, IdentifierSourceSet)
public PcpMmvWriter(File file, IdentifierSourceSet identifierSources)
MmvVersion.MMV_VERSION1
formatfile
- the file to mapidentifierSources
- the sources to use for coming up with identifiers for new metrics etc.public PcpMmvWriter(File file, IdentifierSourceSet identifierSources, MmvVersion mmvVersion)
file
- the file to mapidentifierSources
- the sources to use for coming up with identifiers for new metrics etc.mmvVersion
- the MMV version format to usepublic PcpMmvWriter(io.pcp.parfait.dxm.ByteBufferFactory byteBufferFactory, IdentifierSourceSet identifierSources)
public PcpMmvWriter(io.pcp.parfait.dxm.ByteBufferFactory byteBufferFactory, IdentifierSourceSet identifierSources, MmvVersion mmvVersion)
public PcpMmvWriter(String name, IdentifierSourceSet identifierSources)
MmvVersion.MMV_VERSION1
formatname
- logical name of instrumented subsystem (e.g. "hadoop")identifierSources
- the sources to use for coming up with identifiers for new metrics etc.public PcpMmvWriter(String name, IdentifierSourceSet identifierSources, MmvVersion mmvVersion)
name
- logical name of instrumented subsystem (e.g. "hadoop")identifierSources
- the sources to use for coming up with identifiers for new metrics etc.mmvVersion
- the MMV version format to usepublic final void addMetric(MetricName name, Semantics semantics, javax.measure.Unit<?> unit, Object initialValue)
PcpWriter
TypeHandler
based on the runtime type of the initialValue parameter.addMetric
in interface PcpWriter
name
- the name of the metric to export. Must not exceed any byte-length limits specified
by the implementationsemantics
- the PCP semantics of the metricunit
- the unit used to measure the metric.initialValue
- the 'default' value to write into the file at initialisation timepublic final <T> void addMetric(MetricName name, Semantics semantics, javax.measure.Unit<?> unit, T initialValue, TypeHandler<T> pcpType)
PcpWriter
TypeHandler
based on the runtime type of the initialValue parameter.addMetric
in interface PcpWriter
name
- the name of the metric to export. Must not exceed any byte-length limits specified
by the implementationsemantics
- the PCP semantics of the metricunit
- the unit used to measure the metric.initialValue
- the 'default' value to write into the file at initialisation timepcpType
- the type converter to use to render the initial value (and all subsequent values)
to the PCP streampublic final <T> void registerType(Class<T> runtimeClass, TypeHandler<T> handler)
PcpWriter
TypeHandler
to be used to convert all subsequent values of type
runtimeClassregisterType
in interface PcpWriter
runtimeClass
- the class to be converted by the new handlerhandler
- the handler to usepublic final void updateMetric(MetricName name, Object value)
PcpWriter
updateMetric
in interface PcpWriter
name
- the metric to updatevalue
- the new value (must be convertible by the TypeHandler
used when adding the
metric)public final void start() throws IOException
PcpWriter
start
in interface PcpWriter
IOException
- if the file cannot be created or written.public void reset()
PcpWriter
PcpWriter.start()
method
again.public final void setInstanceDomainHelpText(String instanceDomain, String shortHelpText, String longHelpText)
PcpWriter
setInstanceDomainHelpText
in interface PcpWriter
instanceDomain
- Java pseudo-instance domain identifier (i.e. metric prefix; for
animals.dog[xxx].size this is the 'animals.dog' part)shortHelpText
- the short help text; must not exceed any length limits specified by the
implementationlongHelpText
- the long explanatory text; must not exceed any length limits specified by the
implementationpublic final void setMetricHelpText(String metricName, String shortHelpText, String longHelpText)
PcpWriter
setMetricHelpText
in interface PcpWriter
metricName
- String version of the metric name, ignoring any possible instance domains. (e.g. for
animals.dog[xxx].size this is 'animals.dog.size')shortHelpText
- the short help text; must not exceed any length limits specified by the
implementationlongHelpText
- the long explanatory text; must not exceed any length limits specified by the
implementationpublic void setClusterIdentifier(int clusterIdentifier)
public void setProcessIdentifier(int pid)
public void setPerMetricLock(boolean usePerMetricLock)
public void setFlags(Set<PcpMmvWriter.MmvFlag> flags)
public static void main(String[] args) throws IOException
IOException
Copyright © 2009–2019 Performance Co-Pilot. All rights reserved.