system.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. const os = require('os')
  2. const typeDefs = `
  3. type CPUTime {
  4. user: Int!
  5. nice: Int!
  6. sys: Int!
  7. idle: Int!
  8. irq: Int!
  9. }
  10. type CPU {
  11. model: String!
  12. speed: Int!
  13. times: CPUTime!
  14. }
  15. type NetworkAddress {
  16. address: String!
  17. netmask: String!
  18. family: String!
  19. mac: String!
  20. internal: Boolean!
  21. cidr: String!
  22. scopied: Int
  23. }
  24. type NetworkInterface {
  25. name: String!
  26. addresses: [ NetworkAddress ]!
  27. }
  28. type System {
  29. apiVersion: String!
  30. hostname: String!
  31. type: String!
  32. platform: String!
  33. arch: String!
  34. release: String!
  35. uptime: String!
  36. loadavg: [ Float! ]!
  37. totalmem: String!
  38. freemem: String!
  39. cpus: [ CPU! ]!
  40. networkInterfaces: [ NetworkInterface ]!
  41. }
  42. extend type Query {
  43. system: System!
  44. }
  45. `
  46. function system () {
  47. return {
  48. apiVersion: '0.1',
  49. hostname: os.hostname(),
  50. type: os.type(),
  51. platform: os.platform(),
  52. arch: os.arch(),
  53. release: os.release(),
  54. uptime: os.uptime(),
  55. loadavg: os.loadavg(),
  56. totalmem: os.totalmem(),
  57. freemem: os.freemem(),
  58. cpus: os.cpus(),
  59. networkInterfaces: () => {
  60. const interfaces = os.networkInterfaces()
  61. const ifaceArray = []
  62. for (let key in interfaces) {
  63. ifaceArray.push({
  64. name: key,
  65. addresses: interfaces[key]
  66. })
  67. }
  68. return ifaceArray
  69. }
  70. }
  71. }
  72. const resolvers = {
  73. Query: {
  74. system
  75. }
  76. }
  77. module.exports = { typeDefs, resolvers }