system.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 / MariaDB',
  10. postgres: 'PostgreSQL',
  11. sqlite: 'SQLite',
  12. mssql: 'MS SQL Server'
  13. }
  14. module.exports = {
  15. Query: {
  16. async system() { return {} }
  17. },
  18. Mutation: {
  19. async system() { return {} }
  20. },
  21. SystemQuery: {
  22. async info() { return {} }
  23. },
  24. SystemMutation: { },
  25. SystemInfo: {
  26. configFile() {
  27. return path.join(process.cwd(), 'config.yml')
  28. },
  29. currentVersion() {
  30. return WIKI.version
  31. },
  32. dbType() {
  33. return _.get(dbTypes, WIKI.config.db.type, 'Unknown DB')
  34. },
  35. dbVersion() {
  36. return _.get(WIKI.models, 'knex.client.version', 'Unknown version')
  37. },
  38. dbHost() {
  39. return WIKI.config.db.host
  40. },
  41. latestVersion() {
  42. return '2.0.0' // TODO
  43. },
  44. latestVersionReleaseDate() {
  45. return new Date() // TODO
  46. },
  47. async operatingSystem() {
  48. let osLabel = `${os.type()} (${os.platform()}) ${os.release()} ${os.arch()}`
  49. if (os.platform() === 'linux') {
  50. const osInfo = await getos()
  51. osLabel = `${os.type()} - ${osInfo.dist} (${osInfo.codename || os.platform()}) ${osInfo.release || os.release()} ${os.arch()}`
  52. }
  53. return osLabel
  54. },
  55. hostname() {
  56. return os.hostname()
  57. },
  58. cpuCores() {
  59. return os.cpus().length
  60. },
  61. ramTotal() {
  62. return filesize(os.totalmem())
  63. },
  64. workingDirectory() {
  65. return process.cwd()
  66. },
  67. nodeVersion() {
  68. return process.version.substr(1)
  69. },
  70. redisVersion() {
  71. return WIKI.redis.serverInfo.redis_version
  72. },
  73. redisUsedRAM() {
  74. return WIKI.redis.serverInfo.used_memory_human
  75. },
  76. redisTotalRAM() {
  77. return _.get(WIKI.redis.serverInfo, 'total_system_memory_human', 'N/A')
  78. },
  79. redisHost() {
  80. return WIKI.redis.options.host
  81. },
  82. async groupsTotal() {
  83. const total = await WIKI.models.groups.query().count('* as total').first().pluck('total')
  84. return _.toSafeInteger(total)
  85. },
  86. async pagesTotal() {
  87. const total = await WIKI.models.pages.query().count('* as total').first().pluck('total')
  88. return _.toSafeInteger(total)
  89. },
  90. async usersTotal() {
  91. const total = await WIKI.models.users.query().count('* as total').first().pluck('total')
  92. return _.toSafeInteger(total)
  93. }
  94. }
  95. }