Skip to content

Commit 8cd6245

Browse files
collector: collect process info only when needed (#45)
* collector: collect process info only when needed * collector: add comment to describe collector argument choices * update vendors * collector: remove empty results from JSON * collector/tools: optimize on option parsing
1 parent 43f524a commit 8cd6245

File tree

99 files changed

+10647
-477
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+10647
-477
lines changed

Gopkg.lock

Lines changed: 11 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

collector/collector.go

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,22 +38,23 @@ type Meta struct {
3838

3939
type Metrics struct {
4040
Meta Meta `json:"meta"`
41-
SysInfo sysinfo.SysInfo `json:"sysinfo"`
42-
NTP TimeStat `json:"ntp"`
43-
Partitions []BlockDev `json:"partitions"`
44-
ProcStats []ProcessStat `json:"proc_stats"`
41+
SysInfo sysinfo.SysInfo `json:"sysinfo,omitempty"`
42+
NTP TimeStat `json:"ntp,omitempty"`
43+
Partitions []BlockDev `json:"partitions,omitempty"`
44+
ProcStats []ProcessStat `json:"proc_stats,omitempty"`
4545
}
4646

4747
type options struct {
48-
Pid string
48+
Pid string
49+
Proc bool
4950
}
5051

5152
func parseOpts() options {
5253
optPid := flag.String("pid", "", "The PID of process to collect info. Multiple PIDs can be seperatted by ','.")
54+
optProc := flag.Bool("proc", false, "Only collect process info, disabled (Collect everything except process info) by default.")
5355
flag.Parse()
5456

55-
var opts options
56-
opts.Pid = *optPid
57+
opts := options{*optPid, *optProc}
5758
return opts
5859
}
5960

@@ -73,10 +74,13 @@ func main() {
7374

7475
func (metric *Metrics) getMetrics(opts options) {
7576
metric.Meta.getMeta()
76-
metric.SysInfo.GetSysInfo()
77-
metric.NTP.getNTPInfo()
78-
metric.Partitions = GetPartitionStats()
79-
metric.ProcStats = GetProcStats(opts.Pid)
77+
if opts.Proc {
78+
metric.ProcStats = GetProcStats(opts.Pid)
79+
} else {
80+
metric.SysInfo.GetSysInfo()
81+
metric.NTP.getNTPInfo()
82+
metric.Partitions = GetPartitionStats()
83+
}
8084
}
8185

8286
func (meta *Meta) getMeta() {

insight.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,14 @@ def collector(self, args):
9595
if args.pid:
9696
logging.debug(
9797
"Collecting process infor only for PID %s" % args.pid)
98-
collector_exec = [collector_exec, '-pid', '%s' % args.pid]
98+
collector_exec = [collector_exec, '-proc', '-pid', '%s' % args.pid]
9999
elif args.port:
100100
protocol = 'UDP' if args.udp else 'TCP'
101101
pids = ','.join(
102102
str(_pid) for _pid in proc_meta.find_process_by_port(args.port, protocol))
103103
logging.debug("Collecting process infor for PIDs %s" % pids)
104-
collector_exec = [collector_exec, '-pid', '%s' % pids]
104+
collector_exec = [collector_exec, '-proc', '-pid', '%s' % pids]
105+
# else call collector without any argument
105106

106107
stdout, stderr = util.run_cmd(collector_exec)
107108
if stderr:
@@ -114,6 +115,13 @@ def collector(self, args):
114115

115116
# save various info to seperate .json files
116117
for k, v in self.collector_data.items():
118+
# This is a dirty hack to omit empty results, until Go fix that upstream,
119+
# see: https://github.com/golang/go/issues/11939
120+
if (args.pid or args.port) and k in ['sysinfo', 'ntp']:
121+
continue
122+
if not v or len(v) < 1:
123+
logging.debug("Skipped empty result %s:%s" % (k, v))
124+
continue
117125
fileopt.write_file(os.path.join(collector_outdir, "%s.json" % k),
118126
json.dumps(v, indent=2))
119127

tools/prom2influx.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,8 @@ func parseOpts() options {
4444
influxChunk := flag.Int("chunk", 2000, "The chunk size of writing.")
4545
flag.Parse()
4646

47-
var opts options
48-
opts.Host = *influxHost
49-
opts.Port = *influxPort
50-
opts.User = *influxUser
51-
opts.Passwd = *influxPass
52-
opts.DBName = *influxDB
53-
opts.File = *influxFile
54-
opts.Chunk = *influxChunk
47+
opts := options{*influxHost, *influxPort, *influxUser, *influxPass,
48+
*influxDB, *influxFile, *influxChunk}
5549
return opts
5650
}
5751

vendor/github.com/AstroProfundis/sysinfo/sysinfo.go

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/golang.org/x/sys/unix/dev_aix_ppc.go

Lines changed: 1 addition & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/golang.org/x/sys/unix/dev_aix_ppc64.go

Lines changed: 1 addition & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/golang.org/x/sys/unix/ioctl.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/golang.org/x/sys/unix/mkerrors.sh

Lines changed: 23 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/golang.org/x/sys/unix/mksysctl_openbsd.pl

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)