filestats_windows.go 906 B

1234567891011121314151617181920212223242526
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. //go:build windows
  4. // +build windows
  5. package filestatsreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/filestatsreceiver"
  6. import (
  7. "os"
  8. "syscall"
  9. "time"
  10. "go.opentelemetry.io/collector/pdata/pcommon"
  11. "go.uber.org/zap"
  12. "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/filestatsreceiver/internal/metadata"
  13. )
  14. func collectStats(now pcommon.Timestamp, fileinfo os.FileInfo, metricsBuilder *metadata.MetricsBuilder, logger *zap.Logger) {
  15. stat := fileinfo.Sys().(*syscall.Win32FileAttributeData)
  16. atime := stat.LastAccessTime.Nanoseconds() / int64(time.Second)
  17. ctime := stat.LastWriteTime.Nanoseconds() / int64(time.Second)
  18. metricsBuilder.RecordFileAtimeDataPoint(now, atime)
  19. metricsBuilder.RecordFileCtimeDataPoint(now, ctime, fileinfo.Mode().Perm().String())
  20. }