MCPcopy
hub / github.com/crowdsecurity/crowdsec / dumpSystemInfo

Method dumpSystemInfo

cmd/crowdsec-cli/clisupport/support.go:158–219  ·  view source on GitHub ↗
(zw *zip.Writer)

Source from the content-addressed store, hash-verified

156}
157
158func (cli *cliSupport) dumpSystemInfo(zw *zip.Writer) error {
159 fmt.Fprintln(os.Stdout, "Collecting system info (gopsutil + runtime)")
160
161 type snapshot struct {
162 Timestamp time.Time `yaml:"timestamp"`
163 GoOS string `yaml:"go_os"`
164 GoARCH string `yaml:"go_arch"`
165 GoVersion string `yaml:"go_version"`
166 NumCPU int `yaml:"num_cpu"`
167 Goroutines int `yaml:"goroutines"`
168 CgoCalls int64 `yaml:"cgo_calls"`
169
170 Host *host.InfoStat `yaml:"host,omitempty"`
171 CPUInfo []cpu.InfoStat `yaml:"cpu_info,omitempty"`
172 CPUCounts struct {
173 Logical int `yaml:"logical"`
174 Physical int `yaml:"physical"`
175 } `yaml:"cpu_counts"`
176 BuildInfo *debug.BuildInfo `yaml:"build_info,omitempty"`
177 }
178
179 s := snapshot{
180 Timestamp: time.Now(),
181 GoOS: runtime.GOOS,
182 GoARCH: runtime.GOARCH,
183 GoVersion: runtime.Version(),
184 NumCPU: runtime.NumCPU(),
185 Goroutines: runtime.NumGoroutine(),
186 CgoCalls: runtime.NumCgoCall(),
187 }
188
189 // best-effort, errors ignored
190
191 if h, err := host.Info(); err == nil {
192 s.Host = h
193 }
194
195 if ci, err := cpu.Info(); err == nil {
196 s.CPUInfo = ci
197 }
198
199 if n, err := cpu.Counts(true); err == nil {
200 s.CPUCounts.Logical = n
201 }
202
203 if n, err := cpu.Counts(false); err == nil {
204 s.CPUCounts.Physical = n
205 }
206
207 if bi, ok := debug.ReadBuildInfo(); ok {
208 s.BuildInfo = bi
209 }
210
211 buf, err := yaml.Marshal(&s)
212 if err != nil {
213 return fmt.Errorf("serialize system info to YAML: %w", err)
214 }
215

Callers 1

dumpMethod · 0.95

Calls 4

writeToZipMethod · 0.95
NewReaderMethod · 0.80
VersionMethod · 0.45
InfoMethod · 0.45

Tested by

no test coverage detected