You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

121 lines
3.3 KiB

  1. const _ = require('lodash')
  2. const Promise = require('bluebird')
  3. const getos = Promise.promisify(require('getos'))
  4. const os = require('os')
  5. const filesize = require('filesize')
  6. const path = require('path')
  7. /* global WIKI */
  8. const dbTypes = {
  9. mysql: 'MySQL',
  10. mariadb: 'MariaDB',
  11. postgres: 'PostgreSQL',
  12. sqlite: 'SQLite',
  13. mssql: 'MS SQL Server'
  14. }
  15. module.exports = {
  16. Query: {
  17. async system() { return {} }
  18. },
  19. Mutation: {
  20. async system() { return {} }
  21. },
  22. SystemQuery: {
  23. async info() { return {} }
  24. },
  25. SystemMutation: { },
  26. SystemInfo: {
  27. configFile() {
  28. return path.join(process.cwd(), 'config.yml')
  29. },
  30. currentVersion() {
  31. return WIKI.version
  32. },
  33. dbType() {
  34. return _.get(dbTypes, WIKI.config.db.type, 'Unknown DB')
  35. },
  36. async dbVersion() {
  37. let version = 'Unknown Version'
  38. switch (WIKI.config.db.type) {
  39. case 'mariadb':
  40. case 'mysql':
  41. const resultMYSQL = await WIKI.models.knex.raw('SELECT VERSION() as version;')
  42. version = _.get(resultMYSQL, '[0][0].version', 'Unknown Version')
  43. break
  44. case 'mssql':
  45. const resultMSSQL = await WIKI.models.knex.raw('SELECT @@VERSION as version;')
  46. version = _.get(resultMSSQL, '[0].version', 'Unknown Version')
  47. break
  48. case 'postgres':
  49. version = _.get(WIKI.models, 'knex.client.version', 'Unknown Version')
  50. break
  51. case 'sqlite':
  52. version = _.get(WIKI.models, 'knex.client.driver.VERSION', 'Unknown Version')
  53. break
  54. }
  55. return version
  56. },
  57. dbHost() {
  58. if (WIKI.config.db.type === 'sqlite') {
  59. return WIKI.config.db.storage
  60. } else {
  61. return WIKI.config.db.host
  62. }
  63. },
  64. latestVersion() {
  65. return '2.0.0' // TODO
  66. },
  67. latestVersionReleaseDate() {
  68. return new Date() // TODO
  69. },
  70. async operatingSystem() {
  71. let osLabel = `${os.type()} (${os.platform()}) ${os.release()} ${os.arch()}`
  72. if (os.platform() === 'linux') {
  73. const osInfo = await getos()
  74. osLabel = `${os.type()} - ${osInfo.dist} (${osInfo.codename || os.platform()}) ${osInfo.release || os.release()} ${os.arch()}`
  75. }
  76. return osLabel
  77. },
  78. hostname() {
  79. return os.hostname()
  80. },
  81. cpuCores() {
  82. return os.cpus().length
  83. },
  84. ramTotal() {
  85. return filesize(os.totalmem())
  86. },
  87. workingDirectory() {
  88. return process.cwd()
  89. },
  90. nodeVersion() {
  91. return process.version.substr(1)
  92. },
  93. redisVersion() {
  94. return WIKI.redis.serverInfo.redis_version
  95. },
  96. redisUsedRAM() {
  97. return WIKI.redis.serverInfo.used_memory_human
  98. },
  99. redisTotalRAM() {
  100. return _.get(WIKI.redis.serverInfo, 'total_system_memory_human', 'N/A')
  101. },
  102. redisHost() {
  103. return WIKI.redis.options.host
  104. },
  105. async groupsTotal() {
  106. const total = await WIKI.models.groups.query().count('* as total').first().pluck('total')
  107. return _.toSafeInteger(total)
  108. },
  109. async pagesTotal() {
  110. const total = await WIKI.models.pages.query().count('* as total').first().pluck('total')
  111. return _.toSafeInteger(total)
  112. },
  113. async usersTotal() {
  114. const total = await WIKI.models.users.query().count('* as total').first().pluck('total')
  115. return _.toSafeInteger(total)
  116. }
  117. }
  118. }