Skip to content

Instantly share code, notes, and snippets.

View Rohitrajak1807's full-sized avatar

Rohit Rajak Rohitrajak1807

View GitHub Profile
@Rohitrajak1807
Rohitrajak1807 / log_analytics.go
Created July 8, 2022 09:47
Illustrates the use of Log Analytics Query API to get Max CPU millicores and Max Memory RSS in bytes
// getVirtualNodeUsageStats fetches the virtual node max CPU milli-cores and max memory used in bytes within a span of
// startDateTime to endDateTime. KQL requires the client to ensure that these times are in UTC and ISO 8061 format(RFC3339)
func getVirtualNodeUsageStats(ctx context.Context, tokenCredential azcore.TokenCredential, subscriptionId, clusterName, resourceGroup string, startDateTime, endDateTime time.Time) (map[string]float64, error) {
client, err := armoperationalinsights.NewWorkspacesClient(subscriptionId, tokenCredential, nil)
if err != nil {
zap.S().Error(err)
return nil, err
}
workspace, err := client.Get(ctx, resourceGroup, workspaceName, nil)
if err != nil {
@Rohitrajak1807
Rohitrajak1807 / query.kql
Created July 8, 2022 09:36
KQL get max CPU millicores and max memory bytes
let subscriptionId = '{subscription-id}';
let resourceGroup = '{resource-group}';
let clusterName = '{cluster-name}';
let startDateTime = datetime({start-tate-time});
let endDateTime = datetime({end-date-time});
let clusterId = strcat('/subscriptions/', subscriptionId, '/resourceGroups/', resourceGroup, '/providers/Microsoft.ContainerService/managedClusters/', clusterName);
let memoryUsageCounterName = 'memoryRssBytes';
let primaryInventory = KubePodInventory |
where TimeGenerated >= startDateTime |
where TimeGenerated < endDateTime |
@Rohitrajak1807
Rohitrajak1807 / aggregate.json
Created June 23, 2022 07:38
Aggregated data for metrics
{
"cost": 177,
"interval": "PT1H",
"namespace": "Microsoft.ContainerService/managedClusters",
"resourceregion": "centralindia",
"timespan": "2022-05-17T05:10:12Z/2022-05-17T06:10:12Z",
"value": [
{
"displayDescription": "Aggregated measurement of CPU utilization in millicores across the cluster",
"errorCode": "Success",
@Rohitrajak1807
Rohitrajak1807 / metrics.go
Created June 23, 2022 07:34
ARM resources, Metrics.Get example
package main
import (
"bytes"
"context"
"encoding/json"
"log"
"os"
"time"
@Rohitrajak1807
Rohitrajak1807 / timeseries.json
Created June 23, 2022 07:32
AKS physical node cpu usage time series data
{
"cost": 59,
"timespan": "2022-05-12T08:18:37Z/2022-05-12T09:18:37Z",
"interval": "PT1M",
"value": [
{
"id": "/subscriptions/xxxxxxxxxxxxxxx/resourceGroups/anirudh-dialtone/providers/Microsoft.ContainerService/managedClusters/DialtoneCluster/providers/Microsoft.Insights/metrics/node_cpu_usage_millicores",
"type": "Microsoft.Insights/metrics",
"name": {
"value": "node_cpu_usage_millicores",
@Rohitrajak1807
Rohitrajak1807 / multiTimeseries.json
Created June 23, 2022 07:29
AKS physical node multiple metrics time series data.
{
"cost": 177,
"timespan": "2022-05-12T06:08:36Z/2022-05-12T07:08:36Z",
"interval": "PT1M",
"value": [
{
"id": "/subscriptions/xxxxxxxxxxxxx/resourceGroups/anirudh-dialtone/providers/Microsoft.ContainerService/managedClusters/DialtoneCluster/providers/Microsoft.Insights/metrics/node_cpu_usage_millicores",
"type": "Microsoft.Insights/metrics",
"name": {
"value": "node_cpu_usage_millicores",
@Rohitrajak1807
Rohitrajak1807 / query.go
Created June 21, 2022 16:46
Fetching AKS ACI V Node vital stats
package main
import (
"bytes"
"context"
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"