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.

54 lines
1.7 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 / 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. return {
  29. configFile: path.join(process.cwd(), 'config.yml'),
  30. currentVersion: WIKI.version,
  31. dbType: _.get(dbTypes, WIKI.config.db.type, 'Unknown DB'),
  32. dbVersion: _.get(WIKI.db, 'knex.client.version', 'Unknown version'),
  33. dbHost: WIKI.config.db.host,
  34. latestVersion: WIKI.version, // TODO
  35. latestVersionReleaseDate: new Date(), // TODO
  36. operatingSystem: osLabel,
  37. hostname: os.hostname(),
  38. cpuCores: os.cpus().length,
  39. ramTotal: filesize(os.totalmem()),
  40. workingDirectory: process.cwd(),
  41. nodeVersion: process.version.substr(1),
  42. redisVersion: WIKI.redis.serverInfo.redis_version,
  43. redisUsedRAM: WIKI.redis.serverInfo.used_memory_human,
  44. redisTotalRAM: _.get(WIKI.redis.serverInfo, 'total_system_memory_human', 'N/A'),
  45. redisHost: WIKI.redis.options.host
  46. }
  47. }
  48. },
  49. SystemMutation: { }
  50. }