-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from philterd/4-philter-metrics
Adding metrics from Phileas
- Loading branch information
Showing
8 changed files
with
489 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<artifactId>philter</artifactId> | ||
<groupId>ai.philterd</groupId> | ||
<version>2.6.0-SNAPSHOT</version> | ||
</parent> | ||
<artifactId>philter-configuration</artifactId> | ||
<name>philter-configuration</name> | ||
<dependencies> | ||
<dependency> | ||
<groupId>ai.philterd</groupId> | ||
<artifactId>phileas-model</artifactId> | ||
<version>${phileas.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.commons</groupId> | ||
<artifactId>commons-lang3</artifactId> | ||
<version>${commons.lang3.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<scope>test</scope> | ||
<version>${junit.version}</version> | ||
</dependency> | ||
</dependencies> | ||
</project> |
114 changes: 114 additions & 0 deletions
114
philter-configuration/src/main/java/ai/philterd/philter/PhilterConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
package ai.philterd.philter; | ||
|
||
import java.io.FileReader; | ||
import java.io.IOException; | ||
import java.util.Properties; | ||
import org.apache.commons.lang3.StringUtils; | ||
|
||
public class PhilterConfiguration { | ||
|
||
private final Properties properties; | ||
private final String applicationName; | ||
|
||
public PhilterConfiguration(String propertyFileName, String applicationName) throws IOException { | ||
FileReader fileReader = new FileReader(propertyFileName); | ||
this.properties = new Properties(); | ||
this.properties.load(fileReader); | ||
this.applicationName = applicationName; | ||
} | ||
|
||
public PhilterConfiguration(Properties properties, String applicationName) throws IOException { | ||
this.properties = properties; | ||
this.applicationName = applicationName; | ||
} | ||
|
||
// Metrics | ||
|
||
public String metricsPrefix() { | ||
return getProperty("metrics.prefix", applicationName); | ||
} | ||
|
||
// See: https://github.com/micrometer-metrics/micrometer/blob/master/implementations/micrometer-registry-prometheus/src/main/java/io/micrometer/prometheus/PrometheusConfig.java | ||
// The step size to use in computing windowed statistics like max. The default is 1 minute. | ||
// To get the most out of these statistics, align the step interval to be close to your scrape interval. | ||
public int metricsStep() { | ||
return Integer.parseInt(getProperty("metrics.step", "60")); | ||
} | ||
|
||
public boolean metricsJmxEnabled() { | ||
return Boolean.parseBoolean(getProperty("metrics.jmx.enabled", "false")); | ||
} | ||
|
||
public boolean metricsPrometheusEnabled() { | ||
return Boolean.parseBoolean(getProperty("metrics.prometheus.enabled", "false")); | ||
} | ||
|
||
public int metricsPrometheusPort() { | ||
return Integer.parseInt(getProperty("metrics.prometheus.port", "9100")); | ||
} | ||
|
||
public String metricsPrometheusContext() { | ||
return getProperty("metrics.prometheus.context", "metrics"); | ||
} | ||
|
||
public boolean metricsDataDogEnabled() { | ||
return Boolean.parseBoolean(getProperty("metrics.datadog.enabled", "false")); | ||
} | ||
|
||
public String metricsDataDogApiKey() { | ||
return getProperty("metrics.datadog.apikey", "metrics"); | ||
} | ||
|
||
public boolean metricsCloudWatchEnabled() { | ||
return Boolean.parseBoolean(getProperty("metrics.cloudwatch.enabled", "false")); | ||
} | ||
|
||
public String metricsCloudWatchRegion() { | ||
return String.valueOf(getProperty("metrics.cloudwatch.region", "us-east-1")); | ||
} | ||
|
||
public String metricsCloudWatchNamespace() { | ||
return String.valueOf(getProperty("metrics.cloudwatch.namespace", applicationName)); | ||
} | ||
|
||
public String metricsHostname() { | ||
return String.valueOf(getProperty("metrics.hostname", "")); | ||
} | ||
|
||
private String getProperty(final String property, final String defaultValue) { | ||
|
||
final String environmentVariableValue = getEnvironmentVariable(property); | ||
|
||
if(!StringUtils.isEmpty(environmentVariableValue)) { | ||
return environmentVariableValue; | ||
} | ||
|
||
final String systemPropertyValue = getSystemProperty(property); | ||
|
||
if(!StringUtils.isEmpty(systemPropertyValue)) { | ||
return systemPropertyValue; | ||
} | ||
|
||
final String propertyFileValue = getFileProperty(property); | ||
|
||
if(!StringUtils.isEmpty(propertyFileValue)) { | ||
return propertyFileValue; | ||
} | ||
|
||
return defaultValue; | ||
|
||
} | ||
|
||
private String getEnvironmentVariable(final String environmentVariable) { | ||
return System.getenv(environmentVariable); | ||
} | ||
|
||
private String getSystemProperty(final String property) { | ||
return System.getProperty(property); | ||
} | ||
|
||
private String getFileProperty(final String property) { | ||
return properties.getProperty(property); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<artifactId>philter</artifactId> | ||
<groupId>ai.philterd</groupId> | ||
<version>2.6.0-SNAPSHOT</version> | ||
</parent> | ||
<artifactId>philter-metrics</artifactId> | ||
<name>philter-metrics</name> | ||
<dependencies> | ||
<dependency> | ||
<groupId>ai.philterd</groupId> | ||
<artifactId>philter-configuration</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.micrometer</groupId> | ||
<artifactId>micrometer-registry-jmx</artifactId> | ||
<version>${micrometer.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.micrometer</groupId> | ||
<artifactId>micrometer-registry-prometheus</artifactId> | ||
<version>${dropwizard-metrics-prometheus.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.micrometer</groupId> | ||
<artifactId>micrometer-registry-datadog</artifactId> | ||
<version>${micrometer.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.micrometer</groupId> | ||
<artifactId>micrometer-registry-cloudwatch</artifactId> | ||
<version>${dropwizard-metrics-cloudwatch.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.micrometer</groupId> | ||
<artifactId>micrometer-core</artifactId> | ||
<version>${micrometer.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<scope>test</scope> | ||
<version>${junit.version}</version> | ||
</dependency> | ||
</dependencies> | ||
</project> |
Oops, something went wrong.