├── .github
└── workflows
│ ├── pr.yml
│ ├── release.yml
│ └── snapshot.yml
├── .gitignore
├── .netflixoss
├── CHANGELOG.md
├── CONTRIBUTING.md
├── LICENSE
├── LICENSE.txt
├── NOTICE.txt
├── OSSMETADATA
├── README.md
├── build.gradle
├── codequality
├── HEADER
├── checkstyle.xml
├── checkstyle_test.xml
├── findbugs-exclude.xml
└── pmd.xml
├── dependencies.properties
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── servo-apache
├── README.md
├── build.gradle
└── src
│ ├── main
│ └── java
│ │ └── com
│ │ └── netflix
│ │ └── servo
│ │ └── publish
│ │ └── apache
│ │ └── ApacheStatusPoller.java
│ └── test
│ └── java
│ └── com
│ └── netflix
│ └── servo
│ └── publish
│ └── apache
│ └── ApacheStatusPollerTest.java
├── servo-atlas
├── README.md
├── build.gradle
├── gradle.properties
└── src
│ ├── jmh
│ └── java
│ │ └── com
│ │ └── netflix
│ │ └── servo
│ │ └── publish
│ │ └── atlas
│ │ └── ValidCharactersBench.java
│ ├── main
│ └── java
│ │ └── com
│ │ └── netflix
│ │ └── servo
│ │ └── publish
│ │ └── atlas
│ │ ├── AtlasMetric.java
│ │ ├── AtlasMetricObserver.java
│ │ ├── AtlasPrettyPrinter.java
│ │ ├── BasicAtlasConfig.java
│ │ ├── HttpHelper.java
│ │ ├── JsonPayload.java
│ │ ├── ServoAtlasConfig.java
│ │ ├── UpdateRequest.java
│ │ └── ValidCharacters.java
│ └── test
│ └── java
│ └── com
│ └── netflix
│ └── servo
│ └── publish
│ └── atlas
│ ├── AtlasPrettyPrinterTest.java
│ ├── HttpHelperTest.java
│ └── ValidCharactersTest.java
├── servo-aws
├── build.gradle
├── doc
│ └── ec2Metadata.txt
└── src
│ ├── main
│ └── java
│ │ └── com
│ │ └── netflix
│ │ └── servo
│ │ ├── aws
│ │ ├── AwsPropertyKeys.java
│ │ ├── AwsServiceClients.java
│ │ ├── DataSourceTypeToAwsUnit.java
│ │ ├── constants
│ │ │ ├── Dimensions.java
│ │ │ ├── Namespace.java
│ │ │ └── package-info.java
│ │ └── package-info.java
│ │ ├── publish
│ │ └── cloudwatch
│ │ │ ├── CloudWatchMetricObserver.java
│ │ │ └── package-info.java
│ │ └── tag
│ │ └── aws
│ │ ├── AwsInjectableTag.java
│ │ └── package-info.java
│ └── test
│ └── java
│ └── com
│ └── netflix
│ └── servo
│ ├── aws
│ └── DataSourceTypeToAwsUnitTest.java
│ ├── publish
│ └── cloudwatch
│ │ ├── CloudWatchMetricObserverTest.java
│ │ └── CloudWatchValueTest.java
│ └── tag
│ └── aws
│ └── AwsInjectableTagTest.java
├── servo-core
├── build.gradle
└── src
│ ├── main
│ └── java
│ │ └── com
│ │ └── netflix
│ │ └── servo
│ │ ├── BasicMonitorRegistry.java
│ │ ├── DefaultMonitorRegistry.java
│ │ ├── Metric.java
│ │ ├── MonitorRegistry.java
│ │ ├── NoopMonitorRegistry.java
│ │ ├── SpectatorContext.java
│ │ ├── annotations
│ │ ├── DataSourceLevel.java
│ │ ├── DataSourceType.java
│ │ ├── Monitor.java
│ │ ├── MonitorTags.java
│ │ └── package-info.java
│ │ ├── jmx
│ │ ├── DefaultObjectNameMapper.java
│ │ ├── JmxMonitorRegistry.java
│ │ ├── MonitorMBean.java
│ │ ├── ObjectNameBuilder.java
│ │ ├── ObjectNameMapper.java
│ │ ├── OrderedObjectNameMapper.java
│ │ └── package-info.java
│ │ ├── monitor
│ │ ├── AbstractContextualMonitor.java
│ │ ├── AbstractMonitor.java
│ │ ├── AnnotatedNumberMonitor.java
│ │ ├── AnnotatedStringMonitor.java
│ │ ├── BasicCompositeMonitor.java
│ │ ├── BasicCounter.java
│ │ ├── BasicDistributionSummary.java
│ │ ├── BasicGauge.java
│ │ ├── BasicInformational.java
│ │ ├── BasicStopwatch.java
│ │ ├── BasicTimer.java
│ │ ├── BucketConfig.java
│ │ ├── BucketTimer.java
│ │ ├── CompositeMonitor.java
│ │ ├── CompositeMonitorWrapper.java
│ │ ├── ContextualCounter.java
│ │ ├── ContextualTimer.java
│ │ ├── Counter.java
│ │ ├── DefaultPublishingPolicy.java
│ │ ├── DoubleCounter.java
│ │ ├── DoubleGauge.java
│ │ ├── DoubleMaxGauge.java
│ │ ├── DurationTimer.java
│ │ ├── DynamicCounter.java
│ │ ├── DynamicGauge.java
│ │ ├── DynamicTimer.java
│ │ ├── Gauge.java
│ │ ├── Informational.java
│ │ ├── LongGauge.java
│ │ ├── MaxGauge.java
│ │ ├── MinGauge.java
│ │ ├── Monitor.java
│ │ ├── MonitorConfig.java
│ │ ├── MonitorWrapper.java
│ │ ├── MonitoredCache.java
│ │ ├── MonitoredThreadPool.java
│ │ ├── Monitors.java
│ │ ├── NumberGauge.java
│ │ ├── NumericMonitor.java
│ │ ├── NumericMonitorWrapper.java
│ │ ├── PeakRateCounter.java
│ │ ├── Pollers.java
│ │ ├── PublishingPolicy.java
│ │ ├── ResettableCounter.java
│ │ ├── SpectatorMonitor.java
│ │ ├── SpectatorMonitorWrapper.java
│ │ ├── StatsMonitor.java
│ │ ├── StatsTimer.java
│ │ ├── StepCounter.java
│ │ ├── StepLong.java
│ │ ├── Stopwatch.java
│ │ ├── TimedInterface.java
│ │ ├── TimedStopwatch.java
│ │ ├── Timer.java
│ │ └── package-info.java
│ │ ├── package-info.java
│ │ ├── publish
│ │ ├── AsyncMetricObserver.java
│ │ ├── BaseMetricObserver.java
│ │ ├── BaseMetricPoller.java
│ │ ├── BasicMetricFilter.java
│ │ ├── CompositeMetricPoller.java
│ │ ├── CounterToRateMetricTransform.java
│ │ ├── FileMetricObserver.java
│ │ ├── JmxConnector.java
│ │ ├── JmxMetricPoller.java
│ │ ├── JvmMetricPoller.java
│ │ ├── LocalJmxConnector.java
│ │ ├── MemoryMetricObserver.java
│ │ ├── MetricFilter.java
│ │ ├── MetricObserver.java
│ │ ├── MetricPoller.java
│ │ ├── MetricTransformObserver.java
│ │ ├── MonitorRegistryMetricPoller.java
│ │ ├── NormalizationTransform.java
│ │ ├── PollCallable.java
│ │ ├── PollRunnable.java
│ │ ├── PollScheduler.java
│ │ ├── PrefixMetricFilter.java
│ │ ├── RegexMetricFilter.java
│ │ └── package-info.java
│ │ ├── stats
│ │ ├── StatsBuffer.java
│ │ └── StatsConfig.java
│ │ ├── tag
│ │ ├── BasicTag.java
│ │ ├── BasicTagList.java
│ │ ├── InjectableTag.java
│ │ ├── SmallTagMap.java
│ │ ├── SortedTagList.java
│ │ ├── StandardTagKeys.java
│ │ ├── Tag.java
│ │ ├── TagComparator.java
│ │ ├── TagList.java
│ │ ├── TaggingContext.java
│ │ ├── Tags.java
│ │ ├── ThreadLocalTaggingContext.java
│ │ └── package-info.java
│ │ └── util
│ │ ├── Clock.java
│ │ ├── ClockWithOffset.java
│ │ ├── ExpiringCache.java
│ │ ├── Iterables.java
│ │ ├── ManualClock.java
│ │ ├── Memoizer.java
│ │ ├── Objects.java
│ │ ├── Preconditions.java
│ │ ├── Reflection.java
│ │ ├── Strings.java
│ │ ├── ThreadCpuStats.java
│ │ ├── ThreadFactories.java
│ │ ├── Throwables.java
│ │ ├── TimeLimiter.java
│ │ ├── UnmodifiableList.java
│ │ ├── UnmodifiableSet.java
│ │ └── VisibleForTesting.java
│ └── test
│ ├── java
│ └── com
│ │ └── netflix
│ │ └── servo
│ │ ├── DefaultMonitorRegistryTest.java
│ │ ├── MetricTest.java
│ │ ├── jmx
│ │ ├── DefaultObjectNameMapperTest.java
│ │ ├── ObjectNameBuilderTest.java
│ │ └── OrderedObjectNameMapperTest.java
│ │ ├── monitor
│ │ ├── AbstractMonitorTest.java
│ │ ├── AnnotationsTest.java
│ │ ├── BasicCounterTest.java
│ │ ├── BasicDistributionSummaryTest.java
│ │ ├── BasicGaugeTest.java
│ │ ├── BasicInformationalTest.java
│ │ ├── BasicStopwatchTest.java
│ │ ├── BasicTimerTest.java
│ │ ├── BucketConfigTest.java
│ │ ├── BucketTimerTest.java
│ │ ├── ClassWithBadAnnotation.java
│ │ ├── ClassWithMonitors.java
│ │ ├── DoubleCounterTest.java
│ │ ├── DoubleGaugeTest.java
│ │ ├── DurationTimerTest.java
│ │ ├── DynamicCounterTest.java
│ │ ├── DynamicTimerTest.java
│ │ ├── LongGaugeTest.java
│ │ ├── MaxGaugeTest.java
│ │ ├── MinGaugeTest.java
│ │ ├── MonitorConfigTest.java
│ │ ├── MonitorsTest.java
│ │ ├── ParentHasMonitors.java
│ │ ├── PeakRateCounterTest.java
│ │ ├── PollersTest.java
│ │ ├── PublishingPolicyTest.java
│ │ ├── SpectatorIntegrationTest.java
│ │ ├── StatsMonitorTest.java
│ │ ├── StatsTimerTest.java
│ │ ├── StepCounterTest.java
│ │ ├── SuperClassWithMonitors.java
│ │ └── TimedInterfaceTest.java
│ │ ├── publish
│ │ ├── AsyncMetricObserverTest.java
│ │ ├── BasicMetricFilterTest.java
│ │ ├── CompositeMetricPollerTest.java
│ │ ├── CounterToRateMetricTransformTest.java
│ │ ├── FailingMetricObserver.java
│ │ ├── FileMetricObserverTest.java
│ │ ├── JmxMetricPollerTest.java
│ │ ├── MemoryMetricObserverTest.java
│ │ ├── MockMetricPoller.java
│ │ ├── MonitorRegistryMetricPollerTest.java
│ │ ├── NormalizationTransformTest.java
│ │ ├── PollSchedulerTest.java
│ │ ├── PrefixMetricFilterTest.java
│ │ ├── RegexMetricFilterTest.java
│ │ └── SlowMetricObserver.java
│ │ ├── stats
│ │ └── StatsBufferTest.java
│ │ ├── tag
│ │ ├── BasicTagListTest.java
│ │ ├── BasicTagTest.java
│ │ ├── SmallTagMapTest.java
│ │ ├── SortedTagListTest.java
│ │ └── TagComparatorTest.java
│ │ └── util
│ │ ├── ExpiringCacheTest.java
│ │ └── StringsTest.java
│ └── resources
│ └── log4j.properties
├── servo-example
├── build.gradle
└── src
│ └── main
│ └── java
│ └── com
│ └── netflix
│ └── servo
│ └── example
│ ├── BaseHandler.java
│ ├── Config.java
│ ├── EchoHandler.java
│ ├── ExitHandler.java
│ └── Main.java
├── servo-graphite
├── build.gradle
└── src
│ ├── main
│ └── java
│ │ └── com
│ │ └── netflix
│ │ └── servo
│ │ └── publish
│ │ └── graphite
│ │ ├── BasicGraphiteNamingConvention.java
│ │ ├── GraphiteMetricObserver.java
│ │ └── GraphiteNamingConvention.java
│ └── test
│ └── java
│ └── com
│ └── netflix
│ └── servo
│ └── publish
│ └── graphite
│ ├── BasicGraphiteNamingConventionTest.java
│ ├── GraphiteMetricObserverTest.java
│ └── SocketReceiverTester.java
├── servo-tomcat
├── README.md
├── build.gradle
└── src
│ └── main
│ └── java
│ └── com
│ └── netflix
│ └── servo
│ └── publish
│ └── tomcat
│ └── TomcatPoller.java
└── settings.gradle
/.github/workflows/pr.yml:
--------------------------------------------------------------------------------
1 | name: PR Build
2 |
3 | on: [pull_request]
4 |
5 | jobs:
6 | build:
7 | runs-on: ubuntu-latest
8 | strategy:
9 | matrix:
10 | java: [8, 11, 17]
11 | steps:
12 | - uses: actions/checkout@v3
13 | with:
14 | fetch-depth: 0
15 | - name: Set up JDK ${{ matrix.java }}
16 | uses: actions/setup-java@v3
17 | with:
18 | java-version: ${{ matrix.java }}
19 | distribution: 'temurin'
20 | - uses: actions/cache@v4
21 | id: gradle-cache
22 | with:
23 | path: |
24 | ~/.gradle/caches
25 | key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
26 | - uses: actions/cache@v4
27 | id: gradle-wrapper-cache
28 | with:
29 | path: |
30 | ~/.gradle/wrapper
31 | key: ${{ runner.os }}-gradlewrapper-${{ hashFiles('gradle/wrapper/*') }}
32 | - name: Build
33 | run: ./gradlew build
34 | validation:
35 | name: "Gradle Validation"
36 | runs-on: ubuntu-latest
37 | steps:
38 | - uses: actions/checkout@v3
39 | - uses: gradle/wrapper-validation-action@v1
40 |
--------------------------------------------------------------------------------
/.github/workflows/release.yml:
--------------------------------------------------------------------------------
1 | name: Release
2 |
3 | on:
4 | push:
5 | tags:
6 | - v[0-9]+.[0-9]+.[0-9]+
7 | - v[0-9]+.[0-9]+.[0-9]+-rc.[0-9]+
8 |
9 | jobs:
10 | build:
11 | runs-on: ubuntu-latest
12 | steps:
13 | - uses: actions/checkout@v3
14 | - name: Set up JDK
15 | uses: actions/setup-java@v3
16 | with:
17 | java-version: 8
18 | distribution: 'temurin'
19 | - uses: actions/cache@v4
20 | id: gradle-cache
21 | with:
22 | path: |
23 | ~/.gradle/caches
24 | key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
25 | - uses: actions/cache@v4
26 | id: gradle-wrapper-cache
27 | with:
28 | path: |
29 | ~/.gradle/wrapper
30 | key: ${{ runner.os }}-gradlewrapper-${{ hashFiles('gradle/wrapper/*') }}
31 | - name: Build candidate
32 | if: contains(github.ref, '-rc.')
33 | run: ./gradlew --info --stacktrace -Prelease.useLastTag=true candidate
34 | env:
35 | NETFLIX_OSS_SIGNING_KEY: ${{ secrets.ORG_SIGNING_KEY }}
36 | NETFLIX_OSS_SIGNING_PASSWORD: ${{ secrets.ORG_SIGNING_PASSWORD }}
37 | NETFLIX_OSS_REPO_USERNAME: ${{ secrets.ORG_NETFLIXOSS_USERNAME }}
38 | NETFLIX_OSS_REPO_PASSWORD: ${{ secrets.ORG_NETFLIXOSS_PASSWORD }}
39 | - name: Build release
40 | if: (!contains(github.ref, '-rc.'))
41 | run: ./gradlew --info -Prelease.useLastTag=true final
42 | env:
43 | NETFLIX_OSS_SONATYPE_USERNAME: ${{ secrets.ORG_SONATYPE_USERNAME }}
44 | NETFLIX_OSS_SONATYPE_PASSWORD: ${{ secrets.ORG_SONATYPE_PASSWORD }}
45 | NETFLIX_OSS_SIGNING_KEY: ${{ secrets.ORG_SIGNING_KEY }}
46 | NETFLIX_OSS_SIGNING_PASSWORD: ${{ secrets.ORG_SIGNING_PASSWORD }}
47 | NETFLIX_OSS_REPO_USERNAME: ${{ secrets.ORG_NETFLIXOSS_USERNAME }}
48 | NETFLIX_OSS_REPO_PASSWORD: ${{ secrets.ORG_NETFLIXOSS_PASSWORD }}
49 |
--------------------------------------------------------------------------------
/.github/workflows/snapshot.yml:
--------------------------------------------------------------------------------
1 | name: Snapshot
2 |
3 | on:
4 | push:
5 | branches:
6 | - master
7 |
8 | jobs:
9 | build:
10 | runs-on: ubuntu-latest
11 | steps:
12 | - uses: actions/checkout@v3
13 | with:
14 | fetch-depth: 0
15 | - name: Set up JDK
16 | uses: actions/setup-java@v3
17 | with:
18 | java-version: 8
19 | distribution: 'temurin'
20 | - uses: actions/cache@v4
21 | id: gradle-cache
22 | with:
23 | path: |
24 | ~/.gradle/caches
25 | key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
26 | - uses: actions/cache@v4
27 | id: gradle-wrapper-cache
28 | with:
29 | path: |
30 | ~/.gradle/wrapper
31 | key: ${{ runner.os }}-gradlewrapper-${{ hashFiles('gradle/wrapper/*') }}
32 | - name: Build
33 | run: ./gradlew build snapshot
34 | env:
35 | NETFLIX_OSS_SIGNING_KEY: ${{ secrets.ORG_SIGNING_KEY }}
36 | NETFLIX_OSS_SIGNING_PASSWORD: ${{ secrets.ORG_SIGNING_PASSWORD }}
37 | NETFLIX_OSS_REPO_USERNAME: ${{ secrets.ORG_NETFLIXOSS_USERNAME }}
38 | NETFLIX_OSS_REPO_PASSWORD: ${{ secrets.ORG_NETFLIXOSS_PASSWORD }}
39 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Compiled source #
2 | ###################
3 | *.com
4 | *.class
5 | *.dll
6 | *.exe
7 | *.o
8 | *.so
9 |
10 | # Packages #
11 | ############
12 | # it's better to unpack these files and commit the raw source
13 | # git has its own built in compression methods
14 | *.7z
15 | *.dmg
16 | *.gz
17 | *.iso
18 | *.jar
19 | *.rar
20 | *.tar
21 | *.zip
22 |
23 | # Logs and databases #
24 | ######################
25 | *.log
26 |
27 | # OS generated files #
28 | ######################
29 | .DS_Store*
30 | ehthumbs.db
31 | Icon?
32 | Thumbs.db
33 |
34 | # Editor Files #
35 | ################
36 | *~
37 | *.swp
38 |
39 | # Gradle Files #
40 | ################
41 | .gradle
42 | .m2
43 |
44 | # Build output directies
45 | /target
46 | */target
47 | /build
48 | */build
49 |
50 | # IntelliJ specific files/directories
51 | out
52 | .idea
53 | *.ipr
54 | *.iws
55 | *.iml
56 | atlassian-ide-plugin.xml
57 |
58 | # Eclipse specific files/directories
59 | .classpath
60 | .project
61 | .settings
62 | .metadata
63 |
64 | # NetBeans specific files/directories
65 | .nbattrs
66 | /bin
67 |
--------------------------------------------------------------------------------
/.netflixoss:
--------------------------------------------------------------------------------
1 | pullrequest_cloudbees=false
2 | jdk=1.8
3 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | This file is only here because it is required for automation. See the github releases page for details about changes:
2 |
3 | https://github.com/Netflix/servo/releases
4 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | ## Contributing to Servo
2 |
3 | If you would like to contribute code, then you can do so through the following process:
4 |
5 | * Fork the repository on GitHub and clone your fork.
6 | * Configure the upstream remote, so that you can keep your fork synchronized.
7 | ```
8 | git remote add upstream https://github.com/Netflix/servo.git
9 | ```
10 | * Create a branch for your changes.
11 | ```
12 | git branch my-awesome-bug-fix
13 | git checkout my-awesome-bug-fix
14 | ```
15 | * Check for and merge upstream changes.
16 | ```
17 | git fetch upstream
18 | git checkout master
19 | git merge upstream/master
20 | git checkout my-awesome-bug-fix
21 | git rebase master
22 | ```
23 | * Build your changes and run unit tests. You will see many warnings and errors because Servo unit tests validate error conditions. As long as the final result is BUILD SUCCESSFUL, then the tests have passed.
24 | ```
25 | ./gradlew build
26 | ...
27 | BUILD SUCCESSFUL
28 | ```
29 | * Push your changes and send a pull request.
30 | ```
31 | git push origin
32 | ```
33 | * Watch for the `cloudbees-pull-request-builder` to comment on the status of your pull request.
34 |
35 | When submitting code, please make every effort to follow existing conventions and style in order to keep the code as readable as possible.
36 |
37 | ## License
38 |
39 | By contributing your code, you agree to license your contribution under the terms of the [APLv2](https://github.com/Netflix/servo/blob/master/LICENSE).
40 |
41 | All files are released with the Apache 2.0 license.
42 |
43 | If you are adding a new file it should have a header like this:
44 |
45 | ```
46 | /**
47 | * Copyright 2014 Netflix, Inc.
48 | *
49 | * Licensed under the Apache License, Version 2.0 (the "License");
50 | * you may not use this file except in compliance with the License.
51 | * You may obtain a copy of the License at
52 | *
53 | * http://www.apache.org/licenses/LICENSE-2.0
54 | *
55 | * Unless required by applicable law or agreed to in writing, software
56 | * distributed under the License is distributed on an "AS IS" BASIS,
57 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
58 | * See the License for the specific language governing permissions and
59 | * limitations under the License.
60 | */
61 | ```
62 |
--------------------------------------------------------------------------------
/NOTICE.txt:
--------------------------------------------------------------------------------
1 | Servo
2 | Copyright 2011 Netflix, Inc.
3 |
4 | This product includes software developed by The Apache Software
5 | Foundation (http://www.apache.org/).
6 |
7 | Alternative collection types provided by Google Guava from
8 | http://code.google.com/p/guava-libraries/
9 | Copyright (C) 2007 Google Inc.
10 |
--------------------------------------------------------------------------------
/OSSMETADATA:
--------------------------------------------------------------------------------
1 | osslifecycle=maintenance
2 |
--------------------------------------------------------------------------------
/codequality/HEADER:
--------------------------------------------------------------------------------
1 | Copyright ${year} Netflix, Inc.
2 |
3 | Licensed under the Apache License, Version 2.0 (the "License");
4 | you may not use this file except in compliance with the License.
5 | 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 implied.
12 | See the License for the specific language governing permissions and
13 | limitations under the License.
14 |
--------------------------------------------------------------------------------
/codequality/findbugs-exclude.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
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 |
--------------------------------------------------------------------------------
/dependencies.properties:
--------------------------------------------------------------------------------
1 | # Auto generated by insight-recommendations build
2 | com.amazonaws:aws-java-sdk-autoscaling = 1.11.965
3 | com.amazonaws:aws-java-sdk-cloudwatch = 1.11.965
4 | com.amazonaws:aws-java-sdk-core = 1.11.965
5 | com.fasterxml.jackson.core:jackson-annotations = 2.12.1
6 | com.fasterxml.jackson.core:jackson-core = 2.12.1
7 | com.fasterxml.jackson.core:jackson-databind = 2.12.1
8 | com.fasterxml.jackson.dataformat:jackson-dataformat-smile = 2.12.1
9 | com.google.guava:guava = 19.0
10 | com.netflix.archaius:archaius2-api = 2.3.16
11 | com.netflix.archaius:archaius2-core = 2.3.16
12 | com.netflix.awsobjectmapper:awsobjectmapper = 1.11.965
13 | com.netflix.eureka:eureka-client = 1.10.12
14 | com.netflix.frigga:frigga = 0.24.0
15 | com.netflix.iep-shadow:iepshadow-iep-module-rxnetty = 0.4.18.29
16 | com.netflix.iep-shadow:iepshadow-iep-rxhttp = 0.4.18.29
17 | com.netflix.iep-shadow:iepshadow-rxnetty = 0.4.20.29
18 | com.netflix.iep-shadow:iepshadow-rxnetty-contexts = 0.4.20.29
19 | com.netflix.iep-shadow:iepshadow-rxnetty-spectator = 0.4.20.29
20 | com.netflix.spectator:spectator-api = 0.124.0
21 | io.netty:netty-buffer = 4.1.8.Final
22 | io.netty:netty-codec = 4.1.8.Final
23 | io.netty:netty-codec-http = 4.1.8.Final
24 | io.netty:netty-common = 4.1.8.Final
25 | io.netty:netty-handler = 4.1.8.Final
26 | io.netty:netty-resolver = 4.1.8.Final
27 | io.netty:netty-transport = 4.1.8.Final
28 | io.netty:netty-transport-native-epoll = 4.1.8.Final
29 | io.reactivex:rxjava = 1.3.8
30 | io.reactivex:rxnetty = 0.4.20
31 | io.reactivex:rxnetty-contexts = 0.4.20
32 | io.reactivex:rxnetty-spectator = 0.4.20
33 | org.slf4j:slf4j-api = 1.7.30
34 | org.slf4j:slf4j-log4j12 = 1.7.30
35 | org.slf4j:slf4j-nop = 1.7.30
36 | org.slf4j:slf4j-simple = 1.7.30
37 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | release.scope=patch
2 | org.gradle.jvmargs=-Xms512M -Xmx4G
3 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Netflix/servo/ef720969d2e3fa19ef4f8035aa120c5b9107f410/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Jul 21 14:48:34 CEST 2014
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-all.zip
7 |
--------------------------------------------------------------------------------
/servo-apache/README.md:
--------------------------------------------------------------------------------
1 | The following metrics are collected by Servo from the Apache [mod_status](http://httpd.apache.org/docs/current/mod/mod_status.html) server-status machine readable page. The location of the Apache server-status page is accepted as an argument to the constructor. The typical form of this URL is as follows:
2 |
3 | `http://your.server.name/server-status?auto`
4 |
5 | The CPULoad metric provided by the server-status page has been blacklisted.
6 |
7 | | Name | Class | State | Type | Description |
8 | |-------|-------|-------|------|-------------|
9 | | BusyWorkers | ApacheStatusPoller | -- | GAUGE | number of workers serving requests |
10 | | BytesPerReq | ApacheStatusPoller | -- | GAUGE | average number of bytes per request |
11 | | BytesPerSec | ApacheStatusPoller | -- | GAUGE | average number of bytes served per second |
12 | | IdleWorkers | ApacheStatusPoller | -- | GAUGE | number of idle workers |
13 | | ReqPerSec | ApacheStatusPoller | -- | GAUGE | average number of requests per second |
14 | | Scoreboard | ApacheStatusPoller | ClosingConnection | GAUGE | C |
15 | | Scoreboard | ApacheStatusPoller | DnsLookup | GAUGE | D |
16 | | Scoreboard | ApacheStatusPoller | GracefullyFinishing | GAUGE | G |
17 | | Scoreboard | ApacheStatusPoller | IdleCleanupOfWorker | GAUGE | I |
18 | | Scoreboard | ApacheStatusPoller | Keepalive | GAUGE | K |
19 | | Scoreboard | ApacheStatusPoller | Logging | GAUGE | L |
20 | | Scoreboard | ApacheStatusPoller | OpenSlotWithNoCurrentProcess | GAUGE | . |
21 | | Scoreboard | ApacheStatusPoller | ReadingRequest | GAUGE | R |
22 | | Scoreboard | ApacheStatusPoller | SendingReply | GAUGE | W |
23 | | Scoreboard | ApacheStatusPoller | StartingUp | GAUGE | S |
24 | | Scoreboard | ApacheStatusPoller | UnknownState | GAUGE | unknown symbol in the scoreboard |
25 | | Scoreboard | ApacheStatusPoller | WaitingForConnection | GAUGE | _ |
26 | | Total_Accesses | ApacheStatusPoller | -- | COUNTER | total number of accesses |
27 | | Total_kBytes | ApacheStatusPoller | -- | COUNTER | total byte count served |
28 | | Uptime | ApacheStatusPoller | -- | COUNTER | time the server has been running for |
29 |
--------------------------------------------------------------------------------
/servo-apache/build.gradle:
--------------------------------------------------------------------------------
1 | dependencies {
2 | api project(':servo-core')
3 | }
4 |
5 | jar {
6 | manifest {
7 | attributes(
8 | "Automatic-Module-Name": "com.netflix.servo.apache"
9 | )
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/servo-atlas/build.gradle:
--------------------------------------------------------------------------------
1 | dependencies {
2 | api project(':servo-core')
3 | api 'com.netflix.archaius:archaius2-core'
4 | api 'com.netflix.iep-shadow:iepshadow-rxnetty'
5 | api 'com.netflix.iep-shadow:iepshadow-iep-rxhttp'
6 | api "com.fasterxml.jackson.core:jackson-databind"
7 | api "com.fasterxml.jackson.dataformat:jackson-dataformat-smile"
8 | api 'io.netty:netty-buffer'
9 | api 'io.netty:netty-codec-http'
10 | api 'io.reactivex:rxjava'
11 | jmh project(':servo-core')
12 | }
13 |
14 | jar {
15 | manifest {
16 | attributes(
17 | "Automatic-Module-Name": "com.netflix.servo.atlas"
18 | )
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/servo-atlas/gradle.properties:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright 2015 Netflix, Inc.
3 | #
4 | # Licensed under the Apache License, Version 2.0 (the "License");
5 | # you may not use this file except in compliance with the License.
6 | # 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 implied.
13 | # See the License for the specific language governing permissions and
14 | # limitations under the License.
15 | #
16 | jackson_version=2.5.2
17 |
--------------------------------------------------------------------------------
/servo-atlas/src/jmh/java/com/netflix/servo/publish/atlas/ValidCharactersBench.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2015 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.netflix.servo.publish.atlas;
17 |
18 | import org.openjdk.jmh.annotations.Benchmark;
19 | import org.openjdk.jmh.annotations.Scope;
20 | import org.openjdk.jmh.annotations.State;
21 | import org.openjdk.jmh.annotations.Threads;
22 | import org.openjdk.jmh.infra.Blackhole;
23 |
24 | import java.util.regex.Pattern;
25 |
26 | @State(Scope.Thread)
27 | public class ValidCharactersBench {
28 | private static final Pattern INVALID_CHARS = Pattern.compile("[^a-zA-Z0-9_\\-\\.]");
29 |
30 | static String oldRegexMethod(String str) {
31 | return INVALID_CHARS.matcher(str).replaceAll("_");
32 | }
33 |
34 | @Threads(1)
35 | @Benchmark
36 | public void testUsingRegex(Blackhole bh) {
37 | String sourceStr = "netflix.streaming.vhs.server.pbstats.bitrate.playedSecs";
38 | bh.consume(oldRegexMethod(sourceStr));
39 | }
40 |
41 | @Threads(1)
42 | @Benchmark
43 | public void testNewByHand(Blackhole bh) {
44 | String sourceStr = "netflix.streaming.vhs.server.pbstats.bitrate.playedSecs";
45 | bh.consume(ValidCharacters.toValidCharset(sourceStr));
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/servo-atlas/src/main/java/com/netflix/servo/publish/atlas/BasicAtlasConfig.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2015 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.netflix.servo.publish.atlas;
17 |
18 | /**
19 | * A simple implementation of {@link ServoAtlasConfig} that uses system properties to get
20 | * values.
21 | */
22 | public class BasicAtlasConfig implements ServoAtlasConfig {
23 | @Override
24 | public String getAtlasUri() {
25 | return System.getProperty("servo.atlas.uri");
26 | }
27 |
28 | @Override
29 | public int getPushQueueSize() {
30 | String pushQueueSize = System.getProperty("servo.atlas.queueSize", "1000");
31 | return Integer.parseInt(pushQueueSize);
32 | }
33 |
34 | @Override
35 | public boolean shouldSendMetrics() {
36 | String enabled = System.getProperty("servo.atlas.enabled", "true");
37 | return Boolean.parseBoolean(enabled);
38 | }
39 |
40 | @Override
41 | public int batchSize() {
42 | String batch = System.getProperty("servo.atlas.batchSize", "10000");
43 | return Integer.parseInt(batch);
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/servo-atlas/src/main/java/com/netflix/servo/publish/atlas/JsonPayload.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2015 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.netflix.servo.publish.atlas;
17 |
18 | import com.fasterxml.jackson.core.JsonGenerator;
19 |
20 | import java.io.IOException;
21 |
22 | /**
23 | * payload that can be serialized to json.
24 | */
25 | public interface JsonPayload {
26 |
27 | /**
28 | * Serialize the current entity to JSON using the given generator.
29 | */
30 | void toJson(JsonGenerator gen) throws IOException;
31 | }
32 |
--------------------------------------------------------------------------------
/servo-atlas/src/main/java/com/netflix/servo/publish/atlas/ServoAtlasConfig.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2015 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.netflix.servo.publish.atlas;
17 |
18 | /**
19 | * Configuration for the servo to atlas interface.
20 | */
21 | public interface ServoAtlasConfig {
22 | /**
23 | * Return the URI used to POST values to atlas.
24 | */
25 | String getAtlasUri();
26 |
27 | /**
28 | * Return the size of the queue to be used when pushing metrics to
29 | * the atlas backends. A value of 1000 is quite safe here, but might need
30 | * to be tweaked if attempting to send hundreds of batches per second.
31 | */
32 | int getPushQueueSize();
33 |
34 |
35 | /**
36 | * Whether we should send metrics to atlas. This can be used when running in a dev environment
37 | * for example to avoid affecting production metrics by dev machines.
38 | */
39 | boolean shouldSendMetrics();
40 |
41 | /**
42 | * The maximum size of the batch of metrics to be sent to atlas.
43 | * If attempting to send more metrics than this value,
44 | * the {@link AtlasMetricObserver} will split them into batches before sending
45 | * them to the atlas backends.
46 | *
47 | * A value of 10000 works well for most workloads.
48 | */
49 | int batchSize();
50 | }
51 |
--------------------------------------------------------------------------------
/servo-atlas/src/test/java/com/netflix/servo/publish/atlas/AtlasPrettyPrinterTest.java:
--------------------------------------------------------------------------------
1 | package com.netflix.servo.publish.atlas;
2 |
3 | import com.fasterxml.jackson.core.JsonFactory;
4 | import com.fasterxml.jackson.core.JsonGenerator;
5 | import com.netflix.servo.Metric;
6 | import com.netflix.servo.tag.BasicTagList;
7 | import com.netflix.servo.tag.TagList;
8 | import org.testng.annotations.Test;
9 |
10 | import java.io.StringWriter;
11 |
12 | import static org.testng.Assert.assertEquals;
13 |
14 | public class AtlasPrettyPrinterTest {
15 |
16 | @Test
17 | public void testPayload() throws Exception {
18 | TagList commonTags = BasicTagList.of("nf.app", "example", "nf.cluster", "example-main", "nf.region", "us-west-3");
19 | Metric m1 = new Metric("foo1", BasicTagList.of("id", "ab"), 1000L, 1.0);
20 | Metric m2 = new Metric("foo2", BasicTagList.of("id", "bc", "class", "klz"), 1000L, 2.0);
21 | Metric m3 = new Metric("foo3", BasicTagList.EMPTY, 1000L, 3.0);
22 | Metric[] metrics = new Metric[] {m1, m2, m3};
23 | JsonPayload update = new UpdateRequest(commonTags, metrics, metrics.length);
24 | JsonFactory factory = new JsonFactory();
25 | StringWriter writer = new StringWriter();
26 | JsonGenerator generator = factory.createGenerator(writer);
27 | generator.setPrettyPrinter(new AtlasPrettyPrinter());
28 | update.toJson(generator);
29 | generator.close();
30 | writer.close();
31 | String expected = "{\n\"tags\":{\"nf.app\":\"example\",\"nf.cluster\":\"example-main\",\"nf.region\":\"us-west-3\"},\n\"metrics\":[\n" +
32 | "{\"tags\":{\"name\":\"foo1\",\"id\":\"ab\"},\"start\":1000,\"value\":1.0},\n" +
33 | "{\"tags\":{\"name\":\"foo2\",\"class\":\"klz\",\"id\":\"bc\"},\"start\":1000,\"value\":2.0},\n" +
34 | "{\"tags\":{\"name\":\"foo3\"},\"start\":1000,\"value\":3.0}]\n" +
35 | "}";
36 |
37 | assertEquals(writer.toString(), expected);
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/servo-atlas/src/test/java/com/netflix/servo/publish/atlas/HttpHelperTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2015 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.netflix.servo.publish.atlas;
17 |
18 | import org.testng.annotations.Test;
19 | import rx.Observable;
20 |
21 | import java.util.ArrayList;
22 | import java.util.List;
23 | import java.util.concurrent.TimeUnit;
24 |
25 | import static org.testng.Assert.assertEquals;
26 |
27 | /**
28 | * Basic tests for {@link HttpHelper}.
29 | */
30 | public class HttpHelperTest {
31 | @Test
32 | public void testSendAll() throws Exception {
33 | List> batches = new ArrayList<>();
34 | int expectedSum = 0;
35 | for (int i = 1; i <= 5; ++i) {
36 | batches.add(Observable.just(i));
37 | expectedSum += i;
38 | }
39 |
40 | HttpHelper httpHelper = new HttpHelper(null);
41 | int sent = httpHelper.sendAll(batches, expectedSum, 100L);
42 | assertEquals(sent, expectedSum);
43 |
44 | // now add an observable that should timeout
45 | batches.add(Observable.never());
46 | int partial = httpHelper.sendAll(batches, expectedSum, 100L);
47 | assertEquals(partial, expectedSum);
48 | }
49 |
50 | @Test
51 | public void testSendAllSlow() throws Exception {
52 | Observable interval = Observable.interval(400,
53 | TimeUnit.MILLISECONDS).map(l -> l.intValue() + 1);
54 |
55 | // now add an observable that should timeout
56 | List> batches = new ArrayList<>();
57 | batches.add(interval);
58 |
59 | int expectedSum = 3; // 1 + 2 should have been received from interval
60 | for (int i = 1; i <= 5; ++i) {
61 | batches.add(Observable.just(i));
62 | expectedSum += i;
63 | }
64 |
65 | HttpHelper httpHelper = new HttpHelper(null);
66 | int partial = httpHelper.sendAll(batches, expectedSum, 1000L);
67 | assertEquals(partial, expectedSum);
68 | }
69 |
70 | }
71 |
--------------------------------------------------------------------------------
/servo-aws/build.gradle:
--------------------------------------------------------------------------------
1 | dependencies {
2 | api project(':servo-core')
3 | api('com.amazonaws:aws-java-sdk-autoscaling')
4 | api('com.amazonaws:aws-java-sdk-cloudwatch')
5 | }
6 |
7 | checkstyle {
8 | sourceSets = []
9 | }
10 |
11 | jar {
12 | manifest {
13 | attributes(
14 | "Automatic-Module-Name": "com.netflix.servo.aws"
15 | )
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/servo-aws/doc/ec2Metadata.txt:
--------------------------------------------------------------------------------
1 | http://169.254.169.254/latest/meta-data
2 |
3 | ami-id
4 | ami-launch-index
5 | ami-manifest-path
6 | block-device-mapping/
7 | hostname
8 | instance-action
9 | instance-id
10 | instance-type
11 | kernel-id
12 | local-hostname
13 | local-ipv4
14 | mac
15 | metrics/
16 | network/
17 | placement/
18 | profile
19 | public-hostname
20 | public-ipv4
21 | public-keys/
22 | ramdisk-id
23 | reservation-id
24 |
25 | block-device-mapping/
26 | ami
27 | ephemeral0
28 | ephemeral1
29 | ephemeral2
30 | ephemeral3
31 |
32 | metrics/
33 | vhostmd
34 |
35 | network/interfaces/macs/*/
36 | device-number
37 | local-hostname
38 | local-ipv4s
39 | mac
40 | owner-id
41 | public-hostname
42 | public-ipv4s
43 |
44 | placement/availability-zone
45 | us-east-1c
46 |
47 | public-keys/
48 | 0=test-keypair
--------------------------------------------------------------------------------
/servo-aws/src/main/java/com/netflix/servo/aws/AwsPropertyKeys.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2013 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.netflix.servo.aws;
17 |
18 | /**
19 | * Enum key values for setting aws related properties.
20 | */
21 | public enum AwsPropertyKeys {
22 |
23 | AWS_CREDENTIALS_FILE("com.netflix.servo.aws.credentialsFile"),
24 | AWS_AUTO_SCALING_END_POINT("com.netflix.servo.aws.endpoint.autoscaling"),
25 | AWS_CLOUD_WATCH_END_POINT("com.netflix.servo.aws.endpoint.cloudwatch");
26 |
27 | private final String bundle;
28 |
29 | /**
30 | * Constructor responsible to instantiate the type of bundle.
31 | */
32 | AwsPropertyKeys(String bundle) {
33 | this.bundle = bundle;
34 | }
35 |
36 | public String getBundle() {
37 | return bundle;
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/servo-aws/src/main/java/com/netflix/servo/aws/AwsServiceClients.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2013 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.netflix.servo.aws;
17 |
18 | import com.amazonaws.auth.AWSCredentials;
19 | import com.amazonaws.auth.AWSCredentialsProvider;
20 | import com.amazonaws.services.autoscaling.AmazonAutoScaling;
21 | import com.amazonaws.services.autoscaling.AmazonAutoScalingClient;
22 | import com.amazonaws.services.cloudwatch.AmazonCloudWatch;
23 | import com.amazonaws.services.cloudwatch.AmazonCloudWatchClient;
24 |
25 | /**
26 | * Static helpers for constructing configured AWS service clients.
27 | */
28 | public final class AwsServiceClients {
29 |
30 | private AwsServiceClients() {
31 | }
32 |
33 | /**
34 | * Get a CloudWatch client whose endpoint is configured based on properties.
35 | */
36 | public static AmazonCloudWatch cloudWatch(AWSCredentialsProvider credentials) {
37 | AmazonCloudWatch client = new AmazonCloudWatchClient(credentials);
38 | client.setEndpoint(System.getProperty(AwsPropertyKeys.AWS_CLOUD_WATCH_END_POINT.getBundle(),
39 | "monitoring.amazonaws.com"));
40 | return client;
41 | }
42 |
43 | /**
44 | * Get an AutoScaling client whose endpoint is configured based on properties.
45 | */
46 | public static AmazonAutoScaling autoScaling(AWSCredentials credentials) {
47 | AmazonAutoScaling client = new AmazonAutoScalingClient(credentials);
48 | client.setEndpoint(System.getProperty(
49 | AwsPropertyKeys.AWS_AUTO_SCALING_END_POINT.getBundle(),
50 | "autoscaling.amazonaws.com"));
51 | return client;
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/servo-aws/src/main/java/com/netflix/servo/aws/DataSourceTypeToAwsUnit.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2013 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.netflix.servo.aws;
17 |
18 | import com.amazonaws.services.cloudwatch.model.StandardUnit;
19 | import com.netflix.servo.annotations.DataSourceType;
20 |
21 | /**
22 | * Conversion from internal data types to Amazon Units.
23 | */
24 | public final class DataSourceTypeToAwsUnit {
25 | private DataSourceTypeToAwsUnit() {
26 | }
27 |
28 | public static String getUnit(DataSourceType dataSourceType) {
29 | switch (dataSourceType) {
30 | case COUNTER:
31 | return StandardUnit.CountSecond.toString();
32 | case GAUGE:
33 | return StandardUnit.None.toString();
34 | case INFORMATIONAL:
35 | return StandardUnit.None.toString();
36 | default:
37 | return StandardUnit.None.toString();
38 | }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/servo-aws/src/main/java/com/netflix/servo/aws/constants/Dimensions.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2013 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.netflix.servo.aws.constants;
17 |
18 | /**
19 | * Constants related to the AWS API, and what the labels they use for Dimensions
20 | * across their services.
21 | *
22 | * http://docs.amazonwebservices.com/AmazonCloudWatch/latest/DeveloperGuide/CW_Support_For_AWS.html
23 | */
24 | public enum Dimensions {
25 | //EC2
26 | AMI_IMAGE_ID("ImageId"),
27 | INSTANCE_ID("InstanceId"),
28 | INSTANCE_TYPE("InstanceType"),
29 | //EBS
30 | VOLUME_ID("VolumeId"),
31 | //RDS
32 | DB_INSTANCE_ID("DBInstanceIdentifier"),
33 | DB_CLASS("DatabaseClass"),
34 | ENGINE_NAME("EngineName"),
35 | //SNS
36 | TOPIC_NAME("TopicName"),
37 | //SQS
38 | QUEUE_NAME("QueueName"),
39 | //ASG Also can filter EC2 metrics
40 | AUTOSCALING_GROUP("AutoScalingGroupName"),
41 | //ELB
42 | LOAD_BALANCER_NAME("LoadBalancerName"),
43 | AVAILABILITY_ZONE("AvailabilityZone");
44 |
45 |
46 | private final String awsString;
47 |
48 | Dimensions(String awsString) {
49 | this.awsString = awsString;
50 | }
51 |
52 | public String getAwsString() {
53 | return awsString;
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/servo-aws/src/main/java/com/netflix/servo/aws/constants/Namespace.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2013 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.netflix.servo.aws.constants;
17 |
18 | /**
19 | * Constants for the namespaces aws publish their metrics to cloudwatch under.
20 | */
21 | public enum Namespace {
22 | AWS_EBS("AWS/EBS"),
23 | AWS_EC2("AWS/EC2"),
24 | AWS_RDS("AWS/RDS"),
25 | AWS_SQS("AWS/SQS"),
26 | AWS_SNS("AWS/SNS"),
27 | AWS_AUTOSCALING("AWS/AutoScaling"),
28 | AWS_ELB("AWS/ELB");
29 |
30 | private final String value;
31 |
32 | Namespace(String value) {
33 | this.value = value;
34 | }
35 |
36 | public String getValue() {
37 | return this.value;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/servo-aws/src/main/java/com/netflix/servo/aws/constants/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2013 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | * Constants related to Amazon Web Services (AWS).
17 | */
18 | /**
19 | * Constants related to Amazon Web Services (AWS).
20 | */
21 | package com.netflix.servo.aws.constants;
22 |
--------------------------------------------------------------------------------
/servo-aws/src/main/java/com/netflix/servo/aws/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2013 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | * Code related to Amazon Web Services (AWS).
17 | */
18 | /**
19 | * Code related to Amazon Web Services (AWS).
20 | */
21 | package com.netflix.servo.aws;
22 |
--------------------------------------------------------------------------------
/servo-aws/src/main/java/com/netflix/servo/publish/cloudwatch/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2013 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | * Publishing Metrics to Amazon CloudWatch.
17 | */
18 | /**
19 | * Publishing Metrics to Amazon CloudWatch.
20 | */
21 | package com.netflix.servo.publish.cloudwatch;
22 |
--------------------------------------------------------------------------------
/servo-aws/src/main/java/com/netflix/servo/tag/aws/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2013 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | * Amazon Web Services (AWS) related tags.
17 | */
18 | /**
19 | * Amazon Web Services (AWS) related tags.
20 | */
21 |
22 | package com.netflix.servo.tag.aws;
23 |
--------------------------------------------------------------------------------
/servo-aws/src/test/java/com/netflix/servo/aws/DataSourceTypeToAwsUnitTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2013 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.netflix.servo.aws;
17 |
18 | import com.netflix.servo.annotations.DataSourceType;
19 | import org.testng.annotations.Test;
20 |
21 | import static org.testng.Assert.assertEquals;
22 |
23 | /**
24 | * DataSourceTypeToAwsUnit tests.
25 | * User: gorzell
26 | * Date: 1/9/12
27 | * Time: 6:44 PM
28 | */
29 | public class DataSourceTypeToAwsUnitTest {
30 |
31 | /**
32 | * GetUnit returns the correct unit.
33 | */
34 | @Test
35 | public void testGetUnit() throws Exception {
36 | String cs = "Count/Second";
37 | String none = "None";
38 |
39 | String val = DataSourceTypeToAwsUnit.getUnit(DataSourceType.COUNTER);
40 | assertEquals(val, cs);
41 |
42 | val = DataSourceTypeToAwsUnit.getUnit(DataSourceType.GAUGE);
43 | assertEquals(val, none);
44 |
45 | val = DataSourceTypeToAwsUnit.getUnit(DataSourceType.INFORMATIONAL);
46 | assertEquals(val, none);
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/servo-core/build.gradle:
--------------------------------------------------------------------------------
1 | pmd {
2 | ignoreFailures = true
3 | }
4 |
5 | jar {
6 | manifest {
7 | attributes(
8 | "Automatic-Module-Name": "com.netflix.servo.core"
9 | )
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/servo-core/src/main/java/com/netflix/servo/BasicMonitorRegistry.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.netflix.servo;
17 |
18 | import com.netflix.servo.monitor.Monitor;
19 | import com.netflix.servo.util.Preconditions;
20 | import com.netflix.servo.util.UnmodifiableList;
21 |
22 | import java.util.Collection;
23 | import java.util.Collections;
24 | import java.util.HashSet;
25 | import java.util.Set;
26 |
27 | /**
28 | * Simple monitor registry backed by a {@link java.util.Set}.
29 | */
30 | public final class BasicMonitorRegistry implements MonitorRegistry {
31 |
32 | private final Set> monitors;
33 |
34 | /**
35 | * Creates a new instance.
36 | */
37 | public BasicMonitorRegistry() {
38 | monitors = Collections.synchronizedSet(new HashSet<>());
39 | }
40 |
41 | /**
42 | * The set of registered Monitor objects.
43 | */
44 | @Override
45 | public Collection> getRegisteredMonitors() {
46 | return UnmodifiableList.copyOf(monitors);
47 | }
48 |
49 | /**
50 | * Register a new monitor in the registry.
51 | */
52 | @Override
53 | public void register(Monitor> monitor) {
54 | Preconditions.checkNotNull(monitor, "monitor");
55 | try {
56 | monitors.add(monitor);
57 | } catch (Exception e) {
58 | throw new IllegalArgumentException("invalid object", e);
59 | }
60 | }
61 |
62 | /**
63 | * Unregister a Monitor from the registry.
64 | */
65 | @Override
66 | public void unregister(Monitor> monitor) {
67 | Preconditions.checkNotNull(monitor, "monitor");
68 | try {
69 | monitors.remove(monitor);
70 | } catch (Exception e) {
71 | throw new IllegalArgumentException("invalid object", e);
72 | }
73 | }
74 |
75 | @Override
76 | public boolean isRegistered(Monitor> monitor) {
77 | return monitors.contains(monitor);
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/servo-core/src/main/java/com/netflix/servo/MonitorRegistry.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2013 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.netflix.servo;
17 |
18 | import com.netflix.servo.monitor.Monitor;
19 |
20 | import java.util.Collection;
21 |
22 | /**
23 | * Registry to keep track of objects with
24 | * {@link com.netflix.servo.annotations.Monitor} annotations.
25 | */
26 | public interface MonitorRegistry {
27 | /**
28 | * The set of registered Monitor objects.
29 | */
30 | Collection> getRegisteredMonitors();
31 |
32 | /**
33 | * Register a new monitor in the registry.
34 | */
35 | void register(Monitor> monitor);
36 |
37 | /**
38 | * Unregister a Monitor from the registry.
39 | */
40 | void unregister(Monitor> monitor);
41 |
42 | /**
43 | * Check whether a monitor has been registerd.
44 | */
45 | boolean isRegistered(Monitor> monitor);
46 | }
47 |
--------------------------------------------------------------------------------
/servo-core/src/main/java/com/netflix/servo/NoopMonitorRegistry.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2020 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.netflix.servo;
17 |
18 | import com.netflix.servo.monitor.Monitor;
19 |
20 | import java.util.Collection;
21 | import java.util.Collections;
22 |
23 | /**
24 | * Monitor registry implementation that does as little as possible.
25 | */
26 | public class NoopMonitorRegistry implements MonitorRegistry {
27 |
28 | /** Create a new instance. */
29 | public NoopMonitorRegistry() {
30 | }
31 |
32 | @Override
33 | public Collection> getRegisteredMonitors() {
34 | return Collections.emptyList();
35 | }
36 |
37 | @Override
38 | public void register(Monitor> monitor) {
39 | }
40 |
41 | @Override
42 | public void unregister(Monitor> monitor) {
43 | }
44 |
45 | @Override
46 | public boolean isRegistered(Monitor> monitor) {
47 | return false;
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/servo-core/src/main/java/com/netflix/servo/annotations/DataSourceLevel.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2013 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.netflix.servo.annotations;
17 |
18 | import com.netflix.servo.tag.Tag;
19 |
20 | /**
21 | * Indicates a level for the monitor. This is meant to be similar to log levels to provide a
22 | * quick way to perform high-level filtering.
23 | */
24 | public enum DataSourceLevel implements Tag {
25 | /**
26 | * Fine granularity monitors that provide a high amount of detail.
27 | */
28 | DEBUG,
29 |
30 | /**
31 | * The default level for monitors.
32 | */
33 | INFO,
34 |
35 | /**
36 | * Most important monitors for an application.
37 | */
38 | CRITICAL;
39 |
40 | /**
41 | * Key name used for the data source level tag.
42 | */
43 | public static final String KEY = "level";
44 |
45 | /**
46 | * {@inheritDoc}
47 | */
48 | public String getKey() {
49 | return KEY;
50 | }
51 |
52 | /**
53 | * {@inheritDoc}
54 | */
55 | public String getValue() {
56 | return name();
57 | }
58 |
59 | /**
60 | * {@inheritDoc}
61 | */
62 | public String tagString() {
63 | return getKey() + "=" + getValue();
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/servo-core/src/main/java/com/netflix/servo/annotations/DataSourceType.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2013 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.netflix.servo.annotations;
17 |
18 | import com.netflix.servo.tag.Tag;
19 |
20 | /**
21 | * Indicates the type of value that is annotated to determine how it will be
22 | * measured.
23 | */
24 | public enum DataSourceType implements Tag {
25 | /**
26 | * A gauge is for numeric values that can be sampled without modification.
27 | * Examples of metrics that should be gauges are things like current
28 | * temperature, number of open connections, disk usage, etc.
29 | */
30 | GAUGE,
31 |
32 | /**
33 | * A counter is for numeric values that get incremented when some event
34 | * occurs. Counters will be sampled and converted into a rate of change
35 | * per second. Counter values should be monotonically increasing, i.e.,
36 | * the value should not decrease.
37 | */
38 | COUNTER,
39 |
40 | /**
41 | * A rate is for numeric values that represent a rate per second.
42 | */
43 | RATE,
44 |
45 | /**
46 | * A normalized rate per second. For counters that report values based on step
47 | * boundaries.
48 | */
49 | NORMALIZED,
50 |
51 | /**
52 | * An informational attribute is for values that might be useful for
53 | * debugging, but will not be collected as metrics for monitoring purposes.
54 | * These values are made available in JMX.
55 | */
56 | INFORMATIONAL;
57 |
58 | /**
59 | * Key name used for the data source type tag, configurable via
60 | * servo.datasourcetype.key system property.
61 | */
62 | public static final String KEY = System.getProperty("servo.datasourcetype.key", "type");
63 |
64 | /**
65 | * {@inheritDoc}
66 | */
67 | public String getKey() {
68 | return KEY;
69 | }
70 |
71 | /**
72 | * {@inheritDoc}
73 | */
74 | public String getValue() {
75 | return name();
76 | }
77 |
78 | /**
79 | * {@inheritDoc}
80 | */
81 | public String tagString() {
82 | return getKey() + "=" + getValue();
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/servo-core/src/main/java/com/netflix/servo/annotations/Monitor.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2013 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.netflix.servo.annotations;
17 |
18 | import java.lang.annotation.Documented;
19 | import java.lang.annotation.ElementType;
20 | import java.lang.annotation.Retention;
21 | import java.lang.annotation.RetentionPolicy;
22 | import java.lang.annotation.Target;
23 |
24 | /**
25 | * Annotation indicating a field or method should be collected for monitoring.
26 | * The attributes annotated should be thread-safe for access by a background
27 | * thread. If a method is annotated it should be inexpensive and avoid any
28 | * potentially costly operations such as IO and networking. Expect that the
29 | * fields will be polled frequently and cache values that require expensive
30 | * computation rather than computing them inline.
31 | */
32 | @Documented
33 | @Retention(RetentionPolicy.RUNTIME)
34 | @Target({ ElementType.FIELD, ElementType.METHOD })
35 | public @interface Monitor {
36 | /**
37 | * Name of the annotated attribute.
38 | */
39 | String name() default "";
40 |
41 | /**
42 | * Type of value that is annotated, for more information see
43 | * {@link DataSourceType}.
44 | */
45 | DataSourceType type() default DataSourceType.INFORMATIONAL;
46 |
47 | /**
48 | * Level of the value that is annotated, for more information see
49 | * {@link DataSourceLevel}.
50 | */
51 | DataSourceLevel level() default DataSourceLevel.INFO;
52 |
53 | /**
54 | * A human readable description of the annotated attribute.
55 | */
56 | String description() default "";
57 | }
58 |
--------------------------------------------------------------------------------
/servo-core/src/main/java/com/netflix/servo/annotations/MonitorTags.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2013 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.netflix.servo.annotations;
17 |
18 | import java.lang.annotation.Documented;
19 | import java.lang.annotation.ElementType;
20 | import java.lang.annotation.Retention;
21 | import java.lang.annotation.RetentionPolicy;
22 | import java.lang.annotation.Target;
23 |
24 | /**
25 | * Tags to associate with all metrics in an instance. The tags will be queried
26 | * when the instance is registered with the {@link
27 | * com.netflix.servo.MonitorRegistry} and used to provide a common base set of
28 | * tags for all attribute annotated with {@link Monitor}. Tags provided on the
29 | * {@link Monitor} annotation will override these tags if there is a common
30 | * key.
31 | */
32 | @Documented
33 | @Retention(RetentionPolicy.RUNTIME)
34 | @Target({ ElementType.FIELD, ElementType.METHOD })
35 | public @interface MonitorTags {
36 | }
37 |
--------------------------------------------------------------------------------
/servo-core/src/main/java/com/netflix/servo/annotations/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2013 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | * Annotations to easily expose metrics from a class.
17 | *
18 | * Annotations to easily expose metrics from a class.
19 | *
20 | * Annotations to easily expose metrics from a class.
21 | */
22 | /**
23 | * Annotations to easily expose metrics from a class.
24 | */
25 | package com.netflix.servo.annotations;
26 |
--------------------------------------------------------------------------------
/servo-core/src/main/java/com/netflix/servo/jmx/DefaultObjectNameMapper.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2014 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.netflix.servo.jmx;
17 |
18 | import com.netflix.servo.monitor.Monitor;
19 |
20 | import javax.management.ObjectName;
21 |
22 | /**
23 | * The default {@link ObjectNameMapper} implementation that
24 | * is used by the {@link JmxMonitorRegistry}. This implementation
25 | * simply appends the monitor's name followed by the tags for the monitor.
26 | */
27 | class DefaultObjectNameMapper implements ObjectNameMapper {
28 |
29 | @Override
30 | public ObjectName createObjectName(String domain, Monitor> monitor) {
31 | ObjectNameBuilder objNameBuilder = ObjectNameBuilder.forDomain(domain);
32 | objNameBuilder.addProperty("name", monitor.getConfig().getName());
33 | objNameBuilder.addProperties(monitor.getConfig().getTags());
34 | return objNameBuilder.build();
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/servo-core/src/main/java/com/netflix/servo/jmx/ObjectNameMapper.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2014 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.netflix.servo.jmx;
17 |
18 | import com.netflix.servo.monitor.Monitor;
19 |
20 | import javax.management.ObjectName;
21 |
22 | /**
23 | * Allows for different implementations when mapping a
24 | * monitor to a JMX {@link ObjectName}. The mapper can be
25 | * can be specified when using the {@link JmxMonitorRegistry}.
26 | * This interface also has a reference to the default mapping implementation.
27 | * Note that an {@link ObjectName}'s properties are meant to be unordered,
28 | * however, some tools such as VisualVM use the order to build a hierarchy
29 | * view where the default implementation may not be desirable.
30 | */
31 | public interface ObjectNameMapper {
32 |
33 | /**
34 | * The default mapping implementation. This implementation simply
35 | * appends the monitor's name followed by all the tags as properties
36 | * of the {@link ObjectName}. The mapper remaps any characters that are
37 | * not alphanumeric, a period, or hypen to an underscore.
38 | */
39 | ObjectNameMapper DEFAULT = new DefaultObjectNameMapper();
40 |
41 | /**
42 | * Given the domain and monitor generates an {@link ObjectName} to use.
43 | *
44 | * @param domain the JMX domain
45 | * @param monitor the monitor
46 | * @return The created ObjectName
47 | */
48 | ObjectName createObjectName(String domain, Monitor> monitor);
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/servo-core/src/main/java/com/netflix/servo/jmx/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2013 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | * Monitor registry and helper classes to expose monitored attributes to
17 | * JMX.
18 | *
19 | * Monitor registry and helper classes to expose monitored attributes to
20 | * JMX.
21 | *
22 | * Monitor registry and helper classes to expose monitored attributes to
23 | * JMX.
24 | */
25 | /**
26 | * Monitor registry and helper classes to expose monitored attributes to
27 | * JMX.
28 | */
29 | package com.netflix.servo.jmx;
30 |
--------------------------------------------------------------------------------
/servo-core/src/main/java/com/netflix/servo/monitor/AbstractMonitor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.netflix.servo.monitor;
17 |
18 | import com.netflix.servo.util.Preconditions;
19 |
20 | /**
21 | * Base type to simplify implementing monitors.
22 | */
23 | public abstract class AbstractMonitor implements Monitor {
24 | protected final MonitorConfig config;
25 |
26 | /**
27 | * Create a new instance with the specified configuration.
28 | */
29 | protected AbstractMonitor(MonitorConfig config) {
30 | this.config = Preconditions.checkNotNull(config, "config");
31 | }
32 |
33 | /**
34 | * {@inheritDoc}
35 | */
36 | @Override
37 | public MonitorConfig getConfig() {
38 | return config;
39 | }
40 |
41 | /**
42 | * {@inheritDoc}
43 | */
44 | @Override
45 | public T getValue() {
46 | return getValue(0);
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/servo-core/src/main/java/com/netflix/servo/monitor/AnnotatedStringMonitor.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2013 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.netflix.servo.monitor;
17 |
18 | import com.netflix.servo.util.Throwables;
19 |
20 | import java.lang.reflect.AccessibleObject;
21 | import java.lang.reflect.Field;
22 | import java.lang.reflect.Method;
23 |
24 | /**
25 | * Wraps an annotated field and exposes it as a monitor object.
26 | */
27 | class AnnotatedStringMonitor extends AbstractMonitor {
28 |
29 | private final Object object;
30 | private final AccessibleObject field;
31 |
32 | AnnotatedStringMonitor(MonitorConfig config, Object object, AccessibleObject field) {
33 | super(config);
34 | this.object = object;
35 | this.field = field;
36 | }
37 |
38 | /**
39 | * {@inheritDoc}
40 | */
41 | @Override
42 | public String getValue(int pollerIndex) {
43 | Object v;
44 | try {
45 | field.setAccessible(true);
46 | if (field instanceof Field) {
47 | v = ((Field) field).get(object);
48 | } else {
49 | v = ((Method) field).invoke(object);
50 | }
51 | } catch (Exception e) {
52 | throw Throwables.propagate(e);
53 | }
54 | return (v == null) ? null : v.toString();
55 | }
56 |
57 | /**
58 | * {@inheritDoc}
59 | */
60 | @Override
61 | public boolean equals(Object obj) {
62 | if (obj == null || !(obj instanceof AnnotatedStringMonitor)) {
63 | return false;
64 | }
65 | AnnotatedStringMonitor m = (AnnotatedStringMonitor) obj;
66 | return config.equals(m.getConfig()) && field.equals(m.field);
67 | }
68 |
69 | /**
70 | * {@inheritDoc}
71 | */
72 | @Override
73 | public int hashCode() {
74 | int result = config.hashCode();
75 | result = 31 * result + field.hashCode();
76 | return result;
77 | }
78 |
79 | @Override
80 | public String toString() {
81 | return "AnnotatedStringMonitor{config=" + config + ", field=" + field + '}';
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/servo-core/src/main/java/com/netflix/servo/monitor/BasicInformational.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2013 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.netflix.servo.monitor;
17 |
18 | import com.netflix.servo.annotations.DataSourceType;
19 |
20 | import java.util.concurrent.atomic.AtomicReference;
21 |
22 | /**
23 | * A simple informational implementation that maintains a string value.
24 | */
25 | public final class BasicInformational extends AbstractMonitor implements Informational {
26 | private final AtomicReference info = new AtomicReference<>();
27 |
28 | /**
29 | * Creates a new instance of the counter.
30 | */
31 | public BasicInformational(MonitorConfig config) {
32 | super(config.withAdditionalTag(DataSourceType.INFORMATIONAL));
33 | }
34 |
35 | /**
36 | * Set the value to show for this monitor.
37 | */
38 | public void setValue(String value) {
39 | info.set(value);
40 | }
41 |
42 | /**
43 | * {@inheritDoc}
44 | */
45 | @Override
46 | public String getValue(int pollerIndex) {
47 | return info.get();
48 | }
49 |
50 | /**
51 | * {@inheritDoc}
52 | */
53 | @Override
54 | public boolean equals(Object o) {
55 | if (this == o) {
56 | return true;
57 | }
58 | if (o == null || !(o instanceof BasicInformational)) {
59 | return false;
60 | }
61 | BasicInformational that = (BasicInformational) o;
62 |
63 | String thisInfo = info.get();
64 | String thatInfo = that.info.get();
65 | return config.equals(that.config)
66 | && (thisInfo == null ? thatInfo == null : thisInfo.equals(thatInfo));
67 | }
68 |
69 | /**
70 | * {@inheritDoc}
71 | */
72 | @Override
73 | public int hashCode() {
74 | int result = config.hashCode();
75 | int infoHashcode = info.get() != null ? info.get().hashCode() : 0;
76 | result = 31 * result + infoHashcode;
77 | return result;
78 | }
79 |
80 | /**
81 | * {@inheritDoc}
82 | */
83 | @Override
84 | public String toString() {
85 | return "BasicInformational{config=" + config + ", info=" + info + '}';
86 | }
87 | }
88 |
--------------------------------------------------------------------------------
/servo-core/src/main/java/com/netflix/servo/monitor/BasicStopwatch.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2013 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.netflix.servo.monitor;
17 |
18 | import java.util.concurrent.TimeUnit;
19 | import java.util.concurrent.atomic.AtomicBoolean;
20 | import java.util.concurrent.atomic.AtomicLong;
21 |
22 | /**
23 | * This class does not enforce starting or stopping once and only once without a reset.
24 | */
25 | public class BasicStopwatch implements Stopwatch {
26 | private final AtomicLong startTime = new AtomicLong(0L);
27 | private final AtomicLong endTime = new AtomicLong(0L);
28 | private final AtomicBoolean running = new AtomicBoolean(false);
29 |
30 | /**
31 | * {@inheritDoc}
32 | */
33 | @Override
34 | public void start() {
35 | startTime.set(System.nanoTime());
36 | running.set(true);
37 | }
38 |
39 | /**
40 | * {@inheritDoc}
41 | */
42 | @Override
43 | public void stop() {
44 | endTime.set(System.nanoTime());
45 | running.set(false);
46 | }
47 |
48 | /**
49 | * {@inheritDoc}
50 | */
51 | @Override
52 | public void reset() {
53 | startTime.set(0L);
54 | endTime.set(0L);
55 | running.set(false);
56 | }
57 |
58 | /**
59 | * {@inheritDoc}
60 | */
61 | @Override
62 | public long getDuration(TimeUnit timeUnit) {
63 | return timeUnit.convert(getDuration(), TimeUnit.NANOSECONDS);
64 | }
65 |
66 | /**
67 | * Returns the duration in nanoseconds. No checks are performed to ensure that the stopwatch
68 | * has been properly started and stopped before executing this method. If called before stop
69 | * it will return the current duration.
70 | */
71 | @Override
72 | public long getDuration() {
73 | final long end = running.get() ? System.nanoTime() : endTime.get();
74 | return end - startTime.get();
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/servo-core/src/main/java/com/netflix/servo/monitor/CompositeMonitor.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2013 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.netflix.servo.monitor;
17 |
18 | import java.util.List;
19 |
20 | /**
21 | * Used as a mixin for monitors that are composed of a number of sub-monitors.
22 | */
23 | public interface CompositeMonitor extends Monitor {
24 | /**
25 | * Returns a list of sub-monitors for this composite.
26 | */
27 | List> getMonitors();
28 | }
29 |
--------------------------------------------------------------------------------
/servo-core/src/main/java/com/netflix/servo/monitor/ContextualCounter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011-2018 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.netflix.servo.monitor;
17 |
18 | import com.google.common.base.Function;
19 | import com.netflix.servo.tag.TaggingContext;
20 |
21 | /**
22 | * Composite that maintains separate simple counters for each distinct set of tags returned by the
23 | * tagging context.
24 | */
25 | public class ContextualCounter extends AbstractContextualMonitor
26 | implements Counter {
27 |
28 | /**
29 | * Create a new instance of the counter.
30 | *
31 | * @param config shared configuration
32 | * @param context provider for context specific tags
33 | * @param newMonitor function to create new counters
34 | */
35 | public ContextualCounter(
36 | MonitorConfig config,
37 | TaggingContext context,
38 | Function newMonitor) {
39 | super(config, context, newMonitor);
40 | }
41 |
42 | /**
43 | * {@inheritDoc}
44 | */
45 | @Override
46 | public void increment() {
47 | getMonitorForCurrentContext().increment();
48 | }
49 |
50 | /**
51 | * {@inheritDoc}
52 | */
53 | @Override
54 | public void increment(long amount) {
55 | getMonitorForCurrentContext().increment(amount);
56 | }
57 |
58 | /**
59 | * {@inheritDoc}
60 | */
61 | @Override
62 | public Number getValue(int pollerIndex) {
63 | return getMonitorForCurrentContext().getValue(pollerIndex);
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/servo-core/src/main/java/com/netflix/servo/monitor/ContextualTimer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011-2018 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.netflix.servo.monitor;
17 |
18 | import com.google.common.base.Function;
19 | import com.netflix.servo.tag.TaggingContext;
20 |
21 | import java.util.concurrent.TimeUnit;
22 |
23 | /**
24 | * Composite that maintains separate simple timers for each distinct set of tags returned by the
25 | * tagging context.
26 | */
27 | public class ContextualTimer extends AbstractContextualMonitor implements Timer {
28 |
29 | /**
30 | * Create a new instance of the timer.
31 | *
32 | * @param config shared configuration
33 | * @param context provider for context specific tags
34 | * @param newMonitor function to create new timers
35 | */
36 | public ContextualTimer(
37 | MonitorConfig config,
38 | TaggingContext context,
39 | Function newMonitor) {
40 | super(config, context, newMonitor);
41 | }
42 |
43 | /**
44 | * {@inheritDoc}
45 | */
46 | @Override
47 | public Stopwatch start() {
48 | Stopwatch s = new TimedStopwatch(getMonitorForCurrentContext());
49 | s.start();
50 | return s;
51 | }
52 |
53 | /**
54 | * {@inheritDoc}
55 | */
56 | @Override
57 | public TimeUnit getTimeUnit() {
58 | return getMonitorForCurrentContext().getTimeUnit();
59 | }
60 |
61 | /**
62 | * {@inheritDoc}
63 | */
64 | @Override
65 | @Deprecated
66 | public void record(long duration) {
67 | Timer monitor = getMonitorForCurrentContext();
68 | monitor.record(duration, monitor.getTimeUnit());
69 | }
70 |
71 | /**
72 | * {@inheritDoc}
73 | */
74 | @Override
75 | public void record(long duration, TimeUnit timeUnit) {
76 | getMonitorForCurrentContext().record(duration, timeUnit);
77 | }
78 |
79 | /**
80 | * {@inheritDoc}
81 | */
82 | @Override
83 | public Long getValue(int pollerIndex) {
84 | return getMonitorForCurrentContext().getValue();
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/servo-core/src/main/java/com/netflix/servo/monitor/Counter.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2013 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.netflix.servo.monitor;
17 |
18 | /**
19 | * Monitor type for tracking how often some event is occurring.
20 | */
21 | public interface Counter extends NumericMonitor {
22 | /**
23 | * Update the count by one.
24 | */
25 | void increment();
26 |
27 | /**
28 | * Update the count by the specified amount.
29 | */
30 | void increment(long amount);
31 | }
32 |
--------------------------------------------------------------------------------
/servo-core/src/main/java/com/netflix/servo/monitor/DefaultPublishingPolicy.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2013 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.netflix.servo.monitor;
17 |
18 | /**
19 | * The default publishing policy. Observers must follow the default behaviour when the
20 | * {@link MonitorConfig} associated with a {@link Monitor} uses this policy.
21 | */
22 | public final class DefaultPublishingPolicy implements PublishingPolicy {
23 | private static final DefaultPublishingPolicy INSTANCE = new DefaultPublishingPolicy();
24 |
25 | private DefaultPublishingPolicy() {
26 | }
27 |
28 | public static DefaultPublishingPolicy getInstance() {
29 | return INSTANCE;
30 | }
31 |
32 | @Override
33 | public String toString() {
34 | return "DefaultPublishingPolicy";
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/servo-core/src/main/java/com/netflix/servo/monitor/Gauge.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2013 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.netflix.servo.monitor;
17 |
18 | /**
19 | * Monitor type that provides the current value, e.g., the percentage of disk space used.
20 | */
21 | public interface Gauge extends NumericMonitor {
22 | }
23 |
--------------------------------------------------------------------------------
/servo-core/src/main/java/com/netflix/servo/monitor/Informational.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2013 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.netflix.servo.monitor;
17 |
18 | /**
19 | * Monitor with a value type of string.
20 | */
21 | public interface Informational extends Monitor {
22 | }
23 |
--------------------------------------------------------------------------------
/servo-core/src/main/java/com/netflix/servo/monitor/Monitor.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2013 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.netflix.servo.monitor;
17 |
18 | /**
19 | * Provides a way to sample a value tied to a particular configuration.
20 | */
21 | public interface Monitor {
22 |
23 | /**
24 | * Returns the current value for the monitor for the default polling interval.
25 | */
26 | T getValue();
27 |
28 | /**
29 | * Returns the current value for the monitor for the nth poller.
30 | */
31 | T getValue(int pollerIndex);
32 |
33 |
34 | /**
35 | * Configuration used to identify a monitor and provide metadata used in aggregations.
36 | */
37 | MonitorConfig getConfig();
38 | }
39 |
--------------------------------------------------------------------------------
/servo-core/src/main/java/com/netflix/servo/monitor/MonitorWrapper.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011-2018 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.netflix.servo.monitor;
17 |
18 | import com.netflix.servo.tag.TagList;
19 |
20 | /**
21 | * Wraps another monitor object providing an alternative configuration.
22 | */
23 | class MonitorWrapper extends AbstractMonitor {
24 |
25 | @SuppressWarnings("unchecked")
26 | static MonitorWrapper create(TagList tags, Monitor monitor) {
27 | if (monitor instanceof NumericMonitor>) {
28 | return (MonitorWrapper) ((monitor instanceof SpectatorMonitor)
29 | ? new SpectatorMonitorWrapper(tags, (NumericMonitor>) monitor)
30 | : new NumericMonitorWrapper(tags, (NumericMonitor>) monitor));
31 | } else {
32 | return new MonitorWrapper<>(tags, monitor);
33 | }
34 | }
35 |
36 | private final Monitor monitor;
37 |
38 | /**
39 | * Creates a new instance of the wrapper.
40 | */
41 | MonitorWrapper(TagList tags, Monitor monitor) {
42 | super(monitor.getConfig().withAdditionalTags(tags));
43 | this.monitor = monitor;
44 | }
45 |
46 | /**
47 | * {@inheritDoc}
48 | */
49 | @Override
50 | public T getValue(int pollerIdx) {
51 | return monitor.getValue();
52 | }
53 |
54 | /**
55 | * {@inheritDoc}
56 | */
57 | @Override
58 | public boolean equals(Object obj) {
59 | if (obj == null || !(obj instanceof MonitorWrapper>)) {
60 | return false;
61 | }
62 | MonitorWrapper m = (MonitorWrapper) obj;
63 | return config.equals(m.getConfig()) && monitor.equals(m.monitor);
64 | }
65 |
66 | /**
67 | * {@inheritDoc}
68 | */
69 | @Override
70 | public int hashCode() {
71 | int result = getConfig().hashCode();
72 | result = 31 * result + monitor.hashCode();
73 | return result;
74 | }
75 |
76 | /**
77 | * {@inheritDoc}
78 | */
79 | @Override
80 | public String toString() {
81 | return "MonitorWrapper{config=" + config + ", monitor=" + monitor + '}';
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/servo-core/src/main/java/com/netflix/servo/monitor/MonitoredThreadPool.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2013 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.netflix.servo.monitor;
17 |
18 | import java.util.concurrent.ThreadPoolExecutor;
19 |
20 | import static com.netflix.servo.annotations.DataSourceType.COUNTER;
21 | import static com.netflix.servo.annotations.DataSourceType.GAUGE;
22 |
23 | /**
24 | * Wraps a thread pool to provide common metrics.
25 | */
26 | class MonitoredThreadPool {
27 |
28 | private final ThreadPoolExecutor pool;
29 |
30 | MonitoredThreadPool(ThreadPoolExecutor pool) {
31 | this.pool = pool;
32 | }
33 |
34 | @com.netflix.servo.annotations.Monitor(name = "activeCount", type = GAUGE)
35 | int getActiveCount() {
36 | return pool.getActiveCount();
37 | }
38 |
39 | @com.netflix.servo.annotations.Monitor(name = "completedTaskCount", type = COUNTER)
40 | long getCompletedTaskCount() {
41 | return pool.getCompletedTaskCount();
42 | }
43 |
44 | @com.netflix.servo.annotations.Monitor(name = "corePoolSize", type = GAUGE)
45 | int getCorePoolSize() {
46 | return pool.getCorePoolSize();
47 | }
48 |
49 | @com.netflix.servo.annotations.Monitor(name = "maximumPoolSize", type = GAUGE)
50 | int getMaximumPoolSize() {
51 | return pool.getMaximumPoolSize();
52 | }
53 |
54 | @com.netflix.servo.annotations.Monitor(name = "poolSize", type = GAUGE)
55 | int getPoolSize() {
56 | return pool.getPoolSize();
57 | }
58 |
59 | @com.netflix.servo.annotations.Monitor(name = "queueSize", type = GAUGE)
60 | int getQueueSize() {
61 | return pool.getQueue().size();
62 | }
63 |
64 | @com.netflix.servo.annotations.Monitor(name = "taskCount", type = COUNTER)
65 | long getTaskCount() {
66 | return pool.getTaskCount();
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/servo-core/src/main/java/com/netflix/servo/monitor/NumericMonitor.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2013 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.netflix.servo.monitor;
17 |
18 | /**
19 | * A monitor type that has a numeric value.
20 | */
21 | public interface NumericMonitor extends Monitor {
22 | }
23 |
--------------------------------------------------------------------------------
/servo-core/src/main/java/com/netflix/servo/monitor/NumericMonitorWrapper.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2013 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.netflix.servo.monitor;
17 |
18 | import com.netflix.servo.tag.TagList;
19 |
20 | /**
21 | * Wraps another monitor object providing an alternative configuration.
22 | */
23 | class NumericMonitorWrapper extends MonitorWrapper
24 | implements NumericMonitor {
25 |
26 | /**
27 | * Creates a new instance of the wrapper.
28 | */
29 | NumericMonitorWrapper(TagList tags, NumericMonitor monitor) {
30 | super(tags, monitor);
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/servo-core/src/main/java/com/netflix/servo/monitor/PublishingPolicy.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2013 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.netflix.servo.monitor;
17 |
18 | /**
19 | * A publishing policy allows us to customize the behavior of different observers.
20 | */
21 | public interface PublishingPolicy {
22 | }
23 |
--------------------------------------------------------------------------------
/servo-core/src/main/java/com/netflix/servo/monitor/ResettableCounter.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2013 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.netflix.servo.monitor;
17 |
18 |
19 | /**
20 | * Counter implementation that keeps track of updates since the last reset.
21 | * This class will be removed in the next release. Use a StepCounter directly
22 | * if you specifically need the functionality previously provided by this class.
23 | *
24 | * @deprecated Use Monitors.newCounter() instead to get a default implementation
25 | */
26 | @Deprecated
27 | public class ResettableCounter extends StepCounter {
28 | /**
29 | * Creates a new instance. Prefer a {@link com.netflix.servo.monitor.StepCounter}
30 | */
31 | public ResettableCounter(MonitorConfig config) {
32 | super(config);
33 | }
34 |
35 | /**
36 | * Creates a new instance configured for a given polling interval. Note that the 'l' parameter
37 | * is ignored. The functionality has been replaced by {@link com.netflix.servo.monitor.Pollers}
38 | * and {@link com.netflix.servo.monitor.StepCounter}.
39 | *
40 | * Prefer a {@link com.netflix.servo.monitor.StepCounter}
41 | */
42 | public ResettableCounter(MonitorConfig config, long l) {
43 | super(config);
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/servo-core/src/main/java/com/netflix/servo/monitor/SpectatorMonitor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011-2018 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.netflix.servo.monitor;
17 |
18 | import com.netflix.servo.tag.TagList;
19 |
20 | /**
21 | * Indicates that the monitor implementation will automatically update the spectator
22 | * registry defined in {@code SpectatorContext}. Other monitors need to get polled and
23 | * update the registry.
24 | */
25 | public interface SpectatorMonitor {
26 |
27 | /**
28 | * Servo registration can add tags based on the context. This method will be called
29 | * during the registration to apply that context to the underlying Spectator ids.
30 | */
31 | void initializeSpectator(TagList tags);
32 | }
33 |
--------------------------------------------------------------------------------
/servo-core/src/main/java/com/netflix/servo/monitor/SpectatorMonitorWrapper.java:
--------------------------------------------------------------------------------
1 | package com.netflix.servo.monitor;
2 |
3 | import com.netflix.servo.tag.TagList;
4 |
5 | class SpectatorMonitorWrapper
6 | extends NumericMonitorWrapper implements SpectatorMonitor {
7 |
8 | SpectatorMonitorWrapper(TagList tags, NumericMonitor monitor) {
9 | super(tags, monitor);
10 | if (monitor instanceof SpectatorMonitor) {
11 | ((SpectatorMonitor) monitor).initializeSpectator(tags);
12 | }
13 | }
14 |
15 | /**
16 | * {@inheritDoc}
17 | */
18 | @Override
19 | public void initializeSpectator(TagList tags) {
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/servo-core/src/main/java/com/netflix/servo/monitor/Stopwatch.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2013 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.netflix.servo.monitor;
17 |
18 | import java.util.concurrent.TimeUnit;
19 |
20 | /**
21 | * Measures the time taken for execution of some code.
22 | */
23 | public interface Stopwatch {
24 |
25 | /**
26 | * Mark the start time.
27 | */
28 | void start();
29 |
30 | /**
31 | * Mark the end time.
32 | */
33 | void stop();
34 |
35 | /**
36 | * Reset the stopwatch so that it can be used again.
37 | */
38 | void reset();
39 |
40 | /**
41 | * Returns the duration in the specified time unit.
42 | */
43 | long getDuration(TimeUnit timeUnit);
44 |
45 | /**
46 | * Returns the duration in nanoseconds.
47 | */
48 | long getDuration();
49 | }
50 |
--------------------------------------------------------------------------------
/servo-core/src/main/java/com/netflix/servo/monitor/TimedStopwatch.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.netflix.servo.monitor;
17 |
18 | import com.netflix.servo.util.Preconditions;
19 |
20 | import java.util.concurrent.TimeUnit;
21 |
22 | /**
23 | * Stopwatch that will also record to a timer.
24 | */
25 | public class TimedStopwatch extends BasicStopwatch {
26 | private final Timer timer;
27 |
28 | /**
29 | * Create a new instance with the specified timer.
30 | */
31 | public TimedStopwatch(Timer timer) {
32 | Preconditions.checkNotNull(timer, "timer");
33 | this.timer = timer;
34 | }
35 |
36 | /**
37 | * {@inheritDoc}
38 | */
39 | @Override
40 | public void stop() {
41 | super.stop();
42 | timer.record(getDuration(), TimeUnit.NANOSECONDS);
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/servo-core/src/main/java/com/netflix/servo/monitor/Timer.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2013 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.netflix.servo.monitor;
17 |
18 | import java.util.concurrent.TimeUnit;
19 |
20 | /**
21 | * Monitor type for tracking how much time something is taking.
22 | */
23 | public interface Timer extends NumericMonitor {
24 |
25 | /**
26 | * Returns a stopwatch that has been started and will automatically
27 | * record its result to this timer when stopped.
28 | */
29 | Stopwatch start();
30 |
31 | /**
32 | * The time unit reported by this timer.
33 | */
34 | TimeUnit getTimeUnit();
35 |
36 | /**
37 | * Record a new value for this timer.
38 | *
39 | * @deprecated Use record(duration, timeUnit). By always providing a timeUnit to record()
40 | * you can have a base time unit of seconds, but
41 | * use recordings with timeunit of milliseconds for example.
42 | */
43 | @Deprecated
44 | void record(long duration);
45 |
46 | /**
47 | * Record a new value that was collected with the given TimeUnit.
48 | */
49 | void record(long duration, TimeUnit timeUnit);
50 | }
51 |
--------------------------------------------------------------------------------
/servo-core/src/main/java/com/netflix/servo/monitor/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2013 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | * Subinterfaces and implementations for {@link com.netflix.servo.monitor.Monitor}.
17 | *
18 | * Subinterfaces and implementations for {@link com.netflix.servo.monitor.Monitor}.
19 | *
20 | * Subinterfaces and implementations for {@link com.netflix.servo.monitor.Monitor}.
21 | */
22 | /**
23 | * Subinterfaces and implementations for {@link com.netflix.servo.monitor.Monitor}.
24 | */
25 | package com.netflix.servo.monitor;
26 |
27 |
--------------------------------------------------------------------------------
/servo-core/src/main/java/com/netflix/servo/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2013 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | * Primary interfaces for metrics.
17 | *
18 | * Primary interfaces for metrics.
19 | *
20 | * Primary interfaces for metrics.
21 | */
22 | /**
23 | * Primary interfaces for metrics.
24 | */
25 | package com.netflix.servo;
26 |
--------------------------------------------------------------------------------
/servo-core/src/main/java/com/netflix/servo/publish/BaseMetricPoller.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.netflix.servo.publish;
17 |
18 | import com.netflix.servo.Metric;
19 | import com.netflix.servo.util.Preconditions;
20 | import org.slf4j.Logger;
21 | import org.slf4j.LoggerFactory;
22 |
23 | import java.util.Collections;
24 | import java.util.List;
25 | import java.util.stream.Collectors;
26 |
27 | /**
28 | * Base class for simple pollers that do not benefit from filtering in advance.
29 | * Sub-classes implement {@link #pollImpl} to return a list and all filtering
30 | * will be taken care of by the provided implementation of {@link #poll}.
31 | */
32 | public abstract class BaseMetricPoller implements MetricPoller {
33 |
34 | protected final Logger logger = LoggerFactory.getLogger(getClass());
35 |
36 | /**
37 | * Return a list of all current metrics for this poller.
38 | */
39 | public abstract List pollImpl(boolean reset);
40 |
41 | /**
42 | * {@inheritDoc}
43 | */
44 | public final List poll(MetricFilter filter) {
45 | return poll(filter, false);
46 | }
47 |
48 | /**
49 | * {@inheritDoc}
50 | */
51 | public final List poll(MetricFilter filter, boolean reset) {
52 | Preconditions.checkNotNull(filter, "filter");
53 | List metrics = pollImpl(reset);
54 | List retained = metrics.stream().filter(m -> filter.matches(m.getConfig()))
55 | .collect(Collectors.toList());
56 | logger.debug("received {} metrics, retained {} metrics", metrics.size(), retained.size());
57 |
58 | return Collections.unmodifiableList(retained);
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/servo-core/src/main/java/com/netflix/servo/publish/BasicMetricFilter.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2013 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.netflix.servo.publish;
17 |
18 | import com.netflix.servo.monitor.MonitorConfig;
19 |
20 | /**
21 | * Filter that always returns true or false.
22 | */
23 | public final class BasicMetricFilter implements MetricFilter {
24 |
25 | /**
26 | * Filter that matches all metrics.
27 | */
28 | public static final MetricFilter MATCH_ALL = new BasicMetricFilter(true);
29 |
30 | /**
31 | * Filter that does not match any metrics.
32 | */
33 | public static final MetricFilter MATCH_NONE = new BasicMetricFilter(false);
34 |
35 | private final boolean match;
36 |
37 | /**
38 | * Creates a new instance with a boolean indicating whether it should
39 | * always match or always fail.
40 | *
41 | * @param match should this filter match?
42 | */
43 | public BasicMetricFilter(boolean match) {
44 | this.match = match;
45 | }
46 |
47 | /**
48 | * {@inheritDoc}
49 | */
50 | public boolean matches(MonitorConfig config) {
51 | return match;
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/servo-core/src/main/java/com/netflix/servo/publish/JmxConnector.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2013 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.netflix.servo.publish;
17 |
18 | import javax.management.MBeanServerConnection;
19 |
20 | /**
21 | * Used to get a connection to a JMX mbean server.
22 | */
23 | public interface JmxConnector {
24 | /**
25 | * Returns a connection to an mbean server that can be used to poll metrics
26 | * from JMX.
27 | */
28 | MBeanServerConnection getConnection();
29 | }
30 |
--------------------------------------------------------------------------------
/servo-core/src/main/java/com/netflix/servo/publish/LocalJmxConnector.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2013 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.netflix.servo.publish;
17 |
18 | import javax.management.MBeanServerConnection;
19 | import java.lang.management.ManagementFactory;
20 |
21 | /**
22 | * Retrieves a connection to the local mbean server running in the same JVM.
23 | */
24 | public final class LocalJmxConnector implements JmxConnector {
25 | /**
26 | * {@inheritDoc}
27 | */
28 | public MBeanServerConnection getConnection() {
29 | return ManagementFactory.getPlatformMBeanServer();
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/servo-core/src/main/java/com/netflix/servo/publish/MemoryMetricObserver.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2013 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.netflix.servo.publish;
17 |
18 | import com.netflix.servo.Metric;
19 |
20 | import java.util.ArrayList;
21 | import java.util.Collections;
22 | import java.util.List;
23 |
24 | /**
25 | * Keeps the last N observations in-memory.
26 | */
27 | public final class MemoryMetricObserver extends BaseMetricObserver {
28 |
29 | private static final int DEFAULT_N = 10;
30 |
31 | private final List[] observations;
32 | private int next;
33 |
34 | /**
35 | * Creates a new instance that keeps 10 copies in memory.
36 | */
37 | public MemoryMetricObserver() {
38 | this("unamed observer", DEFAULT_N);
39 | }
40 |
41 | /**
42 | * Creates a new instance that keeps {@code num} copies in memory.
43 | */
44 | @SuppressWarnings("unchecked")
45 | public MemoryMetricObserver(String name, int num) {
46 | super(name);
47 | observations = (List[]) new List[num];
48 | next = 0;
49 | }
50 |
51 | /**
52 | * {@inheritDoc}
53 | */
54 | public void updateImpl(List metrics) {
55 | observations[next] = metrics;
56 | next = (next + 1) % observations.length;
57 | }
58 |
59 | /**
60 | * Returns the current set of observations.
61 | */
62 | public List> getObservations() {
63 | List> builder = new ArrayList<>();
64 | int pos = next;
65 | for (List ignored : observations) {
66 | if (observations[pos] != null) {
67 | builder.add(observations[pos]);
68 | }
69 | pos = (pos + 1) % observations.length;
70 | }
71 | return Collections.unmodifiableList(builder);
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/servo-core/src/main/java/com/netflix/servo/publish/MetricFilter.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2013 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.netflix.servo.publish;
17 |
18 | import com.netflix.servo.monitor.MonitorConfig;
19 |
20 | /**
21 | * A filter to restrict the set of metrics that are polled.
22 | */
23 | public interface MetricFilter {
24 | /**
25 | * Check if a metric with the provided configuration should be selected and
26 | * sent to observers.
27 | *
28 | * @param config config settings associated with the metric
29 | * @return true if the metric should be selected
30 | */
31 | boolean matches(MonitorConfig config);
32 | }
33 |
--------------------------------------------------------------------------------
/servo-core/src/main/java/com/netflix/servo/publish/MetricObserver.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2013 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.netflix.servo.publish;
17 |
18 | import com.netflix.servo.Metric;
19 |
20 | import java.util.List;
21 |
22 | /**
23 | * Observer that receives updates about metrics.
24 | */
25 | public interface MetricObserver {
26 | /**
27 | * Invoked with the most recent values for a set of metrics.
28 | */
29 | void update(List metrics);
30 |
31 | /**
32 | * Name associated with an observer. Mostly used to make log messages more
33 | * informative.
34 | */
35 | String getName();
36 | }
37 |
--------------------------------------------------------------------------------
/servo-core/src/main/java/com/netflix/servo/publish/MetricPoller.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2013 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.netflix.servo.publish;
17 |
18 | import com.netflix.servo.Metric;
19 |
20 | import java.util.List;
21 |
22 | /**
23 | * A poller that can be used to fetch current values for a list of metrics on
24 | * demand.
25 | */
26 | public interface MetricPoller {
27 | /**
28 | * Fetch the current values for a set of metrics that match the provided
29 | * filter. This method should be cheap, thread-safe, and interruptible so
30 | * that it can be called frequently to collect metrics at a regular
31 | * interval.
32 | *
33 | * @param filter retricts the set of metrics
34 | * @return list of current metric values
35 | */
36 | List poll(MetricFilter filter);
37 |
38 | /**
39 | * Fetch the current values for a set of metrics that match the provided
40 | * filter. This method should be cheap, thread-safe, and interruptible so
41 | * that it can be called frequently to collect metrics at a regular
42 | * interval.
43 | *
44 | * @param filter retricts the set of metrics
45 | * @param reset ignored. This is kept for backwards compatibility only.
46 | * @return list of current metric values
47 | */
48 | List poll(MetricFilter filter, boolean reset);
49 | }
50 |
--------------------------------------------------------------------------------
/servo-core/src/main/java/com/netflix/servo/publish/MetricTransformObserver.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2013 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.netflix.servo.publish;
17 |
18 | import com.google.common.base.Function;
19 | import com.netflix.servo.Metric;
20 |
21 | import java.util.List;
22 | import java.util.stream.Collectors;
23 |
24 | /**
25 | * An observer that will transform the list of metrics using a given function.
26 | */
27 | public class MetricTransformObserver implements MetricObserver {
28 | private final Function transformer;
29 | private final MetricObserver observer;
30 |
31 | /**
32 | * Create a new MetricTransformObserver using the given transfomer function.
33 | *
34 | * @param transformer The function used to transform metrics.
35 | * @param observer The MetricObserver that will receive the transfomed metrics.
36 | */
37 | public MetricTransformObserver(Function transformer, MetricObserver observer) {
38 | this.transformer = transformer;
39 | this.observer = observer;
40 | }
41 |
42 | @Override
43 | public void update(List metrics) {
44 | List transformed = metrics.stream()
45 | .map(transformer::apply).collect(Collectors.toList());
46 | observer.update(transformed);
47 | }
48 |
49 | @Override
50 | public String getName() {
51 | return "MetricTransformObserver";
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/servo-core/src/main/java/com/netflix/servo/publish/PollCallable.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2013 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.netflix.servo.publish;
17 |
18 | import com.netflix.servo.Metric;
19 |
20 | import java.util.List;
21 | import java.util.concurrent.Callable;
22 |
23 | /**
24 | * Callable implementation that invokes the {@link MetricPoller#poll} method.
25 | */
26 | public final class PollCallable implements Callable> {
27 |
28 | private final MetricPoller poller;
29 | private final MetricFilter filter;
30 | private final boolean reset;
31 |
32 | /**
33 | * Creates a new instance.
34 | *
35 | * @param poller poller to invoke
36 | * @param filter filter to pass into the poller
37 | */
38 | public PollCallable(MetricPoller poller, MetricFilter filter) {
39 | this(poller, filter, false);
40 | }
41 |
42 | /**
43 | * Creates a new instance.
44 | *
45 | * @param poller poller to invoke
46 | * @param filter filter to pass into the poller
47 | * @param reset reset flag to pass into the poller
48 | */
49 | public PollCallable(MetricPoller poller, MetricFilter filter, boolean reset) {
50 | this.poller = poller;
51 | this.filter = filter;
52 | this.reset = reset;
53 | }
54 |
55 | /**
56 | * {@inheritDoc}
57 | */
58 | public List call() {
59 | return poller.poll(filter, reset);
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/servo-core/src/main/java/com/netflix/servo/publish/RegexMetricFilter.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2013 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.netflix.servo.publish;
17 |
18 | import com.netflix.servo.monitor.MonitorConfig;
19 | import com.netflix.servo.tag.Tag;
20 | import com.netflix.servo.tag.TagList;
21 |
22 | import java.util.regex.Pattern;
23 |
24 | /**
25 | * Filter that checks if a tag value matches a regular expression.
26 | */
27 | public final class RegexMetricFilter implements MetricFilter {
28 |
29 | private final String tagKey;
30 | private final Pattern pattern;
31 | private final boolean matchIfMissingTag;
32 | private final boolean invert;
33 |
34 | /**
35 | * Creates a new regex filter.
36 | *
37 | * @param tagKey tag to check against the pattern
38 | * @param pattern pattern to check
39 | * @param matchIfMissingTag should metrics without the specified tag match?
40 | * @param invert should the match be inverted?
41 | */
42 | public RegexMetricFilter(
43 | String tagKey,
44 | Pattern pattern,
45 | boolean matchIfMissingTag,
46 | boolean invert) {
47 | this.tagKey = tagKey;
48 | this.pattern = pattern;
49 | this.matchIfMissingTag = matchIfMissingTag;
50 | this.invert = invert;
51 | }
52 |
53 | /**
54 | * {@inheritDoc}
55 | */
56 | public boolean matches(MonitorConfig config) {
57 | String name = config.getName();
58 | TagList tags = config.getTags();
59 | String value;
60 | if (tagKey == null) {
61 | value = name;
62 | } else {
63 | Tag t = tags.getTag(tagKey);
64 | value = (t == null) ? null : t.getValue();
65 | }
66 |
67 | boolean match = matchIfMissingTag;
68 | if (value != null) {
69 | match = pattern.matcher(value).matches();
70 | }
71 | return match ^ invert;
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/servo-core/src/main/java/com/netflix/servo/publish/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2013 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | * Interfaces for collecting metrics and publishing them to observers.
17 | *
18 | * Interfaces for collecting metrics and publishing them to observers.
19 | *
20 | * Interfaces for collecting metrics and publishing them to observers.
21 | */
22 | /**
23 | * Interfaces for collecting metrics and publishing them to observers.
24 | */
25 | package com.netflix.servo.publish;
26 |
--------------------------------------------------------------------------------
/servo-core/src/main/java/com/netflix/servo/tag/InjectableTag.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2013 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.netflix.servo.tag;
17 |
18 | import org.slf4j.LoggerFactory;
19 |
20 | import java.net.InetAddress;
21 | import java.net.UnknownHostException;
22 |
23 | /**
24 | * Group of Tags whose values will be dynamically set at runtime
25 | * based on local calls.
26 | */
27 | public enum InjectableTag implements Tag {
28 | /**
29 | * The current hostname.
30 | */
31 | HOSTNAME("hostname", getHostName()),
32 |
33 | /**
34 | * The ip for localhost.
35 | */
36 | IP("ip", getIp());
37 |
38 | private final String key;
39 | private final String value;
40 |
41 | InjectableTag(String key, String val) {
42 | this.key = key;
43 | this.value = val;
44 | }
45 |
46 | /**
47 | * {@inheritDoc}
48 | */
49 | @Override
50 | public String getKey() {
51 | return key;
52 | }
53 |
54 | /**
55 | * {@inheritDoc}
56 | */
57 | @Override
58 | public String getValue() {
59 | return value;
60 | }
61 |
62 | /**
63 | * {@inheritDoc}
64 | */
65 | @Override
66 | public String tagString() {
67 | return key + "=" + value;
68 | }
69 |
70 | private static String getHostName() {
71 | return (loadAddress() != null) ? loadAddress().getHostName() : "unkownHost";
72 | }
73 |
74 | private static String getIp() {
75 | return (loadAddress() != null) ? loadAddress().getHostAddress() : "unknownHost";
76 | }
77 |
78 | private static InetAddress loadAddress() {
79 | try {
80 | return InetAddress.getLocalHost();
81 | } catch (UnknownHostException e) {
82 | LoggerFactory.getLogger(InjectableTag.class).warn("Unable to load INET info.", e);
83 | return null;
84 | }
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/servo-core/src/main/java/com/netflix/servo/tag/StandardTagKeys.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2013 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.netflix.servo.tag;
17 |
18 | /**
19 | * Standard tag keys that are used within this library.
20 | */
21 | public enum StandardTagKeys {
22 | /**
23 | * Canonical name for the class that is providing the metric.
24 | */
25 | CLASS_NAME("ClassName"),
26 |
27 | /**
28 | * Monitor id if one is provided via the annotation.
29 | */
30 | MONITOR_ID("MonitorId");
31 |
32 | private final String keyName;
33 |
34 | StandardTagKeys(String keyName) {
35 | this.keyName = keyName;
36 | }
37 |
38 | public String getKeyName() {
39 | return keyName;
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/servo-core/src/main/java/com/netflix/servo/tag/Tag.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2013 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.netflix.servo.tag;
17 |
18 | /**
19 | * A key-value pair associated with a metric.
20 | */
21 | public interface Tag {
22 | /**
23 | * Returns the key corresponding to this tag.
24 | */
25 | String getKey();
26 |
27 | /**
28 | * Returns the value corresponding to this tag.
29 | */
30 | String getValue();
31 |
32 | /**
33 | * Returns the string representation of this tag.
34 | */
35 | String tagString();
36 | }
37 |
--------------------------------------------------------------------------------
/servo-core/src/main/java/com/netflix/servo/tag/TagComparator.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2013 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.netflix.servo.tag;
17 |
18 | import java.io.Serializable;
19 | import java.util.Comparator;
20 |
21 | /**
22 | * Comparator for ordering tags based on the key then the value.
23 | */
24 | public class TagComparator implements Comparator, Serializable {
25 | /**
26 | * {@inheritDoc}
27 | */
28 | @Override
29 | public int compare(Tag tag, Tag tag1) {
30 | if (tag.getKey().equals(tag1.getKey())) {
31 | return tag.getValue().compareTo(tag1.getValue());
32 | }
33 |
34 | return tag.getKey().compareTo(tag1.getKey());
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/servo-core/src/main/java/com/netflix/servo/tag/TagList.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2013 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.netflix.servo.tag;
17 |
18 | import java.util.Iterator;
19 | import java.util.Map;
20 |
21 | /**
22 | * Represents a list of tags associated with a metric value.
23 | */
24 | public interface TagList extends Iterable {
25 |
26 | /**
27 | * Returns the tag matching a given key or null if not match is found.
28 | */
29 | Tag getTag(String key);
30 |
31 | /**
32 | * Returns the value matching a given key or null if not match is found.
33 | */
34 | String getValue(String key);
35 |
36 | /**
37 | * Returns true if this list has a tag with the given key.
38 | */
39 | boolean containsKey(String key);
40 |
41 | /**
42 | * Returns true if this list is emtpy.
43 | */
44 | boolean isEmpty();
45 |
46 | /**
47 | * Returns the number of tags in this list.
48 | */
49 | int size();
50 |
51 | /**
52 | * {@inheritDoc}
53 | */
54 | Iterator iterator();
55 |
56 | /**
57 | * Returns a map containing a copy of the tags in this list.
58 | */
59 | Map asMap();
60 | }
61 |
--------------------------------------------------------------------------------
/servo-core/src/main/java/com/netflix/servo/tag/TaggingContext.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2013 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.netflix.servo.tag;
17 |
18 | /**
19 | * Returns the set of tags associated with the current execution context.
20 | * Implementations of this interface are used to provide a common set of tags
21 | * for all contextual monitors in a given execution flow.
22 | */
23 | public interface TaggingContext {
24 | /**
25 | * Returns the tags for the current execution context.
26 | */
27 | TagList getTags();
28 | }
29 |
--------------------------------------------------------------------------------
/servo-core/src/main/java/com/netflix/servo/tag/ThreadLocalTaggingContext.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2013 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.netflix.servo.tag;
17 |
18 | /**
19 | * Keeps track of tags that should be applied to counters incremented in the
20 | * current thread. Can be used to customize the context for code executed in
21 | * a particular thread. For example, on a server with a thread per request the
22 | * context can be set so metrics will be tagged accordingly.
23 | */
24 | public final class ThreadLocalTaggingContext implements TaggingContext {
25 |
26 | private final ThreadLocal context = new ThreadLocal<>();
27 |
28 | private static final ThreadLocalTaggingContext INSTANCE = new ThreadLocalTaggingContext();
29 |
30 | /**
31 | * Get the instance.
32 | */
33 | public static ThreadLocalTaggingContext getInstance() {
34 | return INSTANCE;
35 | }
36 |
37 | private ThreadLocalTaggingContext() {
38 | }
39 |
40 | /**
41 | * Set the tags to be associated with the current thread.
42 | */
43 | public void setTags(TagList tags) {
44 | context.set(tags);
45 | }
46 |
47 | /**
48 | * Get the tags associated with the current thread.
49 | */
50 | @Override
51 | public TagList getTags() {
52 | return context.get();
53 | }
54 |
55 | /**
56 | * Remove the tags associated with the current thread.
57 | */
58 | public void reset() {
59 | context.remove();
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/servo-core/src/main/java/com/netflix/servo/tag/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2013 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | * Code related to Tagging objects with metadata.
17 | *
18 | * Code related to Tagging objects with metadata.
19 | *
20 | * Code related to Tagging objects with metadata.
21 | */
22 | /**
23 | * Code related to Tagging objects with metadata.
24 | */
25 | package com.netflix.servo.tag;
26 |
--------------------------------------------------------------------------------
/servo-core/src/main/java/com/netflix/servo/util/Clock.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2014 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.netflix.servo.util;
17 |
18 | /**
19 | * A wrapper around the system clock to allow custom implementations to be used in unit tests
20 | * where we want to fake or control the clock behavior.
21 | */
22 | public interface Clock {
23 | /**
24 | * A Clock instance that returns the current time in milliseconds since
25 | * the epoch using the system clock.
26 | */
27 | Clock WALL = System::currentTimeMillis;
28 |
29 | /**
30 | * Returns the number of milliseconds since the epoch.
31 | */
32 | long now();
33 | }
34 |
--------------------------------------------------------------------------------
/servo-core/src/main/java/com/netflix/servo/util/ClockWithOffset.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2014 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.netflix.servo.util;
17 |
18 | /**
19 | * A {@link Clock} that provides a way to modify the time returned by
20 | * {@link System#currentTimeMillis()}.
21 | *
22 | * This can be used during application shutdown to force the clock forward and get the
23 | * latest values which normally
24 | * would not be returned until the next step boundary is crossed.
25 | */
26 | public enum ClockWithOffset implements Clock {
27 | /**
28 | * Singleton.
29 | */
30 | INSTANCE;
31 |
32 | private volatile long offset = 0L;
33 |
34 | /**
35 | * Sets the offset for the clock.
36 | *
37 | * @param offset Number of milliseconds to add to the current time.
38 | */
39 | public void setOffset(long offset) {
40 | if (offset >= 0) {
41 | this.offset = offset;
42 | }
43 | }
44 |
45 | /**
46 | * {@inheritDoc}
47 | */
48 | @Override
49 | public long now() {
50 | return offset + System.currentTimeMillis();
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/servo-core/src/main/java/com/netflix/servo/util/Iterables.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.netflix.servo.util;
18 |
19 | import java.util.ArrayList;
20 | import java.util.List;
21 |
22 | /**
23 | * Utility class for dealing with Iterables. For internal use of servo only.
24 | */
25 | public final class Iterables {
26 | private Iterables() {
27 | }
28 |
29 | /**
30 | * Creates a new {@link Iterable} by concatenating two iterables.
31 | */
32 | public static Iterable concat(Iterable a, Iterable b) {
33 | List result = new ArrayList<>();
34 | for (E e : a) {
35 | result.add(e);
36 | }
37 | for (E e : b) {
38 | result.add(e);
39 | }
40 |
41 | return result;
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/servo-core/src/main/java/com/netflix/servo/util/ManualClock.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2013 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.netflix.servo.util;
17 |
18 | import java.util.concurrent.atomic.AtomicLong;
19 |
20 | /**
21 | * Mostly for testing, this clock must be explicitly set to a given value. Defaults to init.
22 | */
23 | public class ManualClock implements Clock {
24 |
25 | private final AtomicLong time;
26 |
27 | /**
28 | * Construct a new clock setting the current time to {@code init}.
29 | *
30 | * @param init Number of milliseconds to use as the initial time.
31 | */
32 | public ManualClock(long init) {
33 | time = new AtomicLong(init);
34 | }
35 |
36 | /**
37 | * Update the current time to {@code t}.
38 | *
39 | * @param t Number of milliseconds to use for the current time.
40 | */
41 | public void set(long t) {
42 | time.set(t);
43 | }
44 |
45 | /**
46 | * {@inheritDoc}
47 | */
48 | public long now() {
49 | return time.get();
50 | }
51 |
52 | /**
53 | * {@inheritDoc}
54 | */
55 | @Override
56 | public boolean equals(Object o) {
57 | if (this == o) {
58 | return true;
59 | }
60 | if (o == null || getClass() != o.getClass()) {
61 | return false;
62 | }
63 |
64 | ManualClock clock = (ManualClock) o;
65 | return now() == clock.now();
66 | }
67 |
68 | /**
69 | * {@inheritDoc}
70 | */
71 | @Override
72 | public int hashCode() {
73 | return Long.valueOf(now()).hashCode();
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/servo-core/src/main/java/com/netflix/servo/util/Objects.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2015 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.netflix.servo.util;
17 |
18 | import java.util.Arrays;
19 |
20 | /**
21 | * Utility methods for dealing with objects.
22 | */
23 | public final class Objects {
24 | /**
25 | * Generates a hash code for a sequence of input values.
26 | *
27 | * @param values the values to be hashed
28 | * @return a hash value of the sequence of input values
29 | */
30 | public static int hash(Object... values) {
31 | return Arrays.hashCode(values);
32 | }
33 |
34 | private Objects() {
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/servo-core/src/main/java/com/netflix/servo/util/Strings.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.netflix.servo.util;
17 |
18 | import java.util.Iterator;
19 |
20 | /**
21 | * Static helpers for {@code String} instances.
22 | */
23 | public final class Strings {
24 | private Strings() {
25 | }
26 |
27 | /**
28 | * Returns true if the given string is null or is the empty string.
29 | */
30 | public static boolean isNullOrEmpty(String string) {
31 | return string == null || string.isEmpty();
32 | }
33 |
34 | /**
35 | * Join the string representation of each part separated by the given separator string.
36 | *
37 | * @param separator Separator string. For example ","
38 | * @param parts An iterator of the parts to join
39 | * @return The string formed by joining each part separated by the given separator.
40 | */
41 | public static String join(String separator, Iterator> parts) {
42 | Preconditions.checkNotNull(separator, "separator");
43 | Preconditions.checkNotNull(parts, "parts");
44 |
45 | StringBuilder builder = new StringBuilder();
46 | if (parts.hasNext()) {
47 | builder.append(parts.next().toString());
48 | while (parts.hasNext()) {
49 | builder.append(separator);
50 | builder.append(parts.next().toString());
51 | }
52 | }
53 | return builder.toString();
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/servo-core/src/main/java/com/netflix/servo/util/ThreadFactories.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.netflix.servo.util;
18 |
19 | import java.util.concurrent.Executors;
20 | import java.util.concurrent.ThreadFactory;
21 | import java.util.concurrent.atomic.AtomicLong;
22 |
23 | /**
24 | * Simple utility class to create thread factories.
25 | */
26 | public final class ThreadFactories {
27 | private ThreadFactories() {
28 | }
29 |
30 | private static final ThreadFactory BACKING_FACTORY = Executors.defaultThreadFactory();
31 |
32 | /**
33 | * Create a new {@link ThreadFactory} that produces daemon threads with a given name format.
34 | *
35 | * @param fmt String format: for example foo-%d
36 | * @return a new {@link ThreadFactory}
37 | */
38 | public static ThreadFactory withName(final String fmt) {
39 | return new ThreadFactory() {
40 | private final AtomicLong count = new AtomicLong(0);
41 |
42 | @Override
43 | public Thread newThread(Runnable r) {
44 | final Thread t = BACKING_FACTORY.newThread(r);
45 | t.setDaemon(true);
46 | t.setName(String.format(fmt, count.getAndIncrement()));
47 | return t;
48 | }
49 | };
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/servo-core/src/main/java/com/netflix/servo/util/Throwables.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.netflix.servo.util;
18 |
19 | /**
20 | * Utility class to deal with exceptions. Intended for internal use of servo only.
21 | */
22 | public final class Throwables {
23 | private Throwables() {
24 | }
25 |
26 | /**
27 | * Propagates {@code throwable} as-is if it is an instance of
28 | * {@link RuntimeException} or {@link Error}, or else as a last resort, wraps
29 | * it in a {@code RuntimeException} then propagates.
30 | */
31 | public static RuntimeException propagate(Throwable throwable) {
32 | final Throwable t = Preconditions.checkNotNull(throwable, "throwable");
33 | if (t instanceof Error) {
34 | throw (Error) t;
35 | }
36 | if (t instanceof RuntimeException) {
37 | throw (RuntimeException) t;
38 | }
39 |
40 | throw new RuntimeException(t);
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/servo-core/src/main/java/com/netflix/servo/util/UnmodifiableSet.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.netflix.servo.util;
18 |
19 | import java.util.Collections;
20 | import java.util.HashSet;
21 | import java.util.Iterator;
22 | import java.util.Set;
23 |
24 | /**
25 | * Utility class to create unmodifiable sets.
26 | */
27 | public final class UnmodifiableSet {
28 | private UnmodifiableSet() {
29 | }
30 |
31 | /**
32 | * Returns an unmodifiable view of the set created from the given elements.
33 | *
34 | * @param elements Array of elements
35 | * @param type of the elements
36 | * @return an unmodifiable view of the set created from the given elements.
37 | */
38 | @SafeVarargs
39 | public static Set of(E... elements) {
40 | Set result = new HashSet<>();
41 | Collections.addAll(result, elements);
42 | return Collections.unmodifiableSet(result);
43 | }
44 |
45 | /**
46 | * Returns an unmodifiable view of the set created from the given elements.
47 | *
48 | * @param elementsIterator iterator to get the elements of the set.
49 | * @param type of the elements
50 | * @return an unmodifiable view of the set created from the given elements.
51 | */
52 | public static Set copyOf(Iterator extends E> elementsIterator) {
53 | Set result = new HashSet<>();
54 | while (elementsIterator.hasNext()) {
55 | result.add(elementsIterator.next());
56 | }
57 | return Collections.unmodifiableSet(result);
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/servo-core/src/main/java/com/netflix/servo/util/VisibleForTesting.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.netflix.servo.util;
18 |
19 | /**
20 | * Annotates a program element that exists, or is more widely visible than
21 | * otherwise necessary, only for use in test code.
22 | */
23 | public @interface VisibleForTesting {
24 | }
25 |
--------------------------------------------------------------------------------
/servo-core/src/test/java/com/netflix/servo/jmx/DefaultObjectNameMapperTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2014 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.netflix.servo.jmx;
17 |
18 | import com.netflix.servo.annotations.DataSourceType;
19 | import com.netflix.servo.monitor.BasicCounter;
20 | import com.netflix.servo.monitor.MonitorConfig;
21 | import org.testng.annotations.Test;
22 |
23 | import javax.management.MalformedObjectNameException;
24 | import javax.management.ObjectName;
25 |
26 | import static org.testng.Assert.assertEquals;
27 |
28 | public class DefaultObjectNameMapperTest {
29 |
30 | private static final ObjectNameMapper DEFAULT_MAPPER = new DefaultObjectNameMapper();
31 | private static final String TEST_DOMAIN = "testDomain";
32 |
33 | @Test
34 | public void testStandardMapping() {
35 | MonitorConfig config = MonitorConfig.builder("testName").withTag("foo", "bar").build();
36 | ObjectName name = DEFAULT_MAPPER.createObjectName(TEST_DOMAIN, new BasicCounter(config));
37 | assertEquals(name.getDomain(), TEST_DOMAIN);
38 | // note that this assumes that DataSourceType.KEY is greater than 'foo'
39 | // for String#compareTo purposes
40 | assertEquals(name.getKeyPropertyListString(),
41 | String.format("name=testName,foo=bar,%s=COUNTER",
42 | DataSourceType.KEY));
43 | }
44 |
45 | @Test
46 | public void testMultipleTags() throws MalformedObjectNameException {
47 | BasicCounter counter = new BasicCounter(
48 | MonitorConfig.builder("testName")
49 | .withTag("bbb", "foo")
50 | .withTag("aaa", "bar")
51 | .withTag("zzz", "test")
52 | .build());
53 | ObjectName name = DEFAULT_MAPPER.createObjectName(TEST_DOMAIN, counter);
54 | assertEquals(name.getDomain(), TEST_DOMAIN);
55 | assertEquals(name.getKeyPropertyListString(),
56 | String.format("name=testName,aaa=bar,bbb=foo,%s=COUNTER,zzz=test",
57 | DataSourceType.KEY));
58 | }
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/servo-core/src/test/java/com/netflix/servo/monitor/AbstractMonitorTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2013 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.netflix.servo.monitor;
17 |
18 | import org.testng.annotations.Test;
19 |
20 | import static org.testng.Assert.assertEquals;
21 | import static org.testng.Assert.assertNotEquals;
22 | import static org.testng.Assert.assertTrue;
23 |
24 | /**
25 | * Common test cases for all monitor implementations.
26 | */
27 | public abstract class AbstractMonitorTest> {
28 |
29 | public abstract T newInstance(String name);
30 |
31 | @Test
32 | public void testEqualsName() throws Exception {
33 | assertEquals(newInstance("1234567890"), newInstance("1234567890"));
34 | }
35 |
36 | @Test
37 | public void testNotEqualsName() throws Exception {
38 | assertNotEquals(newInstance("1234567890"), newInstance("47"));
39 | }
40 |
41 | @Test
42 | public void testHashCodeName() throws Exception {
43 | assertEquals(newInstance("1234567890").hashCode(), newInstance("1234567890").hashCode());
44 | }
45 |
46 | @Test
47 | public void testNotHashCodeName() throws Exception {
48 | assertNotEquals(newInstance("1234567890").hashCode(), newInstance("47").hashCode());
49 | }
50 |
51 | @Test
52 | public void testToStringIncludesName() throws Exception {
53 | assertTrue(newInstance("1234567890").toString().contains("1234567890"));
54 | assertTrue(newInstance("47").toString().contains("47"));
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/servo-core/src/test/java/com/netflix/servo/monitor/AnnotationsTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2013 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.netflix.servo.monitor;
17 |
18 | import com.netflix.servo.util.UnmodifiableList;
19 | import org.testng.annotations.Test;
20 |
21 | import java.util.ArrayList;
22 | import java.util.Collections;
23 | import java.util.List;
24 | import java.util.concurrent.atomic.AtomicLong;
25 | import java.util.stream.Collectors;
26 |
27 | import static com.netflix.servo.annotations.DataSourceType.COUNTER;
28 | import static com.netflix.servo.annotations.DataSourceType.GAUGE;
29 | import static com.netflix.servo.annotations.DataSourceType.INFORMATIONAL;
30 | import static org.testng.Assert.assertEquals;
31 |
32 | public class AnnotationsTest {
33 | static class Metrics {
34 | @com.netflix.servo.annotations.Monitor(type = GAUGE)
35 | private final AtomicLong annoGauge = new AtomicLong(0L);
36 |
37 | @com.netflix.servo.annotations.Monitor(type = COUNTER)
38 | public final AtomicLong annoCounter = new AtomicLong(0L);
39 |
40 | @com.netflix.servo.annotations.Monitor(type = GAUGE)
41 | public final long primitiveGauge = 0L;
42 |
43 | @com.netflix.servo.annotations.Monitor(type = INFORMATIONAL)
44 | private String annoInfo() {
45 | return "foo";
46 | }
47 | }
48 |
49 | @Test
50 | public void testDefaultNames() throws Exception {
51 | Metrics m = new Metrics();
52 | List> monitors = new ArrayList<>();
53 | Monitors.addAnnotatedFields(monitors, null, null, m);
54 |
55 | List expectedNames = UnmodifiableList.of(
56 | "annoCounter", "annoGauge", "annoInfo", "primitiveGauge");
57 | List actualNames = monitors.stream().map(
58 | monitor -> monitor.getConfig().getName()).collect(Collectors.toList());
59 | Collections.sort(actualNames);
60 | assertEquals(actualNames, expectedNames);
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/servo-core/src/test/java/com/netflix/servo/monitor/BasicCounterTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2013 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.netflix.servo.monitor;
17 |
18 | import com.netflix.servo.annotations.DataSourceType;
19 | import com.netflix.servo.tag.Tag;
20 | import org.testng.annotations.Test;
21 |
22 | import static org.testng.Assert.assertEquals;
23 | import static org.testng.Assert.assertNotEquals;
24 |
25 | public class BasicCounterTest extends AbstractMonitorTest {
26 |
27 | public BasicCounter newInstance(String name) {
28 | return new BasicCounter(MonitorConfig.builder(name).build());
29 | }
30 |
31 | @Test
32 | public void testHasCounterTag() throws Exception {
33 | Tag type = newInstance("foo").getConfig().getTags().getTag(DataSourceType.KEY);
34 | assertEquals(type.getValue(), "COUNTER");
35 | }
36 |
37 | @Test
38 | public void testGetValue() throws Exception {
39 | BasicCounter c = newInstance("foo");
40 | assertEquals(c.getValue().longValue(), 0L);
41 | c.increment();
42 | assertEquals(c.getValue().longValue(), 1L);
43 | c.increment(13);
44 | assertEquals(c.getValue().longValue(), 14L);
45 | }
46 |
47 | @Test
48 | public void testEqualsCount() throws Exception {
49 | BasicCounter c1 = newInstance("foo");
50 | BasicCounter c2 = newInstance("foo");
51 | assertEquals(c1, c2);
52 |
53 | c1.increment();
54 | assertNotEquals(c1, c2);
55 | c2.increment();
56 | assertEquals(c1, c2);
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/servo-core/src/test/java/com/netflix/servo/monitor/BasicDistributionSummaryTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2014 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.netflix.servo.monitor;
17 |
18 | import org.testng.annotations.Test;
19 |
20 | import static org.testng.Assert.assertEquals;
21 |
22 | public class BasicDistributionSummaryTest extends AbstractMonitorTest {
23 | public BasicDistributionSummary newInstance(String name) {
24 | return new BasicDistributionSummary(MonitorConfig.builder(name).build());
25 | }
26 |
27 | @Test
28 | public void testGetValue() throws Exception {
29 | BasicDistributionSummary m = newInstance("foo");
30 | // initial values
31 | assertEquals(m.getValue().longValue(), 0L);
32 | assertEquals(m.getCount().longValue(), 0L);
33 | assertEquals(m.getTotalAmount().longValue(), 0L);
34 | assertEquals(m.getMax().longValue(), 0L);
35 | assertEquals(m.getMin().longValue(), 0L);
36 |
37 | m.record(42);
38 | assertEquals(m.getValue().longValue(), 42L);
39 | assertEquals(m.getTotalAmount().longValue(), 42L);
40 | assertEquals(m.getCount().longValue(), 1L);
41 | assertEquals(m.getMax().longValue(), 42L);
42 | assertEquals(m.getMin().longValue(), 42L);
43 |
44 | m.record(21);
45 | assertEquals(m.getValue().longValue(), 31L);
46 | assertEquals(m.getTotalAmount().longValue(), 63L);
47 | assertEquals(m.getCount().longValue(), 2L);
48 | assertEquals(m.getMax().longValue(), 42L);
49 | assertEquals(m.getMin().longValue(), 21L);
50 | }
51 |
52 | @Test
53 | public void testRecord0() throws Exception {
54 | BasicDistributionSummary c = newInstance("foo");
55 | assertEquals(c.getCount().longValue(), 0L);
56 |
57 | c.record(42);
58 | assertEquals(c.getCount().longValue(), 1L);
59 |
60 | // Explicit 0 should be counted
61 | c.record(0);
62 | assertEquals(c.getCount().longValue(), 2L);
63 |
64 | // Negative values should be ignored
65 | c.record(-1);
66 | assertEquals(c.getCount().longValue(), 2L);
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/servo-core/src/test/java/com/netflix/servo/monitor/BasicGaugeTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2013 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.netflix.servo.monitor;
17 |
18 | import org.testng.annotations.Test;
19 |
20 | import java.util.concurrent.Callable;
21 |
22 | import static org.testng.Assert.assertEquals;
23 | import static org.testng.Assert.assertNotEquals;
24 |
25 | public class BasicGaugeTest extends AbstractMonitorTest> {
26 |
27 | private static class TestFunc implements Callable {
28 |
29 | private final long value;
30 |
31 | public TestFunc(long v) {
32 | value = v;
33 | }
34 |
35 | public Long call() {
36 | return value;
37 | }
38 |
39 | @Override
40 | public boolean equals(Object o) {
41 | if (this == o) {
42 | return true;
43 | }
44 | if (o == null || getClass() != o.getClass()) {
45 | return false;
46 | }
47 |
48 | TestFunc testFunc = (TestFunc) o;
49 | return value == testFunc.value;
50 | }
51 |
52 | @Override
53 | public int hashCode() {
54 | return (int) (value ^ (value >>> 32));
55 | }
56 | }
57 |
58 | public BasicGauge newInstance(String name) {
59 | long v = Long.parseLong(name);
60 | return new BasicGauge<>(MonitorConfig.builder(name).build(), new TestFunc(v));
61 | }
62 |
63 | @Test
64 | public void testGetValue() throws Exception {
65 | BasicGauge c = newInstance("42");
66 | assertEquals(c.getValue().longValue(), 42L);
67 | }
68 |
69 | @Test
70 | public void testEqualsCount() throws Exception {
71 | BasicGauge c1 = newInstance("42");
72 | BasicGauge c2 = newInstance("43");
73 | BasicGauge c3 = newInstance("43");
74 | assertNotEquals(c1, c2);
75 | assertEquals(c2, c3);
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/servo-core/src/test/java/com/netflix/servo/monitor/BasicInformationalTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2013 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.netflix.servo.monitor;
17 |
18 | import org.testng.annotations.Test;
19 |
20 | import static org.testng.Assert.assertEquals;
21 | import static org.testng.Assert.assertNotEquals;
22 |
23 | public class BasicInformationalTest extends AbstractMonitorTest {
24 |
25 | public BasicInformational newInstance(String name) {
26 | return new BasicInformational(MonitorConfig.builder(name).build());
27 | }
28 |
29 | @Test
30 | public void testGetValue() throws Exception {
31 | BasicInformational c = newInstance("foo");
32 | assertEquals(c.getValue(), null);
33 | c.setValue("bar");
34 | assertEquals(c.getValue(), "bar");
35 | }
36 |
37 | @Test
38 | public void testEqualsSet() throws Exception {
39 | BasicInformational c1 = newInstance("foo");
40 | BasicInformational c2 = newInstance("foo");
41 | assertEquals(c1, c2);
42 |
43 | c1.setValue("bar");
44 | assertNotEquals(c1, c2);
45 | c2.setValue("bar");
46 | assertEquals(c1, c2);
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/servo-core/src/test/java/com/netflix/servo/monitor/BasicStopwatchTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2013 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.netflix.servo.monitor;
17 |
18 | import org.testng.annotations.BeforeMethod;
19 | import org.testng.annotations.Test;
20 |
21 | import static org.testng.Assert.assertTrue;
22 |
23 | public class BasicStopwatchTest {
24 | private BasicStopwatch testStopwatch;
25 |
26 | @BeforeMethod
27 | public void setupTest() throws Exception {
28 | testStopwatch = new BasicStopwatch();
29 | }
30 |
31 | @Test
32 | public void testReset() throws Exception {
33 | testStopwatch.start();
34 | Thread.sleep(10);
35 | testStopwatch.stop();
36 | assertTrue(testStopwatch.getDuration() > 0);
37 |
38 | testStopwatch.reset();
39 | assertTrue(testStopwatch.getDuration() == 0);
40 | }
41 |
42 | @Test
43 | public void testGetDuration() throws Exception {
44 | testStopwatch.start();
45 | Thread.sleep(10);
46 | testStopwatch.stop();
47 |
48 | assertTrue(testStopwatch.getDuration() > 9000000);
49 | }
50 |
51 | @Test
52 | public void testGetDurationBeforeStop() throws Exception {
53 | testStopwatch.start();
54 | Thread.sleep(10);
55 | assertTrue(testStopwatch.getDuration() > 9000000);
56 | testStopwatch.stop();
57 | assertTrue(testStopwatch.getDuration() > 9000000);
58 | }
59 |
60 | @Test
61 | public void testGetDurationWithUnit() throws Exception {
62 | testStopwatch.start();
63 | Thread.sleep(10);
64 | testStopwatch.stop();
65 |
66 | assertTrue(testStopwatch.getDuration() > 12);
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/servo-core/src/test/java/com/netflix/servo/monitor/ClassWithBadAnnotation.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2013 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.netflix.servo.monitor;
17 |
18 | import java.util.concurrent.atomic.AtomicLong;
19 |
20 | import static com.netflix.servo.annotations.DataSourceType.COUNTER;
21 | import static com.netflix.servo.annotations.DataSourceType.GAUGE;
22 | import static com.netflix.servo.annotations.DataSourceType.INFORMATIONAL;
23 |
24 | public class ClassWithBadAnnotation {
25 |
26 | @com.netflix.servo.annotations.Monitor(name = "badGauge", type = GAUGE)
27 | private final String badGauge = "foo";
28 |
29 | @com.netflix.servo.annotations.Monitor(name = "annoGauge", type = GAUGE)
30 | private final AtomicLong a1 = new AtomicLong(0L);
31 |
32 | @com.netflix.servo.annotations.Monitor(name = "annoCounter", type = COUNTER)
33 | public final AtomicLong a2 = new AtomicLong(0L);
34 |
35 | @com.netflix.servo.annotations.Monitor(name = "annoInfo", type = INFORMATIONAL)
36 | private String getInfo() {
37 | return "foo";
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/servo-core/src/test/java/com/netflix/servo/monitor/ClassWithMonitors.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2013 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.netflix.servo.monitor;
17 |
18 | import java.util.concurrent.atomic.AtomicLong;
19 |
20 | import static com.netflix.servo.annotations.DataSourceType.COUNTER;
21 | import static com.netflix.servo.annotations.DataSourceType.GAUGE;
22 | import static com.netflix.servo.annotations.DataSourceType.INFORMATIONAL;
23 |
24 | public class ClassWithMonitors {
25 |
26 | public final Counter c1 = Monitors.newCounter("publicCounter");
27 | final Counter c2 = Monitors.newCounter("packageCounter");
28 | protected final Counter c3 = Monitors.newCounter("protectedCounter");
29 | private final Counter c4 = Monitors.newCounter("privateCounter");
30 |
31 | @com.netflix.servo.annotations.Monitor(name = "annoGauge", type = GAUGE)
32 | private final AtomicLong a1 = new AtomicLong(0L);
33 |
34 | @com.netflix.servo.annotations.Monitor(name = "annoCounter", type = COUNTER)
35 | public final AtomicLong a2 = new AtomicLong(0L);
36 |
37 | @com.netflix.servo.annotations.Monitor(name = "primitiveGauge", type = GAUGE)
38 | public final long a3 = 0L;
39 |
40 | @com.netflix.servo.annotations.Monitor(name = "annoInfo", type = INFORMATIONAL)
41 | private String getInfo() {
42 | return "foo";
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/servo-core/src/test/java/com/netflix/servo/monitor/DoubleGaugeTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2013 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.netflix.servo.monitor;
17 |
18 | import com.netflix.servo.annotations.DataSourceType;
19 | import org.testng.annotations.Test;
20 |
21 | import static org.testng.Assert.assertEquals;
22 |
23 | public class DoubleGaugeTest extends AbstractMonitorTest {
24 | @Override
25 | public DoubleGauge newInstance(String name) {
26 | return new DoubleGauge(MonitorConfig.builder(name).build());
27 | }
28 |
29 | @Test
30 | public void testSet() throws Exception {
31 | DoubleGauge gauge = newInstance("test");
32 | gauge.set(10.0);
33 | assertEquals(gauge.getValue().doubleValue(), 10.0);
34 | }
35 |
36 | @Test
37 | public void testGetConfig() throws Exception {
38 | DoubleGauge gauge = newInstance("test");
39 | MonitorConfig expectedConfig = MonitorConfig.builder("test")
40 | .withTag(DataSourceType.GAUGE).build();
41 | assertEquals(gauge.getConfig(), expectedConfig);
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/servo-core/src/test/java/com/netflix/servo/monitor/LongGaugeTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2013 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.netflix.servo.monitor;
17 |
18 | import com.netflix.servo.annotations.DataSourceType;
19 | import org.testng.annotations.Test;
20 |
21 | import static org.testng.Assert.assertEquals;
22 |
23 | public class LongGaugeTest extends AbstractMonitorTest {
24 | @Override
25 | public LongGauge newInstance(String name) {
26 | return new LongGauge(MonitorConfig.builder(name).build());
27 | }
28 |
29 | @Test
30 | public void testSet() throws Exception {
31 | LongGauge gauge = newInstance("test");
32 | gauge.set(10L);
33 | assertEquals(gauge.getValue().longValue(), 10L);
34 | }
35 |
36 | @Test
37 | public void testGetValue() throws Exception {
38 | LongGauge gauge = newInstance("test");
39 | assertEquals(gauge.getValue().longValue(), 0L);
40 | gauge.set(10L);
41 | assertEquals(gauge.getValue().longValue(), 10L);
42 | }
43 |
44 | @Test
45 | public void testGetConfig() throws Exception {
46 | LongGauge gauge = newInstance("test");
47 | MonitorConfig expectedConfig = MonitorConfig.builder("test")
48 | .withTag(DataSourceType.GAUGE).build();
49 | assertEquals(gauge.getConfig(), expectedConfig);
50 | }
51 |
52 | }
53 |
--------------------------------------------------------------------------------
/servo-core/src/test/java/com/netflix/servo/monitor/MaxGaugeTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2013 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.netflix.servo.monitor;
17 |
18 | import com.netflix.servo.util.ManualClock;
19 | import org.testng.annotations.Test;
20 |
21 | import static org.testng.Assert.assertEquals;
22 |
23 | public class MaxGaugeTest extends AbstractMonitorTest {
24 |
25 | private final ManualClock clock = new ManualClock(0L);
26 |
27 | @Override
28 | public MaxGauge newInstance(String name) {
29 | return new MaxGauge(MonitorConfig.builder(name).build(), clock);
30 | }
31 |
32 | @Test
33 | public void testUpdate() throws Exception {
34 | clock.set(0L);
35 | MaxGauge maxGauge = newInstance("max1");
36 | maxGauge.update(42L);
37 | assertEquals(maxGauge.getValue().longValue(), 0L);
38 | clock.set(60000L);
39 | assertEquals(maxGauge.getValue().longValue(), 42L);
40 | }
41 |
42 | @Test
43 | public void testUpdate2() throws Exception {
44 | clock.set(0L);
45 | MaxGauge maxGauge = newInstance("max1");
46 | maxGauge.update(42L);
47 | maxGauge.update(420L);
48 | clock.set(60000L);
49 | assertEquals(maxGauge.getValue().longValue(), 420L);
50 | }
51 |
52 | @Test
53 | public void testUpdate3() throws Exception {
54 | clock.set(0L);
55 | MaxGauge maxGauge = newInstance("max1");
56 | maxGauge.update(42L);
57 | maxGauge.update(420L);
58 | maxGauge.update(1L);
59 | clock.set(60000L);
60 | assertEquals(maxGauge.getValue().longValue(), 420L);
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/servo-core/src/test/java/com/netflix/servo/monitor/MinGaugeTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2013 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.netflix.servo.monitor;
17 |
18 | import com.netflix.servo.util.ManualClock;
19 | import org.testng.annotations.Test;
20 |
21 | import static org.testng.Assert.assertEquals;
22 |
23 | public class MinGaugeTest extends AbstractMonitorTest {
24 |
25 | private final ManualClock clock = new ManualClock(0L);
26 |
27 | @Override
28 | public MinGauge newInstance(String name) {
29 | MonitorConfig config = MonitorConfig.builder(name).build();
30 | return new MinGauge(config, clock);
31 | }
32 |
33 | @Test
34 | public void testUpdate() throws Exception {
35 | clock.set(0L);
36 | MinGauge minGauge = newInstance("min1");
37 | minGauge.update(42L);
38 | clock.set(60000L);
39 | assertEquals(minGauge.getValue().longValue(), 42L);
40 | }
41 |
42 | @Test
43 | public void testUpdate2() throws Exception {
44 | clock.set(0L);
45 | MinGauge minGauge = newInstance("min1");
46 | minGauge.update(42L);
47 | minGauge.update(420L);
48 | clock.set(60000L);
49 | assertEquals(minGauge.getValue().longValue(), 42L);
50 | }
51 |
52 | @Test
53 | public void testUpdate3() throws Exception {
54 | clock.set(0L);
55 | MinGauge minGauge = newInstance("min1");
56 | minGauge.update(42L);
57 | minGauge.update(420L);
58 | minGauge.update(1L);
59 | clock.set(60000L);
60 | assertEquals(minGauge.getValue().longValue(), 1L);
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/servo-core/src/test/java/com/netflix/servo/monitor/ParentHasMonitors.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2013 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.netflix.servo.monitor;
17 |
18 | import java.util.concurrent.atomic.AtomicLong;
19 |
20 | import static com.netflix.servo.annotations.DataSourceType.GAUGE;
21 |
22 | public class ParentHasMonitors extends ClassWithMonitors {
23 |
24 | private final Counter c = Monitors.newCounter("myCounter");
25 |
26 | @com.netflix.servo.annotations.Monitor(name = "myGauge", type = GAUGE)
27 | private final AtomicLong a1 = new AtomicLong(0L);
28 | }
29 |
--------------------------------------------------------------------------------
/servo-core/src/test/java/com/netflix/servo/monitor/PollersTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2014 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * 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, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 | package com.netflix.servo.monitor;
17 |
18 | import org.testng.annotations.Test;
19 |
20 | import static org.testng.Assert.assertEquals;
21 |
22 | public class PollersTest {
23 | @Test
24 | public void testParseOneEntry() throws Exception {
25 | long[] expected1 = {1L};
26 | assertEquals(Pollers.parse("1"), expected1);
27 |
28 | long[] expected2 = {42000L};
29 | assertEquals(Pollers.parse("42000"), expected2);
30 | }
31 |
32 | @Test
33 | public void testParseInvalid() throws Exception {
34 | assertEquals(Pollers.parse("0"), Pollers.DEFAULT_PERIODS);
35 | assertEquals(Pollers.parse("-1"), Pollers.DEFAULT_PERIODS);
36 | assertEquals(Pollers.parse("1L"), Pollers.DEFAULT_PERIODS);
37 | assertEquals(Pollers.parse("100,-1"), Pollers.DEFAULT_PERIODS);
38 | assertEquals(Pollers.parse("100,0"), Pollers.DEFAULT_PERIODS);
39 | }
40 |
41 | @Test
42 | public void testParseMultiple() throws Exception {
43 | long[] expected = {60000L, 10000L, 2000L};
44 | assertEquals(Pollers.parse("60000,10000,2000"), expected);
45 | }
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/servo-core/src/test/java/com/netflix/servo/monitor/PublishingPolicyTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2013 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.netflix.servo.monitor;
17 |
18 | import org.testng.annotations.Test;
19 |
20 | import static org.testng.Assert.assertEquals;
21 | import static org.testng.Assert.assertNotEquals;
22 |
23 | public class PublishingPolicyTest extends AbstractMonitorTest {
24 |
25 | public BasicCounter newInstance(String name) {
26 | return new BasicCounter(MonitorConfig.builder(name).build());
27 | }
28 |
29 | @Test
30 | public void testDefaultPolicy() throws Exception {
31 | assertEquals(
32 | newInstance("A").getConfig().getPublishingPolicy(),
33 | DefaultPublishingPolicy.getInstance());
34 | }
35 |
36 | private static class OtherPolicy implements PublishingPolicy {
37 | static final OtherPolicy INSTANCE = new OtherPolicy();
38 | }
39 |
40 | @Test
41 | public void testEqualsPolicy() throws Exception {
42 | BasicCounter other = new BasicCounter(
43 | MonitorConfig.builder("name").withPublishingPolicy(OtherPolicy.INSTANCE).build());
44 | BasicCounter dflt = newInstance("name");
45 |
46 | assertNotEquals(other, dflt);
47 | assertNotEquals(other.hashCode(), dflt.hashCode());
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/servo-core/src/test/java/com/netflix/servo/monitor/StatsMonitorTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011-2018 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.netflix.servo.monitor;
17 |
18 | import com.netflix.servo.stats.StatsConfig;
19 | import com.netflix.servo.util.ManualClock;
20 | import org.testng.annotations.Test;
21 |
22 | import java.util.concurrent.Executors;
23 | import java.util.concurrent.TimeUnit;
24 |
25 | import static org.testng.Assert.assertFalse;
26 | import static org.testng.Assert.assertTrue;
27 |
28 | public class StatsMonitorTest {
29 |
30 | @Test
31 | public void testExpiration() throws Exception {
32 | ManualClock clock = new ManualClock(0);
33 | StatsMonitor monitor = new StatsMonitor(MonitorConfig.builder("m1").build(),
34 | new StatsConfig.Builder().withComputeFrequencyMillis(1).build(),
35 | Executors.newSingleThreadScheduledExecutor(),
36 | "total", false, clock);
37 |
38 | clock.set(TimeUnit.MINUTES.toMillis(20));
39 | monitor.computeStats();
40 | assertTrue(monitor.isExpired());
41 | monitor.record(42);
42 | monitor.computeStats();
43 | assertFalse(monitor.isExpired());
44 | }
45 | }
--------------------------------------------------------------------------------
/servo-core/src/test/java/com/netflix/servo/monitor/SuperClassWithMonitors.java:
--------------------------------------------------------------------------------
1 | package com.netflix.servo.monitor;
2 |
3 |
4 | import com.netflix.servo.annotations.*;
5 | import com.netflix.servo.tag.BasicTagList;
6 | import com.netflix.servo.tag.TagList;
7 |
8 | public class SuperClassWithMonitors {
9 |
10 | @com.netflix.servo.annotations.Monitor
11 | public Integer monitor1;
12 | private Integer monitor2;
13 |
14 | public Integer getMonitor1() {
15 | return monitor1;
16 | }
17 |
18 | public void setMonitor1(Integer monitor1) {
19 | this.monitor1 = monitor1;
20 | }
21 |
22 | @com.netflix.servo.annotations.Monitor
23 | public Integer getMonitor2() {
24 | return monitor2;
25 | }
26 |
27 | public void setMonitor2(Integer monitor2) {
28 | this.monitor2 = monitor2;
29 | }
30 |
31 | public static class ChildClassWithMonitors extends SuperClassWithMonitors {
32 |
33 | @com.netflix.servo.annotations.Monitor
34 | public Integer monitor3;
35 | private Integer monitor4;
36 |
37 | @MonitorTags
38 | private TagList tags;
39 |
40 | public ChildClassWithMonitors() {
41 | this.tags = BasicTagList.of("tag1", "tag2");
42 | }
43 |
44 | public Integer getMonitor3() {
45 | return monitor3;
46 | }
47 |
48 | public void setMonitor3(Integer monitor3) {
49 | this.monitor3 = monitor3;
50 | }
51 |
52 | @com.netflix.servo.annotations.Monitor
53 | public Integer getMonitor4() {
54 | return monitor4;
55 | }
56 |
57 | public void setMonitor4(Integer monitor4) {
58 | this.monitor4 = monitor4;
59 | }
60 |
61 | public TagList getTags() {
62 | return tags;
63 | }
64 |
65 | public void setTags(TagList tags) {
66 | this.tags = tags;
67 | }
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/servo-core/src/test/java/com/netflix/servo/publish/BasicMetricFilterTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2013 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.netflix.servo.publish;
17 |
18 | import com.netflix.servo.Metric;
19 | import com.netflix.servo.tag.SortedTagList;
20 | import com.netflix.servo.util.UnmodifiableList;
21 | import org.testng.annotations.Test;
22 |
23 | import java.util.List;
24 |
25 | import static org.testng.Assert.assertEquals;
26 |
27 | public class BasicMetricFilterTest {
28 |
29 | private List mkList() {
30 | return UnmodifiableList.of(
31 | new Metric("m1", SortedTagList.EMPTY, 0L, 0),
32 | new Metric("m2", SortedTagList.builder().withTag("c", "a.b.c.d.M1").build(), 0L, 0),
33 | new Metric("m3", SortedTagList.builder().withTag("c", "a.b.c.c.M3").build(), 0L, 0),
34 | new Metric("m4", SortedTagList.builder().withTag("c", "a.b.c.d.M4").build(), 0L, 0),
35 | new Metric("m5", SortedTagList.builder().withTag("c", "a.a.a.a.M5").build(), 0L, 0)
36 | );
37 | }
38 |
39 | private MetricPoller newPoller() {
40 | MockMetricPoller poller = new MockMetricPoller();
41 | poller.setMetrics(mkList());
42 | return poller;
43 | }
44 |
45 | @Test
46 | public void testFilterFalse() throws Exception {
47 | MetricPoller poller = newPoller();
48 | assertEquals(poller.poll(new BasicMetricFilter(false)).size(), 0);
49 | }
50 |
51 | @Test
52 | public void testFilterTrue() throws Exception {
53 | MetricPoller poller = newPoller();
54 | assertEquals(poller.poll(new BasicMetricFilter(true)), mkList());
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/servo-core/src/test/java/com/netflix/servo/publish/FailingMetricObserver.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2013 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.netflix.servo.publish;
17 |
18 | import com.netflix.servo.Metric;
19 |
20 | import java.util.List;
21 |
22 | public class FailingMetricObserver implements MetricObserver {
23 |
24 | public FailingMetricObserver() {
25 | }
26 |
27 | public String getName() {
28 | return "die";
29 | }
30 |
31 | public void update(List metrics) {
32 | throw new IllegalArgumentException("die");
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/servo-core/src/test/java/com/netflix/servo/publish/MemoryMetricObserverTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2013 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.netflix.servo.publish;
17 |
18 | import com.netflix.servo.Metric;
19 | import com.netflix.servo.tag.SortedTagList;
20 | import com.netflix.servo.util.UnmodifiableList;
21 | import org.testng.annotations.Test;
22 |
23 | import java.util.List;
24 |
25 | import static org.testng.Assert.assertEquals;
26 |
27 | public class MemoryMetricObserverTest {
28 |
29 | private List mkList(int v) {
30 | return UnmodifiableList.of(new Metric("m", SortedTagList.EMPTY, 0L, v));
31 | }
32 |
33 | @Test
34 | public void testUpdate() throws Exception {
35 | MemoryMetricObserver mmo = new MemoryMetricObserver("test", 2);
36 | mmo.update(mkList(1));
37 | assertEquals(mmo.getObservations(), UnmodifiableList.of(mkList(1)));
38 | }
39 |
40 | @Test
41 | public void testExceedN() throws Exception {
42 | MemoryMetricObserver mmo = new MemoryMetricObserver("test", 2);
43 | mmo.update(mkList(1));
44 | mmo.update(mkList(2));
45 | mmo.update(mkList(3));
46 | assertEquals(mmo.getObservations(),
47 | UnmodifiableList.of(mkList(2), mkList(3)));
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/servo-core/src/test/java/com/netflix/servo/publish/MockMetricPoller.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2013 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.netflix.servo.publish;
17 |
18 | import com.netflix.servo.Metric;
19 | import com.netflix.servo.util.UnmodifiableList;
20 |
21 | import java.util.List;
22 |
23 | public class MockMetricPoller extends BaseMetricPoller {
24 |
25 | private List metrics;
26 | private long delay;
27 | private boolean die;
28 |
29 | public MockMetricPoller() {
30 | metrics = UnmodifiableList.of();
31 | delay = 0L;
32 | }
33 |
34 | public void setMetrics(List metrics) {
35 | this.metrics = UnmodifiableList.copyOf(metrics);
36 | }
37 |
38 | public void setDelay(long delay) {
39 | this.delay = delay;
40 | }
41 |
42 | public void setDie(boolean die) {
43 | this.die = die;
44 | }
45 |
46 | public List pollImpl(boolean reset) {
47 | if (die) {
48 | throw new IllegalStateException("die");
49 | }
50 |
51 | try {
52 | Thread.sleep(delay);
53 | } catch (InterruptedException e) {
54 | System.err.println("Ignoring " + e.getMessage());
55 | }
56 | return metrics;
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/servo-core/src/test/java/com/netflix/servo/publish/PollSchedulerTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2013 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.netflix.servo.publish;
17 |
18 | import org.testng.annotations.Test;
19 |
20 | import java.util.concurrent.Executors;
21 | import java.util.concurrent.ScheduledExecutorService;
22 |
23 | import static org.testng.Assert.assertNotNull;
24 | import static org.testng.Assert.assertTrue;
25 |
26 | public class PollSchedulerTest {
27 | @Test
28 | public void testGetInstance() throws Exception {
29 | PollScheduler p = PollScheduler.getInstance();
30 | assertNotNull(p);
31 | }
32 |
33 | @Test
34 | public void testStartNoArg() throws Exception {
35 | PollScheduler.getInstance().start();
36 | assertTrue(PollScheduler.getInstance().isStarted());
37 | PollScheduler.getInstance().stop();
38 | }
39 |
40 | @Test
41 | public void testStart() throws Exception {
42 | ScheduledExecutorService s = Executors.newScheduledThreadPool(2);
43 |
44 | PollScheduler.getInstance().start(s);
45 | assertTrue(PollScheduler.getInstance().isStarted());
46 |
47 | //PollScheduler.getInstance().addPoller( ,60, TimeUnit.SECONDS);
48 |
49 | PollScheduler.getInstance().stop();
50 | }
51 |
52 | @Test
53 | public void testStop() throws Exception {
54 | ScheduledExecutorService s = Executors.newScheduledThreadPool(2);
55 |
56 | PollScheduler.getInstance().start(s);
57 | assertTrue(PollScheduler.getInstance().isStarted());
58 |
59 | PollScheduler.getInstance().stop();
60 | assertTrue(!PollScheduler.getInstance().isStarted());
61 | assertTrue(s.isShutdown());
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/servo-core/src/test/java/com/netflix/servo/publish/SlowMetricObserver.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2013 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.netflix.servo.publish;
17 |
18 | import com.netflix.servo.Metric;
19 | import org.slf4j.Logger;
20 | import org.slf4j.LoggerFactory;
21 |
22 | import java.util.List;
23 |
24 | public class SlowMetricObserver extends BaseMetricObserver {
25 |
26 | private static final Logger LOGGER =
27 | LoggerFactory.getLogger(SlowMetricObserver.class);
28 |
29 | private final MetricObserver wrappedObserver;
30 |
31 | private final long delay;
32 |
33 | public SlowMetricObserver(MetricObserver observer, long delay) {
34 | super("slow");
35 | this.wrappedObserver = observer;
36 | this.delay = delay;
37 | }
38 |
39 | public void updateImpl(List metrics) {
40 | try {
41 | Thread.sleep(delay);
42 | } catch (InterruptedException e) {
43 | LOGGER.warn("sleep interrupted", e);
44 | }
45 | wrappedObserver.update(metrics);
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/servo-core/src/test/java/com/netflix/servo/tag/BasicTagTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2013 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.netflix.servo.tag;
17 |
18 | import org.testng.annotations.Test;
19 |
20 | import static org.testng.Assert.assertEquals;
21 | import static org.testng.Assert.assertTrue;
22 |
23 | public class BasicTagTest {
24 | private static final String TEST_KEY = "foo";
25 | private static final String TEST_VALUE = "bar";
26 | private final BasicTag testTag = new BasicTag(TEST_KEY, TEST_VALUE);
27 |
28 | @Test
29 | public void testEquals() throws Exception {
30 | BasicTag localTag = new BasicTag(TEST_KEY, TEST_VALUE);
31 | BasicTag notEqualTag = new BasicTag(TEST_KEY, "goo");
32 |
33 | assertTrue(testTag != localTag);
34 | assertTrue(testTag.equals(localTag));
35 | assertTrue(testTag.getKey().equals(TEST_KEY));
36 | assertTrue(testTag.getValue().equals(TEST_VALUE));
37 | assertTrue(!testTag.equals(notEqualTag));
38 | }
39 |
40 | @Test
41 | public void testGetKey() throws Exception {
42 | assertEquals(testTag.getKey(), TEST_KEY);
43 | }
44 |
45 | @Test
46 | public void testGetValue() throws Exception {
47 | assertEquals(testTag.getValue(), TEST_VALUE);
48 | }
49 |
50 | @Test
51 | public void testParseTagValid() throws Exception {
52 | String goodString = "foo=bar";
53 |
54 | Tag t = Tags.parseTag(goodString);
55 | assertTrue(t.equals(testTag));
56 |
57 | }
58 |
59 | @Test(expectedExceptions = IllegalArgumentException.class)
60 | public void testParseTagNoEqSign() throws Exception {
61 | String badString = "foobar";
62 | Tags.parseTag(badString);
63 | }
64 |
65 | @Test(expectedExceptions = IllegalArgumentException.class)
66 | public void testParseTagEmptyValue() throws Exception {
67 | String badString = "foo=";
68 | Tags.parseTag(badString);
69 | }
70 |
71 | @Test(expectedExceptions = IllegalArgumentException.class)
72 | public void testParseTagEmptyKey() throws Exception {
73 | String badString = "=bar";
74 | Tags.parseTag(badString);
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/servo-core/src/test/java/com/netflix/servo/tag/TagComparatorTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2013 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.netflix.servo.tag;
17 |
18 | import org.testng.annotations.BeforeTest;
19 | import org.testng.annotations.Test;
20 |
21 | import static org.testng.Assert.assertTrue;
22 |
23 | public class TagComparatorTest {
24 | private Tag a;
25 | private Tag b;
26 | private Tag aa;
27 | private Tag ab;
28 | private TagComparator comparator;
29 |
30 | @BeforeTest
31 | public void setupTest() throws Exception {
32 | comparator = new TagComparator();
33 | a = new BasicTag("a", "a");
34 | b = new BasicTag("b", "b");
35 | aa = new BasicTag("a", "a");
36 | ab = new BasicTag("a", "b");
37 | }
38 |
39 | @Test
40 | public void testCompareFirstLevel() throws Exception {
41 | assertTrue(comparator.compare(a, b) < 0);
42 | assertTrue(comparator.compare(b, a) > 0);
43 |
44 | }
45 |
46 | @Test
47 | public void testCompareSecondLevel() throws Exception {
48 | assertTrue(comparator.compare(aa, ab) < 0);
49 | assertTrue(comparator.compare(ab, aa) > 0);
50 | }
51 |
52 | @Test
53 | public void testCompareEqual() throws Exception {
54 | assertTrue(comparator.compare(a, aa) == 0);
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/servo-core/src/test/java/com/netflix/servo/util/ExpiringCacheTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2013 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.netflix.servo.util;
17 |
18 | import org.testng.annotations.Test;
19 |
20 | import java.util.function.Function;
21 |
22 | import static org.testng.Assert.assertEquals;
23 |
24 | public class ExpiringCacheTest {
25 | static class CountingFun implements Function {
26 | int numCalled = 0;
27 |
28 | @Override
29 | public Integer apply(String s) {
30 | ++numCalled;
31 | return s.length();
32 | }
33 | }
34 |
35 | @Test
36 | public void testGet() throws Exception {
37 | ManualClock clock = new ManualClock(0L);
38 | CountingFun fun = new CountingFun();
39 | ExpiringCache map = new ExpiringCache<>(100L, fun, 100L, clock);
40 |
41 | Integer three = map.get("foo");
42 | assertEquals(three, Integer.valueOf(3));
43 | Integer threeAgain = map.get("foo");
44 | assertEquals(threeAgain, Integer.valueOf(3));
45 |
46 | assertEquals(fun.numCalled, 1, "Properly caches computations");
47 | clock.set(200L);
48 | Thread.sleep(200L);
49 |
50 | Integer threeOnceMore = map.get("foo");
51 | assertEquals(threeOnceMore, Integer.valueOf(3));
52 | assertEquals(fun.numCalled, 2, "Properly expires unused entries");
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/servo-core/src/test/java/com/netflix/servo/util/StringsTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.netflix.servo.util;
18 |
19 | import org.testng.annotations.Test;
20 |
21 | import java.util.Arrays;
22 | import java.util.Collections;
23 | import java.util.Iterator;
24 | import java.util.NoSuchElementException;
25 |
26 | import static org.testng.Assert.assertEquals;
27 | import static org.testng.Assert.assertFalse;
28 | import static org.testng.Assert.assertTrue;
29 |
30 | public class StringsTest {
31 |
32 | @Test
33 | public void testIsNullOrEmpty() throws Exception {
34 | assertTrue(Strings.isNullOrEmpty(null));
35 | assertTrue(Strings.isNullOrEmpty(""));
36 | assertFalse(Strings.isNullOrEmpty(" "));
37 | assertFalse(Strings.isNullOrEmpty("adsf"));
38 | }
39 |
40 | private static Iterator emptyIterator() {
41 | return new Iterator() {
42 | @Override
43 | public boolean hasNext() {
44 | return false;
45 | }
46 |
47 | @Override
48 | public T next() {
49 | throw new NoSuchElementException();
50 | }
51 |
52 | @Override
53 | public void remove() {
54 | throw new IllegalStateException();
55 | }
56 | };
57 | }
58 |
59 | @Test
60 | public void testJoin() throws Exception {
61 | assertEquals(Strings.join(", ", emptyIterator()), "");
62 | assertEquals(Strings.join(", ", Collections.singletonList(1).iterator()), "1");
63 | assertEquals(Strings.join(", ", Arrays.asList(1, 2).iterator()), "1, 2");
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/servo-core/src/test/resources/log4j.properties:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright 2013 Netflix, Inc.
3 | #
4 | # Licensed under the Apache License, Version 2.0 (the "License");
5 | # you may not use this file except in compliance with the License.
6 | # 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 implied.
13 | # See the License for the specific language governing permissions and
14 | # limitations under the License.
15 | #
16 |
17 | log4j.rootLogger=DEBUG, F
18 |
19 | log4j.appender.F=org.apache.log4j.ConsoleAppender
20 | log4j.appender.F.Target=System.err
21 | log4j.appender.F.layout=org.apache.log4j.PatternLayout
22 | log4j.appender.F.layout.ConversionPattern=%p %t %c - %m%n
23 |
--------------------------------------------------------------------------------
/servo-example/build.gradle:
--------------------------------------------------------------------------------
1 | dependencies {
2 | api project(':servo-core')
3 | api project(':servo-atlas')
4 | api project(':servo-graphite')
5 | }
6 |
7 | task(run, dependsOn: 'classes', type: JavaExec) {
8 | main = 'com.netflix.servo.example.Main'
9 | classpath = sourceSets.main.runtimeClasspath
10 | args = []
11 | systemProperties = [ "servo.pollers": "10000" ]
12 | }
13 |
14 | task(runWithAtlas, dependsOn: 'classes', type: JavaExec) {
15 | main = 'com.netflix.servo.example.Main'
16 | classpath = sourceSets.main.runtimeClasspath
17 | args = []
18 | environment([
19 | 'NETFLIX_CLUSTER': 'localhost-dev'
20 | ])
21 | systemProperties = [
22 | "servo.pollers": "10000",
23 | "servo.example.isAtlasObserverEnabled": "true"
24 | ]
25 | }
26 |
27 | checkstyle {
28 | sourceSets = []
29 | }
30 |
31 | pmd {
32 | ignoreFailures = true
33 | }
34 |
35 | jar {
36 | manifest {
37 | attributes(
38 | "Automatic-Module-Name": "com.netflix.servo.example"
39 | )
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/servo-example/src/main/java/com/netflix/servo/example/BaseHandler.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2013 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.netflix.servo.example;
17 |
18 |
19 | import com.google.common.io.CountingInputStream;
20 | import com.google.common.io.CountingOutputStream;
21 | import com.netflix.servo.monitor.Counter;
22 | import com.netflix.servo.monitor.Monitors;
23 | import com.netflix.servo.monitor.Stopwatch;
24 | import com.netflix.servo.monitor.Timer;
25 | import com.sun.net.httpserver.HttpExchange;
26 | import com.sun.net.httpserver.HttpHandler;
27 |
28 | import java.io.IOException;
29 |
30 | /**
31 | * Abstract base class for handling HTTP requests.
32 | */
33 | public abstract class BaseHandler implements HttpHandler {
34 |
35 | private final Timer latency = Monitors.newTimer("latency");
36 |
37 | private final Counter bytesReceived = Monitors.newCounter("bytesReceived");
38 | private final Counter bytesSent = Monitors.newCounter("bytesSent");
39 |
40 | public void init() {
41 | Monitors.registerObject(this);
42 | }
43 |
44 | @Override
45 | public void handle(HttpExchange exchange) throws IOException {
46 | CountingInputStream input = new CountingInputStream(exchange.getRequestBody());
47 | CountingOutputStream output = new CountingOutputStream(exchange.getResponseBody());
48 | exchange.setStreams(input, output);
49 | Stopwatch stopwatch = latency.start();
50 | try {
51 | handleImpl(exchange);
52 | } finally {
53 | stopwatch.stop();
54 | bytesReceived.increment(input.getCount());
55 | bytesSent.increment(output.getCount());
56 | }
57 | }
58 |
59 | protected abstract void handleImpl(HttpExchange exchange) throws IOException;
60 | }
61 |
--------------------------------------------------------------------------------
/servo-example/src/main/java/com/netflix/servo/example/EchoHandler.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2013 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.netflix.servo.example;
17 |
18 | import com.google.common.io.ByteStreams;
19 | import com.sun.net.httpserver.HttpExchange;
20 |
21 | import java.io.IOException;
22 |
23 | public class EchoHandler extends BaseHandler {
24 |
25 | public EchoHandler() {
26 | super();
27 | init();
28 | }
29 |
30 | @Override
31 | protected void handleImpl(HttpExchange exchange) throws IOException {
32 | exchange.sendResponseHeaders(200, 0);
33 | ByteStreams.copy(exchange.getRequestBody(), exchange.getResponseBody());
34 | exchange.close();
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/servo-example/src/main/java/com/netflix/servo/example/ExitHandler.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2013 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.netflix.servo.example;
17 |
18 | import com.sun.net.httpserver.HttpExchange;
19 |
20 | import java.io.Closeable;
21 | import java.io.IOException;
22 |
23 | public class ExitHandler extends BaseHandler {
24 |
25 | private final Closeable server;
26 |
27 | public ExitHandler(Closeable server) {
28 | super();
29 | this.server = server;
30 | init();
31 | }
32 |
33 | @Override
34 | protected void handleImpl(HttpExchange exchange) throws IOException {
35 | try {
36 | exchange.sendResponseHeaders(200, 0);
37 | exchange.close();
38 | } finally {
39 | server.close();
40 | }
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/servo-graphite/build.gradle:
--------------------------------------------------------------------------------
1 | dependencies {
2 | api project(':servo-core')
3 | }
4 |
5 | pmd {
6 | ignoreFailures = true
7 | }
8 |
9 | jar {
10 | manifest {
11 | attributes(
12 | "Automatic-Module-Name": "com.netflix.servo.graphite"
13 | )
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/servo-graphite/src/main/java/com/netflix/servo/publish/graphite/GraphiteNamingConvention.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2013 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.netflix.servo.publish.graphite;
17 |
18 | import com.netflix.servo.Metric;
19 |
20 | /**
21 | * We want to allow the user to override the default graphite naming convention to massage the
22 | * objects into the right shape for their graphite setup. Naming conventions could also be applied
23 | * to other observers such as the file observer in the future.
24 | */
25 | public interface GraphiteNamingConvention {
26 | /**
27 | * Get a name from a {@link Metric}.
28 | */
29 | String getName(Metric metric);
30 | }
31 |
--------------------------------------------------------------------------------
/servo-tomcat/build.gradle:
--------------------------------------------------------------------------------
1 | dependencies {
2 | api project(':servo-core')
3 | }
4 |
5 | pmd {
6 | ignoreFailures = true
7 | }
8 |
9 | jar {
10 | manifest {
11 | attributes(
12 | "Automatic-Module-Name": "com.netflix.servo.tomcat"
13 | )
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2012. Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * 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 implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | include 'servo-core','servo-apache','servo-aws','servo-graphite','servo-example',
18 | 'servo-tomcat', 'servo-atlas'
19 |
--------------------------------------------------------------------------------