cpu_apps.chart.sh 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. # shellcheck shell=bash disable=SC2154,SC1072,SC1073,SC2009,SC2162,SC2006,SC2002,SC2086,SC1117
  2. # no need for shebang - this file is loaded from charts.d.plugin
  3. # SPDX-License-Identifier: GPL-3.0-or-later
  4. # netdata
  5. # real-time performance and health monitoring, done right!
  6. # (C) 2016 Costa Tsaousis <costa@tsaousis.gr>
  7. #
  8. # THIS PLUGIN IS OBSOLETE
  9. # USE apps.plugin INSTEAD
  10. # a space separated list of command to monitor
  11. cpu_apps_apps=
  12. # these are required for computing memory in bytes and cpu in seconds
  13. #cpu_apps_pagesize="`getconf PAGESIZE`"
  14. cpu_apps_clockticks="$(getconf CLK_TCK)"
  15. cpu_apps_update_every=60
  16. cpu_apps_check() {
  17. # this should return:
  18. # - 0 to enable the chart
  19. # - 1 to disable the chart
  20. if [ -z "$cpu_apps_apps" ]
  21. then
  22. error "manual configuration required: please set cpu_apps_apps='command1 command2 ...' in $confd/cpu_apps_apps.conf"
  23. return 1
  24. fi
  25. return 0
  26. }
  27. cpu_apps_bc_finalze=
  28. cpu_apps_create() {
  29. echo "CHART chartsd_apps.cpu '' 'Apps CPU' 'milliseconds / $cpu_apps_update_every sec' apps apps stacked 20001 $cpu_apps_update_every"
  30. local x=
  31. for x in $cpu_apps_apps
  32. do
  33. echo "DIMENSION $x $x incremental 1000 $cpu_apps_clockticks"
  34. # this string is needed later in the update() function
  35. # to finalize the instructions for the bc command
  36. cpu_apps_bc_finalze="$cpu_apps_bc_finalze \"SET $x = \"; $x;"
  37. done
  38. return 0
  39. }
  40. cpu_apps_update() {
  41. # do all the work to collect / calculate the values
  42. # for each dimension
  43. # remember: KEEP IT SIMPLE AND SHORT
  44. echo "BEGIN chartsd_apps.cpu"
  45. ps -o pid,comm -C "$cpu_apps_apps" |\
  46. grep -v "COMMAND" |\
  47. (
  48. while read pid name
  49. do
  50. echo "$name+=`cat /proc/$pid/stat | cut -d ' ' -f 14-15`"
  51. done
  52. ) |\
  53. ( sed -e "s/ \+/ /g" -e "s/ /+/g";
  54. echo "$cpu_apps_bc_finalze"
  55. ) | bc
  56. echo "END"
  57. return 0
  58. }