-
Notifications
You must be signed in to change notification settings - Fork 48
/
main.go
67 lines (57 loc) · 1.49 KB
/
main.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
58
59
60
61
62
63
64
65
66
67
// package main shows a basic usage pattern of the SiganlFlow client.
package main
import (
"fmt"
"log"
"os"
"github.com/signalfx/signalfx-go/signalflow"
)
func main() {
var streamURL = os.Getenv("SIGNALFX_STREAM_URL")
var accessToken = os.Getenv("SIGNALFX_ACCESS_TOKEN")
c, err := signalflow.NewClient(
signalflow.StreamURL(streamURL),
signalflow.AccessToken(accessToken))
if err != nil {
log.Printf("Error creating client: %v", err)
return
}
program := os.Getenv("SIGNALFLOW_PROGRAM")
if program == "" {
program = "data('cpu.utilization').publish()"
}
comp, err := c.Execute(&signalflow.ExecuteRequest{
Program: program,
})
if err != nil {
log.Printf("Could not send execute request: %v", err)
return
}
fmt.Printf("Resolution: %v\n", comp.Resolution())
fmt.Printf("Max Delay: %v\n", comp.MaxDelay())
fmt.Printf("Detected Lag: %v\n", comp.Lag())
go func() {
for msg := range comp.Expirations() {
fmt.Printf("Got expiration notice for TSID %s", msg.TSID)
}
}()
for msg := range comp.Data() {
// This will run as long as there is data, or until the websocket gets
// disconnected.
if len(msg.Payloads) == 0 {
fmt.Printf("\rNo data available")
continue
}
for _, pl := range msg.Payloads {
meta := comp.TSIDMetadata(pl.TSID)
fmt.Printf("%s %v: %v\n", meta.OriginatingMetric, meta.CustomProperties, pl.Value())
}
fmt.Println("")
}
err = comp.Err()
if err != nil {
log.Printf("Error: %v", comp.Err())
} else {
log.Printf("Job completed")
}
}