Created
January 16, 2020 12:08
-
-
Save dlopes7/eeadb82c7adeada50050a2cdcfc1ed34 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import com.squareup.okhttp.OkHttpClient; | |
import com.squareup.okhttp.Request; | |
import com.squareup.okhttp.Response; | |
import java.io.IOException; | |
public class Parser { | |
public static void main(String[] args) { | |
String url_v2 = "http://186.10.95.96/api/v2/metrics/series/builtin:synthetic.browser.event.failure?from=now-1d/d&to=now/d"; | |
parse(url_v2); | |
String url_v1 = "http://186.10.95.96/api/v1/timeseries/com.dynatrace.builtin:synthetic.httpmonitor.availability.percent?customTime=yesterday"; | |
parse(url_v1); | |
} | |
public static void parse(String url){ | |
try { | |
String response = makeRequest(url); | |
String[] lines = response.split(System.getProperty("line.separator")); | |
for (String line: lines) { | |
String[] fields = line.split(","); | |
String metric = fields[0]; | |
String dimension = fields[1]; | |
String timestamp = fields[2]; | |
Float value = null; | |
if (fields.length == 4) { | |
value = Float.valueOf(fields[3]); | |
} | |
System.out.println(String.format("URL=%s, Metric=%s, Dimension=%s, Timestamp=%s, Value=%f", url, metric, dimension, timestamp, value)); | |
} | |
}catch (IOException ex) { | |
System.err.println("Error making request: " + ex.getMessage()); | |
} | |
} | |
public static String makeRequest(String url) throws IOException { | |
OkHttpClient client = new OkHttpClient(); | |
Request request = new Request.Builder() | |
.url(url) | |
.build(); | |
Response response = client.newCall(request).execute(); | |
return response.body().string(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment