-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapplication.go
57 lines (45 loc) · 1.26 KB
/
application.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package main
import (
"cloud.google.com/go/monitoring/apiv3"
"context"
"flag"
"fmt"
"github.com/sirupsen/logrus"
"github.com/team142/go-arm-stackdriver-temps/gast"
"log"
"os"
)
var (
projectID = flag.String("projectid", "", "A GCP project ID")
deviceID = flag.String("deviceid", "", "The label for stackdriver")
filename = flag.String("filename", "", "File to read")
)
func main() {
if projectID == nil || *projectID == "" {
logrus.Fatal("No projectid provided")
}
if deviceID == nil || *deviceID == "" {
logrus.Fatal("No deviceid provided")
}
if filename == nil || *filename == "" {
logrus.Fatal("No filename provided")
}
sigs := make(chan os.Signal, 1)
flag.Parse()
ctx := context.Background()
// Creates a client.
client, err := monitoring.NewMetricClient(ctx)
if err != nil {
log.Fatalf("Failed to create client: %v", err)
}
readings, stop := gast.StartReader(*filename, gast.ReadFile, 60000)
batches := gast.StartAggregator(readings, 1)
gast.StartWriter(batches, gast.BuildWriter(*projectID, *deviceID, client, ctx))
<-sigs
stop <- true
// Closes the client and flushes the data to Stackdriver.
if err := client.Close(); err != nil {
log.Fatalf("Failed to close client: %v", err)
}
fmt.Printf("Done writing time series data.\n")
}