system.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. }
  13. module.exports = {
  14. Query: {
  15. async system() { return {} }
  16. },
  17. Mutation: {
  18. async system() { return {} }
  19. },
  20. SystemQuery: {
  21. async info(obj, args, context, info) {
  22. let osLabel = `${os.type()} (${os.platform()}) ${os.release()} ${os.arch()}`
  23. if (os.platform() === 'linux') {
  24. const osInfo = await getos()
  25. osLabel = `${os.type()} - ${osInfo.dist} (${osInfo.codename || os.platform()}) ${osInfo.release || os.release()} ${os.arch()}`
  26. }
  27. return {
  28. configFile: path.join(process.cwd(), 'config.yml'),
  29. currentVersion: WIKI.version,
  30. dbType: _.get(dbTypes, WIKI.config.db.type, 'Unknown DB'),
  31. dbVersion: WIKI.db.inst.options.databaseVersion,
  32. dbHost: WIKI.db.inst.options.host,
  33. latestVersion: WIKI.version, // TODO
  34. latestVersionReleaseDate: new Date(), // TODO
  35. operatingSystem: osLabel,
  36. hostname: os.hostname(),
  37. cpuCores: os.cpus().length,
  38. ramTotal: filesize(os.totalmem()),
  39. workingDirectory: process.cwd(),
  40. nodeVersion: process.version.substr(1),
  41. redisVersion: WIKI.redis.serverInfo.redis_version,
  42. redisUsedRAM: WIKI.redis.serverInfo.used_memory_human,
  43. redisTotalRAM: _.get(WIKI.redis.serverInfo, 'total_system_memory_human', 'N/A'),
  44. redisHost: WIKI.redis.options.host
  45. }
  46. }
  47. },
  48. SystemMutation: { }
  49. }