nut.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /* Licensed to the public under the Apache License 2.0. */
  2. 'use strict';
  3. 'require baseclass';
  4. return baseclass.extend({
  5. title: _('UPS'),
  6. rrdargs: function(graph, host, plugin, plugin_instance, dtype) {
  7. var definitions = [];
  8. var instances;
  9. function find_instances(dtype, wanted) {
  10. var matching = graph.dataInstances(host, plugin, plugin_instance, dtype).filter(function(instance) {
  11. return wanted.indexOf(instance) > -1;
  12. });
  13. return matching.length ? { [dtype]: matching } : null;
  14. }
  15. if ((instances = find_instances('voltage', [ 'input', 'output' ])) != null) {
  16. definitions.push({
  17. title: "%H: AC voltages on UPS \"%pi\"",
  18. vlabel: "V",
  19. number_format: "%5.1lfV",
  20. data: {
  21. instances: instances,
  22. options: {
  23. voltage_output : { color: "00e000", title: "Output voltage", noarea: true, overlay: true },
  24. voltage_input : { color: "ffb000", title: "Input voltage", noarea: true, overlay: true }
  25. }
  26. }
  27. });
  28. }
  29. if ((instances = find_instances('voltage', [ 'battery' ])) != null) {
  30. definitions.push({
  31. title: "%H: Battery voltage on UPS \"%pi\"",
  32. vlabel: "V",
  33. number_format: "%5.1lfV",
  34. data: {
  35. instances: instances,
  36. options: {
  37. voltage: { color: "0000ff", title: "Battery voltage", noarea: true, overlay: true }
  38. }
  39. }
  40. });
  41. }
  42. if ((instances = find_instances('current', [ 'battery', 'output' ])) != null) {
  43. definitions.push({
  44. title: "%H: Current on UPS \"%pi\"",
  45. vlabel: "A",
  46. number_format: "%5.3lfA",
  47. data: {
  48. instances: instances,
  49. options: {
  50. current_output : { color: "00e000", title: "Output current", noarea: true, overlay: true },
  51. current_battery: { color: "0000ff", title: "Battery current", noarea: true, overlay: true }
  52. }
  53. }
  54. });
  55. }
  56. if ((instances = find_instances('percent', [ 'charge', 'load' ])) != null) {
  57. definitions.push({
  58. title: "%H: Battery charge/load on UPS \"%pi\"",
  59. vlabel: "Percent",
  60. y_min: "0",
  61. y_max: "100",
  62. number_format: "%5.1lf%%",
  63. data: {
  64. instances: instances,
  65. options: {
  66. percent_charge: { color: "00ff00", title: "Charge level", noarea: true, overlay: true },
  67. percent_load: { color: "ff0000", title: "Load", noarea: true, overlay: true }
  68. }
  69. }
  70. });
  71. }
  72. if ((instances = find_instances('temperature', [ 'battery' ])) != null) {
  73. /* Note: This is in ISO8859-1 for rrdtool. Welcome to the 20th century. */
  74. definitions.push({
  75. title: "%H: Battery temperature on UPS \"%pi\"",
  76. vlabel: "\u00b0C",
  77. number_format: "%5.1lf\u00b0C",
  78. data: {
  79. instances: instances,
  80. options: {
  81. temperature_battery: { color: "ffb000", title: "Battery temperature", noarea: true }
  82. }
  83. }
  84. });
  85. }
  86. if ((instances = find_instances('timeleft', [ 'battery' ])) != null) {
  87. definitions.push({
  88. title: "%H: Time left on UPS \"%pi\"",
  89. vlabel: "Minutes",
  90. number_format: "%.1lfm",
  91. data: {
  92. instances: instances,
  93. options: {
  94. timeleft_battery: { color: "0000ff", title: "Time left", transform_rpn: "60,/", noarea: true }
  95. }
  96. }
  97. });
  98. }
  99. if ((instances = find_instances('power', [ 'watt-ups' ])) != null) {
  100. definitions.push({
  101. title: "%H: Power on UPS \"%pi\"",
  102. vlabel: "Watt",
  103. number_format: "%5.1lf%%",
  104. data: {
  105. instances: instances,
  106. options: {
  107. ['power_watt-ups']: { color: "00ff00", title: "Power level (Watt)" }
  108. }
  109. }
  110. });
  111. }
  112. if ((instances = find_instances('power', [ 'ups' ])) != null) {
  113. definitions.push({
  114. title: "%H: Power on UPS \"%pi\"",
  115. vlabel: "VA",
  116. number_format: "%5.1lf%%",
  117. data: {
  118. instances: instances,
  119. options: {
  120. power_ups: { color: "00ff00", title: "Power level (VA)" }
  121. }
  122. }
  123. });
  124. }
  125. if ((instances = find_instances('frequency', [ 'input', 'output' ])) != null) {
  126. definitions.push({
  127. title: "%H: Frequencies on UPS \"%pi\"",
  128. vlabel: "Hz",
  129. number_format: "%5.1lfHz",
  130. data: {
  131. instances: instances,
  132. options: {
  133. frequency_output : { color: "00e000", title: "Output frequency", noarea: true, overlay: true },
  134. frequency_input : { color: "ffb000", title: "Input frequency", noarea: true, overlay: true }
  135. }
  136. }
  137. });
  138. }
  139. return definitions;
  140. }
  141. });