From fdf660909bccdd4a2f781e66709d25d94797b208 Mon Sep 17 00:00:00 2001 From: Ace Eldeib Date: Wed, 5 Sep 2018 14:59:47 -0700 Subject: [PATCH 1/7] Add Log Analytics readme + example --- loganalytics/data-plane/README.md | 102 ++++++++++++++++++++++++++++++ loganalytics/data-plane/pom.xml | 3 + 2 files changed, 105 insertions(+) create mode 100644 loganalytics/data-plane/README.md diff --git a/loganalytics/data-plane/README.md b/loganalytics/data-plane/README.md new file mode 100644 index 000000000000..ca4c90320b6d --- /dev/null +++ b/loganalytics/data-plane/README.md @@ -0,0 +1,102 @@ +# Azure Log Analytics + +This project provides client tools or utilities in Java that make it easy to query data in [Azure Log Analytics](https://azure.microsoft.com/en-us/services/log-analytics/). For reference documentation on classes and models, please see the [Azure SDK for Java reference](https://docs.microsoft.com/en-us/java/api/overview/azure/?view=azure-java-stable). + +Azure Log Analytics provides agents for telemtry collection and enables deep analytics via a [rich query language](https://docs.loganalytics.io/index). This SDK provides query access to data already stored in Log Analytics. To start collecting data from different sources, take a look at these [quickstarts](https://docs.microsoft.com/en-us/azure/log-analytics/log-analytics-quick-collect-azurevm). + +## Example + +```java +import java.util.List; +import java.util.stream.Collectors; +import com.microsoft.azure.AzureEnvironment; +import com.microsoft.azure.loganalytics.implementation.LogAnalyticsDataClientImpl; +import com.microsoft.azure.loganalytics.models.QueryBody; +import com.microsoft.azure.loganalytics.models.QueryResults; +import com.microsoft.azure.credentials.ApplicationTokenCredentials; + +/** + * Basic query example + * + */ +public class LogAnalyticsClientExample +{ + public static void main( String[] args ) + { + // ApplicationTokenCredentials work well for service principal authentication + ApplicationTokenCredentials credentials = new ApplicationTokenCredentials( + "", + "", + "", + AzureEnvironment.AZURE + ); + + // New up client. Accepts credentials, or a pre-authenticated restClient + LogAnalyticsDataClientImpl client = new LogAnalyticsDataClientImpl(credentials); + + // Prepare information for query + String query = "Heartbeat | take 1"; + String workspaceId = ""; + + // Execute! + QueryResults queryResults = client.query(workspaceId, new QueryBody().withQuery(query)); + + // Process and print results + List row = queryResults.tables().get(0).rows().get(0); + List columnNames = queryResults + .tables() + .get(0) + .columns() + .stream() + .map(elt -> elt.name()) + .collect(Collectors.toList()); + + for (int i = 0; i < row.size(); i++){ + System.out.println("The value of " + columnNames.get(i) + " is " + row.get(i)); + } + + return; + } +} +``` + +## Download + +### Latest stable release + +To get the binaries of the official Microsoft Azure Log Analytics SDK as distributed by Microsoft, reade for use within your project, you can use Maven. + +```xml + + com.microsoft.azure + azure-loganalytics + LATEST + +``` + +## Prerequisites + +- A Java Developer Kit (JDK), v 1.7 or later +- Maven + +## Help and Issues + +If you encounter any bugs with these SDKs, please file issues via [Issues](https://github.com/Azure/azure-sdk-for-java/issues) or checkout [StackOverflow for Azure Java SDK](http://stackoverflow.com/questions/tagged/azure-java-sdk). + +## Contribute Code + +If you would like to become an active contributor to this project please follow the instructions provided in [Microsoft Azure Projects Contribution Guidelines](http://azure.github.io/guidelines.html). + +1. Fork it +2. Create your feature branch (`git checkout -b my-new-feature`) +3. Commit your changes (`git commit -am 'Add some feature'`) +4. Push to the branch (`git push origin my-new-feature`) +5. Create new Pull Request + +## More information +- [Azure Java SDKs](https://docs.microsoft.com/java/azure/) +- If you don't have a Microsoft Azure subscription you can get a FREE trial account [here](http://go.microsoft.com/fwlink/?LinkId=330212) + +--- + +This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments. \ No newline at end of file diff --git a/loganalytics/data-plane/pom.xml b/loganalytics/data-plane/pom.xml index ee3869964c3d..3fe837bf0d16 100644 --- a/loganalytics/data-plane/pom.xml +++ b/loganalytics/data-plane/pom.xml @@ -141,6 +141,9 @@ **/*Tests.java **/*TestCase.java + + **/LogAnalyticsDataClientTests.java + ${testMode} From a2e86926577fd8829dd2fd0ff72a7ab59ba8e68e Mon Sep 17 00:00:00 2001 From: Ace Eldeib Date: Wed, 5 Sep 2018 15:58:12 -0700 Subject: [PATCH 2/7] Add App Insights readme, minor fixes --- applicationinsights/data-plane/README.md | 129 ++++++++++++++++++ applicationinsights/data-plane/pom.xml | 3 + .../ApplicationInsightsDataClientTests.java | 7 - loganalytics/data-plane/README.md | 2 +- 4 files changed, 133 insertions(+), 8 deletions(-) create mode 100644 applicationinsights/data-plane/README.md diff --git a/applicationinsights/data-plane/README.md b/applicationinsights/data-plane/README.md new file mode 100644 index 000000000000..4b772ae44ba2 --- /dev/null +++ b/applicationinsights/data-plane/README.md @@ -0,0 +1,129 @@ +# Azure Application Insights + +This project provides client tools or utilities in Java that make it easy to query data in [Azure Application Insights](https://azure.microsoft.com/en-us/services/application-insights/). For reference documentation on classes and models, please see the [Azure SDK for Java reference](https://docs.microsoft.com/en-us/java/api/overview/azure/?view=azure-java-stable). + +Azure Application Insights provides SDKs for telemtry collection and enables deep analytics via a [rich query language](https://docs.loganalytics.io/index). This SDK provides query access to data already stored in Application Insights. To start monitoring a Java application, take a look at the [quickstart](https://docs.microsoft.com/en-us/azure/application-insights/app-insights-java-quick-start). + +## Example + +```java +package com.demo.app; + +import java.util.ArrayList; +import java.util.List; +import com.microsoft.azure.AzureEnvironment; +import com.microsoft.azure.applicationinsights.query.implementation.ApplicationInsightsDataClientImpl; +import com.microsoft.azure.applicationinsights.query.models.QueryBody; +import com.microsoft.azure.applicationinsights.query.models.MetricId; +import com.microsoft.azure.applicationinsights.query.models.MetricsResult; +import com.microsoft.azure.applicationinsights.query.models.MetricsResultsItem; +import com.microsoft.azure.applicationinsights.query.models.MetricsPostBodySchema; +import com.microsoft.azure.applicationinsights.query.models.MetricsPostBodySchemaParameters; +import com.microsoft.azure.applicationinsights.query.models.EventType; +import com.microsoft.azure.applicationinsights.query.models.EventsResult; +import com.microsoft.azure.applicationinsights.query.models.EventsResults; +import com.microsoft.azure.applicationinsights.query.models.QueryResults; +import com.microsoft.azure.credentials.ApplicationTokenCredentials; + +/** + * Basic query example + * + */ +public class ApplicationInsightsClientExample +{ + public static void main( String[] args ) + { + // ApplicationTokenCredentials work well for service principal authentication + ApplicationTokenCredentials credentials = new ApplicationTokenCredentials( + "", + "", + "", + AzureEnvironment.AZURE + ); + + // New up client. Accepts credentials, or a pre-authenticated restClient + ApplicationInsightsDataClientImpl client = new ApplicationInsightsDataClientImpl(credentials); + + // Prepare information for query + String query = "availabilityResults | take 1"; + String appId = ""; + String eventId = ""; + + // POST parameters for multiple metrics + List parameters = new ArrayList(); + parameters.add(new MetricsPostBodySchema().withId("1").withParameters(new MetricsPostBodySchemaParameters().withMetricId(MetricId.AVAILABILITY_RESULTSAVAILABILITY_PERCENTAGE))); + parameters.add(new MetricsPostBodySchema().withId("2").withParameters(new MetricsPostBodySchemaParameters().withMetricId(MetricId.AVAILABILITY_RESULTSDURATION))); + + // Execute log query + QueryResults queryResults = client.querys().execute(appId, new QueryBody().withQuery(query)); + + // Metrics + MetricsResult metricResultSingle = client.metrics().get(appId, MetricId.AVAILABILITY_RESULTSAVAILABILITY_PERCENTAGE); + List metricResultMultiple = client.metrics().getMultiple(appId, parameters); + Object metadata = client.metrics().getMetadata(appId); + + // Events + EventsResults eventsResultByType = client.events().getByType(appId, EventType.AVAILABILITY_RESULTS); + EventsResults eventsResult = client.events().get(appId, EventType.AVAILABILITY_RESULTS, eventId); + + // Process and print query results results + List row = queryResults.tables().get(0).rows().get(0); + List columnNames = queryResults + .tables() + .get(0) + .columns() + .stream() + .map(elt -> elt.name()) + .collect(Collectors.toList()); + + for (int i = 0; i < row.size(); i++){ + System.out.println("The value of " + columnNames.get(i) + " is " + row.get(i)); + } + + System.out.println(metricResultMultiple..value().additionalProperties()); + + } +} + +``` + +## Download + +### Latest release + +To get the binaries of the official Microsoft Azure Log Analytics SDK as distributed by Microsoft, reade for use within your project, you can use Maven. + +```xml + + com.microsoft.azure + azure-applicationinsights-query + LATEST + +``` + +## Prerequisites + +- A Java Developer Kit (JDK), v 1.7 or later +- Maven + +## Help and Issues + +If you encounter any bugs with these SDKs, please file issues via [Issues](https://github.com/Azure/azure-sdk-for-java/issues) or checkout [StackOverflow for Azure Java SDK](http://stackoverflow.com/questions/tagged/azure-java-sdk). + +## Contribute Code + +If you would like to become an active contributor to this project please follow the instructions provided in [Microsoft Azure Projects Contribution Guidelines](http://azure.github.io/guidelines.html). + +1. Fork it +2. Create your feature branch (`git checkout -b my-new-feature`) +3. Commit your changes (`git commit -am 'Add some feature'`) +4. Push to the branch (`git push origin my-new-feature`) +5. Create new Pull Request + +## More information +- [Azure Java SDKs](https://docs.microsoft.com/java/azure/) +- If you don't have a Microsoft Azure subscription you can get a FREE trial account [here](http://go.microsoft.com/fwlink/?LinkId=330212) + +--- + +This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments. \ No newline at end of file diff --git a/applicationinsights/data-plane/pom.xml b/applicationinsights/data-plane/pom.xml index 08e1408d7e8d..897a0ab3cd61 100644 --- a/applicationinsights/data-plane/pom.xml +++ b/applicationinsights/data-plane/pom.xml @@ -141,6 +141,9 @@ **/*Tests.java **/*TestCase.java + + **/ApplicationInsightsDataClientTests.java + ${testMode} diff --git a/applicationinsights/data-plane/src/test/java/com/microsoft/azure/applicationinsights/query/ApplicationInsightsDataClientTests.java b/applicationinsights/data-plane/src/test/java/com/microsoft/azure/applicationinsights/query/ApplicationInsightsDataClientTests.java index bc6cedbce349..ec098ef5b516 100644 --- a/applicationinsights/data-plane/src/test/java/com/microsoft/azure/applicationinsights/query/ApplicationInsightsDataClientTests.java +++ b/applicationinsights/data-plane/src/test/java/com/microsoft/azure/applicationinsights/query/ApplicationInsightsDataClientTests.java @@ -100,11 +100,4 @@ public void canGetEvent() { EventsResults eventsResult = applicationInsightsClient.events().get(appId, EventType.AVAILABILITY_RESULTS, eventId); Assert.assertNotNull(eventsResult.value().get(0).id()); } - - @Test - public void canGetEventsOdataMetadata() { - Object metadata = applicationInsightsClient.events().getOdataMetadata(appId); - // Sanity check - Assert.assertNotNull(metadata); - } } \ No newline at end of file diff --git a/loganalytics/data-plane/README.md b/loganalytics/data-plane/README.md index ca4c90320b6d..9629bccafd00 100644 --- a/loganalytics/data-plane/README.md +++ b/loganalytics/data-plane/README.md @@ -62,7 +62,7 @@ public class LogAnalyticsClientExample ## Download -### Latest stable release +### Latest release To get the binaries of the official Microsoft Azure Log Analytics SDK as distributed by Microsoft, reade for use within your project, you can use Maven. From 653498d5850e5ea051567aa414a2330a1c262b2a Mon Sep 17 00:00:00 2001 From: Ace Eldeib Date: Mon, 10 Sep 2018 12:50:09 -0700 Subject: [PATCH 3/7] working on tests --- applicationinsights/data-plane/pom.xml | 21 ++++++++++++++++--- .../ApplicationInsightsDataClientTests.java | 4 ++-- loganalytics/data-plane/pom.xml | 18 ++++++++++++++++ 3 files changed, 38 insertions(+), 5 deletions(-) diff --git a/applicationinsights/data-plane/pom.xml b/applicationinsights/data-plane/pom.xml index 897a0ab3cd61..ab91c8f8fa3d 100644 --- a/applicationinsights/data-plane/pom.xml +++ b/applicationinsights/data-plane/pom.xml @@ -76,6 +76,24 @@ + + org.codehaus.mojo + properties-maven-plugin + 1.0.0 + + + generate-resources + + write-project-properties + + + + ${project.build.outputDirectory}/maven.properties + + + + + org.apache.maven.plugins maven-jar-plugin @@ -141,9 +159,6 @@ **/*Tests.java **/*TestCase.java - - **/ApplicationInsightsDataClientTests.java - ${testMode} diff --git a/applicationinsights/data-plane/src/test/java/com/microsoft/azure/applicationinsights/query/ApplicationInsightsDataClientTests.java b/applicationinsights/data-plane/src/test/java/com/microsoft/azure/applicationinsights/query/ApplicationInsightsDataClientTests.java index ec098ef5b516..037e31c90b2c 100644 --- a/applicationinsights/data-plane/src/test/java/com/microsoft/azure/applicationinsights/query/ApplicationInsightsDataClientTests.java +++ b/applicationinsights/data-plane/src/test/java/com/microsoft/azure/applicationinsights/query/ApplicationInsightsDataClientTests.java @@ -58,6 +58,8 @@ public void canQuery() { public void canGetMetric() { MetricsResult metricResult = applicationInsightsClient.metrics().get(appId, MetricId.AVAILABILITY_RESULTSAVAILABILITY_PERCENTAGE); // Validate properties + Assert.assertNotNull(metricResult.value().additionalProperties()); + System.out.println(metricResult.value().additionalProperties().keySet()); Assert.assertNotNull(metricResult.value().start()); Assert.assertTrue(metricResult.value().start() instanceof DateTime); } @@ -89,8 +91,6 @@ public void canGetMetricsMetadata() { @Test public void canGetEventsByType() { EventsResults eventsResult = applicationInsightsClient.events().getByType(appId, EventType.AVAILABILITY_RESULTS); - System.out.println(eventsResult.value().get(0)); - System.out.println(eventsResult.value().get(0).id()); Assert.assertNotNull(eventsResult.value().get(0).id()); } diff --git a/loganalytics/data-plane/pom.xml b/loganalytics/data-plane/pom.xml index 3fe837bf0d16..6e5cba4acf80 100644 --- a/loganalytics/data-plane/pom.xml +++ b/loganalytics/data-plane/pom.xml @@ -76,6 +76,24 @@ + + org.codehaus.mojo + properties-maven-plugin + 1.0.0 + + + generate-resources + + write-project-properties + + + + ${project.build.outputDirectory}/maven.properties + + + + + org.apache.maven.plugins maven-jar-plugin From 882796de4c88c397f6482cc89b1ae53a33572d1c Mon Sep 17 00:00:00 2001 From: Ace Eldeib Date: Mon, 10 Sep 2018 12:57:16 -0700 Subject: [PATCH 4/7] update test location + readme --- applicationinsights/data-plane/README.md | 83 +------------------ .../query/samples/BasicSample.java | 77 +++++++++++++++++ loganalytics/data-plane/README.md | 59 +------------ .../loganalytics/samples/BasicSample.java | 52 ++++++++++++ 4 files changed, 135 insertions(+), 136 deletions(-) create mode 100644 applicationinsights/data-plane/src/main/java/com/microsoft/azure/applicationinsights/query/samples/BasicSample.java create mode 100644 loganalytics/data-plane/src/main/java/com/microsoft/azure/loganalytics/samples/BasicSample.java diff --git a/applicationinsights/data-plane/README.md b/applicationinsights/data-plane/README.md index 4b772ae44ba2..97c72bef41e0 100644 --- a/applicationinsights/data-plane/README.md +++ b/applicationinsights/data-plane/README.md @@ -4,88 +4,9 @@ This project provides client tools or utilities in Java that make it easy to que Azure Application Insights provides SDKs for telemtry collection and enables deep analytics via a [rich query language](https://docs.loganalytics.io/index). This SDK provides query access to data already stored in Application Insights. To start monitoring a Java application, take a look at the [quickstart](https://docs.microsoft.com/en-us/azure/application-insights/app-insights-java-quick-start). -## Example - -```java -package com.demo.app; - -import java.util.ArrayList; -import java.util.List; -import com.microsoft.azure.AzureEnvironment; -import com.microsoft.azure.applicationinsights.query.implementation.ApplicationInsightsDataClientImpl; -import com.microsoft.azure.applicationinsights.query.models.QueryBody; -import com.microsoft.azure.applicationinsights.query.models.MetricId; -import com.microsoft.azure.applicationinsights.query.models.MetricsResult; -import com.microsoft.azure.applicationinsights.query.models.MetricsResultsItem; -import com.microsoft.azure.applicationinsights.query.models.MetricsPostBodySchema; -import com.microsoft.azure.applicationinsights.query.models.MetricsPostBodySchemaParameters; -import com.microsoft.azure.applicationinsights.query.models.EventType; -import com.microsoft.azure.applicationinsights.query.models.EventsResult; -import com.microsoft.azure.applicationinsights.query.models.EventsResults; -import com.microsoft.azure.applicationinsights.query.models.QueryResults; -import com.microsoft.azure.credentials.ApplicationTokenCredentials; - -/** - * Basic query example - * - */ -public class ApplicationInsightsClientExample -{ - public static void main( String[] args ) - { - // ApplicationTokenCredentials work well for service principal authentication - ApplicationTokenCredentials credentials = new ApplicationTokenCredentials( - "", - "", - "", - AzureEnvironment.AZURE - ); - - // New up client. Accepts credentials, or a pre-authenticated restClient - ApplicationInsightsDataClientImpl client = new ApplicationInsightsDataClientImpl(credentials); - - // Prepare information for query - String query = "availabilityResults | take 1"; - String appId = ""; - String eventId = ""; - - // POST parameters for multiple metrics - List parameters = new ArrayList(); - parameters.add(new MetricsPostBodySchema().withId("1").withParameters(new MetricsPostBodySchemaParameters().withMetricId(MetricId.AVAILABILITY_RESULTSAVAILABILITY_PERCENTAGE))); - parameters.add(new MetricsPostBodySchema().withId("2").withParameters(new MetricsPostBodySchemaParameters().withMetricId(MetricId.AVAILABILITY_RESULTSDURATION))); - - // Execute log query - QueryResults queryResults = client.querys().execute(appId, new QueryBody().withQuery(query)); - - // Metrics - MetricsResult metricResultSingle = client.metrics().get(appId, MetricId.AVAILABILITY_RESULTSAVAILABILITY_PERCENTAGE); - List metricResultMultiple = client.metrics().getMultiple(appId, parameters); - Object metadata = client.metrics().getMetadata(appId); - - // Events - EventsResults eventsResultByType = client.events().getByType(appId, EventType.AVAILABILITY_RESULTS); - EventsResults eventsResult = client.events().get(appId, EventType.AVAILABILITY_RESULTS, eventId); - - // Process and print query results results - List row = queryResults.tables().get(0).rows().get(0); - List columnNames = queryResults - .tables() - .get(0) - .columns() - .stream() - .map(elt -> elt.name()) - .collect(Collectors.toList()); - - for (int i = 0; i < row.size(); i++){ - System.out.println("The value of " + columnNames.get(i) + " is " + row.get(i)); - } - - System.out.println(metricResultMultiple..value().additionalProperties()); - - } -} +## Examples -``` +Please see [here] for code examples using this SDK. (https://github.com/Azure/azure-sdk-for-java/tree/master/applicationinsights/data-plane/src/main/java/com/microsoft/azure/applicationinsights/query/samples) ## Download diff --git a/applicationinsights/data-plane/src/main/java/com/microsoft/azure/applicationinsights/query/samples/BasicSample.java b/applicationinsights/data-plane/src/main/java/com/microsoft/azure/applicationinsights/query/samples/BasicSample.java new file mode 100644 index 000000000000..0e59c375ca5e --- /dev/null +++ b/applicationinsights/data-plane/src/main/java/com/microsoft/azure/applicationinsights/query/samples/BasicSample.java @@ -0,0 +1,77 @@ +package com.demo.app; + +import java.util.ArrayList; +import java.util.List; +import com.microsoft.azure.AzureEnvironment; +import com.microsoft.azure.applicationinsights.query.implementation.ApplicationInsightsDataClientImpl; +import com.microsoft.azure.applicationinsights.query.models.QueryBody; +import com.microsoft.azure.applicationinsights.query.models.MetricId; +import com.microsoft.azure.applicationinsights.query.models.MetricsResult; +import com.microsoft.azure.applicationinsights.query.models.MetricsResultsItem; +import com.microsoft.azure.applicationinsights.query.models.MetricsPostBodySchema; +import com.microsoft.azure.applicationinsights.query.models.MetricsPostBodySchemaParameters; +import com.microsoft.azure.applicationinsights.query.models.EventType; +import com.microsoft.azure.applicationinsights.query.models.EventsResult; +import com.microsoft.azure.applicationinsights.query.models.EventsResults; +import com.microsoft.azure.applicationinsights.query.models.QueryResults; +import com.microsoft.azure.credentials.ApplicationTokenCredentials; + +/** + * Basic query example + * + */ +public class ApplicationInsightsClientExample +{ + public static void main( String[] args ) + { + // ApplicationTokenCredentials work well for service principal authentication + ApplicationTokenCredentials credentials = new ApplicationTokenCredentials( + "", + "", + "", + AzureEnvironment.AZURE + ); + + // New up client. Accepts credentials, or a pre-authenticated restClient + ApplicationInsightsDataClientImpl client = new ApplicationInsightsDataClientImpl(credentials); + + // Prepare information for query + String query = "availabilityResults | take 1"; + String appId = ""; + String eventId = ""; + + // POST parameters for multiple metrics + List parameters = new ArrayList(); + parameters.add(new MetricsPostBodySchema().withId("1").withParameters(new MetricsPostBodySchemaParameters().withMetricId(MetricId.AVAILABILITY_RESULTSAVAILABILITY_PERCENTAGE))); + parameters.add(new MetricsPostBodySchema().withId("2").withParameters(new MetricsPostBodySchemaParameters().withMetricId(MetricId.AVAILABILITY_RESULTSDURATION))); + + // Execute log query + QueryResults queryResults = client.querys().execute(appId, new QueryBody().withQuery(query)); + + // Metrics + MetricsResult metricResultSingle = client.metrics().get(appId, MetricId.AVAILABILITY_RESULTSAVAILABILITY_PERCENTAGE); + List metricResultMultiple = client.metrics().getMultiple(appId, parameters); + Object metadata = client.metrics().getMetadata(appId); + + // Events + EventsResults eventsResultByType = client.events().getByType(appId, EventType.AVAILABILITY_RESULTS); + EventsResults eventsResult = client.events().get(appId, EventType.AVAILABILITY_RESULTS, eventId); + + // Process and print query results results + List row = queryResults.tables().get(0).rows().get(0); + List columnNames = queryResults + .tables() + .get(0) + .columns() + .stream() + .map(elt -> elt.name()) + .collect(Collectors.toList()); + + for (int i = 0; i < row.size(); i++){ + System.out.println("The value of " + columnNames.get(i) + " is " + row.get(i)); + } + + System.out.println(metricResultMultiple..value().additionalProperties()); + + } +} \ No newline at end of file diff --git a/loganalytics/data-plane/README.md b/loganalytics/data-plane/README.md index 9629bccafd00..9167c82f53d1 100644 --- a/loganalytics/data-plane/README.md +++ b/loganalytics/data-plane/README.md @@ -4,61 +4,10 @@ This project provides client tools or utilities in Java that make it easy to que Azure Log Analytics provides agents for telemtry collection and enables deep analytics via a [rich query language](https://docs.loganalytics.io/index). This SDK provides query access to data already stored in Log Analytics. To start collecting data from different sources, take a look at these [quickstarts](https://docs.microsoft.com/en-us/azure/log-analytics/log-analytics-quick-collect-azurevm). -## Example - -```java -import java.util.List; -import java.util.stream.Collectors; -import com.microsoft.azure.AzureEnvironment; -import com.microsoft.azure.loganalytics.implementation.LogAnalyticsDataClientImpl; -import com.microsoft.azure.loganalytics.models.QueryBody; -import com.microsoft.azure.loganalytics.models.QueryResults; -import com.microsoft.azure.credentials.ApplicationTokenCredentials; - -/** - * Basic query example - * - */ -public class LogAnalyticsClientExample -{ - public static void main( String[] args ) - { - // ApplicationTokenCredentials work well for service principal authentication - ApplicationTokenCredentials credentials = new ApplicationTokenCredentials( - "", - "", - "", - AzureEnvironment.AZURE - ); - - // New up client. Accepts credentials, or a pre-authenticated restClient - LogAnalyticsDataClientImpl client = new LogAnalyticsDataClientImpl(credentials); - - // Prepare information for query - String query = "Heartbeat | take 1"; - String workspaceId = ""; - - // Execute! - QueryResults queryResults = client.query(workspaceId, new QueryBody().withQuery(query)); - - // Process and print results - List row = queryResults.tables().get(0).rows().get(0); - List columnNames = queryResults - .tables() - .get(0) - .columns() - .stream() - .map(elt -> elt.name()) - .collect(Collectors.toList()); - - for (int i = 0; i < row.size(); i++){ - System.out.println("The value of " + columnNames.get(i) + " is " + row.get(i)); - } - - return; - } -} -``` +## Examples + +Please see [here] for code examples using this SDK. (https://github.com/Azure/azure-sdk-for-java/tree/master/loganalytics/data-plane/src/main/java/com/microsoft/azure/loganalytics/samples) + ## Download diff --git a/loganalytics/data-plane/src/main/java/com/microsoft/azure/loganalytics/samples/BasicSample.java b/loganalytics/data-plane/src/main/java/com/microsoft/azure/loganalytics/samples/BasicSample.java new file mode 100644 index 000000000000..69c0acd3a295 --- /dev/null +++ b/loganalytics/data-plane/src/main/java/com/microsoft/azure/loganalytics/samples/BasicSample.java @@ -0,0 +1,52 @@ +import java.util.List; +import java.util.stream.Collectors; +import com.microsoft.azure.AzureEnvironment; +import com.microsoft.azure.loganalytics.implementation.LogAnalyticsDataClientImpl; +import com.microsoft.azure.loganalytics.models.QueryBody; +import com.microsoft.azure.loganalytics.models.QueryResults; +import com.microsoft.azure.credentials.ApplicationTokenCredentials; + +/** + * Basic query example + * + */ +public class BasicSample +{ + public static void main( String[] args ) + { + // ApplicationTokenCredentials work well for service principal authentication + ApplicationTokenCredentials credentials = new ApplicationTokenCredentials( + "", + "", + "", + AzureEnvironment.AZURE + ); + + // New up client. Accepts credentials, or a pre-authenticated restClient + LogAnalyticsDataClientImpl client = new LogAnalyticsDataClientImpl(credentials); + + // Prepare information for query + String query = "Heartbeat | take 1"; + String workspaceId = ""; + + // Execute! + QueryResults queryResults = client.query(workspaceId, new QueryBody().withQuery(query)); + + // Process and print results + List row = queryResults.tables().get(0).rows().get(0); + List columnNames = queryResults + .tables() + .get(0) + .columns() + .stream() + .map(elt -> elt.name()) + .collect(Collectors.toList()); + + for (int i = 0; i < row.size(); i++){ + System.out.println("The value of " + columnNames.get(i) + " is " + row.get(i)); + } + + return; + } +} +``` \ No newline at end of file From d406153af6071c4dc0d85e64a3e25ae8c447c43a Mon Sep 17 00:00:00 2001 From: Ace Eldeib Date: Mon, 10 Sep 2018 13:11:44 -0700 Subject: [PATCH 5/7] fix link spacing --- applicationinsights/data-plane/README.md | 2 +- loganalytics/data-plane/README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/applicationinsights/data-plane/README.md b/applicationinsights/data-plane/README.md index 97c72bef41e0..a7f3bbec11d9 100644 --- a/applicationinsights/data-plane/README.md +++ b/applicationinsights/data-plane/README.md @@ -6,7 +6,7 @@ Azure Application Insights provides SDKs for telemtry collection and enables dee ## Examples -Please see [here] for code examples using this SDK. (https://github.com/Azure/azure-sdk-for-java/tree/master/applicationinsights/data-plane/src/main/java/com/microsoft/azure/applicationinsights/query/samples) +Please see [here](https://github.com/Azure/azure-sdk-for-java/tree/master/applicationinsights/data-plane/src/main/java/com/microsoft/azure/applicationinsights/query/samples) for code examples using this SDK. ## Download diff --git a/loganalytics/data-plane/README.md b/loganalytics/data-plane/README.md index 9167c82f53d1..37e53fc2c6e7 100644 --- a/loganalytics/data-plane/README.md +++ b/loganalytics/data-plane/README.md @@ -6,7 +6,7 @@ Azure Log Analytics provides agents for telemtry collection and enables deep ana ## Examples -Please see [here] for code examples using this SDK. (https://github.com/Azure/azure-sdk-for-java/tree/master/loganalytics/data-plane/src/main/java/com/microsoft/azure/loganalytics/samples) +Please see [here](https://github.com/Azure/azure-sdk-for-java/tree/master/loganalytics/data-plane/src/main/java/com/microsoft/azure/loganalytics/samples) for code examples using this SDK. ## Download From fa19ef327c471ea6751068a4fc0c4eb0b0dd358c Mon Sep 17 00:00:00 2001 From: Ace Eldeib Date: Mon, 10 Sep 2018 13:13:38 -0700 Subject: [PATCH 6/7] prefer relative links, because github breaks absolute links all the time. --- applicationinsights/data-plane/README.md | 2 +- loganalytics/data-plane/README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/applicationinsights/data-plane/README.md b/applicationinsights/data-plane/README.md index a7f3bbec11d9..15885629d728 100644 --- a/applicationinsights/data-plane/README.md +++ b/applicationinsights/data-plane/README.md @@ -6,7 +6,7 @@ Azure Application Insights provides SDKs for telemtry collection and enables dee ## Examples -Please see [here](https://github.com/Azure/azure-sdk-for-java/tree/master/applicationinsights/data-plane/src/main/java/com/microsoft/azure/applicationinsights/query/samples) for code examples using this SDK. +Please see [here](src/main/java/com/microsoft/azure/applicationinsights/query/samples) for code examples using this SDK. ## Download diff --git a/loganalytics/data-plane/README.md b/loganalytics/data-plane/README.md index 37e53fc2c6e7..aceb30a278e4 100644 --- a/loganalytics/data-plane/README.md +++ b/loganalytics/data-plane/README.md @@ -6,7 +6,7 @@ Azure Log Analytics provides agents for telemtry collection and enables deep ana ## Examples -Please see [here](https://github.com/Azure/azure-sdk-for-java/tree/master/loganalytics/data-plane/src/main/java/com/microsoft/azure/loganalytics/samples) for code examples using this SDK. +Please see [here](src/main/java/com/microsoft/azure/loganalytics/samples) for code examples using this SDK. ## Download From 56752425393a32de982b4c84bde823a01ae5a12a Mon Sep 17 00:00:00 2001 From: Ace Eldeib Date: Mon, 10 Sep 2018 13:21:09 -0700 Subject: [PATCH 7/7] remove AI due to addlProps not working --- applicationinsights/data-plane/README.md | 50 ------------ .../query/samples/BasicSample.java | 77 ------------------- 2 files changed, 127 deletions(-) delete mode 100644 applicationinsights/data-plane/README.md delete mode 100644 applicationinsights/data-plane/src/main/java/com/microsoft/azure/applicationinsights/query/samples/BasicSample.java diff --git a/applicationinsights/data-plane/README.md b/applicationinsights/data-plane/README.md deleted file mode 100644 index 15885629d728..000000000000 --- a/applicationinsights/data-plane/README.md +++ /dev/null @@ -1,50 +0,0 @@ -# Azure Application Insights - -This project provides client tools or utilities in Java that make it easy to query data in [Azure Application Insights](https://azure.microsoft.com/en-us/services/application-insights/). For reference documentation on classes and models, please see the [Azure SDK for Java reference](https://docs.microsoft.com/en-us/java/api/overview/azure/?view=azure-java-stable). - -Azure Application Insights provides SDKs for telemtry collection and enables deep analytics via a [rich query language](https://docs.loganalytics.io/index). This SDK provides query access to data already stored in Application Insights. To start monitoring a Java application, take a look at the [quickstart](https://docs.microsoft.com/en-us/azure/application-insights/app-insights-java-quick-start). - -## Examples - -Please see [here](src/main/java/com/microsoft/azure/applicationinsights/query/samples) for code examples using this SDK. - -## Download - -### Latest release - -To get the binaries of the official Microsoft Azure Log Analytics SDK as distributed by Microsoft, reade for use within your project, you can use Maven. - -```xml - - com.microsoft.azure - azure-applicationinsights-query - LATEST - -``` - -## Prerequisites - -- A Java Developer Kit (JDK), v 1.7 or later -- Maven - -## Help and Issues - -If you encounter any bugs with these SDKs, please file issues via [Issues](https://github.com/Azure/azure-sdk-for-java/issues) or checkout [StackOverflow for Azure Java SDK](http://stackoverflow.com/questions/tagged/azure-java-sdk). - -## Contribute Code - -If you would like to become an active contributor to this project please follow the instructions provided in [Microsoft Azure Projects Contribution Guidelines](http://azure.github.io/guidelines.html). - -1. Fork it -2. Create your feature branch (`git checkout -b my-new-feature`) -3. Commit your changes (`git commit -am 'Add some feature'`) -4. Push to the branch (`git push origin my-new-feature`) -5. Create new Pull Request - -## More information -- [Azure Java SDKs](https://docs.microsoft.com/java/azure/) -- If you don't have a Microsoft Azure subscription you can get a FREE trial account [here](http://go.microsoft.com/fwlink/?LinkId=330212) - ---- - -This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments. \ No newline at end of file diff --git a/applicationinsights/data-plane/src/main/java/com/microsoft/azure/applicationinsights/query/samples/BasicSample.java b/applicationinsights/data-plane/src/main/java/com/microsoft/azure/applicationinsights/query/samples/BasicSample.java deleted file mode 100644 index 0e59c375ca5e..000000000000 --- a/applicationinsights/data-plane/src/main/java/com/microsoft/azure/applicationinsights/query/samples/BasicSample.java +++ /dev/null @@ -1,77 +0,0 @@ -package com.demo.app; - -import java.util.ArrayList; -import java.util.List; -import com.microsoft.azure.AzureEnvironment; -import com.microsoft.azure.applicationinsights.query.implementation.ApplicationInsightsDataClientImpl; -import com.microsoft.azure.applicationinsights.query.models.QueryBody; -import com.microsoft.azure.applicationinsights.query.models.MetricId; -import com.microsoft.azure.applicationinsights.query.models.MetricsResult; -import com.microsoft.azure.applicationinsights.query.models.MetricsResultsItem; -import com.microsoft.azure.applicationinsights.query.models.MetricsPostBodySchema; -import com.microsoft.azure.applicationinsights.query.models.MetricsPostBodySchemaParameters; -import com.microsoft.azure.applicationinsights.query.models.EventType; -import com.microsoft.azure.applicationinsights.query.models.EventsResult; -import com.microsoft.azure.applicationinsights.query.models.EventsResults; -import com.microsoft.azure.applicationinsights.query.models.QueryResults; -import com.microsoft.azure.credentials.ApplicationTokenCredentials; - -/** - * Basic query example - * - */ -public class ApplicationInsightsClientExample -{ - public static void main( String[] args ) - { - // ApplicationTokenCredentials work well for service principal authentication - ApplicationTokenCredentials credentials = new ApplicationTokenCredentials( - "", - "", - "", - AzureEnvironment.AZURE - ); - - // New up client. Accepts credentials, or a pre-authenticated restClient - ApplicationInsightsDataClientImpl client = new ApplicationInsightsDataClientImpl(credentials); - - // Prepare information for query - String query = "availabilityResults | take 1"; - String appId = ""; - String eventId = ""; - - // POST parameters for multiple metrics - List parameters = new ArrayList(); - parameters.add(new MetricsPostBodySchema().withId("1").withParameters(new MetricsPostBodySchemaParameters().withMetricId(MetricId.AVAILABILITY_RESULTSAVAILABILITY_PERCENTAGE))); - parameters.add(new MetricsPostBodySchema().withId("2").withParameters(new MetricsPostBodySchemaParameters().withMetricId(MetricId.AVAILABILITY_RESULTSDURATION))); - - // Execute log query - QueryResults queryResults = client.querys().execute(appId, new QueryBody().withQuery(query)); - - // Metrics - MetricsResult metricResultSingle = client.metrics().get(appId, MetricId.AVAILABILITY_RESULTSAVAILABILITY_PERCENTAGE); - List metricResultMultiple = client.metrics().getMultiple(appId, parameters); - Object metadata = client.metrics().getMetadata(appId); - - // Events - EventsResults eventsResultByType = client.events().getByType(appId, EventType.AVAILABILITY_RESULTS); - EventsResults eventsResult = client.events().get(appId, EventType.AVAILABILITY_RESULTS, eventId); - - // Process and print query results results - List row = queryResults.tables().get(0).rows().get(0); - List columnNames = queryResults - .tables() - .get(0) - .columns() - .stream() - .map(elt -> elt.name()) - .collect(Collectors.toList()); - - for (int i = 0; i < row.size(); i++){ - System.out.println("The value of " + columnNames.get(i) + " is " + row.get(i)); - } - - System.out.println(metricResultMultiple..value().additionalProperties()); - - } -} \ No newline at end of file