software_versions_dimension.rb 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. # frozen_string_literal: true
  2. class Admin::Metrics::Dimension::SoftwareVersionsDimension < Admin::Metrics::Dimension::BaseDimension
  3. include Redisable
  4. def key
  5. 'software_versions'
  6. end
  7. protected
  8. def perform_query
  9. [mastodon_version, ruby_version, postgresql_version, redis_version]
  10. end
  11. def mastodon_version
  12. value = Mastodon::Version.to_s
  13. {
  14. key: 'mastodon',
  15. human_key: 'Mastodon',
  16. value: value,
  17. human_value: value,
  18. }
  19. end
  20. def ruby_version
  21. value = "#{RUBY_VERSION}p#{RUBY_PATCHLEVEL}"
  22. {
  23. key: 'ruby',
  24. human_key: 'Ruby',
  25. value: value,
  26. human_value: value,
  27. }
  28. end
  29. def postgresql_version
  30. value = ActiveRecord::Base.connection.execute('SELECT VERSION()').first['version'].match(/\A(?:PostgreSQL |)([^\s]+).*\z/)[1]
  31. {
  32. key: 'postgresql',
  33. human_key: 'PostgreSQL',
  34. value: value,
  35. human_value: value,
  36. }
  37. end
  38. def redis_version
  39. value = redis_info['redis_version']
  40. {
  41. key: 'redis',
  42. human_key: 'Redis',
  43. value: value,
  44. human_value: value,
  45. }
  46. end
  47. def redis_info
  48. @redis_info ||= begin
  49. if redis.is_a?(Redis::Namespace)
  50. redis.redis.info
  51. else
  52. redis.info
  53. end
  54. end
  55. end
  56. end