Performance,Utilities,Monitoring, etc tools for Devuan This tools will be used in Single Board Computers and maybe others device images..
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.
 
 
 

121 lines
5.2 KiB

  1. #! /usr/bin/awk -f
  2. # Maintainer: tuxd3v@sapo.pt
  3. # 2020/05/20
  4. # LAst Colummn is dynamic in size
  5. function state(a,b) {
  6. switch (b) {
  7. case "Discharging":
  8. if( a == "spacing" )
  9. a="-----------"
  10. else if( a == "State" )
  11. a=" State "
  12. else if( a == "AC" )
  13. a=" \033[1;31mUnplugged\033[0m "
  14. else if( a == "bat_state" )
  15. a="\033[1;33m"b"\033[0m"
  16. break
  17. case "Charging":
  18. if( a == "spacing" )
  19. a="--------"
  20. else if( a == "State" )
  21. a=" State "
  22. else if( a == "AC" )
  23. a=" \033[1;32mAC\033[0m "
  24. else if( a == "bat_state" )
  25. a="\033[1;33m"b"\033[0m"
  26. break
  27. case "Full":
  28. if( a == "spacing" )
  29. a="-----"
  30. else if( a == "State" )
  31. a="State"
  32. else if( a == "AC" )
  33. a=" \033[1;32mAC\033[0m "
  34. else if( a == "bat_state" )
  35. a="\033[1;32m"b"\033[0m "
  36. break
  37. case "Not charging":
  38. if( a == "spacing" )
  39. a="------------"
  40. else if( a == "State" )
  41. a=" State "
  42. else if( a == "AC" )
  43. a=" \033[1;32mAC\033[0m "
  44. else if( a == "bat_state" )
  45. a=b
  46. break
  47. default:
  48. a="------"
  49. break
  50. }
  51. return a
  52. }
  53. # First Colummn is dynamic in size bellow 10
  54. function capacity(a) {
  55. if( a < 10 )
  56. return " "
  57. else if( a < 100 )
  58. return " "
  59. else
  60. return ""
  61. }
  62. BEGIN {
  63. source[ "HWMON0" ] = "hwmon0"
  64. source[ "HWMON1" ] = "hwmon1"
  65. getline check < "/sys/class/hwmon/hwmon1/name"
  66. if( check == "axp20x_ac" ){
  67. source[ "HWMON0" ] = "hwmon1"
  68. source[ "HWMON1" ] = "hwmon0"
  69. source[ "AC_name" ] = check
  70. getline source[ "BATTERY_name" ] < sprintf( "/sys/class/hwmon/%s/name", source[ "HWMON1" ] )
  71. }else{
  72. getline source[ "AC_name" ] < sprintf( "/sys/class/hwmon/%s/name", source[ "HWMON0" ] )
  73. source[ "BATTERY_name" ] = check
  74. }
  75. getline source[ "AC_type" ] < sprintf( "/sys/class/hwmon/%s/device/type", source[ "HWMON0" ] )
  76. getline source[ "AC_present" ] < sprintf( "/sys/class/hwmon/%s/device/present", source[ "HWMON0" ] )
  77. getline source[ "AC_online" ] < sprintf( "/sys/class/hwmon/%s/device/online", source[ "HWMON0" ] )
  78. getline source[ "AC_health" ] < sprintf( "/sys/class/hwmon/%s/device/health", source[ "HWMON0" ] )
  79. getline source[ "AC_voltage_now" ] < sprintf( "/sys/class/hwmon/%s/device/voltage_now", source[ "HWMON0" ] )
  80. getline source[ "AC_current_now" ] < sprintf( "/sys/class/hwmon/%s/device/current_now", source[ "HWMON0" ] )
  81. getline source[ "BATTERY_type" ] < sprintf( "/sys/class/hwmon/%s/device/type", source[ "HWMON1" ] )
  82. getline source[ "BATTERY_capacity" ] < sprintf( "/sys/class/hwmon/%s/device/capacity", source[ "HWMON1" ] )
  83. getline source[ "BATTERY_status" ] < sprintf( "/sys/class/hwmon/%s/device/status", source[ "HWMON1" ] )
  84. getline source[ "BATTERY_present" ] < sprintf( "/sys/class/hwmon/%s/device/present", source[ "HWMON1" ] )
  85. getline source[ "BATTERY_online" ] < sprintf( "/sys/class/hwmon/%s/device/online", source[ "HWMON1" ] )
  86. getline source[ "BATTERY_health" ] < sprintf( "/sys/class/hwmon/%s/device/health", source[ "HWMON1" ] )
  87. getline source[ "BATTERY_voltage_now" ] < sprintf( "/sys/class/hwmon/%s/device/voltage_now", source[ "HWMON1" ] )
  88. getline source[ "BATTERY_current_now" ] < sprintf( "/sys/class/hwmon/%s/device/current_now", source[ "HWMON1" ] )
  89. #Pass Values to Units
  90. source[ "AC_voltage_now" ] = source[ "AC_voltage_now" ]/1000000
  91. source[ "AC_current_now" ] = source[ "AC_current_now" ]/1000000
  92. source[ "BATTERY_voltage_now" ] = source[ "BATTERY_voltage_now" ]/1000000
  93. source[ "BATTERY_current_now" ] = source[ "BATTERY_current_now"]/1000000
  94. # Get Dev1 Version
  95. getline Dev1ver < "/etc/devuan_version"
  96. # Correct Battery Capacity when battery offline
  97. if( source["BATTERY_present"] == 0 && source["BATTERY_present"] == 0 )
  98. source["BATTERY_capacity"] = 0
  99. print "+----------------------------+"
  100. printf "| \033[1;35mDE\033[1;31mVUA\033[1;35mN\033[1;32marm\033[0m \033[1;31m%s\033[0m |\n", Dev1ver
  101. printf "+--------------+-------------+---------+--------+------------+------------+%s+\n", state("spacing", source["BATTERY_status"])
  102. printf "| PowerSource | Capacity[%] | Present | Online | Voltage[V] | Current[A] |%s|\n", state("State", source["BATTERY_status"])
  103. printf "+--------------+-------------+---------+--------+------------+------------+%s+\n", state("spacing", source["BATTERY_status"])
  104. printf "|%s | %s | %d | %d | %.4f | %.4f |%s|\n", source["AC_name"],"NA",source["AC_present"],source["AC_online"],source["AC_voltage_now"],source["AC_current_now"], state("AC", source["BATTERY_status"])
  105. printf "+--------------+-------------+---------+--------+------------+------------+%s+\n", state("spacing", source["BATTERY_status"])
  106. printf "|%s| %.4f%s | %d | %d | %.4f | %.4f |%s|\n", source["BATTERY_name"],source["BATTERY_capacity"],capacity(source["BATTERY_capacity"]),source["BATTERY_present"],source[ "BATTERY_online"],source["BATTERY_voltage_now"],source[ "BATTERY_current_now" ], state("bat_state", source["BATTERY_status"])
  107. printf "+--------------+-------------+---------+--------+------------+------------+%s+\n", state("spacing", source["BATTERY_status"])
  108. exit 0
  109. }