Skip to content

Commit

Permalink
apache status url and change version
Browse files Browse the repository at this point in the history
  • Loading branch information
antobaldu committed Aug 14, 2020
1 parent 4d01ba1 commit 13cc135
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 60 deletions.
24 changes: 0 additions & 24 deletions .github/workflows/maven-publish-central.yml.old

This file was deleted.

4 changes: 4 additions & 0 deletions .github/workflows/maven-publish-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ jobs:
server-id: github # Value of the distributionManagement/repository/id field of the pom.xml
settings-path: ${{ github.workspace }} # location for the settings.xml file

- if: github.event.release
name: Update version in pom.xml (Release only)
run: mvn -B versions:set -DnewVersion=${{ github.event.release.tag_name }} -DgenerateBackupPoms=false

- name: Build with Maven
run: mvn -B package --file pom.xml

Expand Down
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,20 @@ It can be importer in your Maven project with

```
<dependency>
<groupId>ch.postfinance.prometheus</groupId>
<artifactId>apache-exporter</artifactId>
<version>v1.0.0</version>
<groupId>com.github.postfinance.prometheus</groupId>
<artifactId>apache-exporter</artifactId>
<version>0.0.0-SNAPSHOT</version>
</dependency>
```

The Apache ModStatus URL where the metrics are read, can be configured with

* A System Property: httpdModStatusUrl
* An Environment Property: HTTPD_MOD_STATUS_URL

The default value is http://localhost/server-status?auto

To obtain the metrics, use the method:


Expand Down
31 changes: 0 additions & 31 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,40 +66,9 @@
</execution>
</executions>
</plugin>
<!--plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
<configuration>
<gpgArguments>
<arg>-pinentry-mode</arg>
<arg>loopback</arg>
</gpgArguments>
</configuration>
</plugin-->
</plugins>
</build>

<!--distributionManagement>
<snapshotRepository>
<id>ossrh</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
<repository>
<id>ossrh</id>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2</url>
</repository>
</distributionManagement!-->

<distributionManagement>
<repository>
<id>github</id>
Expand Down
16 changes: 15 additions & 1 deletion src/main/java/ch/postfinance/prometheus/ApacheExporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ private void mapStatusToMetrics(String statusData) {

String readApacheStatus() throws IOException, InterruptedException {
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("http://localhost/server-status?auto"))
.uri(URI.create(getStatusUrl()))
.timeout(Duration.ofSeconds(5))
.GET()
.build();
Expand Down Expand Up @@ -204,4 +204,18 @@ static String mapToState(int scoreValue) {
return "unknown";
}

static String getStatusUrl(){

String statusUrl = System.getProperty("httpdModStatusUrl");

if(statusUrl == null || statusUrl.trim().isEmpty()) {
statusUrl = System.getenv("HTTPD_MOD_STATUS_URL");

if(statusUrl == null || statusUrl.trim().isEmpty())
statusUrl = "http://localhost/server-status?auto";
}

return statusUrl;
}

}
14 changes: 13 additions & 1 deletion src/test/java/ch/postfinance/prometheus/ApacheExporterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,24 @@ public class ApacheExporterTest {
public void export() {
ApacheExporter exporter = new ApacheExporter();
try {
for (int i = 0; i < 2; i++) {
for (int i = 0; i < 5; i++) {
System.out.println(exporter.export());
Thread.sleep(1000);
}
} catch (IOException | InterruptedException e) {
fail(e.getMessage());
}
}

@Test
public void testProperty(){

assertEquals(ApacheExporter.getStatusUrl(), "http://localhost/server-status?auto");

System.setProperty("httpdModStatusUrl", "http://e1-xxx-alsu001/server-status?auto");

assertEquals(ApacheExporter.getStatusUrl(), "http://e1-xxx-alsu001/server-status?auto");


}
}

0 comments on commit 13cc135

Please sign in to comment.