-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[Monitor Query] Monitor Query Resource Centric sample #26416
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
Merged
scottaddie
merged 28 commits into
Azure:main
from
KarishmaGhiya:monitor-ingestion-samples
Aug 30, 2023
Merged
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
f53d05d
update samples
KarishmaGhiya 39c846b
update samples
KarishmaGhiya b0e7c33
Update sdk/monitor/monitor-query/samples-dev/logsResourceCentricQuery.ts
KarishmaGhiya 721a3b1
Update sdk/monitor/monitor-query/README.md
KarishmaGhiya 1d35dde
Update sdk/monitor/monitor-query/samples-dev/logsResourceCentricQuery.ts
KarishmaGhiya 2e87c26
Update sdk/monitor/monitor-query/samples/v1/javascript/logsResourceCe…
KarishmaGhiya dd63c84
Update sdk/monitor/monitor-query/README.md
KarishmaGhiya bd2017a
Update sdk/monitor/monitor-query/samples/v1/typescript/README.md
KarishmaGhiya 2c4c18f
Update sdk/monitor/monitor-query/samples/v1/javascript/README.md
KarishmaGhiya 7204185
Update sdk/monitor/monitor-query/samples/v1/javascript/README.md
KarishmaGhiya 0784f28
Update sdk/monitor/monitor-query/samples/v1/javascript/logsResourceCe…
KarishmaGhiya 923d5ed
Update sdk/monitor/monitor-query/samples/v1/typescript/README.md
KarishmaGhiya 9de28e6
Update sdk/monitor/monitor-query/samples/v1/typescript/README.md
KarishmaGhiya 9001d7b
Update sdk/monitor/monitor-query/samples/v1/typescript/src/logsResour…
KarishmaGhiya f6c46e1
Update sdk/monitor/monitor-query/samples/v1/typescript/src/logsResour…
KarishmaGhiya fb7a12c
Update sdk/monitor/monitor-query/samples-dev/logsResourceCentricQuery.ts
KarishmaGhiya 8e342da
update readme
KarishmaGhiya af2db2d
update TOC
KarishmaGhiya 2f82715
Update sdk/monitor/monitor-query/README.md
KarishmaGhiya 11ff097
Update sdk/monitor/monitor-query/README.md
KarishmaGhiya b86da4b
Update sdk/monitor/monitor-query/samples/v1/typescript/README.md
KarishmaGhiya f01c9aa
Update sdk/monitor/monitor-query/README.md
KarishmaGhiya d0e6251
Update sdk/monitor/monitor-query/README.md
KarishmaGhiya 88b3dcd
Update sdk/monitor/monitor-query/README.md
KarishmaGhiya 0aace8b
update readme
KarishmaGhiya d4c8cf4
update readme
KarishmaGhiya 2ed7f74
Apply suggestions from code review
scottaddie b69cf37
Apply suggestions from code review
scottaddie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
90 changes: 90 additions & 0 deletions
90
sdk/monitor/monitor-query/samples-dev/logsResourceCentricQuery.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT license. | ||
|
|
||
| /** | ||
| * @summary Demonstrates how to run a query against a Log Analytics workspace, using an Azure resource ID. | ||
| */ | ||
|
|
||
| import { DefaultAzureCredential } from "@azure/identity"; | ||
| import { | ||
| Durations, | ||
| LogsQueryClient, | ||
| LogsTable, | ||
| LogsQueryOptions, | ||
| LogsQueryResultStatus, | ||
| } from "@azure/monitor-query"; | ||
| import * as dotenv from "dotenv"; | ||
| dotenv.config(); | ||
|
|
||
| const logsResourceId = process.env.LOGS_RESOURCE_ID; | ||
|
|
||
| export async function main() { | ||
| const tokenCredential = new DefaultAzureCredential(); | ||
| const logsQueryClient = new LogsQueryClient(tokenCredential); | ||
|
|
||
| if (!logsResourceId) { | ||
| throw new Error("LOGS_RESOURCE_ID must be set in the environment for this sample"); | ||
| } | ||
|
|
||
| const kustoQuery = `MyTable_CL | summarize count()`; | ||
|
|
||
| console.log(`Running '${kustoQuery}' over the last One Hour`); | ||
| const queryLogsOptions: LogsQueryOptions = { | ||
| // explicitly control the amount of time the server can spend processing the query. | ||
| serverTimeoutInSeconds: 600, // sets the timeout to 10 minutes | ||
| // optionally enable returning additional statistics about the query's execution. | ||
| // (by default, this is off) | ||
| includeQueryStatistics: true, | ||
| }; | ||
|
|
||
| const result = await logsQueryClient.queryResource( | ||
| logsResourceId, | ||
| kustoQuery, | ||
| { duration: Durations.sevenDays }, | ||
| queryLogsOptions); | ||
|
|
||
| const executionTime = | ||
| result.statistics && result.statistics.query && (result.statistics.query as any).executionTime; | ||
|
|
||
| console.log( | ||
| `Results for query '${kustoQuery}', execution time: ${ | ||
| executionTime == null ? "unknown" : executionTime | ||
| }` | ||
| ); | ||
|
|
||
| if (result.status === LogsQueryResultStatus.Success) { | ||
| const tablesFromResult: LogsTable[] = result.tables; | ||
|
|
||
| if (tablesFromResult.length === 0) { | ||
| console.log(`No results for query '${kustoQuery}'`); | ||
| return; | ||
| } | ||
| console.log(`This query has returned table(s) - `); | ||
| processTables(tablesFromResult); | ||
| } else { | ||
| console.log(`Error processing the query '${kustoQuery}' - ${result.partialError}`); | ||
| if (result.partialTables.length > 0) { | ||
| console.log(`This query has also returned partial data in the following table(s) - `); | ||
| processTables(result.partialTables); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| async function processTables(tablesFromResult: LogsTable[]) { | ||
| for (const table of tablesFromResult) { | ||
| const columnHeaderString = table.columnDescriptors | ||
| .map((column) => `${column.name}(${column.type}) `) | ||
| .join("| "); | ||
| console.log("| " + columnHeaderString); | ||
|
|
||
| for (const row of table.rows) { | ||
| const columnValuesString = row.map((columnValue) => `'${columnValue}' `).join("| "); | ||
| console.log("| " + columnValuesString); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| main().catch((err) => { | ||
| console.error("The sample encountered an error:", err); | ||
| process.exit(1); | ||
| }); |
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
86 changes: 86 additions & 0 deletions
86
sdk/monitor/monitor-query/samples/v1/javascript/logsResourceCentricQuery.js
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT license. | ||
|
|
||
| /** | ||
| * @summary Demonstrates how to run a query against a Log Analytics workspace, using an Azure resource ID. | ||
| */ | ||
|
|
||
| const { DefaultAzureCredential } = require("@azure/identity"); | ||
| const { Durations, LogsQueryClient, LogsQueryResultStatus } = require("@azure/monitor-query"); | ||
| require("dotenv").config(); | ||
|
|
||
| const logsResourceId = process.env.LOGS_RESOURCE_ID; | ||
|
|
||
| async function main() { | ||
| const tokenCredential = new DefaultAzureCredential(); | ||
| const logsQueryClient = new LogsQueryClient(tokenCredential); | ||
|
|
||
| if (!logsResourceId) { | ||
| throw new Error("LOGS_RESOURCE_ID must be set in the environment for this sample"); | ||
| } | ||
|
|
||
| const kustoQuery = `MyTable_CL | summarize count()`; | ||
|
|
||
| console.log(`Running '${kustoQuery}' over the last One Hour`); | ||
| const queryLogsOptions = { | ||
| // explicitly control the amount of time the server can spend processing the query. | ||
| serverTimeoutInSeconds: 600, | ||
| // optionally enable returning additional statistics about the query's execution. | ||
| // (by default, this is off) | ||
| includeQueryStatistics: true, | ||
| }; | ||
|
|
||
| const result = await logsQueryClient.queryResource( | ||
| logsResourceId, | ||
| kustoQuery, | ||
| { duration: Durations.sevenDays }, | ||
| queryLogsOptions | ||
| ); | ||
|
|
||
| const executionTime = | ||
| result.statistics && result.statistics.query && result.statistics.query.executionTime; | ||
|
|
||
| console.log( | ||
| `Results for query '${kustoQuery}', execution time: ${ | ||
| executionTime == null ? "unknown" : executionTime | ||
| }` | ||
| ); | ||
|
|
||
| if (result.status === LogsQueryResultStatus.Success) { | ||
| const tablesFromResult = result.tables; | ||
|
|
||
| if (tablesFromResult.length === 0) { | ||
| console.log(`No results for query '${kustoQuery}'`); | ||
| return; | ||
| } | ||
| console.log(`This query has returned table(s) - `); | ||
| processTables(tablesFromResult); | ||
| } else { | ||
| console.log(`Error processing the query '${kustoQuery}' - ${result.partialError}`); | ||
| if (result.partialTables.length > 0) { | ||
| console.log(`This query has also returned partial data in the following table(s) - `); | ||
| processTables(result.partialTables); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| async function processTables(tablesFromResult) { | ||
| for (const table of tablesFromResult) { | ||
| const columnHeaderString = table.columnDescriptors | ||
| .map((column) => `${column.name}(${column.type}) `) | ||
| .join("| "); | ||
| console.log("| " + columnHeaderString); | ||
|
|
||
| for (const row of table.rows) { | ||
| const columnValuesString = row.map((columnValue) => `'${columnValue}' `).join("| "); | ||
| console.log("| " + columnValuesString); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| main().catch((err) => { | ||
| console.error("The sample encountered an error:", err); | ||
| process.exit(1); | ||
| }); | ||
|
|
||
| module.exports = { main }; |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.