-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Add Log Analytics readme + example #2363
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
fdf6609
a2e8692
653498d
882796d
d406153
fa19ef3
5675242
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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()); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems like the client doesn't properly populate this field from JSON? Here's what the return shape from API looks like, but the assert fails. I would expect something like {
"value": {
"start": "2018-09-10T07:47:08.518Z",
"end":"2018-09-10T19:47:08.518Z",
"availabilityResults/availabilityPercentage": {
"avg":100
}
}
} |
||
| 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()); | ||
| } | ||
|
|
||
|
|
@@ -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); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| # 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). | ||
|
|
||
| ## Examples | ||
|
|
||
| Please see [here](src/main/java/com/microsoft/azure/loganalytics/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-loganalytics</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 [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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( | ||
| "<clientId>", | ||
| "<tenantId>", | ||
| "<clientSecret>", | ||
| 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 = "<logAnalyticsWorkspaceGUID>"; | ||
|
|
||
| // Execute! | ||
| QueryResults queryResults = client.query(workspaceId, new QueryBody().withQuery(query)); | ||
|
|
||
| // Process and print results | ||
| List<Object> row = queryResults.tables().get(0).rows().get(0); | ||
| List<String> 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; | ||
| } | ||
| } | ||
| ``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This got
mvn testworking properly for me.