-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmain.go
167 lines (143 loc) · 4.15 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
package main
import (
"flag"
"fmt"
"log"
"os"
"time"
"code.cloudfoundry.org/cli/plugin"
)
var (
logger *log.Logger
mc Metrics
arvhiveEnabled = false
ofh *os.File
accessToken string
systemDomain string
cfCLI plugin.CliConnection
sampleDuration *string
sampleOffset *string
firehoseUsage = `
cf firehose-analyzer <options>
Options
-d <duration> - default is 5m
-o <offset> - default is 2m`
)
// BasicPlugin implement cf cli plugin api
type BasicPlugin struct{}
// Run execute the firehose analyzer tool
func (c *BasicPlugin) Run(cliConnection plugin.CliConnection, args []string) {
fs := flag.NewFlagSet("firehose-args", flag.ExitOnError)
sampleDuration = fs.String("d", "5m", "Specify sample duration")
sampleOffset = fs.String("o", "2m", "Specify sample offset")
fs.Usage = func() { fmt.Println(firehoseUsage) }
err := fs.Parse(args[1:])
if err != nil {
fmt.Println(err)
os.Exit(1)
}
// Ensure that we called the command basic-plugin-command
cfCLI = cliConnection
if args[0] == "firehose-analyzer" {
startAnalyzer()
}
}
// GetMetadata interface for plugin api
func (c *BasicPlugin) GetMetadata() plugin.PluginMetadata {
return plugin.PluginMetadata{
Name: "firehose-analyzer",
Version: plugin.VersionType{
Major: 1,
Minor: 3,
Build: 1,
},
MinCliVersion: plugin.VersionType{
Major: 6,
Minor: 7,
Build: 0,
},
Commands: []plugin.Command{
{
Name: "firehose-analyzer",
HelpText: "Displays basic firehose metrics for troubleshooting scaling issues",
// UsageDetails is optional
// It is used to show help of usage of each command
UsageDetails: plugin.Usage{
Usage: firehoseUsage,
},
},
},
}
}
const (
tcJob = "loggregator_trafficcontroller"
dopplerJob = "doppler"
metronJob = "metron"
trafficControllerSID = "traffic_controller"
dopplerSID = "doppler"
syslogDrainAdapterSID = "drain_adapter"
syslogDrainScheduleSID = "drain_scheduler"
syslogAgentSID = "syslog_agent"
metronSID = "metron"
logCacheSID = "log-cache"
logCacheNozzleSID = "log-cache-nozzle"
rlpSID = "reverse_log_proxy"
boshSystemMetricsSID = "bosh-system-metrics-forwarder" // cpu and memory
// common stats
ingressCounter = "ingress"
egressCounter = "egress"
droppedCounter = "dropped"
subscriptionsGauge = "subscriptions"
// boshSystemMetricsSID metrics
cpuUserGauge = "system_cpu_user"
cpuWaitGauge = "system_cpu_wait"
cpuSYSGauge = "system_cpu_sys"
memoryPercentGauge = "system_mem_percent"
// trafficControllerSID metrics
slowConsumerCounter = "doppler_proxy_slow_consumer"
firehosesGauge = "doppler_proxy_firehoses"
appStreamsGauge = "doppler_proxy_app_streams"
containerMetricsLatencyGauge = "doppler_proxy_container_metrics_latency"
// dopplerSID metrics
dopplerSubscritionsGauge = "subscriptions"
dumpSinksGauge = "dump_sinks"
sinksDroppedCounter = "sinks_dropped"
sinkErrorsDroppedCounter = "sinks_errors_dropped"
// syslogAgentSID metrics
drainsNonAppGauge = "non_app_drains"
drainsBlacklistedGauge = "blacklisted_drains"
drainsActiveGauge = "active_drains"
drainsInvlaidGauge = "invalid_drains"
drainsGauge = "drains"
// metronSID
averageEnvelopGauge = "average_envelope" // bytes/minute
// logCacheSID
lcSystemMemGauge = "available-system-memory"
lcTotalMemGauge = "total-system-memory"
lcExpiredCounter = "expired"
lcCachePeriodGauge = "cache-period"
// logCacheNozzleSID
lcnErrCounter = "err"
)
func startAnalyzer() {
fmt.Println("Inializing Analyzer...")
mc = Metrics{}
apiURL, err := cfCLI.ApiEndpoint()
if err != nil {
logger.Fatalln(err)
}
sysDomain := fmt.Sprintf("https://log-cache.%s", apiURL[12:len(apiURL)])
lcc, err := NewLogCacheClient(sysDomain)
if err != nil {
logger.Fatalf("Could not create log cache client: %s\n", err)
}
go loopTerm(&lcc)
for {
lcc.Collect()
time.Sleep(30 * time.Second)
}
}
func main() {
logger = log.New(os.Stdout, "logger: ", log.Ldate|log.Ltime|log.Lshortfile)
plugin.Start(new(BasicPlugin))
}