-
Notifications
You must be signed in to change notification settings - Fork 74
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 #744 from jotak/merge-dropwizard
[HWKMETRICS-585] Merge dropwizard reporter in metrics
- Loading branch information
Showing
25 changed files
with
3,065 additions
and
0 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
36 changes: 36 additions & 0 deletions
36
clients/common/src/main/java/org/hawkular/metrics/client/common/HawkularClientConfig.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,36 @@ | ||
/* | ||
* Copyright 2014-2017 Red Hat, Inc. and/or its affiliates | ||
* and other contributors as indicated by the @author tags. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.hawkular.metrics.client.common; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* @author Joel Takvorian | ||
*/ | ||
public interface HawkularClientConfig { | ||
String getTenant(); | ||
String getUri(); | ||
String getBearerToken(); | ||
String getPrefix(); | ||
Map<String, String> getHeaders(); | ||
Map<String, String> getGlobalTags(); | ||
Map<String, Map<String, String>> getPerMetricTags(); | ||
String getUsername(); | ||
String getPassword(); | ||
Long getFailoverCacheDuration(); | ||
Integer getFailoverCacheMaxSize(); | ||
} |
32 changes: 32 additions & 0 deletions
32
clients/common/src/main/java/org/hawkular/metrics/client/common/http/HawkularHttpClient.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,32 @@ | ||
/* | ||
* Copyright 2014-2017 Red Hat, Inc. and/or its affiliates | ||
* and other contributors as indicated by the @author tags. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.hawkular.metrics.client.common.http; | ||
|
||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
/** | ||
* Http client interface for Hawkular, in case someone would like to use other than the default one | ||
* @author Joel Takvorian | ||
*/ | ||
public interface HawkularHttpClient { | ||
void addHeaders(Map<String, String> headers); | ||
HawkularHttpResponse postMetrics(String jsonBody); | ||
HawkularHttpResponse putTags(String type, String metricName, String jsonBody); | ||
void setFailoverOptions(Optional<Long> failoverCacheDuration, Optional<Integer> failoverCacheMaxSize); | ||
void manageFailover(); | ||
} |
52 changes: 52 additions & 0 deletions
52
...ts/common/src/main/java/org/hawkular/metrics/client/common/http/HawkularHttpResponse.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,52 @@ | ||
/* | ||
* Copyright 2014-2017 Red Hat, Inc. and/or its affiliates | ||
* and other contributors as indicated by the @author tags. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.hawkular.metrics.client.common.http; | ||
|
||
/** | ||
* Minimalist and API-agnostic response wrapper | ||
* @author Joel Takvorian | ||
*/ | ||
public class HawkularHttpResponse { | ||
|
||
private final String content; | ||
private final int responseCode; | ||
private final String errorMsg; | ||
|
||
public HawkularHttpResponse(String content, int responseCode) { | ||
this.content = content; | ||
this.responseCode = responseCode; | ||
this.errorMsg = null; | ||
} | ||
|
||
public HawkularHttpResponse(String content, int responseCode, String errorMsg) { | ||
this.content = content; | ||
this.responseCode = responseCode; | ||
this.errorMsg = errorMsg; | ||
} | ||
|
||
public int getResponseCode() { | ||
return responseCode; | ||
} | ||
|
||
public String getErrorMsg() { | ||
return errorMsg; | ||
} | ||
|
||
public String getContent() { | ||
return content; | ||
} | ||
} |
86 changes: 86 additions & 0 deletions
86
clients/common/src/main/java/org/hawkular/metrics/client/common/http/HawkularJson.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,86 @@ | ||
/* | ||
* Copyright 2014-2017 Red Hat, Inc. and/or its affiliates | ||
* and other contributors as indicated by the @author tags. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.hawkular.metrics.client.common.http; | ||
|
||
import java.util.Map; | ||
import java.util.function.BiFunction; | ||
|
||
import javax.json.Json; | ||
import javax.json.JsonArray; | ||
import javax.json.JsonArrayBuilder; | ||
import javax.json.JsonObject; | ||
import javax.json.JsonObjectBuilder; | ||
|
||
/** | ||
* Some Json utility for Hawkular data model | ||
* @author Joel Takvorian | ||
*/ | ||
public final class HawkularJson { | ||
|
||
private HawkularJson() { | ||
} | ||
|
||
public static String metricsToString(Long timestamp, | ||
Map<String, Long> counters, | ||
Map<String, Double> gauges) { | ||
JsonObjectBuilder builder = Json.createObjectBuilder(); | ||
if (!counters.isEmpty()) { | ||
builder.add("counters", metricsJson(timestamp, counters, HawkularJson::longDataPoint)); | ||
} | ||
if (!gauges.isEmpty()) { | ||
builder.add("gauges", metricsJson(timestamp, gauges, HawkularJson::doubleDataPoint)); | ||
} | ||
return builder.build().toString(); | ||
} | ||
|
||
public static String tagsToString(Map<String, String> tags) { | ||
JsonObjectBuilder jsonObjectBuilder = Json.createObjectBuilder(); | ||
tags.forEach(jsonObjectBuilder::add); | ||
return jsonObjectBuilder.build().toString(); | ||
} | ||
|
||
private static <T> JsonArray metricsJson(Long timestamp, | ||
Map<String, T> metricsPoints, | ||
BiFunction<Long, T, JsonObject> bf) { | ||
final JsonArrayBuilder builder = Json.createArrayBuilder(); | ||
metricsPoints.entrySet().stream() | ||
.map(e -> metricJson(e.getKey(), bf.apply(timestamp, e.getValue()))) | ||
.forEach(builder::add); | ||
return builder.build(); | ||
} | ||
|
||
private static JsonObject metricJson(String name, JsonObject dataPoint) { | ||
return Json.createObjectBuilder() | ||
.add("id", name) | ||
.add("dataPoints", Json.createArrayBuilder().add(dataPoint).build()) | ||
.build(); | ||
} | ||
|
||
private static JsonObject doubleDataPoint(long timestamp, double value) { | ||
return Json.createObjectBuilder() | ||
.add("timestamp", timestamp) | ||
.add("value", value) | ||
.build(); | ||
} | ||
|
||
private static JsonObject longDataPoint(long timestamp, long value) { | ||
return Json.createObjectBuilder() | ||
.add("timestamp", timestamp) | ||
.add("value", value) | ||
.build(); | ||
} | ||
} |
Oops, something went wrong.