Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions applicationinsights/data-plane/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# 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
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-applicationinsights-query</artifactId>
<version>LATEST</version>
</dependency>
```

## 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 [[email protected]](mailto:[email protected]) with any additional questions or comments.
76 changes: 76 additions & 0 deletions applicationinsights/data-plane/samples/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<!--
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for
* license information.
*
* Code generated by Microsoft (R) AutoRest Code Generator.
-->
<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>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-applicationinsights-query-sample</artifactId>
<version>1.0.0-Preview-1</version>
<packaging>jar</packaging>
<name>Microsoft Azure SDK for Application Insights Query Sample</name>
<description>This package contains Microsoft Application Insights Query SDK Sample.</description>
<url>https://github.com/Azure/azure-sdk-for-java</url>
<licenses>
<license>
<name>The MIT License (MIT)</name>
<url>http://opensource.org/licenses/MIT</url>
<distribution>repo</distribution>
</license>
</licenses>
<scm>
<url>scm:git:https://github.com/Azure/azure-sdk-for-java</url>
<connection>scm:git:[email protected]:Azure/azure-sdk-for-java.git</connection>
<tag>HEAD</tag>
</scm>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<legal><![CDATA[[INFO] Any downloads listed may be third party software. Microsoft grants you no rights for third party software.]]></legal>
<runtime.version>1.6.3</runtime.version>
</properties>
<developers>
<developer>
<id>microsoft</id>
<name>Microsoft</name>
</developer>
</developers>
<dependencies>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-applicationinsights-query</artifactId>
<version>${version}</version>
</dependency>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-client-authentication</artifactId>
<version>${runtime.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<annotationProcessors>
<annotationProcessor>
com.microsoft.azure.management.apigeneration.LangDefinitionProcessor
</annotationProcessor>
</annotationProcessors>
<debug>true</debug>
<optimize>true</optimize>
<compilerArguments>
<AaddGeneratedAnnotation>true</AaddGeneratedAnnotation>
<Adebug>true</Adebug>
</compilerArguments>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/**
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for
* license information.
*
*/
package com.microsoft.azure.applicationinsights.query.samples;

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.applicationinsights.query.models.Column;
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(
"<clientId>",
"<tenantId>",
"<clientSecret>",
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 = "<appInsightsAppGUID>";
String eventId = "<eventGuid>";

// POST parameters for multiple metrics
List<MetricsPostBodySchema> parameters = new ArrayList<MetricsPostBodySchema>();
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<MetricsResultsItem> 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 results
List<Object> row = queryResults.tables().get(0).rows().get(0);
List<Column> columnNames = queryResults
.tables()
.get(0)
.columns();

for (int i = 0; i < row.size(); i++){
System.out.println("The value of " + columnNames.get(i).name() + " is " + row.get(i));
}

System.out.println(metricResultMultiple.get(0).body().value().additionalProperties());

}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/**
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for
* license information.
*
*/
package com.microsoft.azure.applicationinsights.query;

import java.util.ArrayList;
Expand Down Expand Up @@ -59,7 +65,6 @@ 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);
}
Expand Down