├── .github ├── FUNDING.yml └── workflows │ ├── ci.yml │ └── codeql.yml ├── parfait-agent ├── .gitignore ├── src │ ├── main │ │ ├── resources │ │ │ └── META-INF │ │ │ │ └── MANIFEST.MF │ │ └── java │ │ │ └── io │ │ │ └── pcp │ │ │ └── parfait │ │ │ ├── JmxException.java │ │ │ ├── SpecificationAdapter.java │ │ │ ├── MBeanServerException.java │ │ │ └── SpecificationException.java │ └── test │ │ └── resources │ │ ├── test.properties │ │ └── test.xml └── license │ ├── header.txt~ │ ├── header.txt │ └── parfait-agent-java.xml ├── examples ├── acme │ └── src │ │ ├── main │ │ ├── resources │ │ │ └── META-INF │ │ │ │ └── MANIFEST.MF │ │ └── java │ │ │ ├── Main.java │ │ │ └── Acme.java │ │ └── test │ │ └── java │ │ └── AcmeTest.java ├── counter │ └── src │ │ ├── main │ │ ├── resources │ │ │ └── META-INF │ │ │ │ └── MANIFEST.MF │ │ └── java │ │ │ ├── Main.java │ │ │ └── Counter.java │ │ └── test │ │ └── java │ │ └── CounterTest.java ├── sleep │ └── src │ │ ├── main │ │ ├── resources │ │ │ └── META-INF │ │ │ │ └── MANIFEST.MF │ │ └── java │ │ │ ├── Main.java │ │ │ └── Sleep.java │ │ └── test │ │ └── java │ │ └── SleepTest.java └── pom.xml ├── dxm └── src │ ├── test │ ├── resources │ │ └── mockito-extensions │ │ │ └── org.mockito.plugins.MockMaker │ └── java │ │ └── io │ │ └── pcp │ │ └── parfait │ │ └── dxm │ │ ├── ErrorThrowingIdentifierSourceTest.java │ │ ├── ConstantIdentifierSource.java │ │ ├── InstanceStoreFactoryV1Test.java │ │ ├── InstanceStoreFactoryV2Test.java │ │ ├── InstanceDomainTest.java │ │ ├── PcpClient.java │ │ └── Matchers.java │ └── main │ └── java │ └── io │ └── pcp │ └── parfait │ └── dxm │ ├── PcpId.java │ ├── PcpOffset.java │ ├── semantics │ ├── UnitValued.java │ ├── Semantics.java │ └── Dimension.java │ ├── IdentifierSource.java │ ├── MmvWritable.java │ ├── ByteBufferFactory.java │ ├── InstanceStoreFactory.java │ ├── ErrorThrowingIdentifierSource.java │ ├── InstanceStoreFactoryV1.java │ ├── InstanceStoreFactoryV2.java │ ├── types │ ├── MmvMetricType.java │ ├── AbstractTypeHandler.java │ └── TypeHandler.java │ ├── FixedValueIdentifierSource.java │ ├── WarningIdentifierSource.java │ ├── Instance.java │ ├── HashingIdentifierSource.java │ ├── InMemoryByteBufferFactory.java │ ├── MetricNameValidator.java │ └── PcpConfig.java ├── site └── images │ ├── logo.jpg │ ├── logo-large.png │ ├── logo-medium.png │ └── parfait-layers.png ├── parfait-dropwizard └── src │ ├── main │ ├── resources │ │ └── META-INF │ │ │ └── services │ │ │ └── io.dropwizard.metrics.ReporterFactory │ └── java │ │ └── io │ │ └── pcp │ │ └── parfait │ │ └── dropwizard │ │ ├── MetricAdapter.java │ │ ├── MetricAdapterFactory.java │ │ ├── MetricDescriptorLookup.java │ │ ├── MetricNameTranslator.java │ │ ├── MetricDescriptor.java │ │ ├── DefaultMetricNameTranslator.java │ │ ├── DefaultMetricDescriptorLookup.java │ │ ├── metricadapters │ │ ├── CountingAdapter.java │ │ ├── GaugeAdapter.java │ │ ├── TimerAdapter.java │ │ └── HistogramAdapter.java │ │ └── NonSelfRegisteringSettableValue.java │ └── test │ └── resources │ └── io │ └── pcp │ └── parfait │ └── dropwizard │ └── metric-app.yml ├── .hgignore ├── Dockerfile ├── .gitignore ├── CHANGELOG.md ├── license ├── #header.txt# ├── header.txt ├── header.txt~ └── parfait-java.xml ├── parfait-cxf └── src │ ├── main │ └── java │ │ └── io │ │ └── pcp │ │ └── parfait │ │ └── cxf │ │ └── X.java │ └── test │ ├── resources │ └── io │ │ └── pcp │ │ └── parfait │ │ └── cxf │ │ └── WEB-INF │ │ ├── web.xml │ │ └── beans.xml │ └── java │ └── io │ └── pcp │ └── parfait │ └── cxf │ └── RestDemo.java ├── parfait-core ├── src │ ├── main │ │ └── java │ │ │ └── io │ │ │ └── pcp │ │ │ └── parfait │ │ │ ├── MonitorableRegistryListener.java │ │ │ ├── Scheduler.java │ │ │ ├── timing │ │ │ ├── Timeable.java │ │ │ ├── StepMeasurementSink.java │ │ │ ├── ThreadMetric.java │ │ │ ├── InProgressExporter.java │ │ │ ├── ThreadValueMetric.java │ │ │ ├── AbstractThreadMetric.java │ │ │ ├── CounterPair.java │ │ │ ├── CounterPairFactory.java │ │ │ ├── ThreadMetricSuite.java │ │ │ ├── EventMetricCounters.java │ │ │ ├── DummyEventTimer.java │ │ │ ├── ThreadCounter.java │ │ │ └── EventCounters.java │ │ │ ├── SystemTimePoller.java │ │ │ ├── Counter.java │ │ │ ├── TimerScheduler.java │ │ │ ├── CompositeCounter.java │ │ │ ├── ValueSemantics.java │ │ │ ├── MonitoredNumeric.java │ │ │ ├── Monitor.java │ │ │ ├── CompositeMonitoringView.java │ │ │ ├── MonitoredIntValue.java │ │ │ ├── SettableValue.java │ │ │ ├── MonitoredConstant.java │ │ │ ├── MonitoredLongValue.java │ │ │ └── MonitoredValue.java │ └── test │ │ └── java │ │ └── io │ │ └── pcp │ │ └── parfait │ │ ├── ManualTimeSupplier.java │ │ ├── ManualScheduler.java │ │ ├── timing │ │ ├── DummyThreadMetric.java │ │ └── LoggerSinkTest.java │ │ ├── TimeWindowTest.java │ │ ├── MonitoredConstantTest.java │ │ ├── CompositeCounterTest.java │ │ ├── DummyMonitorable.java │ │ ├── PollingMonitoredValueTest.java │ │ ├── MonitoredIntValueTest.java │ │ └── MonitoredLongValueTest.java └── pom.xml ├── parfait-spring └── src │ ├── main │ └── java │ │ └── io │ │ └── pcp │ │ └── parfait │ │ └── spring │ │ ├── AdvisedAware.java │ │ ├── Profiled.java │ │ └── timing │ │ ├── BeanSpecification.java │ │ └── BeanPredicates.java │ └── test │ ├── java │ └── io │ │ └── pcp │ │ └── parfait │ │ └── spring │ │ ├── DelayingBean.java │ │ └── SelfStartingMonitoringViewTest.java │ └── resources │ └── test.xml ├── parfait-pcp ├── src │ └── main │ │ └── java │ │ └── io │ │ └── pcp │ │ └── parfait │ │ └── pcp │ │ ├── TextSource.java │ │ ├── EmptyTextSource.java │ │ ├── MetricDescriptionTextSource.java │ │ ├── MetricNameMapper.java │ │ ├── MapTextSource.java │ │ ├── RegexSequenceNameMapper.java │ │ └── StringParsingTextSource.java └── pom.xml ├── bin ├── manuals.sh ├── setenv.bat └── imports.sh ├── releasing.sh ├── parfait-benchmark └── src │ └── main │ ├── java │ └── io │ │ └── pcp │ │ └── parfait │ │ └── benchmark │ │ ├── ReportHelper.java │ │ ├── BlockedMetricHelper.java │ │ ├── CounterIncrementer.java │ │ └── BlockedMetricCollector.java │ └── assembly │ └── appassembler.xml ├── parfait-io └── pom.xml ├── parfait-jmx ├── pom.xml └── src │ └── test │ └── java │ └── io │ └── pcp │ └── parfait │ └── jmx │ └── MonitoredMBeanAttributeFactoryTest.java └── parfait-jdbc ├── pom.xml └── src └── test └── java └── io └── pcp └── parfait └── jdbc └── ParfaitDataSourceTest.java /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | open_collective: pcp 2 | -------------------------------------------------------------------------------- /parfait-agent/.gitignore: -------------------------------------------------------------------------------- 1 | dependency-reduced-pom.xml 2 | -------------------------------------------------------------------------------- /examples/acme/src/main/resources/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Main-Class: Main 2 | -------------------------------------------------------------------------------- /examples/counter/src/main/resources/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Main-Class: Main 2 | -------------------------------------------------------------------------------- /examples/sleep/src/main/resources/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Main-Class: Main 2 | -------------------------------------------------------------------------------- /dxm/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker: -------------------------------------------------------------------------------- 1 | mock-maker-inline -------------------------------------------------------------------------------- /site/images/logo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/performancecopilot/parfait/HEAD/site/images/logo.jpg -------------------------------------------------------------------------------- /site/images/logo-large.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/performancecopilot/parfait/HEAD/site/images/logo-large.png -------------------------------------------------------------------------------- /site/images/logo-medium.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/performancecopilot/parfait/HEAD/site/images/logo-medium.png -------------------------------------------------------------------------------- /site/images/parfait-layers.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/performancecopilot/parfait/HEAD/site/images/parfait-layers.png -------------------------------------------------------------------------------- /parfait-agent/src/main/resources/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Premain-Class: io.pcp.parfait.ParfaitAgent 2 | Main-Class: io.pcp.parfait.ParfaitAgent 3 | -------------------------------------------------------------------------------- /parfait-agent/src/test/resources/test.properties: -------------------------------------------------------------------------------- 1 | parfait.cluster=1001 2 | parfait.interval=500 3 | parfait.startup=2002 4 | parfait.name=TestApp 5 | -------------------------------------------------------------------------------- /parfait-dropwizard/src/main/resources/META-INF/services/io.dropwizard.metrics.ReporterFactory: -------------------------------------------------------------------------------- 1 | io.pcp.parfait.dropwizard.ParfaitReporterFactory 2 | -------------------------------------------------------------------------------- /.hgignore: -------------------------------------------------------------------------------- 1 | target 2 | .*\.orig 3 | .*\.iws 4 | .*\.ipr 5 | .*\.iml 6 | .*\.project 7 | .*\.classpath 8 | .*\.prefs 9 | atlassian-ide-plugin.xml 10 | \.idea 11 | 12 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM quay.io/performancecopilot/pcp 2 | 3 | RUN yum update -y 4 | RUN yum install -y pcp-gui git java-11-openjdk maven maven-openjdk11 5 | 6 | WORKDIR /parfait 7 | 8 | 9 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | lib 2 | target 3 | .idea 4 | .project 5 | .metadata 6 | .settings 7 | .classpath 8 | release.properties 9 | *.releaseBackup 10 | *.class 11 | *.iml 12 | *.swp 13 | .releasing.env 14 | .DS_Store -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | While not ALL changes are outlined here, important changes that have potential impacts are covered. 2 | 3 | 1.1.1 4 | ===== 5 | 6 | * fixed bug with UnitMapping #79 7 | * dependency updates (xstream via parfait-cxf) 8 | 9 | 1.1 10 | === 11 | Update to use JSR 385 Units of Measure. This required a package name change in various places. 12 | 13 | 14 | 1.0 15 | === 16 | A variety of dependencies were upgraded: 17 | * Xstream 18 | * DropWizard 19 | * Google Guava 20 | * Spring 21 | * Log4j (minor) 22 | -------------------------------------------------------------------------------- /license/#header.txt#: -------------------------------------------------------------------------------- 1 | 2 | Copyright 2009-2017 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); you 5 | may not use this file except in compliance with the License. You may 6 | obtain a copy of the License at: 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | implied. See the License for the specific language governing 14 | permissions and limitations under the License. 15 | -------------------------------------------------------------------------------- /license/header.txt: -------------------------------------------------------------------------------- 1 | Copyright 2009-2017 Aconex 2 | 3 | Licensed under the Apache License, Version 2.0 4 | (the "License"); you may not use this file except in compliance with 5 | the License. You may obtain a copy of the License at: 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 12 | implied. See the License for the specific language governing 13 | permissions and limitations under the License. 14 | 15 | -------------------------------------------------------------------------------- /parfait-agent/license/header.txt~: -------------------------------------------------------------------------------- 1 | Copyright 2009-2017 Aconex 2 | 3 | Licensed under the Apache License, Version 2.0 4 | (the "License"); you may not use this file except in compliance with 5 | the License. You may obtain a copy of the License at: 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 12 | implied. See the License for the specific language governing 13 | permissions and limitations under the License. 14 | 15 | -------------------------------------------------------------------------------- /parfait-agent/license/header.txt: -------------------------------------------------------------------------------- 1 | Copyright 2009-2017 Red Hat Inc. 2 | 3 | Licensed under the Apache License, Version 2.0 4 | (the "License"); you may not use this file except in compliance with 5 | the License. You may obtain a copy of the License at: 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 12 | implied. See the License for the specific language governing 13 | permissions and limitations under the License. 14 | 15 | -------------------------------------------------------------------------------- /parfait-agent/src/test/resources/test.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | classpath:test.properties 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /parfait-dropwizard/src/test/resources/io/pcp/parfait/dropwizard/metric-app.yml: -------------------------------------------------------------------------------- 1 | reporters: 2 | - type: parfait 3 | prefix: test 4 | pcpName: test-api 5 | registryName: dropwizard-default 6 | quietPeriod: 5000 7 | clusterIdentifier: 100 8 | frequency: 10s 9 | includes: 10 | - io.dropwizard 11 | replacements: 12 | "org.eclipse.jetty.util.thread.": "" 13 | "io.dropwizard.jetty.MutableServletContextHandler": "MSCH" 14 | "org.eclipse.jetty.server.HttpConnectionFactory.": "HCF" 15 | "org.apache.http.conn.HttpClientConnectionManager.": "HCCM" 16 | "org.apache.http.client.HttpClient.": "" 17 | "\\-": "_" 18 | "\\s": "_" 19 | -------------------------------------------------------------------------------- /parfait-cxf/src/main/java/io/pcp/parfait/cxf/X.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | package io.pcp.parfait.cxf; 18 | 19 | public class X { 20 | 21 | } 22 | -------------------------------------------------------------------------------- /dxm/src/main/java/io/pcp/parfait/dxm/PcpId.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | /** 18 | * 19 | */ 20 | package io.pcp.parfait.dxm; 21 | 22 | interface PcpId { 23 | int getId(); 24 | } -------------------------------------------------------------------------------- /parfait-cxf/src/test/resources/io/pcp/parfait/cxf/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | contextConfigLocation 5 | WEB-INF/beans.xml 6 | 7 | 8 | org.springframework.web.context.ContextLoaderListener 9 | 10 | 11 | 12 | CXFServlet 13 | CXF Servlet 14 | org.apache.cxf.transport.servlet.CXFServlet 15 | 1 16 | 17 | 18 | CXFServlet 19 | /* 20 | 21 | 22 | -------------------------------------------------------------------------------- /license/header.txt~: -------------------------------------------------------------------------------- 1 | Licensed to the Apache Software Foundation (ASF) under one 2 | or more contributor license agreements. See the NOTICE file 3 | distributed with this work for additional information 4 | regarding copyright ownership. The ASF licenses this file 5 | to you under the Apache License, Version 2.0 (the 6 | "License"); you may not use this file except in compliance 7 | with the License. You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, 12 | software distributed under the License is distributed on an 13 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | KIND, either express or implied. See the License for the 15 | specific language governing permissions and limitations 16 | under the License. 17 | -------------------------------------------------------------------------------- /dxm/src/main/java/io/pcp/parfait/dxm/PcpOffset.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | /** 18 | * 19 | */ 20 | package io.pcp.parfait.dxm; 21 | 22 | interface PcpOffset { 23 | void setOffset(int offset); 24 | int byteSize(); 25 | } -------------------------------------------------------------------------------- /dxm/src/main/java/io/pcp/parfait/dxm/semantics/UnitValued.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | /** 18 | * 19 | */ 20 | package io.pcp.parfait.dxm.semantics; 21 | 22 | interface UnitValued { 23 | public int getPmUnitsValue(); 24 | } -------------------------------------------------------------------------------- /examples/acme/src/main/java/Main.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | 18 | public class Main { 19 | public static void main(String args[]) { 20 | Acme factory = new Acme(); 21 | factory.start(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /examples/sleep/src/main/java/Main.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | public class Main { 18 | public static void main (String args[]) { 19 | Thread t = new Thread(new Sleep()); 20 | t.start(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /examples/counter/src/main/java/Main.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | public class Main { 18 | public static void main (String args[]) { 19 | Thread t = new Thread(new Counter()); 20 | t.start(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /parfait-core/src/main/java/io/pcp/parfait/MonitorableRegistryListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | package io.pcp.parfait; 18 | 19 | public interface MonitorableRegistryListener { 20 | void monitorableAdded(Monitorable monitorable); 21 | } 22 | -------------------------------------------------------------------------------- /dxm/src/main/java/io/pcp/parfait/dxm/IdentifierSource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | package io.pcp.parfait.dxm; 18 | 19 | import java.util.Set; 20 | 21 | public interface IdentifierSource { 22 | int calculateId(String name, Set usedIds); 23 | } -------------------------------------------------------------------------------- /dxm/src/main/java/io/pcp/parfait/dxm/MmvWritable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | package io.pcp.parfait.dxm; 18 | 19 | import java.nio.ByteBuffer; 20 | 21 | interface MmvWritable { 22 | 23 | int getOffset(); 24 | void writeToMmv(ByteBuffer byteBuffer); 25 | 26 | } -------------------------------------------------------------------------------- /parfait-spring/src/main/java/io/pcp/parfait/spring/AdvisedAware.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | package io.pcp.parfait.spring; 18 | 19 | public interface AdvisedAware { 20 | public void addAdvised(Object advised, String name); 21 | 22 | public String getName(); 23 | } -------------------------------------------------------------------------------- /dxm/src/main/java/io/pcp/parfait/dxm/ByteBufferFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | package io.pcp.parfait.dxm; 18 | 19 | import java.io.IOException; 20 | import java.nio.ByteBuffer; 21 | 22 | interface ByteBufferFactory { 23 | ByteBuffer build(int length) throws IOException; 24 | } 25 | -------------------------------------------------------------------------------- /parfait-core/src/main/java/io/pcp/parfait/Scheduler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | package io.pcp.parfait; 18 | 19 | import java.util.TimerTask; 20 | 21 | interface Scheduler { 22 | public void schedule(TimerTask task, long rate); 23 | 24 | public void schedule(TimerTask timerTask, long delay, long rate); 25 | } -------------------------------------------------------------------------------- /examples/sleep/src/test/java/SleepTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | import static org.junit.Assert.assertNotNull; 18 | import org.junit.Test; 19 | 20 | public class SleepTest { 21 | @Test 22 | public void constructor() { 23 | Sleep nod = new Sleep(); 24 | assertNotNull(nod); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /parfait-spring/src/main/java/io/pcp/parfait/spring/Profiled.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | package io.pcp.parfait.spring; 18 | 19 | import java.lang.annotation.*; 20 | 21 | @Inherited 22 | @Retention(RetentionPolicy.RUNTIME) 23 | @Target({ElementType.METHOD, ElementType.TYPE}) 24 | public @interface Profiled { 25 | } 26 | -------------------------------------------------------------------------------- /dxm/src/main/java/io/pcp/parfait/dxm/InstanceStoreFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | package io.pcp.parfait.dxm; 18 | 19 | import io.pcp.parfait.dxm.PcpMmvWriter.Store; 20 | 21 | interface InstanceStoreFactory { 22 | 23 | Store createNewInstanceStore(String name, InstanceDomain instanceDomain); 24 | 25 | } 26 | -------------------------------------------------------------------------------- /examples/counter/src/test/java/CounterTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | import static org.junit.Assert.assertNotNull; 18 | import org.junit.Test; 19 | 20 | public class CounterTest { 21 | @Test 22 | public void constructor() { 23 | Counter inc = new Counter(); 24 | assertNotNull(inc); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /parfait-pcp/src/main/java/io/pcp/parfait/pcp/TextSource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | package io.pcp.parfait.pcp; 18 | 19 | import io.pcp.parfait.Monitorable; 20 | import io.pcp.parfait.dxm.MetricName; 21 | 22 | public interface TextSource { 23 | public String getText(Monitorable monitorable, MetricName mappedName); 24 | } 25 | -------------------------------------------------------------------------------- /parfait-core/src/main/java/io/pcp/parfait/timing/Timeable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | package io.pcp.parfait.timing; 18 | 19 | 20 | /** 21 | * An object that implements some form of metric collection via a {@link EventTimer}. 22 | */ 23 | public interface Timeable { 24 | 25 | public void setEventTimer(EventTimer timer); 26 | 27 | } 28 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: ci 2 | 3 | on: [ push, pull_request ] 4 | 5 | jobs: 6 | java: 7 | runs-on: ubuntu-20.04 8 | steps: 9 | - uses: actions/checkout@v2 10 | - name: install pcp 11 | run: | 12 | wget -qO - https://pcp.io/GPG-KEY-PCP | sudo apt-key add - 13 | #sudo add-apt-repository 'deb https://performancecopilot.jfrog.io/artifactory/pcp-deb-release focal main' -y 14 | curl -s https://packagecloud.io/install/repositories/performancecopilot/pcp/script.deb.sh | sudo bash 15 | sudo apt-get update -q 16 | sudo apt-get install -y pcp-zeroconf pcp-gui 17 | - name: verify pcp install 18 | run: pcp 19 | - uses: actions/setup-java@v4 20 | with: 21 | distribution: 'zulu' 22 | java-version: '11' 23 | - name: open up access 24 | run: sudo chmod o+w /var/lib/pcp/tmp/mmv 25 | - name: verify parfait 26 | run: mvn -B -V clean install verify 27 | -------------------------------------------------------------------------------- /parfait-core/src/main/java/io/pcp/parfait/timing/StepMeasurementSink.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | package io.pcp.parfait.timing; 18 | 19 | /** 20 | * Destination for measurements of an individual event timing step. Implementations must be threadsafe. 21 | */ 22 | public interface StepMeasurementSink { 23 | void handle(StepMeasurements measurements, int level); 24 | } 25 | -------------------------------------------------------------------------------- /.github/workflows/codeql.yml: -------------------------------------------------------------------------------- 1 | name: "CodeQL" 2 | 3 | on: 4 | push: 5 | branches: [ "main" ] 6 | pull_request: 7 | branches: [ "main" ] 8 | schedule: 9 | - cron: "54 6 * * 1" 10 | 11 | jobs: 12 | analyze: 13 | name: Analyze 14 | runs-on: ubuntu-latest 15 | permissions: 16 | actions: read 17 | contents: read 18 | security-events: write 19 | 20 | strategy: 21 | fail-fast: false 22 | matrix: 23 | language: [ java ] 24 | 25 | steps: 26 | - name: Checkout 27 | uses: actions/checkout@v3 28 | 29 | - name: Initialize CodeQL 30 | uses: github/codeql-action/init@v2 31 | with: 32 | languages: ${{ matrix.language }} 33 | queries: +security-and-quality 34 | 35 | - name: Autobuild 36 | uses: github/codeql-action/autobuild@v2 37 | 38 | - name: Perform CodeQL Analysis 39 | uses: github/codeql-action/analyze@v2 40 | with: 41 | category: "/language:${{ matrix.language }}" 42 | -------------------------------------------------------------------------------- /parfait-core/src/main/java/io/pcp/parfait/timing/ThreadMetric.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | package io.pcp.parfait.timing; 18 | 19 | import javax.measure.Unit; 20 | 21 | 22 | public interface ThreadMetric { 23 | long getValueForThread(Thread t); 24 | 25 | String getMetricName(); 26 | 27 | Unit getUnit(); 28 | 29 | String getCounterSuffix(); 30 | 31 | String getDescription(); 32 | } 33 | -------------------------------------------------------------------------------- /examples/acme/src/test/java/AcmeTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | import static org.junit.Assert.assertNotNull; 18 | import org.junit.Test; 19 | 20 | public class AcmeTest { 21 | @Test 22 | public void constructor() { 23 | Acme factory = new Acme(); 24 | assertNotNull(factory); 25 | 26 | ProductBuilder product = new ProductBuilder("test"); 27 | assertNotNull(product); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /parfait-pcp/src/main/java/io/pcp/parfait/pcp/EmptyTextSource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | /** 18 | * 19 | */ 20 | package io.pcp.parfait.pcp; 21 | 22 | import io.pcp.parfait.Monitorable; 23 | import io.pcp.parfait.dxm.MetricName; 24 | 25 | public final class EmptyTextSource implements TextSource { 26 | @Override 27 | public String getText(Monitorable monitorable, MetricName mappedName) { 28 | return ""; 29 | } 30 | } -------------------------------------------------------------------------------- /parfait-core/src/main/java/io/pcp/parfait/SystemTimePoller.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | package io.pcp.parfait; 18 | 19 | import com.google.common.base.Supplier; 20 | 21 | /** 22 | * An implementation of {@link Supplier} to get the System time. 23 | */ 24 | public class SystemTimePoller implements Supplier { 25 | 26 | public Long get() { 27 | return System.currentTimeMillis(); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /parfait-core/src/main/java/io/pcp/parfait/Counter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | package io.pcp.parfait; 18 | 19 | public interface Counter { 20 | public static final Counter NULL_COUNTER = new Counter(){ 21 | @Override 22 | public void inc() { 23 | } 24 | 25 | @Override 26 | public void inc(long increment) { 27 | } 28 | }; 29 | 30 | void inc(); 31 | 32 | void inc(long increment); 33 | } 34 | -------------------------------------------------------------------------------- /parfait-pcp/src/main/java/io/pcp/parfait/pcp/MetricDescriptionTextSource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | package io.pcp.parfait.pcp; 18 | 19 | import io.pcp.parfait.Monitorable; 20 | import io.pcp.parfait.dxm.MetricName; 21 | 22 | public class MetricDescriptionTextSource implements TextSource { 23 | @Override 24 | public String getText(Monitorable monitorable, MetricName mappedName) { 25 | return monitorable.getDescription(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /dxm/src/main/java/io/pcp/parfait/dxm/semantics/Semantics.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | package io.pcp.parfait.dxm.semantics; 18 | 19 | public enum Semantics { 20 | NO_SEMANTICS(0), 21 | COUNTER(1), 22 | INSTANT(3), 23 | DISCRETE(4); 24 | 25 | private final int pcpValue; 26 | 27 | Semantics(int pcpValue) { 28 | this.pcpValue = pcpValue; 29 | } 30 | 31 | public int getPcpValue() { 32 | return pcpValue; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /examples/sleep/src/main/java/Sleep.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | public class Sleep implements Runnable { 18 | public void run() { 19 | try { 20 | System.out.println("G'day World!"); 21 | synchronized(this) { 22 | while (true) { 23 | this.wait(); 24 | } 25 | } 26 | } catch (InterruptedException e) { 27 | e.printStackTrace(); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /bin/manuals.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Copyright (c) 2017 Red Hat 4 | # 5 | # This is free software; you can redistribute it and/or modify it 6 | # under the terms of the GNU Lesser General Public License as 7 | # published by the Free Software Foundation; either version 2.1 of 8 | # the License, or (at your option) any later version. 9 | # 10 | # This software is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # Lesser General Public License for more details. 14 | # 15 | # Generate Parfait man page and html docs from Markdown. 16 | # 17 | 18 | which ronn >/dev/null 2>&1 19 | if [ $? -ne 0 ] 20 | then 21 | echo "Cannot find 'ronn' program on the PATH" 22 | exit 1 23 | fi 24 | echo "Building" 25 | ronn PARFAIT.1.md 26 | if [ $? -ne 0 ] 27 | then 28 | echo "Failed to execute 'ronn' on PARFAIT.1.md" 29 | exit 1 30 | fi 31 | 32 | echo 33 | mv PARFAIT.1 man/parfait.1 34 | mv PARFAIT.1.html man/parfait.html 35 | 36 | echo "Manuals:" 37 | find man/ -type f 38 | -------------------------------------------------------------------------------- /dxm/src/main/java/io/pcp/parfait/dxm/semantics/Dimension.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | /** 18 | * 19 | */ 20 | package io.pcp.parfait.dxm.semantics; 21 | 22 | enum Dimension implements UnitValued { 23 | PER(-1), 24 | NONE(0), 25 | UNITS(1); 26 | 27 | private final int pcpDimension; 28 | 29 | Dimension(int pcpDimension) { 30 | this.pcpDimension = pcpDimension; 31 | } 32 | 33 | public int getPmUnitsValue() { 34 | return pcpDimension; 35 | } 36 | } -------------------------------------------------------------------------------- /parfait-core/src/test/java/io/pcp/parfait/ManualTimeSupplier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | package io.pcp.parfait; 18 | 19 | import com.google.common.base.Supplier; 20 | 21 | final class ManualTimeSupplier implements Supplier { 22 | private long time; 23 | 24 | public void setTime(long time) { 25 | this.time = time; 26 | } 27 | 28 | public void tick(long increment) { 29 | this.time += increment; 30 | } 31 | 32 | @Override 33 | public Long get() { 34 | return time; 35 | } 36 | } -------------------------------------------------------------------------------- /dxm/src/test/java/io/pcp/parfait/dxm/ErrorThrowingIdentifierSourceTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | package io.pcp.parfait.dxm; 18 | 19 | import java.util.Collections; 20 | 21 | import org.junit.Test; 22 | 23 | public class ErrorThrowingIdentifierSourceTest { 24 | @Test(expected = UnsupportedOperationException.class) 25 | public void shouldThrowExceptionWhenIdentifierRequested() { 26 | new ErrorThrowingIdentifierSource().calculateId("foo", Collections. emptySet()); 27 | 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /parfait-pcp/src/main/java/io/pcp/parfait/pcp/MetricNameMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | package io.pcp.parfait.pcp; 18 | 19 | import io.pcp.parfait.dxm.MetricName; 20 | 21 | /** 22 | * Maps a String to a PCP {@link MetricName}. 23 | */ 24 | public interface MetricNameMapper { 25 | static final MetricNameMapper PASSTHROUGH_MAPPER = new MetricNameMapper() { 26 | @Override 27 | public MetricName map(String name) { 28 | return MetricName.parse(name); 29 | } 30 | }; 31 | 32 | MetricName map(String name); 33 | } 34 | -------------------------------------------------------------------------------- /dxm/src/test/java/io/pcp/parfait/dxm/ConstantIdentifierSource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | package io.pcp.parfait.dxm; 18 | 19 | import java.util.Set; 20 | 21 | public class ConstantIdentifierSource implements IdentifierSource { 22 | private final int returnValue; 23 | 24 | public ConstantIdentifierSource(int returnValue) { 25 | this.returnValue = returnValue; 26 | } 27 | 28 | @Override 29 | public int calculateId(String name, Set usedIds) { 30 | return returnValue; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /parfait-spring/src/test/java/io/pcp/parfait/spring/DelayingBean.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | package io.pcp.parfait.spring; 18 | 19 | import java.util.Random; 20 | 21 | @Profiled 22 | public class DelayingBean { 23 | private final int delay; 24 | 25 | public DelayingBean() { 26 | this.delay = new Random().nextInt(100); 27 | } 28 | 29 | @Profiled 30 | public void doThing() { 31 | try { 32 | Thread.sleep(delay); 33 | } catch (InterruptedException e) { 34 | throw new RuntimeException(e); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /parfait-dropwizard/src/main/java/io/pcp/parfait/dropwizard/MetricAdapter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | package io.pcp.parfait.dropwizard; 18 | 19 | import java.util.Set; 20 | 21 | import io.pcp.parfait.Monitorable; 22 | 23 | /** 24 | * An adapter for a Dropwizard metric 25 | */ 26 | public interface MetricAdapter { 27 | 28 | /** 29 | * Get the set of Monitorables for this Metric 30 | */ 31 | Set getMonitorables(); 32 | 33 | /** 34 | * Update the Monitorable(s) from the Metric 35 | */ 36 | void updateMonitorables(); 37 | } 38 | -------------------------------------------------------------------------------- /parfait-core/src/main/java/io/pcp/parfait/timing/InProgressExporter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | package io.pcp.parfait.timing; 18 | 19 | 20 | 21 | public class InProgressExporter { 22 | private final EventTimer timer; 23 | private final ThreadContext context; 24 | 25 | public InProgressExporter(EventTimer timer, ThreadContext context) { 26 | this.timer = timer; 27 | this.context = context; 28 | } 29 | 30 | public InProgressSnapshot getSnapshot() { 31 | return InProgressSnapshot.capture(timer, context); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /parfait-dropwizard/src/main/java/io/pcp/parfait/dropwizard/MetricAdapterFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | package io.pcp.parfait.dropwizard; 18 | 19 | import com.codahale.metrics.Metric; 20 | 21 | public interface MetricAdapterFactory { 22 | 23 | /** 24 | * Create a MetricAdapted for a Dropwizard metric 25 | * 26 | * @param name The name the metric is published under in Dropwizard 27 | * @param metric The metric 28 | * @return A MetricAdapter representing the passed Metric 29 | */ 30 | MetricAdapter createMetricAdapterFor(String name, Metric metric); 31 | } 32 | -------------------------------------------------------------------------------- /parfait-dropwizard/src/main/java/io/pcp/parfait/dropwizard/MetricDescriptorLookup.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | package io.pcp.parfait.dropwizard; 18 | 19 | /** 20 | * The strategy used to retrieve the metric descriptor for metrics being adapted 21 | */ 22 | public interface MetricDescriptorLookup { 23 | 24 | /** 25 | * Get the metric descriptor for the specified metric 26 | * 27 | * @param metricName The name the metric is publish under in Dropwizard 28 | * @return The MetricDescriptor for that metric 29 | */ 30 | MetricDescriptor getDescriptorFor(String metricName); 31 | } 32 | -------------------------------------------------------------------------------- /parfait-core/src/main/java/io/pcp/parfait/TimerScheduler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | package io.pcp.parfait; 18 | 19 | import java.util.Timer; 20 | import java.util.TimerTask; 21 | 22 | public class TimerScheduler implements Scheduler { 23 | private final Timer timer; 24 | 25 | public TimerScheduler(Timer timer) { 26 | this.timer = timer; 27 | } 28 | 29 | @Override 30 | public void schedule(TimerTask task, long rate) { 31 | schedule(task, rate, rate); 32 | 33 | } 34 | 35 | @Override 36 | public void schedule(TimerTask timerTask, long delay, long rate) { 37 | timer.scheduleAtFixedRate(timerTask, delay, rate); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /dxm/src/main/java/io/pcp/parfait/dxm/ErrorThrowingIdentifierSource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | package io.pcp.parfait.dxm; 18 | 19 | import java.util.Set; 20 | 21 | /** 22 | * {@link IdentifierSource} which throws an error on every generation. Can be used as a 'fallback' 23 | * IdentifierSource when only explicitly-provided IDs should be used. 24 | */ 25 | public class ErrorThrowingIdentifierSource implements IdentifierSource { 26 | @Override 27 | public int calculateId(String name, Set usedIds) { 28 | throw new UnsupportedOperationException("No identifier provided for value " + name 29 | + "; please specify an explicit ID"); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /dxm/src/main/java/io/pcp/parfait/dxm/InstanceStoreFactoryV1.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | package io.pcp.parfait.dxm; 18 | 19 | import io.pcp.parfait.dxm.InstanceV1.InstanceStoreV1; 20 | import io.pcp.parfait.dxm.PcpMmvWriter.Store; 21 | 22 | class InstanceStoreFactoryV1 implements InstanceStoreFactory { 23 | 24 | private IdentifierSourceSet instanceStores; 25 | 26 | InstanceStoreFactoryV1(IdentifierSourceSet instanceStores) { 27 | this.instanceStores = instanceStores; 28 | } 29 | 30 | @Override 31 | public Store createNewInstanceStore(String name, InstanceDomain instanceDomain) { 32 | return new InstanceStoreV1(instanceStores, name, instanceDomain); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /bin/setenv.bat: -------------------------------------------------------------------------------- 1 | @rem ----------------------------------------------------------------------------------- 2 | @rem 3 | @rem Copyright (c) 2016 Red Hat 4 | @rem 5 | @rem This is free software; you can redistribute it and/or modify it 6 | @rem under the terms of the GNU Lesser General Public License as 7 | @rem published by the Free Software Foundation; either version 2.1 of 8 | @rem the License, or (at your option) any later version. 9 | @rem 10 | @rem This software is distributed in the hope that it will be useful, 11 | @rem but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | @rem MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | @rem Lesser General Public License for more details. 14 | @rem 15 | @rem Batch file to set PARFAIT_HOME and PARFAIT_JAR in the environment. 16 | @rem 17 | @rem ----------------------------------------------------------------------------------- 18 | 19 | @rem use PARFAIT_HOME to locate installed parfait release 20 | if not "%PARFAIT_HOME%" == "" goto gotHome 21 | set "CURRENT_DIR=%cd%" 22 | cd %~dp0 23 | cd .. 24 | set "PARFAIT_HOME=%cd%" 25 | cd "%CURRENT_DIR%" 26 | 27 | :gotHome 28 | if exist "%PARFAIT_HOME%\lib\parfait.jar" goto okJar 29 | echo Cannot locate parfait agent jar 30 | exit /b 1 31 | 32 | :okJar 33 | set "PARFAIT_JAR=%PARFAIT_HOME%\lib\parfait.jar" 34 | -------------------------------------------------------------------------------- /license/parfait-java.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 21 | /* 22 | * 23 | */EOL 24 | EOL 25 | 26 | (\s|\t)*/\*.*$ 27 | .*\*/(\s|\t)*$ 28 | false 29 | true 30 | false 31 | 32 | 33 | -------------------------------------------------------------------------------- /releasing.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | 5 | [ ! -f .releasing.env ] && echo ".releasing.env file not found" && exit 1 6 | source .releasing.env 7 | 8 | [ ! "$GIT_USERNAME" ] && echo "GIT_USERNAME is not set" && exit 1 9 | [ ! "$GIT_EMAIL" ] && echo "GIT_EMAIL is not set" && exit 1 10 | [ ! "$GPG_PASSPHRASE" ] && echo "GPG_PASSPHRASE is not set" && exit 1 11 | 12 | [ ! "$RELEASE_VERSION" ] && echo "RELEASE_VERSION is not set" && exit 1 13 | [ ! "$DEVELOPMENT_VERSION" ] && echo "DEVELOPMENT_VERSION is not set" && exit 1 14 | 15 | docker build . -t parfait-builder 16 | # This runs the Docker-based build: 17 | # * sets up Git & PGP environment variables 18 | # * mounts the code base into /parfait (which becomes the WORKDIR) 19 | # * mounts your GPG exported key (see RELEASING.md for the requirements there) 20 | # * mounts the SSH_AUTH_SOCK so you can leverage your local SSH agent 21 | # * then launches the releasing-scripts/docker-release-build.sh to perform the build inside the container 22 | docker run --rm --env-file .releasing.env --env SSH_AUTH_SOCK="/run/host-services/ssh-auth.sock" --volume `pwd`:/parfait --volume ~/.m2:/root/.m2 --volume ~/gpgkeyexport:/root/gpgkeyexport --mount type=bind,src=/run/host-services/ssh-auth.sock,target=/run/host-services/ssh-auth.sock parfait-builder sh -c 'releasing-scripts/docker-release-build.sh' 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /parfait-dropwizard/src/main/java/io/pcp/parfait/dropwizard/MetricNameTranslator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | package io.pcp.parfait.dropwizard; 18 | 19 | /** 20 | * MetricNameTranslators can be provided to {@link io.pcp.parfait.dropwizard.MetricAdapterFactoryImpl} 21 | * to translate the metric names originating from Dropwizard to those that will be published in Parfait. 22 | */ 23 | public interface MetricNameTranslator { 24 | 25 | /** 26 | * Translate a metric name into the name the metric will be published under in Parfait 27 | * 28 | * @param name The metric name provided by Dropwizard 29 | * @return The name to use to publish the metric in Parfait 30 | */ 31 | String translate(String name); 32 | } 33 | -------------------------------------------------------------------------------- /parfait-agent/license/parfait-agent-java.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 21 | /* 22 | * 23 | */EOL 24 | EOL 25 | 26 | (\s|\t)*/\*.*$ 27 | .*\*/(\s|\t)*$ 28 | false 29 | true 30 | false 31 | 32 | 33 | -------------------------------------------------------------------------------- /parfait-core/src/main/java/io/pcp/parfait/timing/ThreadValueMetric.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | package io.pcp.parfait.timing; 18 | 19 | import javax.measure.Unit; 20 | 21 | public class ThreadValueMetric extends AbstractThreadMetric { 22 | public ThreadValue source; 23 | 24 | public ThreadValueMetric(String name, Unit unit, String counterSuffix, 25 | String description, ThreadValue source) { 26 | super(name, unit, counterSuffix, description); 27 | this.source = source; 28 | } 29 | 30 | @Override 31 | public long getValueForThread(Thread t) { 32 | Number n = source.getForThread(t); 33 | return n == null ? 0 : n.longValue(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /examples/acme/src/main/java/Acme.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | 18 | public class Acme { 19 | private ProductBuilder rockets = new ProductBuilder("Rockets"); 20 | private ProductBuilder anvils = new ProductBuilder("Anvils"); 21 | private ProductBuilder gbrs = new ProductBuilder("Giant_Rubber_Bands"); 22 | 23 | Acme() { 24 | rockets.difficulty(4500); 25 | anvils.difficulty(150); 26 | gbrs.difficulty(25); 27 | } 28 | 29 | public void start() { 30 | rockets.start(); 31 | anvils.start(); 32 | gbrs.start(); 33 | try { 34 | gbrs.join(); // blocks forever 35 | } catch (Exception e) { 36 | System.out.println("Shutdown"); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /parfait-agent/src/main/java/io/pcp/parfait/JmxException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Red Hat Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | package io.pcp.parfait; 18 | 19 | /** 20 | * General base exception to be thrown on JMX errors. 21 | */ 22 | @SuppressWarnings("serial") 23 | public class JmxException extends RuntimeException { 24 | /** 25 | * Constructor for JmxException. 26 | * @param msg the detail message 27 | */ 28 | public JmxException(String msg) { 29 | super(msg); 30 | } 31 | 32 | /** 33 | * Constructor for JmxException. 34 | * @param msg the detail message 35 | * @param cause the root cause (raw JMX API exception) 36 | */ 37 | public JmxException(String msg, Throwable cause) { 38 | super(msg, cause); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /examples/counter/src/main/java/Counter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | import io.pcp.parfait.MonitoredCounter; 18 | 19 | public class Counter implements Runnable { 20 | private MonitoredCounter counter; 21 | private int time = 1000; 22 | 23 | Counter () { 24 | counter = new MonitoredCounter("example.counter", "A simple Counter that increments once per second"); 25 | } 26 | 27 | public void run () { 28 | try { 29 | while (true) { 30 | counter.inc(); 31 | System.out.println("Counter set to: " + counter.get()); 32 | Thread.sleep(time); 33 | } 34 | } catch (InterruptedException e) { 35 | e.printStackTrace(); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /parfait-spring/src/main/java/io/pcp/parfait/spring/timing/BeanSpecification.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | package io.pcp.parfait.spring.timing; 18 | 19 | import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; 20 | 21 | public final class BeanSpecification { 22 | private final String name; 23 | private final ConfigurableListableBeanFactory beanFactory; 24 | 25 | public BeanSpecification(String name, ConfigurableListableBeanFactory beanFactory) { 26 | this.name = name; 27 | this.beanFactory = beanFactory; 28 | } 29 | 30 | public String getName() { 31 | return name; 32 | } 33 | 34 | public ConfigurableListableBeanFactory getBeanFactory() { 35 | return beanFactory; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /bin/imports.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Copyright (c) 2016 Red Hat 4 | # 5 | # This is free software; you can redistribute it and/or modify it 6 | # under the terms of the GNU Lesser General Public License as 7 | # published by the Free Software Foundation; either version 2.1 of 8 | # the License, or (at your option) any later version. 9 | # 10 | # This software is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # Lesser General Public License for more details. 14 | # 15 | # Convert specified files (and/or recurse directories) and convert 16 | # all com.custardsource.parfait references to io.pcp.parfait. 17 | # 18 | 19 | old="com.custardsource.parfait" 20 | new="io.pcp.parfait" 21 | 22 | convert() 23 | { 24 | files=`find $@ -type f -print` 25 | for file in $files 26 | do 27 | sum1=`sum $file` 28 | sed -i \ 29 | -e "s/^import $old/import $new/g" \ 30 | $file 31 | sum2=`sum $file` 32 | if [ "$sum1" != "$sum2" ] 33 | then 34 | echo "Updated $file" 35 | total=`expr $total + 1` 36 | fi 37 | done 38 | } 39 | 40 | total=0 41 | [ $# -eq 0 ] && convert . 42 | for anything in $@ 43 | do 44 | convert "$anything" 45 | done 46 | echo "$total files converted" 47 | -------------------------------------------------------------------------------- /parfait-core/src/test/java/io/pcp/parfait/ManualScheduler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | package io.pcp.parfait; 18 | 19 | import java.util.Map; 20 | import java.util.TimerTask; 21 | 22 | import com.google.common.collect.Maps; 23 | 24 | final class ManualScheduler implements Scheduler { 25 | Map scheduledRates = Maps.newHashMap(); 26 | 27 | @Override 28 | public void schedule(TimerTask task, long rate) { 29 | scheduledRates.put(task, rate); 30 | } 31 | 32 | void runAllScheduledTasks() { 33 | for (TimerTask task : scheduledRates.keySet()) { 34 | task.run(); 35 | } 36 | } 37 | 38 | @Override 39 | public void schedule(TimerTask timerTask, long delay, long rate) { 40 | // We can safely ignore delay here 41 | schedule(timerTask, rate); 42 | } 43 | 44 | } -------------------------------------------------------------------------------- /parfait-cxf/src/test/java/io/pcp/parfait/cxf/RestDemo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | package io.pcp.parfait.cxf; 18 | 19 | import jakarta.ws.rs.GET; 20 | import jakarta.ws.rs.Path; 21 | import jakarta.ws.rs.Produces; 22 | 23 | import io.pcp.parfait.timing.EventTimer; 24 | import io.pcp.parfait.timing.Timeable; 25 | 26 | @Path("/restdemo/") 27 | @Produces("text/plain") 28 | public class RestDemo implements Timeable { 29 | @GET 30 | @Path("/sayhello/") 31 | public String sayHello() { 32 | return "Hi there!"; 33 | } 34 | 35 | @GET 36 | @Path("/snooze/") 37 | public String sleepyTime() throws InterruptedException { 38 | Thread.sleep(2000); 39 | return "ZZZZZ"; 40 | } 41 | 42 | @Override 43 | public void setEventTimer(EventTimer timer) { 44 | } 45 | } -------------------------------------------------------------------------------- /parfait-agent/src/main/java/io/pcp/parfait/SpecificationAdapter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Red Hat Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | package io.pcp.parfait; 18 | 19 | import com.fasterxml.jackson.databind.JsonNode; 20 | 21 | class SpecificationAdapter { 22 | 23 | Specification fromJson(JsonNode jsonNode) { 24 | return new Specification(jsonNode.path("name").asText(), 25 | jsonNode.path("optional").asBoolean(), 26 | jsonNode.path("description").asText(), 27 | jsonNode.path("semantics").asText(), 28 | jsonNode.path("units").asText(), 29 | jsonNode.path("mBeanName").asText(), 30 | jsonNode.path("mBeanAttributeName").asText(), 31 | jsonNode.path("mBeanCompositeDataItem").asText()); 32 | 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /examples/pom.xml: -------------------------------------------------------------------------------- 1 | 18 | 19 | 4.0.0 20 | pom 21 | parfait examples 22 | Example Java applications demonstrating Parfait 23 | 24 | io.pcp 25 | parfait 26 | 1.2.2-SNAPSHOT 27 | 28 | io.pcp.parfait 29 | examples 30 | 31 | acme 32 | sleep 33 | counter 34 | 35 | 36 | -------------------------------------------------------------------------------- /parfait-core/src/main/java/io/pcp/parfait/CompositeCounter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | package io.pcp.parfait; 18 | 19 | import java.util.Collection; 20 | 21 | import com.google.common.collect.ImmutableList; 22 | 23 | public class CompositeCounter implements Counter { 24 | private final Collection counters; 25 | 26 | public CompositeCounter(Collection counters) { 27 | this.counters = ImmutableList.copyOf(counters); 28 | } 29 | 30 | @Override 31 | public void inc() { 32 | for (Counter counter : counters) { 33 | counter.inc(); 34 | } 35 | } 36 | 37 | @Override 38 | public void inc(long increment) { 39 | for (Counter counter : counters) { 40 | counter.inc(increment); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /parfait-spring/src/main/java/io/pcp/parfait/spring/timing/BeanPredicates.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | package io.pcp.parfait.spring.timing; 18 | 19 | import com.google.common.base.Predicate; 20 | import org.springframework.beans.factory.config.BeanDefinition; 21 | 22 | public class BeanPredicates { 23 | public static Predicate hasAttribute(final String meta, final Object value) { 24 | return new Predicate() { 25 | @Override 26 | public boolean apply(BeanSpecification input) { 27 | BeanDefinition definition = input.getBeanFactory().getBeanDefinition(input.getName()); 28 | Object attribute = definition.getAttribute(meta); 29 | return value.equals(attribute); 30 | } 31 | }; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /parfait-benchmark/src/main/java/io/pcp/parfait/benchmark/ReportHelper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | package io.pcp.parfait.benchmark; 18 | 19 | import static java.net.InetAddress.getLocalHost; 20 | 21 | import java.net.UnknownHostException; 22 | 23 | import org.apache.commons.lang3.SystemUtils; 24 | 25 | public class ReportHelper { 26 | static void environmentReportHeader() { 27 | String hostName = getCurrentHostname(); 28 | System.out.printf("Host: %s\tJava: %s\n", hostName, SystemUtils.JAVA_VERSION); 29 | } 30 | 31 | private static String getCurrentHostname() { 32 | String hostName = "UNKNOWN"; 33 | try { 34 | hostName = getLocalHost().getCanonicalHostName(); 35 | } catch (UnknownHostException ignored) { 36 | } 37 | return hostName; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /parfait-core/src/test/java/io/pcp/parfait/timing/DummyThreadMetric.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | package io.pcp.parfait.timing; 18 | 19 | import java.util.concurrent.atomic.AtomicLong; 20 | 21 | import javax.measure.Unit; 22 | 23 | public class DummyThreadMetric extends AbstractThreadMetric { 24 | public static final String METRIC_NAME = "dummy"; 25 | public static final String METRIC_SUFFIX = "dummy.value"; 26 | 27 | private AtomicLong value = new AtomicLong(); 28 | 29 | public DummyThreadMetric(Unit unit) { 30 | super(METRIC_NAME, unit, METRIC_SUFFIX, METRIC_NAME); 31 | } 32 | 33 | @Override 34 | public long getValueForThread(Thread t) { 35 | return value.get(); 36 | } 37 | 38 | public void incrementValue(int amount) { 39 | value.addAndGet(amount); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /parfait-benchmark/src/main/assembly/appassembler.xml: -------------------------------------------------------------------------------- 1 | 18 | 19 | bin 20 | 21 | tar.gz 22 | 23 | 24 | 25 | 26 | README* 27 | LICENSE* 28 | NOTICE* 29 | 30 | 31 | 32 | target/appassembler/lib 33 | lib 34 | 35 | 36 | target/appassembler/bin 37 | bin 38 | 755 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /parfait-dropwizard/src/main/java/io/pcp/parfait/dropwizard/MetricDescriptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | package io.pcp.parfait.dropwizard; 18 | 19 | import javax.measure.Unit; 20 | 21 | import io.pcp.parfait.ValueSemantics; 22 | 23 | /** 24 | * The metadata published with a metric in Parfait 25 | */ 26 | public interface MetricDescriptor { 27 | 28 | /** 29 | * The unit of the metric 30 | * 31 | * @return The JSR-363 unit 32 | */ 33 | Unit getUnit(); 34 | 35 | /** 36 | * The human-readable description of the metric 37 | * 38 | * @return The description 39 | */ 40 | String getDescription(); 41 | 42 | /** 43 | * The ValueSemantics of the metric 44 | * 45 | * @return the ValueSemantics 46 | * @see io.pcp.parfait.ValueSemantics 47 | */ 48 | ValueSemantics getSemantics(); 49 | } 50 | -------------------------------------------------------------------------------- /parfait-dropwizard/src/main/java/io/pcp/parfait/dropwizard/DefaultMetricNameTranslator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | package io.pcp.parfait.dropwizard; 18 | 19 | import java.util.LinkedHashMap; 20 | import java.util.Map; 21 | 22 | public class DefaultMetricNameTranslator implements MetricNameTranslator { 23 | 24 | private Map replacements = new LinkedHashMap<>(); 25 | 26 | public DefaultMetricNameTranslator(Map replacements) { 27 | this.replacements = replacements; 28 | } 29 | 30 | @Override 31 | public String translate(String name) { 32 | String translatedName = name; 33 | for (Map.Entry entry : replacements.entrySet()) { 34 | translatedName = translatedName.replaceAll(entry.getKey(), entry.getValue()); 35 | } 36 | return translatedName; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /parfait-agent/src/main/java/io/pcp/parfait/MBeanServerException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Red Hat Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | package io.pcp.parfait; 18 | 19 | /** 20 | * Exception thrown when we cannot locate an instance of an {@code MBeanServer} 21 | */ 22 | @SuppressWarnings("serial") 23 | public class MBeanServerException extends JmxException { 24 | /** 25 | * Create a new {@code MBeanServerException} with the given error message. 26 | * @param msg the error message 27 | */ 28 | public MBeanServerException(String msg) { 29 | super(msg); 30 | } 31 | 32 | /** 33 | * Create a new {@code MBeanServerException} with the 34 | * given error message and root cause. 35 | * @param msg the error message 36 | * @param cause the root cause 37 | */ 38 | public MBeanServerException(String msg, Throwable cause) { 39 | super(msg, cause); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /parfait-agent/src/main/java/io/pcp/parfait/SpecificationException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Red Hat Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | package io.pcp.parfait; 18 | 19 | /** 20 | * General Specification parsing error exceptions. 21 | */ 22 | @SuppressWarnings("serial") 23 | public class SpecificationException extends RuntimeException { 24 | /** 25 | * Constructor for SpecificationException. 26 | * @param name the metric being parsed 27 | * @param details the detailed message 28 | */ 29 | public SpecificationException(String name, String details) { 30 | super("Metric " + name + ": " + details); 31 | } 32 | 33 | /** 34 | * Constructor for SpecificationException. 35 | * @param msg the detail message 36 | * @param cause the root cause (raw Java exception) 37 | */ 38 | public SpecificationException(String msg, Throwable cause) { 39 | super(msg, cause); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /dxm/src/main/java/io/pcp/parfait/dxm/InstanceStoreFactoryV2.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | package io.pcp.parfait.dxm; 18 | 19 | import io.pcp.parfait.dxm.InstanceV2.InstanceStoreV2; 20 | import io.pcp.parfait.dxm.PcpMmvWriter.Store; 21 | import io.pcp.parfait.dxm.PcpString.PcpStringStore; 22 | 23 | class InstanceStoreFactoryV2 implements InstanceStoreFactory { 24 | 25 | private IdentifierSourceSet identifierSourceSet; 26 | private PcpStringStore stringStore; 27 | 28 | InstanceStoreFactoryV2(IdentifierSourceSet identifierSourceSet, PcpStringStore stringStore) { 29 | this.identifierSourceSet = identifierSourceSet; 30 | this.stringStore = stringStore; 31 | } 32 | 33 | @Override 34 | public Store createNewInstanceStore(String name, InstanceDomain instanceDomain) { 35 | return new InstanceStoreV2(identifierSourceSet, name, instanceDomain, stringStore); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /parfait-pcp/src/main/java/io/pcp/parfait/pcp/MapTextSource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | package io.pcp.parfait.pcp; 18 | 19 | import java.util.Map; 20 | 21 | import io.pcp.parfait.Monitorable; 22 | import io.pcp.parfait.dxm.MetricName; 23 | 24 | public class MapTextSource implements TextSource { 25 | private final TextSource fallback; 26 | private final Map descriptionsByMetricName; 27 | 28 | public MapTextSource(TextSource fallback, Map descriptionsByMetricName) { 29 | this.fallback = fallback; 30 | this.descriptionsByMetricName = descriptionsByMetricName; 31 | } 32 | 33 | @Override 34 | public String getText(Monitorable monitorable, MetricName mappedName) { 35 | String override = descriptionsByMetricName.get(mappedName.getMetric()); 36 | return override == null ? fallback.getText(monitorable, mappedName) : override; 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /dxm/src/main/java/io/pcp/parfait/dxm/types/MmvMetricType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | package io.pcp.parfait.dxm.types; 18 | 19 | 20 | /** 21 | * Metric types as represented in mmv_stats.h (which in turn parallel pmapi.h) 22 | * 23 | * @author Cowan 24 | */ 25 | public enum MmvMetricType { 26 | NOT_SUPPORTED(-1, "unsupported"), 27 | I32(0, "int"), 28 | U32(1, "uint"), 29 | I64(2, "long"), 30 | U64(3, "ulong"), 31 | FLOAT(4, "float"), 32 | DOUBLE(5, "double"), 33 | STRING(6, "string"); 34 | 35 | private final int identifier; 36 | private final String description; 37 | 38 | private MmvMetricType(int identifier, String description) { 39 | this.identifier = identifier; 40 | this.description = description; 41 | } 42 | 43 | public int getIdentifier() { 44 | return this.identifier; 45 | } 46 | 47 | public String getDescription() { 48 | return description; 49 | } 50 | } -------------------------------------------------------------------------------- /parfait-benchmark/src/main/java/io/pcp/parfait/benchmark/BlockedMetricHelper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | package io.pcp.parfait.benchmark; 18 | 19 | import java.util.List; 20 | 21 | public class BlockedMetricHelper { 22 | private BlockedMetricHelper() { 23 | } 24 | 25 | static long computeTotalBlockedCount(List blockedMetricCollectors) { 26 | long totalBlockedCount = 0; 27 | for (BlockedMetricCollector collector : blockedMetricCollectors) { 28 | totalBlockedCount += collector.getTotalBlockedCount(); 29 | } 30 | return totalBlockedCount; 31 | } 32 | 33 | static long computeTotalBlockedTime(List blockedMetricCollectors) { 34 | long totalBlockedTime = 0; 35 | for (BlockedMetricCollector collector : blockedMetricCollectors) { 36 | totalBlockedTime += collector.getTotalBlockedTime(); 37 | } 38 | return totalBlockedTime; 39 | } 40 | } -------------------------------------------------------------------------------- /dxm/src/main/java/io/pcp/parfait/dxm/types/AbstractTypeHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | package io.pcp.parfait.dxm.types; 18 | 19 | 20 | /** 21 | * Convenience TypeHandler to provide a simple implementation of {@link TypeHandler#getMetricType()} 22 | * 23 | * @author Cowan 24 | * @param 25 | * the Java type handled by this TypeHandler implementation 26 | */ 27 | public abstract class AbstractTypeHandler implements TypeHandler { 28 | private final MmvMetricType type; 29 | private final int dataLength; 30 | 31 | public AbstractTypeHandler(MmvMetricType type, int dataLength) { 32 | this.type = type; 33 | this.dataLength = dataLength; 34 | } 35 | 36 | public MmvMetricType getMetricType() { 37 | return type; 38 | } 39 | 40 | public int getDataLength() { 41 | return dataLength; 42 | } 43 | 44 | @Override 45 | public boolean requiresLargeStorage() { 46 | return false; 47 | } 48 | } -------------------------------------------------------------------------------- /parfait-dropwizard/src/main/java/io/pcp/parfait/dropwizard/DefaultMetricDescriptorLookup.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | package io.pcp.parfait.dropwizard; 18 | 19 | import static tech.units.indriya.AbstractUnit.ONE; 20 | 21 | import io.pcp.parfait.ValueSemantics; 22 | 23 | import javax.measure.quantity.Dimensionless; 24 | import javax.measure.Unit; 25 | 26 | public class DefaultMetricDescriptorLookup implements MetricDescriptorLookup { 27 | 28 | @Override 29 | public MetricDescriptor getDescriptorFor(final String metricName) { 30 | return new MetricDescriptor() { 31 | @Override 32 | public Unit getUnit() { 33 | return ONE; 34 | } 35 | 36 | @Override 37 | public String getDescription() { 38 | return metricName; 39 | } 40 | 41 | @Override 42 | public ValueSemantics getSemantics() { 43 | return ValueSemantics.FREE_RUNNING; 44 | } 45 | }; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /dxm/src/main/java/io/pcp/parfait/dxm/FixedValueIdentifierSource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | package io.pcp.parfait.dxm; 18 | 19 | import java.util.HashSet; 20 | import java.util.Map; 21 | import java.util.Set; 22 | 23 | import com.google.common.collect.Sets; 24 | 25 | public class FixedValueIdentifierSource implements IdentifierSource { 26 | private final Map reservedIds; 27 | private final IdentifierSource fallback; 28 | 29 | public FixedValueIdentifierSource(Map reservedIds, IdentifierSource fallback) { 30 | this.reservedIds = reservedIds; 31 | this.fallback = fallback; 32 | } 33 | 34 | @Override 35 | public int calculateId(String name, Set usedIds) { 36 | Integer reservedId = reservedIds.get(name); 37 | if (reservedId == null || usedIds.contains(reservedId)) { 38 | return fallback.calculateId(name, Sets.union(usedIds, new HashSet(reservedIds 39 | .values()))); 40 | } 41 | return reservedId; 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /parfait-core/src/test/java/io/pcp/parfait/TimeWindowTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | package io.pcp.parfait; 18 | 19 | import static org.junit.Assert.assertEquals; 20 | 21 | import org.junit.Test; 22 | 23 | public class TimeWindowTest { 24 | 25 | @Test(expected=IllegalArgumentException.class) 26 | public void constructionShouldRejectZeroPeriod() { 27 | TimeWindow.of(100, 0, "foo"); 28 | } 29 | 30 | @Test(expected=IllegalArgumentException.class) 31 | public void constructionShouldRejectZeroResolution() { 32 | TimeWindow.of(0, 400, "foo"); 33 | } 34 | 35 | @Test(expected=IllegalArgumentException.class) 36 | public void constructionShouldRejectMoreThanMaxintWindows() { 37 | TimeWindow.of(1000, 4000000000000L, "foo"); 38 | } 39 | 40 | @Test(expected=IllegalArgumentException.class) 41 | public void constructionShouldRejectPeriodNotMultipleOfResolution() { 42 | TimeWindow.of(3, 10, "foo"); 43 | } 44 | 45 | @Test 46 | public void testCalculateBucketCount() { 47 | assertEquals(100, TimeWindow.of(10, 1000, "foo").getBuckets()); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /dxm/src/main/java/io/pcp/parfait/dxm/WarningIdentifierSource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | package io.pcp.parfait.dxm; 18 | 19 | import java.util.Set; 20 | import java.util.concurrent.atomic.AtomicInteger; 21 | 22 | import org.slf4j.Logger; 23 | import org.slf4j.LoggerFactory; 24 | 25 | /** 26 | * {@link IdentifierSource} which logs a warning on every generation, and returns a dummy value. 27 | * Useful for generating a list of IDs which should later be explicity-provided. 28 | */ 29 | public class WarningIdentifierSource implements IdentifierSource { 30 | private static final Logger LOG = LoggerFactory.getLogger(WarningIdentifierSource.class); 31 | 32 | private final AtomicInteger nextId; 33 | 34 | public WarningIdentifierSource(int initialId) { 35 | nextId = new AtomicInteger(initialId); 36 | } 37 | 38 | @Override 39 | public int calculateId(String name, Set usedIds) { 40 | LOG.warn("No identifier provided for value " + name + "; please specify an explicit ID"); 41 | return nextId.getAndIncrement(); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /dxm/src/main/java/io/pcp/parfait/dxm/Instance.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | /** 18 | * 19 | */ 20 | package io.pcp.parfait.dxm; 21 | 22 | 23 | import java.nio.ByteBuffer; 24 | 25 | abstract class Instance implements PcpId, PcpOffset, MmvWritable { 26 | protected final String name; 27 | protected final int id; 28 | protected final InstanceDomain instanceDomain; 29 | protected int offset; 30 | 31 | Instance(InstanceDomain domain, String name, int id) { 32 | this.instanceDomain = domain; 33 | this.name = name; 34 | this.id = id; 35 | } 36 | 37 | @Override 38 | public String toString() { 39 | return name + " (" + id + ")"; 40 | } 41 | 42 | @Override 43 | public int getOffset() { 44 | return offset; 45 | } 46 | 47 | @Override 48 | public void setOffset(int offset) { 49 | this.offset = offset; 50 | } 51 | 52 | @Override 53 | public int getId() { 54 | return id; 55 | } 56 | 57 | @Override 58 | public abstract void writeToMmv(ByteBuffer byteBuffer); 59 | 60 | } -------------------------------------------------------------------------------- /parfait-io/pom.xml: -------------------------------------------------------------------------------- 1 | 18 | 19 | 4.0.0 20 | io.pcp.parfait 21 | parfait-io 22 | 1.2.2-SNAPSHOT 23 | jar 24 | parfait-io 25 | Toolset for collection IO-related metrics for parfait 26 | 27 | io.pcp 28 | parfait 29 | 1.2.2-SNAPSHOT 30 | 31 | 32 | 33 | io.pcp.parfait 34 | parfait-core 35 | ${project.version} 36 | 37 | 38 | commons-io 39 | commons-io 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /parfait-core/src/test/java/io/pcp/parfait/MonitoredConstantTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | package io.pcp.parfait; 18 | 19 | import static org.junit.Assert.assertEquals; 20 | import static tech.units.indriya.unit.Units.FARAD; 21 | 22 | import org.junit.Test; 23 | 24 | public class MonitoredConstantTest { 25 | @Test 26 | public void newMonitoredConstantHasCorrectSemantics() { 27 | assertEquals(ValueSemantics.CONSTANT, newConstant().getSemantics()); 28 | } 29 | 30 | @Test 31 | public void newMonitoredConstantHasSuppliedValues() { 32 | assertEquals("AAA", newConstant().getName()); 33 | assertEquals("BBB", newConstant().getDescription()); 34 | assertEquals(7, newConstant().get().intValue()); 35 | assertEquals(FARAD, newConstant().getUnit()); 36 | assertEquals(Integer.class, newConstant().getType()); 37 | } 38 | 39 | private MonitoredConstant newConstant() { 40 | return new MonitoredConstant("AAA", "BBB", new MonitorableRegistry(), 7, FARAD); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /parfait-core/src/main/java/io/pcp/parfait/ValueSemantics.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | package io.pcp.parfait; 18 | 19 | /** 20 | * Possible semantics of the individual values of a metric. This is used by some 21 | * output mechanisms to associate metadata with a particular value, do rate 22 | * conversion, etc etc. 23 | */ 24 | public enum ValueSemantics { 25 | /** 26 | * A value which never (or very seldom) changes over the lifetime of a 27 | * virtual machine. Examples might be maximum heap size, JVM version, etc. 28 | */ 29 | CONSTANT, 30 | /** 31 | * Values which freely and arbitrarily change over time, either upwards or 32 | * downwards. Examples might include Java heap memory in use, number of 33 | * currently-logged-on users, etc. 34 | */ 35 | FREE_RUNNING, 36 | /** 37 | * Values which only ever increase over time during the life of a metric. 38 | * Examples may include total number of Java Garbage Collections executed, 39 | * or the total number of users to have logged on to the application since 40 | * startup. 41 | */ 42 | MONOTONICALLY_INCREASING; 43 | } 44 | -------------------------------------------------------------------------------- /parfait-core/src/main/java/io/pcp/parfait/timing/AbstractThreadMetric.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | package io.pcp.parfait.timing; 18 | 19 | import javax.measure.Unit; 20 | 21 | public abstract class AbstractThreadMetric implements ThreadMetric { 22 | private final String name; 23 | private final Unit unit; 24 | private final String counterSuffix; 25 | private final String description; 26 | 27 | public AbstractThreadMetric(String name, Unit unit, String counterSuffix, String description) { 28 | this.name = name; 29 | this.unit = unit; 30 | this.counterSuffix = counterSuffix; 31 | this.description = description; 32 | } 33 | 34 | public String getMetricName() { 35 | return name; 36 | } 37 | 38 | public Unit getUnit() { 39 | return unit; 40 | } 41 | 42 | public String getCounterSuffix() { 43 | return counterSuffix; 44 | } 45 | 46 | public String getDescription() { 47 | return description; 48 | } 49 | 50 | @Override 51 | public String toString() { 52 | return "Metric[" + name + "]"; 53 | } 54 | 55 | 56 | } 57 | -------------------------------------------------------------------------------- /parfait-core/src/main/java/io/pcp/parfait/timing/CounterPair.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | package io.pcp.parfait.timing; 18 | 19 | import io.pcp.parfait.Counter; 20 | import io.pcp.parfait.MonitoredCounter; 21 | 22 | public class CounterPair implements Counter { 23 | private final MonitoredCounter primaryCounter; 24 | private final ThreadCounter threadCounter; 25 | 26 | CounterPair(MonitoredCounter primaryCounter, ThreadCounter threadCounter) { 27 | this.primaryCounter = primaryCounter; 28 | this.threadCounter = threadCounter; 29 | } 30 | 31 | @Override 32 | public void inc() { 33 | inc(1L); 34 | } 35 | 36 | @Override 37 | public void inc(long increment) { 38 | primaryCounter.inc(increment); 39 | threadCounter.inc(increment); 40 | } 41 | 42 | public ThreadCounter getThreadCounter() { 43 | return threadCounter; 44 | } 45 | 46 | public MonitoredCounter getPrimaryCounter() { 47 | return primaryCounter; 48 | } 49 | 50 | @Deprecated 51 | public MonitoredCounter getMasterCounter() { 52 | return getPrimaryCounter(); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /parfait-core/src/main/java/io/pcp/parfait/MonitoredNumeric.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | package io.pcp.parfait; 18 | 19 | import javax.measure.Unit; 20 | 21 | /** 22 | * Base implementation of {@link Monitorable} which deals with numeric values. 23 | * Provides convenience methods to increment and decrement the current value by 24 | * one unit. 25 | */ 26 | abstract class MonitoredNumeric extends MonitoredValue { 27 | public MonitoredNumeric(String name, String description, MonitorableRegistry registry, 28 | T initialValue, Unit unit) { 29 | super(name, description, registry, initialValue, unit); 30 | } 31 | 32 | /** 33 | * Increments the current value by 1. 34 | */ 35 | public abstract void inc(); 36 | 37 | /** 38 | * Increments the current value by the specified amount. 39 | */ 40 | public abstract void inc(int delta); 41 | 42 | /** 43 | * Decrements the current value by 1. 44 | */ 45 | public abstract void dec(); 46 | 47 | /** 48 | * Decrements the current value by the specified amount. 49 | */ 50 | public abstract void dec(int delta); 51 | } 52 | -------------------------------------------------------------------------------- /parfait-core/src/test/java/io/pcp/parfait/CompositeCounterTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | package io.pcp.parfait; 18 | 19 | import java.util.Arrays; 20 | 21 | import org.junit.Assert; 22 | import org.junit.Test; 23 | 24 | public class CompositeCounterTest { 25 | @Test 26 | public void incrementActionsIncrementAllSubcounters() { 27 | SimpleCounter first = new SimpleCounter(); 28 | SimpleCounter second = new SimpleCounter(); 29 | 30 | CompositeCounter counter = new CompositeCounter(Arrays.asList(first, second)); 31 | counter.inc(); 32 | Assert.assertEquals(1, first.value); 33 | Assert.assertEquals(1, second.value); 34 | 35 | counter.inc(10); 36 | Assert.assertEquals(11, first.value); 37 | Assert.assertEquals(11, second.value); 38 | 39 | } 40 | 41 | private static final class SimpleCounter implements Counter { 42 | private int value; 43 | 44 | @Override 45 | public void inc() { 46 | inc(1); 47 | } 48 | 49 | @Override 50 | public void inc(long increment) { 51 | value += increment; 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /dxm/src/test/java/io/pcp/parfait/dxm/InstanceStoreFactoryV1Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | package io.pcp.parfait.dxm; 18 | 19 | import io.pcp.parfait.dxm.InstanceV1.InstanceStoreV1; 20 | import io.pcp.parfait.dxm.PcpMmvWriter.Store; 21 | import org.junit.Test; 22 | 23 | import static org.mockito.Mockito.mock; 24 | import static org.unitils.reflectionassert.ReflectionAssert.assertReflectionEquals; 25 | 26 | public class InstanceStoreFactoryV1Test { 27 | 28 | private static final String STORE_NAME = "mystore"; 29 | 30 | @Test 31 | public void createNewInstanceStoreShouldReturnACorrectlyConstructedInstanceStore() { 32 | IdentifierSourceSet identifierSourceSet = mock(IdentifierSourceSet.class); 33 | InstanceDomain instanceDomain = mock(InstanceDomain.class); 34 | 35 | InstanceStoreFactory instanceStoreFactory = new InstanceStoreFactoryV1(identifierSourceSet); 36 | 37 | Store actual = instanceStoreFactory.createNewInstanceStore(STORE_NAME, instanceDomain); 38 | Store expected = new InstanceStoreV1(identifierSourceSet, STORE_NAME, instanceDomain); 39 | 40 | assertReflectionEquals(expected, actual); 41 | } 42 | 43 | } -------------------------------------------------------------------------------- /parfait-core/src/main/java/io/pcp/parfait/timing/CounterPairFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | package io.pcp.parfait.timing; 18 | 19 | import io.pcp.parfait.*; 20 | 21 | import javax.measure.Unit; 22 | 23 | public class CounterPairFactory { 24 | private final MonitorableRegistry registry; 25 | private final ThreadMetricSuite metricSuite; 26 | 27 | public CounterPairFactory(MonitorableRegistry registry, ThreadMetricSuite metricSuite) { 28 | this.registry = registry; 29 | this.metricSuite = metricSuite; 30 | } 31 | 32 | public Counter createCounterPair(Unit unit, String globalCounterName, String threadMetricName, 33 | String threadMetricSuffix, String description) { 34 | MonitoredCounter metric = new MonitoredCounter(globalCounterName, description, registry, unit); 35 | ThreadCounter threadCounter = new ThreadCounter.ThreadMapCounter(); 36 | 37 | ThreadMetric threadMetric = new ThreadValueMetric(threadMetricName, unit, threadMetricSuffix, 38 | description, threadCounter); 39 | metricSuite.addMetric(threadMetric); 40 | return new CounterPair(metric, threadCounter); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /dxm/src/main/java/io/pcp/parfait/dxm/HashingIdentifierSource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | package io.pcp.parfait.dxm; 18 | 19 | import java.util.Set; 20 | 21 | public class HashingIdentifierSource implements IdentifierSource { 22 | private final int allowedIdentifierCount; 23 | 24 | public HashingIdentifierSource(int allowedIdentifierCount) { 25 | this.allowedIdentifierCount = allowedIdentifierCount; 26 | } 27 | 28 | @Override 29 | public int calculateId(String name, Set usedIds) { 30 | if (usedIds.size() == this.allowedIdentifierCount) { 31 | throw new IllegalStateException("All identifiers in use; cannot assign another"); 32 | } 33 | int value = name.hashCode(); 34 | // Math.abs(MIN_VALUE) == MIN_VALUE, better deal with that just in case... 35 | if (value == Integer.MIN_VALUE) { 36 | value = 0; 37 | } 38 | value = Math.abs(value) % allowedIdentifierCount; 39 | while (usedIds.contains(value)) { 40 | value++; 41 | if (value == allowedIdentifierCount) { 42 | value = 0; 43 | } 44 | } 45 | return value; 46 | } 47 | } -------------------------------------------------------------------------------- /parfait-pcp/src/main/java/io/pcp/parfait/pcp/RegexSequenceNameMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | package io.pcp.parfait.pcp; 18 | 19 | import java.util.ArrayList; 20 | import java.util.List; 21 | import java.util.regex.Matcher; 22 | import java.util.regex.Pattern; 23 | 24 | import io.pcp.parfait.dxm.MetricName; 25 | 26 | public class RegexSequenceNameMapper implements MetricNameMapper { 27 | private final List replacements; 28 | 29 | public RegexSequenceNameMapper(List replacements) { 30 | this.replacements = new ArrayList(replacements); 31 | } 32 | 33 | @Override 34 | public MetricName map(String name) { 35 | for (Replacement replacement : replacements) { 36 | Matcher m = replacement.pattern.matcher(name); 37 | if (m.matches()) { 38 | name = m.replaceAll(replacement.replacement); 39 | } 40 | 41 | } 42 | return MetricName.parse(name); 43 | } 44 | 45 | public static class Replacement { 46 | private final Pattern pattern; 47 | private final String replacement; 48 | 49 | public Replacement(Pattern pattern, String replacement) { 50 | this.pattern = pattern; 51 | this.replacement = replacement; 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /parfait-core/src/main/java/io/pcp/parfait/Monitor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | package io.pcp.parfait; 18 | 19 | /** 20 | * A monitor is notified of any changes to the value of any {@link Monitorable} 21 | * objects it is attached to. This makes it effectively an 'output sink' for all 22 | * monitorable changes. When a Monitorable changes value, it will notify all 23 | * Monitors via {@link #valueChanged(Monitorable)}. Note that Monitors are under 24 | * no obligation to process this immediately - they may elect to queue the 25 | * notification for later update, swallow intermediate updates, etc., depending 26 | * on implementation. 27 | */ 28 | public interface Monitor { 29 | 30 | /** 31 | * Notifies the Monitor about a change in the underlying value of a 32 | * {@link Monitorable}. It is not guaranteed that the value obtained by 33 | * {@link Monitorable#get()} will return the value that triggered the 34 | * update, as the value may update in the meantime. 35 | * 36 | * @param monitorable 37 | * the Monitorable whose value has changed. 38 | */ 39 | void valueChanged(Monitorable monitorable); 40 | 41 | } 42 | -------------------------------------------------------------------------------- /parfait-core/src/test/java/io/pcp/parfait/DummyMonitorable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | package io.pcp.parfait; 18 | 19 | import static tech.units.indriya.AbstractUnit.ONE; 20 | 21 | import javax.measure.Unit; 22 | 23 | public class DummyMonitorable implements Monitorable { 24 | private final String name; 25 | 26 | public DummyMonitorable(String name) { 27 | this.name = name; 28 | } 29 | 30 | @Override 31 | public String get() { 32 | return "DummyValue"; 33 | } 34 | 35 | @Override 36 | public String getDescription() { 37 | return "Blah"; 38 | } 39 | 40 | @Override 41 | public String getName() { 42 | return name; 43 | } 44 | 45 | @Override 46 | public ValueSemantics getSemantics() { 47 | return ValueSemantics.CONSTANT; 48 | } 49 | 50 | @Override 51 | public Class getType() { 52 | return String.class; 53 | } 54 | 55 | @Override 56 | public Unit getUnit() { 57 | return ONE; 58 | } 59 | 60 | @Override 61 | public void attachMonitor(Monitor m) { 62 | } 63 | 64 | @Override 65 | public void removeMonitor(Monitor m) { 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /parfait-core/src/main/java/io/pcp/parfait/timing/ThreadMetricSuite.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | package io.pcp.parfait.timing; 18 | 19 | import java.util.Collection; 20 | import java.util.Collections; 21 | import java.util.List; 22 | import java.util.concurrent.CopyOnWriteArrayList; 23 | 24 | public class ThreadMetricSuite { 25 | private final List metrics; 26 | 27 | private ThreadMetricSuite(Collection metrics) { 28 | this.metrics = new CopyOnWriteArrayList(metrics); 29 | } 30 | 31 | public final void addMetric(ThreadMetric metric) { 32 | metrics.add(metric); 33 | } 34 | 35 | public final void addAllMetrics(Collection metrics) { 36 | this.metrics.addAll(metrics); 37 | } 38 | 39 | public final List metrics() { 40 | return Collections.unmodifiableList(metrics); 41 | } 42 | 43 | public static ThreadMetricSuite blank() { 44 | return new ThreadMetricSuite(Collections.emptyList()); 45 | } 46 | 47 | public static ThreadMetricSuite withDefaultMetrics() { 48 | return new ThreadMetricSuite(StandardThreadMetrics.defaults()); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /dxm/src/test/java/io/pcp/parfait/dxm/InstanceStoreFactoryV2Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | package io.pcp.parfait.dxm; 18 | 19 | import io.pcp.parfait.dxm.PcpMmvWriter.Store; 20 | import io.pcp.parfait.dxm.PcpString.PcpStringStore; 21 | import org.junit.Test; 22 | 23 | import static org.mockito.Mockito.mock; 24 | import static org.unitils.reflectionassert.ReflectionAssert.assertReflectionEquals; 25 | 26 | public class InstanceStoreFactoryV2Test { 27 | 28 | private static final String STORE_NAME = "mystore"; 29 | 30 | @Test 31 | public void shouldCreateANewInstanceStoreV2() { 32 | IdentifierSourceSet identifierSourceSet = mock(IdentifierSourceSet.class); 33 | PcpStringStore stringStore = mock(PcpStringStore.class); 34 | InstanceDomain instanceDomain = mock(InstanceDomain.class); 35 | 36 | InstanceStoreFactory instanceStoreFactory = new InstanceStoreFactoryV2(identifierSourceSet, stringStore); 37 | 38 | Store actual = instanceStoreFactory.createNewInstanceStore(STORE_NAME, instanceDomain); 39 | Store expected = new InstanceV2.InstanceStoreV2(identifierSourceSet, STORE_NAME, instanceDomain, stringStore); 40 | 41 | assertReflectionEquals(expected, actual); 42 | } 43 | 44 | } -------------------------------------------------------------------------------- /dxm/src/main/java/io/pcp/parfait/dxm/types/TypeHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | package io.pcp.parfait.dxm.types; 18 | 19 | import java.nio.ByteBuffer; 20 | 21 | 22 | /** 23 | * A class responsible for rendering a Java type into a byte format suitable for transfer to PCP. 24 | * 25 | * @author Cowan 26 | * @param 27 | * the Java type which can be converted by this handler 28 | */ 29 | public interface TypeHandler { 30 | /** 31 | * Render the provided value into the given ByteBuffer for access by PCP. No more than 16 bytes 32 | * should be written to the buffer, unless you want to overflow into the next metric. 33 | * 34 | * @param buffer 35 | * a ByteBuffer, positioned ready to receive the bytes representing this Java type to 36 | * PCP 37 | * @param value 38 | * the value to be converted 39 | */ 40 | void putBytes(ByteBuffer buffer, JavaType value); 41 | 42 | /** 43 | * @return the {@link MmvMetricType} used by PCP to understand the bytes written by 44 | * {@link #putBytes(ByteBuffer, Object)} 45 | */ 46 | MmvMetricType getMetricType(); 47 | 48 | int getDataLength(); 49 | 50 | boolean requiresLargeStorage(); 51 | } 52 | -------------------------------------------------------------------------------- /parfait-benchmark/src/main/java/io/pcp/parfait/benchmark/CounterIncrementer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | package io.pcp.parfait.benchmark; 18 | 19 | import java.lang.management.ManagementFactory; 20 | import java.util.List; 21 | 22 | import io.pcp.parfait.MonitoredCounter; 23 | 24 | class CounterIncrementer implements Runnable{ 25 | 26 | private final List counters; 27 | private final int iterations; 28 | private BlockedMetricCollector blockedMetricCollector; 29 | 30 | public CounterIncrementer(List counters, int iterations) { 31 | this.counters = counters; 32 | this.iterations = iterations; 33 | } 34 | 35 | @Override 36 | public void run() { 37 | ManagementFactory.getThreadMXBean().setThreadContentionMonitoringEnabled(true); 38 | 39 | this.blockedMetricCollector = new BlockedMetricCollector(); 40 | for (int i = 0; i < iterations; i++) { 41 | 42 | for (MonitoredCounter counter : counters) { 43 | counter.inc(); 44 | } 45 | } 46 | blockedMetricCollector.computeFinalValues(); 47 | } 48 | 49 | public BlockedMetricCollector getBlockedMetricCollector() { 50 | return blockedMetricCollector; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /parfait-jmx/pom.xml: -------------------------------------------------------------------------------- 1 | 18 | 19 | 4.0.0 20 | io.pcp.parfait 21 | parfait-jmx 22 | 1.2.2-SNAPSHOT 23 | jar 24 | parfait-jmx 25 | Library to allow Parfait to import metric values from, and export results to, JMX 26 | 27 | io.pcp 28 | parfait 29 | 1.2.2-SNAPSHOT 30 | 31 | 32 | 33 | io.pcp.parfait 34 | parfait-core 35 | ${project.version} 36 | 37 | 38 | org.springframework 39 | spring-core 40 | 41 | 42 | org.springframework 43 | spring-context 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /dxm/src/main/java/io/pcp/parfait/dxm/InMemoryByteBufferFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | package io.pcp.parfait.dxm; 18 | 19 | import java.io.IOException; 20 | import java.nio.ByteBuffer; 21 | 22 | /** 23 | * Builds a ByteBuffer in memory, mostly useful for unit testing purposes 24 | */ 25 | public class InMemoryByteBufferFactory implements ByteBufferFactory{ 26 | private ByteBuffer byteBuffer; 27 | private int numAllocations; 28 | 29 | @Override 30 | public ByteBuffer build(int length) throws IOException { 31 | byteBuffer = ByteBuffer.allocate(length); 32 | numAllocations++; 33 | return byteBuffer; 34 | } 35 | 36 | /** 37 | * Returns the last allocated ByteBuffer used during creation, so that further inspection can be done during unit tests. 38 | * 39 | * You are reminded that this class may be used multiple times, this reference is only the last one created 40 | */ 41 | public ByteBuffer getAllocatedBuffer() { 42 | return byteBuffer; 43 | } 44 | 45 | /** 46 | * Returns the # ByteBuffer allocations that have occured, since this Factory may produce more than one in its 47 | * life 48 | */ 49 | public int getNumAllocations() { 50 | return numAllocations; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /dxm/src/main/java/io/pcp/parfait/dxm/MetricNameValidator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | package io.pcp.parfait.dxm; 18 | 19 | import static io.pcp.parfait.dxm.PcpMmvWriter.PCP_CHARSET; 20 | 21 | class MetricNameValidator { 22 | 23 | private final int nameLimit; 24 | private final int domainLimit; 25 | 26 | MetricNameValidator(int nameLimit, int domainLimit) { 27 | this.nameLimit = nameLimit; 28 | this.domainLimit = domainLimit; 29 | } 30 | 31 | void validateNameConstraints(MetricName metricName) { 32 | validateName(metricName); 33 | validateInstance(metricName); 34 | } 35 | 36 | private void validateInstance(MetricName metricName) { 37 | if (metricName.hasInstance() 38 | && metricName.getInstance().getBytes(PCP_CHARSET).length > domainLimit) { 39 | throw new IllegalArgumentException("Cannot add metric " + metricName 40 | + "; instance name is too long"); 41 | } 42 | } 43 | 44 | private void validateName(MetricName metricName) { 45 | if (metricName.getMetric().getBytes(PCP_CHARSET).length > nameLimit) { 46 | throw new IllegalArgumentException("Cannot add metric " + metricName 47 | + "; name exceeds length limit"); 48 | } 49 | } 50 | 51 | 52 | } 53 | -------------------------------------------------------------------------------- /parfait-dropwizard/src/main/java/io/pcp/parfait/dropwizard/metricadapters/CountingAdapter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | package io.pcp.parfait.dropwizard.metricadapters; 18 | 19 | import static tech.units.indriya.AbstractUnit.ONE; 20 | 21 | import java.util.Set; 22 | 23 | import io.pcp.parfait.dropwizard.MetricAdapter; 24 | import io.pcp.parfait.dropwizard.NonSelfRegisteringSettableValue; 25 | import com.codahale.metrics.Counting; 26 | import io.pcp.parfait.Monitorable; 27 | import io.pcp.parfait.ValueSemantics; 28 | import com.google.common.collect.Sets; 29 | 30 | public class CountingAdapter implements MetricAdapter { 31 | 32 | private final Counting counter; 33 | private final NonSelfRegisteringSettableValue monitoredValue; 34 | 35 | public CountingAdapter(Counting counter, String name, String description, ValueSemantics valueSemantics) { 36 | this.counter = counter; 37 | this.monitoredValue = new NonSelfRegisteringSettableValue<>(name, description, ONE, counter.getCount(), valueSemantics); 38 | } 39 | 40 | @Override 41 | public Set getMonitorables() { 42 | return Sets.newHashSet(monitoredValue); 43 | } 44 | 45 | @Override 46 | public void updateMonitorables() { 47 | monitoredValue.set(counter.getCount()); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /parfait-dropwizard/src/main/java/io/pcp/parfait/dropwizard/metricadapters/GaugeAdapter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | package io.pcp.parfait.dropwizard.metricadapters; 18 | 19 | import javax.measure.Unit; 20 | import java.util.Set; 21 | 22 | import io.pcp.parfait.dropwizard.MetricAdapter; 23 | import io.pcp.parfait.dropwizard.NonSelfRegisteringSettableValue; 24 | import com.codahale.metrics.Gauge; 25 | import io.pcp.parfait.Monitorable; 26 | import io.pcp.parfait.ValueSemantics; 27 | import com.google.common.collect.Sets; 28 | 29 | public class GaugeAdapter implements MetricAdapter { 30 | 31 | private final Gauge theGauge; 32 | private final NonSelfRegisteringSettableValue monitoredValue; 33 | 34 | @SuppressWarnings("PMD.ExcessiveParameterList") 35 | public GaugeAdapter(Gauge theGauge, String name, String description, Unit unit, ValueSemantics valueSemantics) { 36 | this.theGauge = theGauge; 37 | this.monitoredValue = new NonSelfRegisteringSettableValue<>(name, description, unit, theGauge.getValue(), valueSemantics); 38 | } 39 | 40 | @Override 41 | public Set getMonitorables() { 42 | return Sets.newHashSet(monitoredValue); 43 | } 44 | 45 | @Override 46 | public void updateMonitorables() { 47 | monitoredValue.set(theGauge.getValue()); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /parfait-cxf/src/test/resources/io/pcp/parfait/cxf/WEB-INF/beans.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /dxm/src/test/java/io/pcp/parfait/dxm/InstanceDomainTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | package io.pcp.parfait.dxm; 18 | 19 | import io.pcp.parfait.dxm.PcpMmvWriter.Store; 20 | import org.junit.Test; 21 | 22 | import java.util.Collection; 23 | 24 | import static java.util.Collections.singletonList; 25 | import static org.hamcrest.MatcherAssert.assertThat; 26 | import static org.hamcrest.core.Is.is; 27 | import static org.mockito.ArgumentMatchers.any; 28 | import static org.mockito.ArgumentMatchers.eq; 29 | import static org.mockito.Mockito.mock; 30 | import static org.mockito.Mockito.when; 31 | 32 | public class InstanceDomainTest { 33 | 34 | private static final String DOMAIN = "mydomain"; 35 | 36 | @Test 37 | public void shouldReturnInstancesAssociatedWithTheStore() { 38 | InstanceStoreFactory instanceStoreFactory = mock(InstanceStoreFactory.class); 39 | Store instanceStore = mock(Store.class); 40 | Collection instances = singletonList(mock(Instance.class)); 41 | 42 | when(instanceStoreFactory.createNewInstanceStore(eq(DOMAIN), any(InstanceDomain.class))).thenReturn(instanceStore); 43 | when(instanceStore.all()).thenReturn(instances); 44 | 45 | InstanceDomain instanceDomain = new InstanceDomain(DOMAIN, 111, instanceStoreFactory); 46 | 47 | assertThat(instanceDomain.getInstances(), is(instances)); 48 | } 49 | } -------------------------------------------------------------------------------- /dxm/src/test/java/io/pcp/parfait/dxm/PcpClient.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | package io.pcp.parfait.dxm; 18 | 19 | import org.apache.commons.io.IOUtils; 20 | 21 | import java.io.IOException; 22 | import java.nio.charset.Charset; 23 | import java.util.regex.Matcher; 24 | import java.util.regex.Pattern; 25 | 26 | class PcpClient { 27 | 28 | String getMetric(String metricName) throws Exception { 29 | Process exec = Runtime.getRuntime().exec("pmdumptext -s 1 -t 0.001 -r " + metricName); 30 | exec.waitFor(); 31 | if (exec.exitValue() != 0) { 32 | throw new PcpFetchException(exec); 33 | } 34 | 35 | String result = IOUtils.toString(exec.getInputStream(), Charset.defaultCharset()); 36 | Pattern pattern = Pattern.compile("\t(.*?)\n"); 37 | Matcher matcher = pattern.matcher(result); 38 | if(matcher.find()) { 39 | return matcher.group(1); 40 | } 41 | throw new PcpFetchException("Could not find metric in the output: " + result); 42 | } 43 | 44 | private static class PcpFetchException extends RuntimeException { 45 | 46 | PcpFetchException(Process process) throws IOException { 47 | super(IOUtils.toString(process.getErrorStream(), Charset.defaultCharset())); 48 | } 49 | 50 | PcpFetchException(String message) { 51 | super(message); 52 | } 53 | } 54 | 55 | } -------------------------------------------------------------------------------- /parfait-spring/src/test/java/io/pcp/parfait/spring/SelfStartingMonitoringViewTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | package io.pcp.parfait.spring; 18 | 19 | import io.pcp.parfait.DynamicMonitoringView; 20 | import org.junit.Before; 21 | import org.junit.Test; 22 | import org.junit.runner.RunWith; 23 | import org.mockito.Mock; 24 | import org.mockito.junit.MockitoJUnitRunner; 25 | 26 | import static org.mockito.Mockito.verify; 27 | 28 | @RunWith(MockitoJUnitRunner.class) 29 | public class SelfStartingMonitoringViewTest { 30 | 31 | private SelfStartingMonitoringView selfStartingMonitoringView; 32 | 33 | @Mock 34 | DynamicMonitoringView dynamicMonitoringView; 35 | 36 | @Before 37 | public void setUp() { 38 | selfStartingMonitoringView = new SelfStartingMonitoringView(dynamicMonitoringView); 39 | } 40 | 41 | @Test 42 | public void shouldInvokeDelegateStart() throws Exception { 43 | selfStartingMonitoringView.start(); 44 | verify(dynamicMonitoringView).start(); 45 | } 46 | 47 | @Test 48 | public void shouldInvokeDelegateStop() throws Exception { 49 | selfStartingMonitoringView.stop(); 50 | verify(dynamicMonitoringView).stop(); 51 | } 52 | 53 | @Test 54 | public void shouldInvokeDelegateIsRunning() throws Exception { 55 | selfStartingMonitoringView.isRunning(); 56 | verify(dynamicMonitoringView).isRunning(); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /parfait-dropwizard/src/main/java/io/pcp/parfait/dropwizard/metricadapters/TimerAdapter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | package io.pcp.parfait.dropwizard.metricadapters; 18 | 19 | import static javax.measure.MetricPrefix.NANO; 20 | import static tech.units.indriya.unit.Units.SECOND; 21 | 22 | import com.codahale.metrics.Timer; 23 | import io.pcp.parfait.Monitorable; 24 | import io.pcp.parfait.dropwizard.MetricAdapter; 25 | import com.google.common.collect.Sets; 26 | 27 | import java.util.Set; 28 | 29 | public class TimerAdapter implements MetricAdapter { 30 | 31 | private final MeteredAdapter meteredAdapter; 32 | private final SamplingAdapter samplingAdapter; 33 | 34 | public TimerAdapter(Timer timer, String name, String description) { 35 | meteredAdapter = new MeteredAdapter(timer, name, description); 36 | samplingAdapter = new SamplingAdapter(timer, name, description, NANO(SECOND)); 37 | } 38 | 39 | @Override 40 | public Set getMonitorables() { 41 | Set allMonitorables = Sets.newHashSet(); 42 | allMonitorables.addAll(meteredAdapter.getMonitorables()); 43 | allMonitorables.addAll(samplingAdapter.getMonitorables()); 44 | return allMonitorables; 45 | } 46 | 47 | @Override 48 | public void updateMonitorables() { 49 | meteredAdapter.updateMonitorables(); 50 | samplingAdapter.updateMonitorables(); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /parfait-core/src/main/java/io/pcp/parfait/timing/EventMetricCounters.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | package io.pcp.parfait.timing; 18 | 19 | import io.pcp.parfait.MonitoredCounter; 20 | import com.google.common.base.Preconditions; 21 | 22 | /** 23 | * This class is a wrapper class which holds both a counter for an event metric and another 24 | * counter for the same metric but its value is a total value across all events. It is 25 | * important to ensure that the total counter is the same instance of the class across all 26 | * EventMetricCounters objects which are measuring the same metric. 27 | */ 28 | public class EventMetricCounters { 29 | private final MonitoredCounter eventSpecificCounter; 30 | private final MonitoredCounter totalCounter; 31 | 32 | public EventMetricCounters(MonitoredCounter eventSpecificCounter, MonitoredCounter totalCounter) { 33 | this.eventSpecificCounter = Preconditions.checkNotNull(eventSpecificCounter, 34 | "Cannot provide null event-specific metric counter"); 35 | this.totalCounter = Preconditions.checkNotNull(totalCounter, 36 | "Cannot provide null total metric counter"); 37 | } 38 | 39 | public void incrementCounters(long value) { 40 | eventSpecificCounter.inc(value); 41 | totalCounter.inc(value); 42 | 43 | } 44 | 45 | MonitoredCounter getTotalCounter() { 46 | return totalCounter; 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /parfait-pcp/pom.xml: -------------------------------------------------------------------------------- 1 | 18 | 19 | 4.0.0 20 | io.pcp.parfait 21 | parfait-pcp 22 | 1.2.2-SNAPSHOT 23 | jar 24 | parfait-pcp 25 | Bridge between Parfait-collected metrics and the DXM PCP Bridge to enable monitoring of Java applications via PCP 26 | 27 | io.pcp 28 | parfait 29 | 1.2.2-SNAPSHOT 30 | 31 | 32 | 33 | io.pcp.parfait 34 | dxm 35 | ${project.version} 36 | 37 | 38 | io.pcp.parfait 39 | parfait-core 40 | ${project.version} 41 | 42 | 43 | io.pcp.parfait 44 | parfait-core 45 | ${project.version} 46 | test 47 | tests 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /parfait-jdbc/pom.xml: -------------------------------------------------------------------------------- 1 | 18 | 19 | 4.0.0 20 | io.pcp.parfait 21 | parfait-jdbc 22 | 1.2.2-SNAPSHOT 23 | jar 24 | parfait-jdbc 25 | JDBC driver to allow collection of Parfait performance metrics 26 | 27 | io.pcp 28 | parfait 29 | 1.2.2-SNAPSHOT 30 | 31 | 32 | 33 | io.pcp.parfait 34 | parfait-core 35 | ${project.version} 36 | 37 | 38 | org.hsqldb 39 | hsqldb 40 | 2.7.3 41 | test 42 | 43 | 44 | org.springframework 45 | spring-core 46 | test 47 | 48 | 49 | org.springframework 50 | spring-jdbc 51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /parfait-core/src/test/java/io/pcp/parfait/timing/LoggerSinkTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | package io.pcp.parfait.timing; 18 | 19 | import static tech.units.indriya.unit.Units.HERTZ; 20 | import static javax.measure.MetricPrefix.MEGA; 21 | 22 | import javax.measure.Unit; 23 | import junit.framework.TestCase; 24 | 25 | public class LoggerSinkTest extends TestCase { 26 | public void testShouldProduceExpectedMetricString() { 27 | MetricMeasurement measurement = getUnitMeasurement(HERTZ, 1); 28 | String result = new LoggerSink().buildSingleMetricResult(measurement); 29 | assertEquals("dummy: own 1 Hz, total 1 Hz", result); 30 | } 31 | 32 | public void testShouldNormalizeMetricStringToCorrectUnit() { 33 | MetricMeasurement measurement = getUnitMeasurement(HERTZ, 1000000001); 34 | LoggerSink sink = new LoggerSink(); 35 | sink.normalizeUnits(HERTZ, MEGA(HERTZ)); 36 | String result = sink.buildSingleMetricResult(measurement); 37 | assertEquals("dummy: own 1000.000001 MHz, total 1000.000001 MHz", result); 38 | } 39 | 40 | private MetricMeasurement getUnitMeasurement(Unit unit, int amount) { 41 | DummyThreadMetric metric = new DummyThreadMetric(unit); 42 | MetricMeasurement measurement = new MetricMeasurement(metric, Thread.currentThread()); 43 | measurement.startTimer(); 44 | metric.incrementValue(amount); 45 | measurement.stopTimer(); 46 | return measurement; 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /parfait-core/src/main/java/io/pcp/parfait/timing/DummyEventTimer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | package io.pcp.parfait.timing; 18 | 19 | import java.util.Collections; 20 | 21 | import io.pcp.parfait.MonitorableRegistry; 22 | 23 | 24 | /** 25 | * A dummy EventTimer which implements all functionality as no-ops. 26 | */ 27 | public final class DummyEventTimer extends EventTimer { 28 | private static final EventMetricCollector DUMMY_EVENT_METRIC_COLLECTOR = new EventMetricCollector( 29 | null, Collections.emptyList()) { 30 | @Override 31 | public void startTiming(Object eventGroup, String event) { 32 | // no-op 33 | } 34 | 35 | @Override 36 | public void stopTiming() { 37 | // no-op 38 | } 39 | 40 | @Override 41 | public void pauseForForward() { 42 | // no-op 43 | } 44 | 45 | @Override 46 | public void resumeAfterForward() { 47 | // no-op 48 | } 49 | }; 50 | 51 | public DummyEventTimer() { 52 | super("dummy", new MonitorableRegistry(), ThreadMetricSuite.blank(), false, false, 53 | Collections.emptyList()); 54 | } 55 | 56 | public EventMetricCollector getCollector() { 57 | return DUMMY_EVENT_METRIC_COLLECTOR; 58 | } 59 | 60 | public void registerTimeable(Timeable timeable, String eventGroup) { 61 | timeable.setEventTimer(this); 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /parfait-dropwizard/src/main/java/io/pcp/parfait/dropwizard/NonSelfRegisteringSettableValue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | package io.pcp.parfait.dropwizard; 18 | 19 | import javax.measure.Unit; 20 | 21 | import io.pcp.parfait.AbstractMonitorable; 22 | import io.pcp.parfait.ValueSemantics; 23 | import com.google.common.base.Objects; 24 | import com.google.common.base.Preconditions; 25 | 26 | public class NonSelfRegisteringSettableValue extends AbstractMonitorable { 27 | 28 | private T value; 29 | 30 | @SuppressWarnings({"unchecked", "PMD.ExcessiveParameterList"}) 31 | public NonSelfRegisteringSettableValue(String name, String description, Unit unit, T initialValue, ValueSemantics valueSemantics) { 32 | super(name, description, (Class) initialValue.getClass(), unit, valueSemantics); 33 | value = initialValue; 34 | } 35 | 36 | @Override 37 | public T get() { 38 | return value; 39 | } 40 | 41 | /** 42 | * Sets the current value of this Monitorable. Some level of optimization is 43 | * performed to ensure that spurious updates are not sent out (i.e. when the 44 | * new value is the same as the old), but this is optimized for performance 45 | * and no guarantee is made that such notifications will not be sent. 46 | */ 47 | public void set(T newValue) { 48 | Preconditions.checkNotNull(newValue, "Monitored value can not be null"); 49 | if (Objects.equal(this.value, newValue)) { 50 | return; 51 | } 52 | this.value = newValue; 53 | notifyMonitors(); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /parfait-core/src/main/java/io/pcp/parfait/CompositeMonitoringView.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | package io.pcp.parfait; 18 | 19 | import com.google.common.base.Predicate; 20 | import com.google.common.collect.Iterators; 21 | 22 | import java.util.Collection; 23 | import java.util.List; 24 | 25 | import static com.google.common.collect.ImmutableList.copyOf; 26 | 27 | public class CompositeMonitoringView implements MonitoringView{ 28 | 29 | private final List monitoringViews; 30 | 31 | public CompositeMonitoringView(MonitoringView... monitoringViews) { 32 | this.monitoringViews = copyOf(monitoringViews); 33 | } 34 | 35 | @Override 36 | public void startMonitoring(Collection> monitorables) { 37 | for (MonitoringView monitoringView : monitoringViews) { 38 | monitoringView.startMonitoring(monitorables); 39 | } 40 | } 41 | 42 | @Override 43 | public void stopMonitoring(Collection> monitorables) { 44 | for (MonitoringView monitoringView : monitoringViews) { 45 | monitoringView.stopMonitoring(monitorables); 46 | } 47 | } 48 | 49 | @Override 50 | /** 51 | * For a Composite view, isRunning() is true if any of the underlying views are still running 52 | */ 53 | public boolean isRunning() { 54 | return Iterators.any(monitoringViews.iterator(), new Predicate() { 55 | @Override 56 | public boolean apply(MonitoringView mv) { 57 | return mv.isRunning(); 58 | } 59 | }); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /parfait-core/src/main/java/io/pcp/parfait/timing/ThreadCounter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | package io.pcp.parfait.timing; 18 | 19 | import java.util.concurrent.atomic.AtomicLong; 20 | 21 | import io.pcp.parfait.Counter; 22 | 23 | public interface ThreadCounter extends ThreadValue, Counter { 24 | public static class ThreadLocalCounter extends ThreadValue.ThreadLocalMap implements ThreadCounter { 25 | 26 | public ThreadLocalCounter() { 27 | super(new ThreadLocal() { 28 | @Override 29 | protected AtomicLong initialValue() { 30 | return new AtomicLong(); 31 | } 32 | }); 33 | } 34 | 35 | @Override 36 | public void inc() { 37 | inc(1L); 38 | } 39 | 40 | @Override 41 | public void inc(long increment) { 42 | threadLocal.get().addAndGet(increment); 43 | } 44 | } 45 | 46 | public static class ThreadMapCounter extends ThreadValue.WeakReferenceThreadMap 47 | implements ThreadCounter { 48 | 49 | public ThreadMapCounter() { 50 | super(); 51 | } 52 | 53 | @Override 54 | protected AtomicLong initialValue() { 55 | return new AtomicLong(); 56 | } 57 | 58 | @Override 59 | public void inc() { 60 | inc(1L); 61 | } 62 | 63 | @Override 64 | public void inc(long increment) { 65 | loadingCache.getUnchecked(Thread.currentThread()).addAndGet(increment); 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /parfait-core/pom.xml: -------------------------------------------------------------------------------- 1 | 18 | 19 | 4.0.0 20 | io.pcp.parfait 21 | parfait-core 22 | jar 23 | parfait-core 24 | Java performance monitoring framework, including PCP bridge 25 | 26 | io.pcp 27 | parfait 28 | 1.2.2-SNAPSHOT 29 | 30 | 31 | 32 | org.mockito 33 | mockito-core 34 | test 35 | 36 | 37 | net.jcip 38 | jcip-annotations 39 | 40 | 41 | com.google.guava 42 | guava 43 | 44 | 45 | javax.measure 46 | unit-api 47 | 48 | 49 | tech.units 50 | indriya 51 | 52 | 53 | systems.uom 54 | systems-quantity 55 | 56 | 57 | systems.uom 58 | systems-unicode 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /parfait-core/src/main/java/io/pcp/parfait/MonitoredIntValue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | package io.pcp.parfait; 18 | 19 | import static tech.units.indriya.AbstractUnit.ONE; 20 | 21 | import java.util.concurrent.atomic.AtomicInteger; 22 | import javax.measure.Unit; 23 | 24 | /** 25 | * {@link Monitorable} implementation for a free-running Integer value. 26 | */ 27 | public class MonitoredIntValue extends MonitoredNumeric { 28 | public MonitoredIntValue(String name, String description, 29 | MonitorableRegistry registry, Integer initialValue) { 30 | this(name, description, registry, initialValue, ONE); 31 | } 32 | 33 | public MonitoredIntValue(String name, String description, 34 | Integer initialValue) { 35 | this(name, description, MonitorableRegistry.DEFAULT_REGISTRY, initialValue, ONE); 36 | } 37 | 38 | public MonitoredIntValue(String name, String description, MonitorableRegistry registry, 39 | Integer initialValue, Unit unit) { 40 | super(name, description, registry, new AtomicInteger( 41 | initialValue), unit); 42 | 43 | } 44 | 45 | /** 46 | * Convenience method to increment atomic numeric types. 47 | */ 48 | public void inc() { 49 | inc(1); 50 | } 51 | 52 | @Override 53 | public void inc(int delta) { 54 | value.addAndGet(delta); 55 | notifyMonitors(); 56 | } 57 | 58 | /** 59 | * Convenience method to decrement atomic numeric types. 60 | */ 61 | public void dec() { 62 | dec(1); 63 | } 64 | 65 | @Override 66 | public void dec(int delta) { 67 | inc(-delta); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /dxm/src/main/java/io/pcp/parfait/dxm/PcpConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | package io.pcp.parfait.dxm; 18 | 19 | import java.io.File; 20 | import java.io.FileInputStream; 21 | import java.io.FileNotFoundException; 22 | import java.io.IOException; 23 | import java.io.InputStream; 24 | import java.util.Properties; 25 | 26 | import com.google.common.io.Closeables; 27 | 28 | public class PcpConfig { 29 | 30 | private final static String pcpConf = System.getenv("PCP_CONF"); 31 | private final static String pcpDir = System.getenv("PCP_DIR"); 32 | 33 | public File getRoot() { 34 | return new File(pcpDir, "/"); 35 | } 36 | 37 | private File getConfigFile() { 38 | if (pcpConf == null) { 39 | File etcDir = new File(getRoot(), "etc"); 40 | return new File(etcDir, "pcp.conf"); 41 | } 42 | return new File(pcpConf); 43 | } 44 | 45 | public String getValue(String key) { 46 | Properties properties = new Properties(); 47 | File configuration = getConfigFile(); 48 | InputStream is = null; 49 | String value = System.getenv(key); 50 | 51 | if (value != null) { 52 | return value; 53 | } 54 | 55 | try { 56 | is = new FileInputStream(configuration); 57 | properties.load(is); 58 | value = properties.get(key).toString(); 59 | } catch (FileNotFoundException e) { 60 | } catch (IOException e) { 61 | // just drop these, and go with defaults 62 | } 63 | finally { 64 | Closeables.closeQuietly(is); 65 | } 66 | return value; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /parfait-jdbc/src/test/java/io/pcp/parfait/jdbc/ParfaitDataSourceTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | package io.pcp.parfait.jdbc; 18 | 19 | import static org.junit.Assert.assertEquals; 20 | 21 | import java.sql.Connection; 22 | import java.sql.DatabaseMetaData; 23 | import java.sql.DriverManager; 24 | import java.sql.SQLException; 25 | import java.sql.Statement; 26 | import javax.sql.DataSource; 27 | 28 | import io.pcp.parfait.timing.ThreadMetric; 29 | import org.junit.Before; 30 | import org.junit.Test; 31 | import org.springframework.jdbc.datasource.SingleConnectionDataSource; 32 | 33 | public class ParfaitDataSourceTest { 34 | private ParfaitDataSource dataSource; 35 | 36 | @Before 37 | public void setUp() throws SQLException, ClassNotFoundException { 38 | Class.forName("org.hsqldb.jdbcDriver"); 39 | Connection c = DriverManager.getConnection("jdbc:hsqldb:mem:parfait", "sa", ""); 40 | DataSource wrapped = new SingleConnectionDataSource(c, false); 41 | dataSource = new ParfaitDataSource(wrapped); 42 | } 43 | 44 | @Test 45 | public void testExecutionCountForCurrentThread() throws SQLException { 46 | Statement s = dataSource.getConnection().createStatement(); 47 | ThreadMetric counter = dataSource.getCounterMetric(); 48 | assertEquals(0, counter.getValueForThread(Thread.currentThread())); 49 | s.execute("ROLLBACK"); 50 | assertEquals(1, counter.getValueForThread(Thread.currentThread())); 51 | } 52 | 53 | @Test 54 | public void testExecutingNonProxiedMethod() throws SQLException { 55 | DatabaseMetaData data = dataSource.getConnection().getMetaData(); 56 | assertEquals("HSQL Database Engine", data.getDatabaseProductName()); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /parfait-spring/src/test/resources/test.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /parfait-core/src/main/java/io/pcp/parfait/timing/EventCounters.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | /** 18 | * 19 | */ 20 | package io.pcp.parfait.timing; 21 | 22 | import java.util.Collection; 23 | import java.util.Collections; 24 | import java.util.LinkedHashMap; 25 | import java.util.Map; 26 | 27 | class EventCounters { 28 | private final Map metrics = new LinkedHashMap(); 29 | private final EventMetricCounters invocationCounter; 30 | private final String eventGroupName; 31 | 32 | public EventCounters(EventMetricCounters invocationCounter, String eventGroupName) { 33 | this.invocationCounter = invocationCounter; 34 | this.eventGroupName = eventGroupName; 35 | } 36 | 37 | public EventMetricCounters getInvocationCounter() { 38 | return invocationCounter; 39 | } 40 | 41 | public void addMetric(ThreadMetric metric) { 42 | addMetric(metric, null); 43 | } 44 | 45 | public void addMetric(ThreadMetric metric, EventMetricCounters counter) { 46 | metrics.put(metric, counter); 47 | } 48 | 49 | Collection getMetricSources() { 50 | return metrics.keySet(); 51 | } 52 | 53 | EventMetricCounters getCounterForMetric(ThreadMetric metric) { 54 | return metrics.get(metric); 55 | } 56 | 57 | Integer numberOfTimerCounters() { 58 | return metrics.values().size(); 59 | } 60 | 61 | Map getMetrics() { 62 | return Collections.unmodifiableMap(metrics); 63 | } 64 | 65 | public String getEventGroupName() { 66 | return eventGroupName; 67 | } 68 | } -------------------------------------------------------------------------------- /parfait-core/src/main/java/io/pcp/parfait/SettableValue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | package io.pcp.parfait; 18 | 19 | import javax.measure.Unit; 20 | 21 | import com.google.common.base.Objects; 22 | import com.google.common.base.Preconditions; 23 | 24 | /** 25 | * A base class for Monitorables which can have their value set to an arbitrary 26 | * value at runtime. 27 | */ 28 | abstract class SettableValue extends AbstractMonitorable { 29 | protected volatile T value; 30 | 31 | @SuppressWarnings("unchecked") 32 | protected SettableValue(String name, String description, MonitorableRegistry registry, 33 | T initialValue, Unit unit, ValueSemantics semantics) { 34 | super(name, description, (Class) initialValue.getClass(), unit, semantics); 35 | Preconditions.checkNotNull(initialValue, "Monitored value can not be null"); 36 | this.value = initialValue; 37 | registerSelf(registry); 38 | } 39 | 40 | @Override 41 | public T get() { 42 | return value; 43 | } 44 | 45 | /** 46 | * Sets the current value of this Monitorable. Some level of optimization is 47 | * performed to ensure that spurious updates are not sent out (i.e. when the 48 | * new value is the same as the old), but this is optimized for performance 49 | * and no guarantee is made that such notifications will not be sent. 50 | */ 51 | public void set(T newValue) { 52 | Preconditions.checkNotNull(newValue, "Monitored value can not be null"); 53 | if (Objects.equal(this.value, newValue)) { 54 | return; 55 | } 56 | this.value = newValue; 57 | notifyMonitors(); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /parfait-benchmark/src/main/java/io/pcp/parfait/benchmark/BlockedMetricCollector.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | package io.pcp.parfait.benchmark; 18 | 19 | import java.lang.management.ManagementFactory; 20 | import java.lang.management.ThreadInfo; 21 | 22 | public class BlockedMetricCollector { 23 | 24 | private final long initialBlockedCount; 25 | private final long initialBlockedTime; 26 | private final long threadId; 27 | private long totalBlockedCount; 28 | private long totalBlockedTime; 29 | 30 | public BlockedMetricCollector(long threadId) { 31 | this.threadId = threadId; 32 | ThreadInfo initialThreadInfo = getThreadInfo(threadId); 33 | initialBlockedCount = initialThreadInfo.getBlockedCount(); 34 | initialBlockedTime = initialThreadInfo.getBlockedTime(); 35 | } 36 | 37 | public BlockedMetricCollector() { 38 | this(Thread.currentThread().getId()); 39 | } 40 | 41 | private ThreadInfo getThreadInfo(long threadId) { 42 | return ManagementFactory.getThreadMXBean().getThreadInfo(threadId); 43 | } 44 | 45 | public void computeFinalValues() { 46 | ThreadInfo finalThreadInfo = getThreadInfo(threadId); 47 | 48 | long finalBlockedCount = finalThreadInfo.getBlockedCount(); 49 | long finalBlockedTime = finalThreadInfo.getBlockedTime(); 50 | 51 | totalBlockedCount = finalBlockedCount - initialBlockedCount; 52 | totalBlockedTime = finalBlockedTime - initialBlockedTime; 53 | } 54 | 55 | public long getTotalBlockedCount() { 56 | return totalBlockedCount; 57 | } 58 | 59 | public long getTotalBlockedTime() { 60 | return totalBlockedTime; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /dxm/src/test/java/io/pcp/parfait/dxm/Matchers.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | package io.pcp.parfait.dxm; 18 | 19 | import org.hamcrest.Description; 20 | import org.hamcrest.TypeSafeMatcher; 21 | import org.unitils.reflectionassert.ReflectionComparator; 22 | import org.unitils.reflectionassert.ReflectionComparatorMode; 23 | import org.unitils.reflectionassert.difference.Difference; 24 | import org.unitils.reflectionassert.report.impl.DefaultDifferenceReport; 25 | 26 | import static org.unitils.reflectionassert.ReflectionComparatorFactory.createRefectionComparator; 27 | 28 | public class Matchers { 29 | 30 | public static class ReflectiveMatcher extends TypeSafeMatcher { 31 | 32 | private final Object expected; 33 | private Difference difference; 34 | 35 | private ReflectiveMatcher(Object expected) { 36 | this.expected = expected; 37 | } 38 | 39 | @Override 40 | protected boolean matchesSafely(Object actual) { 41 | ReflectionComparator refectionComparator = createRefectionComparator(ReflectionComparatorMode.LENIENT_ORDER); 42 | difference = refectionComparator.getDifference(expected, actual); 43 | return refectionComparator.isEqual(expected, actual); 44 | } 45 | 46 | @Override 47 | public void describeTo(Description description) { 48 | if(difference != null) { 49 | description.appendText(new DefaultDifferenceReport().createReport(difference)); 50 | } 51 | } 52 | 53 | public static ReflectiveMatcher reflectivelyEqualing(Object expected) { 54 | return new ReflectiveMatcher(expected); 55 | } 56 | 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /parfait-core/src/test/java/io/pcp/parfait/PollingMonitoredValueTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | package io.pcp.parfait; 18 | 19 | import static org.junit.Assert.assertEquals; 20 | import static tech.units.indriya.AbstractUnit.ONE; 21 | 22 | import org.junit.Test; 23 | 24 | import com.google.common.base.Supplier; 25 | 26 | public class PollingMonitoredValueTest { 27 | 28 | @Test 29 | public void shouldScheduleTaskAtDesiredRate() { 30 | TestPoller poller = new TestPoller(); 31 | ManualScheduler scheduler = new ManualScheduler(); 32 | new PollingMonitoredValue("polling.test", "", 33 | new MonitorableRegistry(), 275, poller, 34 | ValueSemantics.FREE_RUNNING, ONE, scheduler); 35 | assertEquals(1, scheduler.scheduledRates.size()); 36 | assertEquals(275, scheduler.scheduledRates.values().iterator().next() 37 | .intValue()); 38 | } 39 | 40 | @Test 41 | public void scheduledTaskExecutionShouldUpdateValue() 42 | throws InterruptedException { 43 | TestPoller poller = new TestPoller(); 44 | MonitorableRegistry registry = new MonitorableRegistry(); 45 | ManualScheduler scheduler = new ManualScheduler(); 46 | PollingMonitoredValue p = new PollingMonitoredValue( 47 | "polling.test", "", registry, 275, 48 | poller, ValueSemantics.FREE_RUNNING, ONE, scheduler); 49 | poller.value = 17; 50 | assertEquals(0, p.get().intValue()); 51 | scheduler.runAllScheduledTasks(); 52 | assertEquals(17, p.get().intValue()); 53 | } 54 | 55 | private final class TestPoller implements Supplier { 56 | private int value = 0; 57 | 58 | public Integer get() { 59 | return value; 60 | } 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /parfait-jmx/src/test/java/io/pcp/parfait/jmx/MonitoredMBeanAttributeFactoryTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | package io.pcp.parfait.jmx; 18 | 19 | import junit.framework.TestCase; 20 | 21 | import javax.management.AttributeNotFoundException; 22 | import javax.management.InstanceNotFoundException; 23 | import javax.management.IntrospectionException; 24 | import javax.management.MBeanException; 25 | import javax.management.ReflectionException; 26 | 27 | import java.io.IOException; 28 | import java.lang.management.ManagementFactory; 29 | 30 | public class MonitoredMBeanAttributeFactoryTest extends TestCase { 31 | 32 | public void testCanMonitorCompositeDataItem() throws InstanceNotFoundException, 33 | IntrospectionException, ReflectionException, AttributeNotFoundException, MBeanException, IOException { 34 | MonitoredMBeanAttributeFactory f = new MonitoredMBeanAttributeFactory("aconex.free.memory", 35 | "", "java.lang:type=Memory", "HeapMemoryUsage", "max"); 36 | assertEquals(ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getMax(), f 37 | .getObject().get().longValue()); 38 | } 39 | 40 | public void testCanMonitorStandardAttribute() throws InstanceNotFoundException, 41 | IntrospectionException, ReflectionException, AttributeNotFoundException, MBeanException, IOException { 42 | MonitoredMBeanAttributeFactory f = new MonitoredMBeanAttributeFactory( 43 | "aconex.system.startTime", "", "java.lang:type=Runtime", "StartTime", ""); 44 | assertEquals(ManagementFactory.getRuntimeMXBean().getStartTime(), f.getObject().get().longValue()); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /parfait-core/src/main/java/io/pcp/parfait/MonitoredConstant.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | package io.pcp.parfait; 18 | 19 | import static tech.units.indriya.AbstractUnit.ONE; 20 | import javax.measure.Unit; 21 | 22 | /** 23 | * MonitoredConstant provides an implementation of {@link Monitorable} for 24 | * simple values that are rarely (read: never) updated, once initialised. 25 | *

26 | * This class should be used as for values which rarely change, such as the 27 | * number of installed CPUs or the application version number. 28 | *

29 | * A setter exists for those cases where the value is not known until after 30 | * creation (pre-registration of the Monitorable is required, but the value is 31 | * not known at creation time), but this should not be called as a matter of 32 | * course. 33 | */ 34 | public class MonitoredConstant extends SettableValue { 35 | public MonitoredConstant(String name, String description, T initialValue) { 36 | this(name, description, MonitorableRegistry.DEFAULT_REGISTRY, 37 | initialValue); 38 | } 39 | 40 | public MonitoredConstant(String name, String description, T initialValue, Unit unit) { 41 | this(name, description, MonitorableRegistry.DEFAULT_REGISTRY, initialValue, unit); 42 | } 43 | 44 | public MonitoredConstant(String name, String description, MonitorableRegistry registry, 45 | T initialValue) { 46 | this(name, description, registry, initialValue, ONE); 47 | } 48 | 49 | public MonitoredConstant(String name, String description, MonitorableRegistry registry, 50 | T initialValue, Unit unit) { 51 | super(name, description, registry, initialValue, unit, ValueSemantics.CONSTANT); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /parfait-pcp/src/main/java/io/pcp/parfait/pcp/StringParsingTextSource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | package io.pcp.parfait.pcp; 18 | 19 | import java.util.Map; 20 | 21 | import io.pcp.parfait.Monitorable; 22 | import io.pcp.parfait.dxm.MetricName; 23 | import com.google.common.collect.Maps; 24 | 25 | public class StringParsingTextSource implements TextSource { 26 | private final TextSource delegate; 27 | 28 | public StringParsingTextSource(Iterable input, TextSource fallback) { 29 | delegate = new MapTextSource(fallback, parseMap(input)); 30 | } 31 | 32 | private Map parseMap(Iterable input) { 33 | Map output = Maps.newHashMap(); 34 | int lineNumber = 0; 35 | for (String currentLine : input) { 36 | lineNumber++; 37 | if (!(currentLine.trim().isEmpty() || currentLine.trim().startsWith("#"))) { 38 | String[] elements = currentLine.trim().split("\t"); 39 | if (elements.length != 2) { 40 | throw new IllegalArgumentException( 41 | "Error parsing line " 42 | + lineNumber 43 | + " of input; should have two tab-delimited columns in format \\t"); 44 | } 45 | String metricName = elements[0]; 46 | String text = elements[1]; 47 | 48 | output.put(metricName, text); 49 | } 50 | } 51 | return output; 52 | } 53 | 54 | @Override 55 | public String getText(Monitorable monitorable, MetricName mappedName) { 56 | return delegate.getText(monitorable, mappedName); 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /parfait-dropwizard/src/main/java/io/pcp/parfait/dropwizard/metricadapters/HistogramAdapter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | package io.pcp.parfait.dropwizard.metricadapters; 18 | 19 | import static com.codahale.metrics.MetricRegistry.name; 20 | import static tech.units.indriya.AbstractUnit.ONE; 21 | 22 | import javax.measure.Unit; 23 | import java.util.Set; 24 | 25 | import com.codahale.metrics.Histogram; 26 | import io.pcp.parfait.Monitorable; 27 | import io.pcp.parfait.ValueSemantics; 28 | import io.pcp.parfait.dropwizard.MetricAdapter; 29 | import com.google.common.collect.Sets; 30 | 31 | public class HistogramAdapter implements MetricAdapter { 32 | 33 | private final SamplingAdapter samplingAdapter; 34 | private final CountingAdapter countingAdapter; 35 | 36 | public HistogramAdapter(Histogram histogram, String name, String description, Unit unit) { 37 | this.samplingAdapter = new SamplingAdapter(histogram, name, description, unit); 38 | this.countingAdapter = new CountingAdapter(histogram, name(name, "count"), description + " - Count", ValueSemantics.MONOTONICALLY_INCREASING); 39 | } 40 | 41 | public HistogramAdapter(Histogram histogram, String name, String description) { 42 | this(histogram, name, description, ONE); 43 | } 44 | 45 | @Override 46 | public Set getMonitorables() { 47 | Set monitorables = Sets.newHashSet(); 48 | monitorables.addAll(samplingAdapter.getMonitorables()); 49 | monitorables.addAll(countingAdapter.getMonitorables()); 50 | return monitorables; 51 | } 52 | 53 | @Override 54 | public void updateMonitorables() { 55 | samplingAdapter.updateMonitorables(); 56 | countingAdapter.updateMonitorables(); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /parfait-core/src/main/java/io/pcp/parfait/MonitoredLongValue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | package io.pcp.parfait; 18 | 19 | import static tech.units.indriya.AbstractUnit.ONE; 20 | 21 | import java.util.concurrent.atomic.AtomicLong; 22 | import javax.measure.Unit; 23 | 24 | /** 25 | * {@link Monitorable} implementation for a free-running Long value. 26 | */ 27 | public class MonitoredLongValue extends MonitoredNumeric implements Counter { 28 | public MonitoredLongValue(String name, String description, 29 | MonitorableRegistry registry, Long initialValue) { 30 | this(name, description, registry, initialValue, ONE); 31 | } 32 | 33 | public MonitoredLongValue(String name, String description, 34 | Long initialValue) { 35 | this(name, description, MonitorableRegistry.DEFAULT_REGISTRY, initialValue, ONE); 36 | } 37 | 38 | public MonitoredLongValue(String name, String description, 39 | MonitorableRegistry registry, Long initialValue, Unit unit) { 40 | super(name, description, registry, new AtomicLong(initialValue), unit); 41 | } 42 | 43 | /** 44 | * Convenience method to increment atomic numeric types. 45 | */ 46 | public void inc() { 47 | inc(1); 48 | } 49 | 50 | @Override 51 | public void inc(int delta) { 52 | value.addAndGet(delta); 53 | notifyMonitors(); 54 | } 55 | 56 | /** 57 | * Convenience method to decrement atomic numeric types. 58 | */ 59 | public void dec() { 60 | dec(1); 61 | } 62 | 63 | @Override 64 | public void dec(int delta) { 65 | inc(-delta); 66 | } 67 | 68 | @Override 69 | public void inc(long increment) { 70 | value.addAndGet(increment); 71 | notifyMonitors(); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /parfait-core/src/test/java/io/pcp/parfait/MonitoredIntValueTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | package io.pcp.parfait; 18 | 19 | import static org.junit.Assert.assertEquals; 20 | import static tech.units.indriya.AbstractUnit.ONE; 21 | 22 | import java.util.concurrent.atomic.AtomicInteger; 23 | import org.junit.Test; 24 | 25 | public class MonitoredIntValueTest { 26 | @Test 27 | public void newMonitoredIntegerHasCorrectSemantics() { 28 | assertEquals(ValueSemantics.FREE_RUNNING, newValue().getSemantics()); 29 | } 30 | 31 | @Test 32 | public void newMonitoredIntegerHasSuppliedValues() { 33 | assertEquals("AAA", newValue().getName()); 34 | assertEquals("BBB", newValue().getDescription()); 35 | assertEquals(23, newValue().get().intValue()); 36 | assertEquals(ONE, newValue().getUnit()); 37 | assertEquals(AtomicInteger.class, newValue().getType()); 38 | } 39 | 40 | @Test 41 | public void incrementIncreasesValueByOne() { 42 | MonitoredIntValue value = newValue(); 43 | value.inc(); 44 | assertEquals(24, value.get().intValue()); 45 | } 46 | 47 | @Test 48 | public void decrementDecreasesValueByOne() { 49 | MonitoredIntValue value = newValue(); 50 | value.dec(); 51 | assertEquals(22, value.get().intValue()); 52 | } 53 | 54 | @Test 55 | public void setReplacesValue() { 56 | MonitoredIntValue value = newValue(); 57 | value.set(new AtomicInteger(17)); 58 | assertEquals(17, value.get().intValue()); 59 | } 60 | 61 | private MonitoredIntValue newValue() { 62 | return new MonitoredIntValue("AAA", "BBB", new MonitorableRegistry(), 23); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /parfait-core/src/main/java/io/pcp/parfait/MonitoredValue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | package io.pcp.parfait; 18 | 19 | import static tech.units.indriya.AbstractUnit.ONE; 20 | 21 | import javax.measure.Unit; 22 | 23 | /** 24 | * MonitoredValue provides a convenient implementation of {@link Monitorable} 25 | * for free-running values that are updatable through a single set method call. 26 | *

27 | * A free-running value is a value that increments and decrements at-will over 28 | * time. This is essentially a "point in time" measurement. An example of an 29 | * instantaneous value is the number of active HTTP sessions. 30 | *

31 | * It is recommended that monotonically-increasing counters be implemented using 32 | * the class {@link MonitoredCounter} in preference to this class. 33 | */ 34 | public class MonitoredValue extends SettableValue { 35 | public MonitoredValue(String name, String description, T initialValue) { 36 | this(name, description, MonitorableRegistry.DEFAULT_REGISTRY, 37 | initialValue); 38 | } 39 | 40 | public MonitoredValue(String name, String description, T initialValue, Unit unit) { 41 | this(name, description, MonitorableRegistry.DEFAULT_REGISTRY, initialValue, unit); 42 | } 43 | 44 | public MonitoredValue(String name, String description, MonitorableRegistry registry, 45 | T initialValue) { 46 | this(name, description, registry, initialValue, ONE); 47 | } 48 | 49 | public MonitoredValue(String name, String description, MonitorableRegistry registry, 50 | T initialValue, Unit unit) { 51 | super(name, description, registry, initialValue, unit, ValueSemantics.FREE_RUNNING); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /parfait-core/src/test/java/io/pcp/parfait/MonitoredLongValueTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2017 Aconex 3 | * 4 | * Licensed under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | package io.pcp.parfait; 18 | 19 | import static org.junit.Assert.assertEquals; 20 | 21 | import static tech.units.indriya.AbstractUnit.ONE; 22 | 23 | import java.util.concurrent.atomic.AtomicLong; 24 | 25 | import org.junit.Test; 26 | 27 | public class MonitoredLongValueTest { 28 | @Test 29 | public void newMonitoredLongHasCorrectSemantics() { 30 | assertEquals(ValueSemantics.FREE_RUNNING, newValue().getSemantics()); 31 | } 32 | 33 | @Test 34 | public void newMonitoredLongHasSuppliedValues() { 35 | assertEquals("AAA", newValue().getName()); 36 | assertEquals("BBB", newValue().getDescription()); 37 | assertEquals(23L, newValue().get().longValue()); 38 | assertEquals(ONE, newValue().getUnit()); 39 | assertEquals(AtomicLong.class, newValue().getType()); 40 | } 41 | 42 | @Test 43 | public void incrementIncreasesValueByOne() { 44 | MonitoredLongValue value = newValue(); 45 | value.inc(); 46 | assertEquals(24L, value.get().longValue()); 47 | } 48 | 49 | @Test 50 | public void decrementDecreasesValueByOne() { 51 | MonitoredLongValue value = newValue(); 52 | value.dec(); 53 | assertEquals(22, value.get().longValue()); 54 | } 55 | 56 | @Test 57 | public void setReplacesValue() { 58 | MonitoredLongValue value = newValue(); 59 | value.set(new AtomicLong(17)); 60 | assertEquals(17L, value.get().longValue()); 61 | } 62 | 63 | private MonitoredLongValue newValue() { 64 | return new MonitoredLongValue("AAA", "BBB", new MonitorableRegistry(), 23L); 65 | } 66 | } 67 | --------------------------------------------------------------------------------