No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 

67 líneas
1.9 KiB

  1. // Copyright 2019 The Prometheus Authors
  2. // Licensed under the Apache License, Version 2.0 (the "License");
  3. // you may not use this file except in compliance with the License.
  4. // You may obtain a copy of the License at
  5. //
  6. // http://www.apache.org/licenses/LICENSE-2.0
  7. //
  8. // Unless required by applicable law or agreed to in writing, software
  9. // distributed under the License is distributed on an "AS IS" BASIS,
  10. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. // See the License for the specific language governing permissions and
  12. // limitations under the License.
  13. //go:build !windows
  14. // +build !windows
  15. package prometheus
  16. import (
  17. "github.com/prometheus/procfs"
  18. )
  19. func canCollectProcess() bool {
  20. _, err := procfs.NewDefaultFS()
  21. return err == nil
  22. }
  23. func (c *processCollector) processCollect(ch chan<- Metric) {
  24. pid, err := c.pidFn()
  25. if err != nil {
  26. c.reportError(ch, nil, err)
  27. return
  28. }
  29. p, err := procfs.NewProc(pid)
  30. if err != nil {
  31. c.reportError(ch, nil, err)
  32. return
  33. }
  34. if stat, err := p.Stat(); err == nil {
  35. ch <- MustNewConstMetric(c.cpuTotal, CounterValue, stat.CPUTime())
  36. ch <- MustNewConstMetric(c.vsize, GaugeValue, float64(stat.VirtualMemory()))
  37. ch <- MustNewConstMetric(c.rss, GaugeValue, float64(stat.ResidentMemory()))
  38. if startTime, err := stat.StartTime(); err == nil {
  39. ch <- MustNewConstMetric(c.startTime, GaugeValue, startTime)
  40. } else {
  41. c.reportError(ch, c.startTime, err)
  42. }
  43. } else {
  44. c.reportError(ch, nil, err)
  45. }
  46. if fds, err := p.FileDescriptorsLen(); err == nil {
  47. ch <- MustNewConstMetric(c.openFDs, GaugeValue, float64(fds))
  48. } else {
  49. c.reportError(ch, c.openFDs, err)
  50. }
  51. if limits, err := p.Limits(); err == nil {
  52. ch <- MustNewConstMetric(c.maxFDs, GaugeValue, float64(limits.OpenFiles))
  53. ch <- MustNewConstMetric(c.maxVsize, GaugeValue, float64(limits.AddressSpace))
  54. } else {
  55. c.reportError(ch, nil, err)
  56. }
  57. }