Skip to content

Instantly share code, notes, and snippets.

View hfleitas's full-sized avatar
👔
working

Hiram Fleitas hfleitas

👔
working
View GitHub Profile
@hfleitas
hfleitas / AzCostMgmt.kql
Created February 15, 2024 02:24
AzCostMgmt.kql
// https://aka.ms/adx.blog
UsagePreliminary
| where Date == datetime(2023-08-01)
| where MeterId == "2c57ed84-f939-4f5c-ba90-782349a367b8"
| where ResourceId == "/subscriptions/9ec51cfd-5ca7-4d76-8101-dd0a4abc5674/resourcegroups/mc_analyticsengine_analyticsengine_eastus/providers/microsoft.compute/virtualmachinescalesets/aks-secretagent-37798712-vmss"
UsagePreliminary
| summarize Quantity=sum(Quantity)
@hfleitas
hfleitas / Garmin.kql
Created February 15, 2024 02:22
Garmin.kql
#connect @MyFreeCluster/MyDatabase
let data = dynamic(
```
<?xml version="1.0" encoding="UTF-8"?>
<duration>
<value>118.0</value>
<count>5.0</count>
<min>100.0</min>
<max>150.0</max>
@hfleitas
hfleitas / OpenAI.kql
Created February 15, 2024 02:19
OpenAI.kql
//external
#connect cluster('kvc0wyc7zw8bafmkdc1bzv.southcentralus').database('MyDatabase')
.set-or-append async OpenAIQnA <|
let d= dynamic(
{
"statusCode": 200,
"headers": {
"Transfer-Encoding": "chunked",
"Vary": "Accept-Encoding",
@hfleitas
hfleitas / VectorSearch.kql
Created February 15, 2024 02:16
VectorSearch.kql
let series_cosine_similarity_fl=(vec1:dynamic, vec2:dynamic, vec1_size:real=double(null), vec2_size:real=double(null))
{
let dp = series_dot_product(vec1, vec2);
let v1l = iff(isnull(vec1_size), sqrt(series_dot_product(vec1, vec1)), vec1_size);
let v2l = iff(isnull(vec2_size), sqrt(series_dot_product(vec2, vec2)), vec2_size);
dp/(v1l*v2l)
};
let s1=pack_array(0, 1);
let s2=pack_array(sqrt(2), sqrt(2));
print angle=acos(series_cosine_similarity_fl(s1, s2))/(2*pi())*360
@hfleitas
hfleitas / ADXInADay3.kql
Created February 15, 2024 02:15
ADXInADay3.kql
// PLEASE TRY ON YOUR OWN FIRST! https://aka.ms/adxinaday
// Labs are subject to change in the future based on feedback.
// SPOILER ALERT: Answers below.
//v2
.create-merge table logsRaw(Timestamp:datetime, Source:string, Node:string, Level:string, Component:string, ClientRequestId:string, Message:string, Properties:dynamic)
//3.2
logsRaw
@hfleitas
hfleitas / ResourceGraph.kql
Created February 15, 2024 02:14
ResourceGraph.kql
#connect cluster('kvc43f0ee6600e24ef2b0e.southcentralus.kusto.windows.net').database('MyDatabase')
// GET
let Uri = "https://prices.azure.com/api/retail/prices?$filter=serviceName eq 'Azure Purview' and location eq 'EU West'";
evaluate http_request(Uri)
| project ResponseBody.Items
| mv-expand ResponseBody_Items
| evaluate bag_unpack(ResponseBody_Items)
@hfleitas
hfleitas / Plotly.kql
Created February 15, 2024 02:08
Plotly.kql
#connect cluster('adxpm10774.eastus.kusto.windows.net').database('IoTAnalytics')
.set-or-replace PlotlyTemplate <| cluster('help.kusto.windows.net').database('Samples').PlotlyTemplate
PlotlyTemplate
.create-or-alter function with (folder = "Packages\\Plotly", docstring = "Render 3D scatter chart using plotly template")
plotly_scatter3d_fl(tbl:(*), x_col:string, y_col:string, z_col:string, aggr_col:string='', chart_title:string='3D Scatter chart')
{
@hfleitas
hfleitas / Time_Series.kql
Created February 15, 2024 02:00
Time_Series.kql
#connect cluster('https://demo11.westus.kusto.windows.net').database('ML')
demo_make_series1
| take 100
demo_make_series1
| summarize count() by bin(TimeStamp, 1h)
| render timechart
demo_make_series1
@hfleitas
hfleitas / IOT-HOL.kql
Created February 15, 2024 01:55
IOT-HOL.kql
#connect cluster('adxpm10774.eastus').database('IoTAnalytics')
//Data lands in the StageIoTRaw table so lets look at that first
.show table StageIoTRawData
StageIoTRawData
| limit 10
//We use an update policy to flatten this data and append it to the Thermostat table
.show table Thermostats
@hfleitas
hfleitas / HOL.kql
Created February 15, 2024 01:54
HOL.kql
#connect cluster('adxpm10774.eastus').database('IoTAnalytics')
//Data lands in the StageIoTRaw table so lets look at that first
.show table StageIoTRawData
StageIoTRawData
| limit 10
//We use an update policy to flatten this data and append it to the Thermostat table