Blob Blame History Raw
<?xml version="1.0" ?>
<!DOCTYPE vhostmd SYSTEM "vhostmd.dtd">

<!--

Configuration file for virtual host metrics daemon (vhostmd).

A better, less noisy, more minimal configuration file
which doesn't depend on Xen.

Supported metric types are: int32, uint32, int64, uint64, real32,
real64, and string.

A metric's value is set to the output produced by executing its action.

'action' can include the special token NAME, in which case the name of
the vm currently under inspection is substituted for NAME.  Only useful
within the vm element.

-->


<!--     1         2         3         4         5         6         -->
<!-- 678901234567890123456789012345678901234567890123456789012345678 -->


<!--
We sometimes use the following awk form to filter the output of the
virsh command (mostly `virsh -r CONNECT dominfo NAME' - use
`virsh -r dominfo <dom id>' to test on the commandline) into a standard
format like

  ID:6
  NAME:ls3055v0
  UUID:955c3b65-d013-547f-321b-9fea65439c40
  OS_TYPE:hvm
  STATE:running
  CPU(S):4
  CPU_TIME:433016.4:S
  MAX_MEMORY:20000000:KB
  USED_MEMORY:16384000:KB
  AUTOSTART:disable

We do this to extract numbers out of physical quantities in a reliable
way.
-->
<!--
          |awk -F ':' '
          function mkvarnam(s)  { # UPPER_CASE_UNDERSCORE
            sub("(^[[:space:]]+|[[:space:]]+$)", "", s);  # trim
            gsub("[[:space:]]+", "_", s); s = toupper(s);
            return s;
          }
          function filt_phys(s, sep,    num, unit) {  # 42.0 KM
            sub("(^[[:space:]]+|[[:space:]]+$)", "", s);  # trim
            if ( s ~ /^[0-9]*\.?[0-9]+[[:space:]]*[[:alpha:]]+$/ )
            {
              num = s; unit = s;
              sub("[[:space:]]*[[:alpha:]]+$", "", num);
              sub("^[0-9]*[.]?[0-9]+[[:space:]]*", "", unit);
              return num sep toupper(unit);
            }
            else
            {
              return s;
            }
          }
          /:/ {
            d1    = substr($0, 1, index($0, ":") - 1);
            rest  = substr($0, index($0, ":") + 1);
            printf("%s:%s\n", mkvarnam(d1), filt_phys(rest, ":"));
          }'                                  \
-->

<vhostmd>
  <globals>
    <disk>
      <name>host-metrics-disk</name>
      <path>/dev/shm/vhostmd0</path>
      <!-- must be between [128 KB, 256 MB] in size -->
      <size unit="k">256</size>
    </disk>
    <virtio>
      <max_channels>1024</max_channels>
      <expiration_time>15</expiration_time>
    </virtio>
    <update_period>60</update_period>
    <path>/bin:/sbin:/usr/bin:/usr/sbin:/usr/share/vhostmd/scripts</path>
    <transport>vbd</transport>
    <!-- <transport>xenstore</transport> -->
    <transport>virtio</transport>
  </globals>
  <metrics>
    <metric type="string" context="host">
      <name>HostName</name>
      <action>hostname</action>
    </metric>
    <metric type="uint64" context="host">
      <name>Time</name>
      <action>date +%s</action>
    </metric>
    <metric type="string" context="host">
      <name>VirtualizationVendor</name>
      <action>
        rpm -q --queryformat "%{VENDOR}\n" libvirt | sort -u
      </action>
    </metric>
    <!-- SAP "CIM"  -->
    <metric type="string" context="host">
      <name>VirtProductInfo</name>
      <action>
        virsh -r CONNECT version        \
          |awk -F ':' '
          function mkvarnam(s)  { # UPPER_CASE_UNDERSCORE
            sub("(^[[:space:]]+|[[:space:]]+$)", "", s);  # trim
            gsub("[[:space:]]+", "_", s); s = toupper(s);
            return s;
          }
          function filt_phys(s, sep,    num, unit) {  # 42.0 KM
            sub("(^[[:space:]]+|[[:space:]]+$)", "", s);  # trim
            if ( s ~ /^[0-9]*\.?[0-9]+[[:space:]]*[[:alpha:]]+$/ )
            {
              num = s; unit = s;
              sub("[[:space:]]*[[:alpha:]]+$", "", num);
              sub("^[0-9]*[.]?[0-9]+[[:space:]]*", "", unit);
              return num sep toupper(unit);
            }
            else
            {
              return s;
            }
          }
          /:/ {
            d1    = substr($0, 1, index($0, ":") - 1);
            rest  = substr($0, index($0, ":") + 1);
            printf("%s:%s\n", mkvarnam(d1), filt_phys(rest, ":"));
          }'                                  \
          | awk -F: '$1 == "USING_API" { print $2; }'
      </action>
    </metric>
    <!-- SAP "CIM"  -->
    <metric type="string" context="host">
      <name>HostSystemInfo</name>
      <action>hostname -s</action>
    </metric>
    <!-- SAP "XCIM" -->
    <metric type="uint32" context="host">
      <name>NumberOfPhysicalCPUs</name>
      <!-- physical CPUs usable by the virtual machines -->
      <!-- SAP "CIM" uses "NumberOfPhysicalCPUsUtilized"  -->
      <!-- which means something different, i.e.          -->
      <!--  "physical CPUs used by the virtual machines"  -->
      <!-- but may be calculated (on client side) by      -->
      <!-- Delta TotalCPUTime / Delta ElapsedTime         -->
      <action>
        virsh -r CONNECT nodeinfo       \
          |awk -F ':' '
          function mkvarnam(s)  { # UPPER_CASE_UNDERSCORE
            sub("(^[[:space:]]+|[[:space:]]+$)", "", s);  # trim
            gsub("[[:space:]]+", "_", s); s = toupper(s);
            return s;
          }
          function filt_phys(s, sep,    num, unit) {  # 42.0 KM
            sub("(^[[:space:]]+|[[:space:]]+$)", "", s);  # trim
            if ( s ~ /^[0-9]*\.?[0-9]+[[:space:]]*[[:alpha:]]+$/ )
            {
              num = s; unit = s;
              sub("[[:space:]]*[[:alpha:]]+$", "", num);
              sub("^[0-9]*[.]?[0-9]+[[:space:]]*", "", unit);
              return num sep toupper(unit);
            }
            else
            {
              return s;
            }
          }
          /:/ {
            d1    = substr($0, 1, index($0, ":") - 1);
            rest  = substr($0, index($0, ":") + 1);
            printf("%s:%s\n", mkvarnam(d1), filt_phys(rest, ":"));
          }'                                  \
          | awk -F: '$1 == "CPU(S)" { print $2; }'
      </action>
    </metric>
    <!-- SAP "CIM"  -->
    <metric type="uint64" context="host">
      <name>MemoryAllocatedToVirtualServers</name>
      <!-- physical memory used by the virtual machines,      -->
      <!-- (_not_ physical memory usable by the virtual       -->
      <!-- machines)                                          -->
      <action>
        free|egrep -i '^[[:space:]]*(Mem:)'   \
          | awk 'BEGIN { sum = 0; }
              { sum += $3; }
              END { printf "%d\n", sum/1024; }'
      </action>
    </metric>
    <!-- SAP "CIM"  -->
    <metric type="uint64" context="host">
      <name>FreePhysicalMemory</name>
      <action>
        free|egrep -i '^[[:space:]]*(Mem:)'   \
          | awk 'BEGIN { sum = 0; }
              { sum += $4; }
              END { printf "%d\n", sum/1024; }'
      </action>
    </metric>
    <!-- SAP "CIM"  -->
    <metric type="uint64" context="host">
      <name>FreeVirtualMemory</name>
      <action>
        free|egrep -i '^[[:space:]]*(Mem:|Swap:)'   \
          | awk 'BEGIN { sum = 0; }
              { sum += $4; }
              END { printf "%d\n", sum/1024; }'
      </action>
    </metric>
    <!-- SAP "CIM"  -->
    <metric type="uint64" context="host">
      <name>UsedVirtualMemory</name>
      <action>
        free|egrep -i '^[[:space:]]*(Mem:|Swap:)'   \
          | awk 'BEGIN { sum = 0; }
              { sum += $3; }
              END { printf "%d\n", sum/1024; }'
      </action>
    </metric>
    <!-- SAP "XCIM" -->
    <metric type="uint64" context="host">
      <name>PagedInMemory</name>
      <action>
        vmstat -s | awk 'BEGIN {
                        cmd = "getconf PAGESIZE";
                        cmd | getline pagesize;
                        close(cmd);
                      }
                      /pages swapped in/ {
                        printf "%d\n", $1 / 1024 * pagesize / 1024;
                      }'
      </action>
    </metric>
    <!-- SAP "CIM"  -->
    <metric type="uint64" context="host">
      <name>PagedOutMemory</name>
      <action>
        vmstat -s | awk 'BEGIN {
                        cmd = "getconf PAGESIZE";
                        cmd | getline pagesize;
                        close(cmd);
                      }
                      /pages swapped out/ {
                        printf "%d\n", $1 / 1024 * pagesize / 1024;
                      }'
      </action>
    </metric>
    <!-- SAP "CIM"  -->
    <metric type="real64" context="host">
      <name>TotalCPUTime</name>
      <action>
        awk '
        function user_hz(   hz)
        {
          cmd = "getconf CLK_TCK";
          cmd | getline;
          hz  = $1;
          close(cmd);

          return hz;
        }

        BEGIN {
          USER_HZ      = user_hz();
          TotalCPUTime = 0;

          while ( 0 &lt; ( getline &lt; "/proc/stat" ) )
          {
            if ( "cpu" == $1 )
            {
              TotalCPUTime = $2 + $3 + $4;

              break;
            }
          }
          close("/proc/stat");

          #printf "USER_HZ = %d\n", USER_HZ  | "cat 1&gt;&amp;2";
          TotalCPUTime /= USER_HZ;
          printf "%f\n", TotalCPUTime;

          #close("cat 1&gt;&amp;2");
        }'
      </action>
    </metric>
    <!-- SAP "CIM"  -->
    <metric type="real64" context="vm">
      <name>TotalCPUTime</name>
      <action>
        virsh -r CONNECT dominfo NAME   \
          |awk -F ':' '
          function mkvarnam(s)  { # UPPER_CASE_UNDERSCORE
            sub("(^[[:space:]]+|[[:space:]]+$)", "", s);  # trim
            gsub("[[:space:]]+", "_", s); s = toupper(s);
            return s;
          }
          function filt_phys(s, sep,    num, unit) {  # 42.0 KM
            sub("(^[[:space:]]+|[[:space:]]+$)", "", s);  # trim
            if ( s ~ /^[0-9]*\.?[0-9]+[[:space:]]*[[:alpha:]]+$/ )
            {
              num = s; unit = s;
              sub("[[:space:]]*[[:alpha:]]+$", "", num);
              sub("^[0-9]*[.]?[0-9]+[[:space:]]*", "", unit);
              return num sep toupper(unit);
            }
            else
            {
              return s;
            }
          }
          /:/ {
            d1    = substr($0, 1, index($0, ":") - 1);
            rest  = substr($0, index($0, ":") + 1);
            printf("%s:%s\n", mkvarnam(d1), filt_phys(rest, ":"));
          }'                                  \
          | awk -F: '$1 == "CPU_TIME" { print $2; }'
      </action>
    </metric>
    <!-- SAP "CIM"  -->
    <metric type="uint32" context="vm">
      <name>ResourceProcessorLimit</name>
      <action>
        virsh -r CONNECT dominfo NAME   \
          |awk -F ':' '
          function mkvarnam(s)  { # UPPER_CASE_UNDERSCORE
            sub("(^[[:space:]]+|[[:space:]]+$)", "", s);  # trim
            gsub("[[:space:]]+", "_", s); s = toupper(s);
            return s;
          }
          function filt_phys(s, sep,    num, unit) {  # 42.0 KM
            sub("(^[[:space:]]+|[[:space:]]+$)", "", s);  # trim
            if ( s ~ /^[0-9]*\.?[0-9]+[[:space:]]*[[:alpha:]]+$/ )
            {
              num = s; unit = s;
              sub("[[:space:]]*[[:alpha:]]+$", "", num);
              sub("^[0-9]*[.]?[0-9]+[[:space:]]*", "", unit);
              return num sep toupper(unit);
            }
            else
            {
              return s;
            }
          }
          /:/ {
            d1    = substr($0, 1, index($0, ":") - 1);
            rest  = substr($0, index($0, ":") + 1);
            printf("%s:%s\n", mkvarnam(d1), filt_phys(rest, ":"));
          }'                                  \
          | awk -F: '$1 == "CPU(S)" { print $2; }'
      </action>
    </metric>
    <!-- SAP "CIM"  -->
    <metric type="uint64" context="vm">
      <name>ResourceMemoryLimit</name>
      <action>
        virsh -r CONNECT dominfo NAME   \
          |awk -F ':' '
          function mkvarnam(s)  { # UPPER_CASE_UNDERSCORE
            sub("(^[[:space:]]+|[[:space:]]+$)", "", s);  # trim
            gsub("[[:space:]]+", "_", s); s = toupper(s);
            return s;
          }
          function filt_phys(s, sep,    num, unit) {  # 42.0 KM
            sub("(^[[:space:]]+|[[:space:]]+$)", "", s);  # trim
            if ( s ~ /^[0-9]*\.?[0-9]+[[:space:]]*[[:alpha:]]+$/ )
            {
              num = s; unit = s;
              sub("[[:space:]]*[[:alpha:]]+$", "", num);
              sub("^[0-9]*[.]?[0-9]+[[:space:]]*", "", unit);
              return num sep toupper(unit);
            }
            else
            {
              return s;
            }
          }
          /:/ {
            d1    = substr($0, 1, index($0, ":") - 1);
            rest  = substr($0, index($0, ":") + 1);
            printf("%s:%s\n", mkvarnam(d1), filt_phys(rest, ":"));
          }'                                  \
          | awk -F: '$1 == "MAX_MEMORY" { print int($2/1024); }'
      </action>
    </metric>
    <!-- SAP "CIM"  -->
    <metric type="uint64" context="vm">
      <name>PhysicalMemoryAllocatedToVirtualSystem</name>
      <action>
        virsh -r CONNECT dominfo NAME   \
          |awk -F ':' '
          function mkvarnam(s)  { # UPPER_CASE_UNDERSCORE
            sub("(^[[:space:]]+|[[:space:]]+$)", "", s);  # trim
            gsub("[[:space:]]+", "_", s); s = toupper(s);
            return s;
          }
          function filt_phys(s, sep,    num, unit) {  # 42.0 KM
            sub("(^[[:space:]]+|[[:space:]]+$)", "", s);  # trim
            if ( s ~ /^[0-9]*\.?[0-9]+[[:space:]]*[[:alpha:]]+$/ )
            {
              num = s; unit = s;
              sub("[[:space:]]*[[:alpha:]]+$", "", num);
              sub("^[0-9]*[.]?[0-9]+[[:space:]]*", "", unit);
              return num sep toupper(unit);
            }
            else
            {
              return s;
            }
          }
          /:/ {
            d1    = substr($0, 1, index($0, ":") - 1);
            rest  = substr($0, index($0, ":") + 1);
            printf("%s:%s\n", mkvarnam(d1), filt_phys(rest, ":"));
          }'                                  \
          | awk -F: '$1 == "USED_MEMORY" { print int($2/1024); }'
      </action>
    </metric>
  </metrics>
</vhostmd>
<!--
  vi:ts=2:sw=2:expandtab:ignorecase:nu:ruler
-->
<!-- EOF -->