metric_functions.go 4.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. package redisreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/redisreceiver"
  4. import (
  5. "go.opentelemetry.io/collector/pdata/pcommon"
  6. "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/redisreceiver/internal/metadata"
  7. )
  8. // dataPointRecorders is called once at startup. Returns recorders for all metrics (except keyspace)
  9. // we want to extract from Redis INFO.
  10. func (rs *redisScraper) dataPointRecorders() map[string]any {
  11. return map[string]any{
  12. "blocked_clients": rs.mb.RecordRedisClientsBlockedDataPoint,
  13. "client_recent_max_input_buffer": rs.mb.RecordRedisClientsMaxInputBufferDataPoint,
  14. "client_recent_max_output_buffer": rs.mb.RecordRedisClientsMaxOutputBufferDataPoint,
  15. "connected_clients": rs.mb.RecordRedisClientsConnectedDataPoint,
  16. "connected_slaves": rs.mb.RecordRedisSlavesConnectedDataPoint,
  17. "evicted_keys": rs.mb.RecordRedisKeysEvictedDataPoint,
  18. "expired_keys": rs.mb.RecordRedisKeysExpiredDataPoint,
  19. "instantaneous_ops_per_sec": rs.mb.RecordRedisCommandsDataPoint,
  20. "keyspace_hits": rs.mb.RecordRedisKeyspaceHitsDataPoint,
  21. "keyspace_misses": rs.mb.RecordRedisKeyspaceMissesDataPoint,
  22. "latest_fork_usec": rs.mb.RecordRedisLatestForkDataPoint,
  23. "master_repl_offset": rs.mb.RecordRedisReplicationOffsetDataPoint,
  24. "maxmemory": rs.mb.RecordRedisMaxmemoryDataPoint,
  25. "mem_fragmentation_ratio": rs.mb.RecordRedisMemoryFragmentationRatioDataPoint,
  26. "rdb_changes_since_last_save": rs.mb.RecordRedisRdbChangesSinceLastSaveDataPoint,
  27. "rejected_connections": rs.mb.RecordRedisConnectionsRejectedDataPoint,
  28. "repl_backlog_first_byte_offset": rs.mb.RecordRedisReplicationBacklogFirstByteOffsetDataPoint,
  29. "total_commands_processed": rs.mb.RecordRedisCommandsProcessedDataPoint,
  30. "total_connections_received": rs.mb.RecordRedisConnectionsReceivedDataPoint,
  31. "total_net_input_bytes": rs.mb.RecordRedisNetInputDataPoint,
  32. "total_net_output_bytes": rs.mb.RecordRedisNetOutputDataPoint,
  33. "uptime_in_seconds": rs.mb.RecordRedisUptimeDataPoint,
  34. "used_cpu_sys": rs.recordUsedCPUSys,
  35. "used_cpu_sys_children": rs.recordUsedCPUSysChildren,
  36. "used_cpu_sys_main_thread": rs.recordUsedCPUSysMainThread,
  37. "used_cpu_user": rs.recordUsedCPUUser,
  38. "used_cpu_user_children": rs.recordUsedCPUUserChildren,
  39. "used_cpu_user_main_thread": rs.recordUsedCPUUserMainThread,
  40. "used_memory": rs.mb.RecordRedisMemoryUsedDataPoint,
  41. "used_memory_lua": rs.mb.RecordRedisMemoryLuaDataPoint,
  42. "used_memory_peak": rs.mb.RecordRedisMemoryPeakDataPoint,
  43. "used_memory_rss": rs.mb.RecordRedisMemoryRssDataPoint,
  44. }
  45. }
  46. func (rs *redisScraper) recordUsedCPUSys(now pcommon.Timestamp, val float64) {
  47. rs.mb.RecordRedisCPUTimeDataPoint(now, val, metadata.AttributeStateSys)
  48. }
  49. func (rs *redisScraper) recordUsedCPUSysChildren(now pcommon.Timestamp, val float64) {
  50. rs.mb.RecordRedisCPUTimeDataPoint(now, val, metadata.AttributeStateSysChildren)
  51. }
  52. func (rs *redisScraper) recordUsedCPUSysMainThread(now pcommon.Timestamp, val float64) {
  53. rs.mb.RecordRedisCPUTimeDataPoint(now, val, metadata.AttributeStateSysMainThread)
  54. }
  55. func (rs *redisScraper) recordUsedCPUUser(now pcommon.Timestamp, val float64) {
  56. rs.mb.RecordRedisCPUTimeDataPoint(now, val, metadata.AttributeStateUser)
  57. }
  58. func (rs *redisScraper) recordUsedCPUUserChildren(now pcommon.Timestamp, val float64) {
  59. rs.mb.RecordRedisCPUTimeDataPoint(now, val, metadata.AttributeStateUserChildren)
  60. }
  61. func (rs *redisScraper) recordUsedCPUUserMainThread(now pcommon.Timestamp, val float64) {
  62. rs.mb.RecordRedisCPUTimeDataPoint(now, val, metadata.AttributeStateUserMainThread)
  63. }