system_collector.go 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package diagnostic
  2. import "context"
  3. type DiskVolumeInformation struct {
  4. Name string `json:"name"` // represents the filesystem in linux/macos or device name in windows
  5. SizeMaximum uint64 `json:"sizeMaximum"` // represents the maximum size of the disk in kilobytes
  6. SizeCurrent uint64 `json:"sizeCurrent"` // represents the current size of the disk in kilobytes
  7. }
  8. func NewDiskVolumeInformation(name string, maximum, current uint64) *DiskVolumeInformation {
  9. return &DiskVolumeInformation{
  10. name,
  11. maximum,
  12. current,
  13. }
  14. }
  15. type SystemInformation struct {
  16. MemoryMaximum uint64 `json:"memoryMaximum"` // represents the maximum memory of the system in kilobytes
  17. MemoryCurrent uint64 `json:"memoryCurrent"` // represents the system's memory in use in kilobytes
  18. FileDescriptorMaximum uint64 `json:"fileDescriptorMaximum"` // represents the maximum number of file descriptors of the system
  19. FileDescriptorCurrent uint64 `json:"fileDescriptorCurrent"` // represents the system's file descriptors in use
  20. OsSystem string `json:"osSystem"` // represents the operating system name i.e.: linux, windows, darwin
  21. HostName string `json:"hostName"` // represents the system host name
  22. OsVersion string `json:"osVersion"` // detailed information about the system's release version level
  23. OsRelease string `json:"osRelease"` // detailed information about the system's release
  24. Architecture string `json:"architecture"` // represents the system's hardware platform i.e: arm64/amd64
  25. CloudflaredVersion string `json:"cloudflaredVersion"` // the runtime version of cloudflared
  26. Disk []*DiskVolumeInformation `json:"disk"`
  27. }
  28. func NewSystemInformation(
  29. memoryMaximum,
  30. memoryCurrent,
  31. filesMaximum,
  32. filesCurrent uint64,
  33. osystem,
  34. name,
  35. osVersion,
  36. osRelease,
  37. architecture,
  38. cloudflaredVersion string,
  39. disk []*DiskVolumeInformation,
  40. ) *SystemInformation {
  41. return &SystemInformation{
  42. memoryMaximum,
  43. memoryCurrent,
  44. filesMaximum,
  45. filesCurrent,
  46. osystem,
  47. name,
  48. osVersion,
  49. osRelease,
  50. architecture,
  51. cloudflaredVersion,
  52. disk,
  53. }
  54. }
  55. type SystemCollector interface {
  56. // If the collection is successful it will return `SystemInformation` struct,
  57. // an empty string, and a nil error.
  58. // In case there is an error a string with the raw data will be returned
  59. // however the returned string not contain all the data points.
  60. //
  61. // This function expects that the caller sets the context timeout to prevent
  62. // long-lived collectors.
  63. Collect(ctx context.Context) (*SystemInformation, string, error)
  64. }