forked from RobustPerception/azure_metrics_exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.go
37 lines (32 loc) · 1.05 KB
/
utils.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package main
import (
"encoding/json"
"fmt"
"log"
"strings"
"time"
)
// PrintPrettyJSON - Prints structs nicely for debugging.
func PrintPrettyJSON(input map[string]interface{}) {
out, err := json.MarshalIndent(input, "", "\t")
if err != nil {
log.Fatalf("Error indenting JSON: %v", err)
}
fmt.Println(string(out))
}
// GetTimes - Returns the endTime and startTime used for querying Azure Metrics API
func GetTimes() (string, string) {
// Make sure we are using UTC
now := time.Now().UTC()
// Use query delay of 3 minutes when querying for latest metric data
endTime := now.Add(time.Minute * time.Duration(-3)).Format(time.RFC3339)
startTime := now.Add(time.Minute * time.Duration(-4)).Format(time.RFC3339)
return endTime, startTime
}
// CreateResourceLabels - Returns resource labels for a give resource ID.
func CreateResourceLabels(resourceID string) map[string]string {
labels := make(map[string]string)
labels["resource_group"] = strings.Split(resourceID, "/")[4]
labels["resource_name"] = strings.Split(resourceID, "/")[8]
return labels
}