system.js 1.8 KB

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