e2f0417
e2f0417
e2f0417
e2f0417
e2f0417
e2f0417
Configuration file for virtual host metrics daemon (vhostmd).
e2f0417
e2f0417
A better, less noisy, more minimal configuration file
e2f0417
which doesn't depend on Xen.
e2f0417
e2f0417
Supported metric types are: int32, uint32, int64, uint64, real32,
e2f0417
real64, and string.
e2f0417
e2f0417
A metric's value is set to the output produced by executing its action.
e2f0417
e2f0417
'action' can include the special token NAME, in which case the name of
e2f0417
the vm currently under inspection is substituted for NAME.  Only useful
e2f0417
within the vm element.
e2f0417
e2f0417
-->
e2f0417
1279120
1279120
1279120
1279120
1279120
1279120
1279120
We sometimes use the following awk form to filter the output of the
1279120
virsh command (mostly `virsh -r CONNECT dominfo NAME' - use
1279120
`virsh -r dominfo <dom id>' to test on the commandline) into a standard
1279120
format like
1279120
1279120
  ID:6
1279120
  NAME:ls3055v0
1279120
  UUID:955c3b65-d013-547f-321b-9fea65439c40
1279120
  OS_TYPE:hvm
1279120
  STATE:running
1279120
  CPU(S):4
1279120
  CPU_TIME:433016.4:S
1279120
  MAX_MEMORY:20000000:KB
1279120
  USED_MEMORY:16384000:KB
1279120
  AUTOSTART:disable
1279120
1279120
We do this to extract numbers out of physical quantities in a reliable
1279120
way.
1279120
-->
1279120
1279120
          |awk -F ':' '
1279120
          function mkvarnam(s)  { # UPPER_CASE_UNDERSCORE
1279120
            sub("(^[[:space:]]+|[[:space:]]+$)", "", s);  # trim
1279120
            gsub("[[:space:]]+", "_", s); s = toupper(s);
1279120
            return s;
1279120
          }
1279120
          function filt_phys(s, sep,    num, unit) {  # 42.0 KM
1279120
            sub("(^[[:space:]]+|[[:space:]]+$)", "", s);  # trim
1279120
            if ( s ~ /^[0-9]*\.?[0-9]+[[:space:]]*[[:alpha:]]+$/ )
1279120
            {
1279120
              num = s; unit = s;
1279120
              sub("[[:space:]]*[[:alpha:]]+$", "", num);
1279120
              sub("^[0-9]*[.]?[0-9]+[[:space:]]*", "", unit);
1279120
              return num sep toupper(unit);
1279120
            }
1279120
            else
1279120
            {
1279120
              return s;
1279120
            }
1279120
          }
1279120
          /:/ {
1279120
            d1    = substr($0, 1, index($0, ":") - 1);
1279120
            rest  = substr($0, index($0, ":") + 1);
1279120
            printf("%s:%s\n", mkvarnam(d1), filt_phys(rest, ":"));
1279120
          }'                                  \
1279120
-->
1279120
e2f0417
<vhostmd>
e2f0417
  <globals>
e2f0417
    <disk>
e2f0417
      <name>host-metrics-disk</name>
e2f0417
      <path>/dev/shm/vhostmd0</path>
e2f0417
      
e2f0417
      <size unit="k">256</size>
e2f0417
    </disk>
24499ef
    <virtio>
24499ef
      <max_channels>1024</max_channels>
24499ef
      <expiration_time>15</expiration_time>
24499ef
    </virtio>
e2f0417
    <update_period>60</update_period>
e2f0417
    <path>/bin:/sbin:/usr/bin:/usr/sbin:/usr/share/vhostmd/scripts</path>
e2f0417
    <transport>vbd</transport>
e2f0417
    
24499ef
    <transport>virtio</transport>
e2f0417
  </globals>
e2f0417
  <metrics>
e2f0417
    <metric type="string" context="host">
e2f0417
      <name>HostName</name>
e2f0417
      <action>hostname</action>
e2f0417
    </metric>
65ca3e0
    <metric type="uint64" context="host">
65ca3e0
      <name>Time</name>
65ca3e0
      <action>date +%s</action>
65ca3e0
    </metric>
e2f0417
    <metric type="string" context="host">
e2f0417
      <name>VirtualizationVendor</name>
dd2e205
      <action>
24499ef
        rpm -q --queryformat "%{VENDOR}\n" libvirt | sort -u
dd2e205
      </action>
e2f0417
    </metric>
b1baa92
    
e2f0417
    <metric type="string" context="host">
b1baa92
      <name>VirtProductInfo</name>
dd2e205
      <action>
1279120
        virsh -r CONNECT version        \
1279120
          |awk -F ':' '
1279120
          function mkvarnam(s)  { # UPPER_CASE_UNDERSCORE
1279120
            sub("(^[[:space:]]+|[[:space:]]+$)", "", s);  # trim
1279120
            gsub("[[:space:]]+", "_", s); s = toupper(s);
1279120
            return s;
1279120
          }
1279120
          function filt_phys(s, sep,    num, unit) {  # 42.0 KM
1279120
            sub("(^[[:space:]]+|[[:space:]]+$)", "", s);  # trim
1279120
            if ( s ~ /^[0-9]*\.?[0-9]+[[:space:]]*[[:alpha:]]+$/ )
1279120
            {
1279120
              num = s; unit = s;
1279120
              sub("[[:space:]]*[[:alpha:]]+$", "", num);
1279120
              sub("^[0-9]*[.]?[0-9]+[[:space:]]*", "", unit);
1279120
              return num sep toupper(unit);
1279120
            }
1279120
            else
1279120
            {
1279120
              return s;
1279120
            }
1279120
          }
1279120
          /:/ {
1279120
            d1    = substr($0, 1, index($0, ":") - 1);
1279120
            rest  = substr($0, index($0, ":") + 1);
1279120
            printf("%s:%s\n", mkvarnam(d1), filt_phys(rest, ":"));
1279120
          }'                                  \
1279120
          | awk -F: '$1 == "USING_API" { print $2; }'
dd2e205
      </action>
e2f0417
    </metric>
b1baa92
    
b1baa92
    <metric type="string" context="host">
b1baa92
      <name>HostSystemInfo</name>
b1baa92
      <action>hostname -s</action>
e2f0417
    </metric>
1279120
    
e2f0417
    <metric type="uint32" context="host">
1279120
      <name>NumberOfPhysicalCPUs</name>
1279120
      
1279120
      
1279120
      
1279120
      
1279120
      
1279120
      
dd2e205
      <action>
1279120
        virsh -r CONNECT nodeinfo       \
1279120
          |awk -F ':' '
1279120
          function mkvarnam(s)  { # UPPER_CASE_UNDERSCORE
1279120
            sub("(^[[:space:]]+|[[:space:]]+$)", "", s);  # trim
1279120
            gsub("[[:space:]]+", "_", s); s = toupper(s);
1279120
            return s;
1279120
          }
1279120
          function filt_phys(s, sep,    num, unit) {  # 42.0 KM
1279120
            sub("(^[[:space:]]+|[[:space:]]+$)", "", s);  # trim
1279120
            if ( s ~ /^[0-9]*\.?[0-9]+[[:space:]]*[[:alpha:]]+$/ )
1279120
            {
1279120
              num = s; unit = s;
1279120
              sub("[[:space:]]*[[:alpha:]]+$", "", num);
1279120
              sub("^[0-9]*[.]?[0-9]+[[:space:]]*", "", unit);
1279120
              return num sep toupper(unit);
1279120
            }
1279120
            else
1279120
            {
1279120
              return s;
1279120
            }
1279120
          }
1279120
          /:/ {
1279120
            d1    = substr($0, 1, index($0, ":") - 1);
1279120
            rest  = substr($0, index($0, ":") + 1);
1279120
            printf("%s:%s\n", mkvarnam(d1), filt_phys(rest, ":"));
1279120
          }'                                  \
1279120
          | awk -F: '$1 == "CPU(S)" { print $2; }'
dd2e205
      </action>
e2f0417
    </metric>
b1baa92
    
e2f0417
    <metric type="uint64" context="host">
b1baa92
      <name>MemoryAllocatedToVirtualServers</name>
1279120
      
1279120
      
1279120
      
dd2e205
      <action>
1279120
        free|egrep -i '^[[:space:]]*(Mem:)'   \
1279120
          | awk 'BEGIN { sum = 0; }
1279120
              { sum += $3; }
1279120
              END { printf "%d\n", sum/1024; }'
dd2e205
      </action>
e2f0417
    </metric>
b1baa92
    
e2f0417
    <metric type="uint64" context="host">
b1baa92
      <name>FreePhysicalMemory</name>
b1baa92
      <action>
dd2e205
        free|egrep -i '^[[:space:]]*(Mem:)'   \
1279120
          | awk 'BEGIN { sum = 0; }
b1baa92
              { sum += $4; }
dd2e205
              END { printf "%d\n", sum/1024; }'
b1baa92
      </action>
b1baa92
    </metric>
b1baa92
    
b1baa92
    <metric type="uint64" context="host">
b1baa92
      <name>FreeVirtualMemory</name>
b1baa92
      <action>
dd2e205
        free|egrep -i '^[[:space:]]*(Mem:|Swap:)'   \
1279120
          | awk 'BEGIN { sum = 0; }
b1baa92
              { sum += $4; }
dd2e205
              END { printf "%d\n", sum/1024; }'
b1baa92
      </action>
e2f0417
    </metric>
b1baa92
    
e2f0417
    <metric type="uint64" context="host">
b1baa92
      <name>UsedVirtualMemory</name>
b1baa92
      <action>
dd2e205
        free|egrep -i '^[[:space:]]*(Mem:|Swap:)'   \
1279120
          | awk 'BEGIN { sum = 0; }
b1baa92
              { sum += $3; }
dd2e205
              END { printf "%d\n", sum/1024; }'
b1baa92
      </action>
e2f0417
    </metric>
1279120
    
e2f0417
    <metric type="uint64" context="host">
e2f0417
      <name>PagedInMemory</name>
dd2e205
      <action>
1279120
        vmstat -s | awk 'BEGIN {
dd2e205
                        cmd = "getconf PAGESIZE";
dd2e205
                        cmd | getline pagesize;
dd2e205
                        close(cmd);
dd2e205
                      }
dd2e205
                      /pages swapped in/ {
dd2e205
                        printf "%d\n", $1 / 1024 * pagesize / 1024;
dd2e205
                      }'
dd2e205
      </action>
e2f0417
    </metric>
b1baa92
    
e2f0417
    <metric type="uint64" context="host">
e2f0417
      <name>PagedOutMemory</name>
dd2e205
      <action>
1279120
        vmstat -s | awk 'BEGIN {
dd2e205
                        cmd = "getconf PAGESIZE";
dd2e205
                        cmd | getline pagesize;
dd2e205
                        close(cmd);
dd2e205
                      }
dd2e205
                      /pages swapped out/ {
dd2e205
                        printf "%d\n", $1 / 1024 * pagesize / 1024;
dd2e205
                      }'
dd2e205
      </action>
e2f0417
    </metric>
1279120
    
685be0d
    <metric type="real64" context="host">
b1baa92
      <name>TotalCPUTime</name>
dd2e205
      <action>
1279120
        awk '
1279120
        function user_hz(   hz)
1279120
        {
1279120
          cmd = "getconf CLK_TCK";
1279120
          cmd | getline;
1279120
          hz  = $1;
1279120
          close(cmd);
1279120
1279120
          return hz;
1279120
        }
1279120
1279120
        BEGIN {
1279120
          USER_HZ      = user_hz();
1279120
          TotalCPUTime = 0;
1279120
1279120
          while ( 0 < ( getline < "/proc/stat" ) )
685be0d
          {
685be0d
            if ( "cpu" == $1 )
685be0d
            {
1279120
              TotalCPUTime = $2 + $3 + $4;
685be0d
685be0d
              break;
685be0d
            }
685be0d
          }
1279120
          close("/proc/stat");
1279120
1279120
          #printf "USER_HZ = %d\n", USER_HZ  | "cat 1>&2";
1279120
          TotalCPUTime /= USER_HZ;
1279120
          printf "%f\n", TotalCPUTime;
1279120
685be0d
          #close("cat 1>&2");
685be0d
        }'
dd2e205
      </action>
685be0d
    </metric>
b1baa92
    
e2f0417
    <metric type="real64" context="vm">
e2f0417
      <name>TotalCPUTime</name>
dd2e205
      <action>
1279120
        virsh -r CONNECT dominfo NAME   \
1279120
          |awk -F ':' '
1279120
          function mkvarnam(s)  { # UPPER_CASE_UNDERSCORE
1279120
            sub("(^[[:space:]]+|[[:space:]]+$)", "", s);  # trim
1279120
            gsub("[[:space:]]+", "_", s); s = toupper(s);
1279120
            return s;
1279120
          }
1279120
          function filt_phys(s, sep,    num, unit) {  # 42.0 KM
1279120
            sub("(^[[:space:]]+|[[:space:]]+$)", "", s);  # trim
1279120
            if ( s ~ /^[0-9]*\.?[0-9]+[[:space:]]*[[:alpha:]]+$/ )
1279120
            {
1279120
              num = s; unit = s;
1279120
              sub("[[:space:]]*[[:alpha:]]+$", "", num);
1279120
              sub("^[0-9]*[.]?[0-9]+[[:space:]]*", "", unit);
1279120
              return num sep toupper(unit);
1279120
            }
1279120
            else
1279120
            {
1279120
              return s;
1279120
            }
1279120
          }
1279120
          /:/ {
1279120
            d1    = substr($0, 1, index($0, ":") - 1);
1279120
            rest  = substr($0, index($0, ":") + 1);
1279120
            printf("%s:%s\n", mkvarnam(d1), filt_phys(rest, ":"));
1279120
          }'                                  \
1279120
          | awk -F: '$1 == "CPU_TIME" { print $2; }'
dd2e205
      </action>
e2f0417
    </metric>
1279120
    
b1baa92
    <metric type="uint32" context="vm">
1279120
      <name>ResourceProcessorLimit</name>
dd2e205
      <action>
1279120
        virsh -r CONNECT dominfo NAME   \
1279120
          |awk -F ':' '
1279120
          function mkvarnam(s)  { # UPPER_CASE_UNDERSCORE
1279120
            sub("(^[[:space:]]+|[[:space:]]+$)", "", s);  # trim
1279120
            gsub("[[:space:]]+", "_", s); s = toupper(s);
1279120
            return s;
1279120
          }
1279120
          function filt_phys(s, sep,    num, unit) {  # 42.0 KM
1279120
            sub("(^[[:space:]]+|[[:space:]]+$)", "", s);  # trim
1279120
            if ( s ~ /^[0-9]*\.?[0-9]+[[:space:]]*[[:alpha:]]+$/ )
1279120
            {
1279120
              num = s; unit = s;
1279120
              sub("[[:space:]]*[[:alpha:]]+$", "", num);
1279120
              sub("^[0-9]*[.]?[0-9]+[[:space:]]*", "", unit);
1279120
              return num sep toupper(unit);
1279120
            }
1279120
            else
1279120
            {
1279120
              return s;
1279120
            }
1279120
          }
1279120
          /:/ {
1279120
            d1    = substr($0, 1, index($0, ":") - 1);
1279120
            rest  = substr($0, index($0, ":") + 1);
1279120
            printf("%s:%s\n", mkvarnam(d1), filt_phys(rest, ":"));
1279120
          }'                                  \
1279120
          | awk -F: '$1 == "CPU(S)" { print $2; }'
dd2e205
      </action>
b1baa92
    </metric>
b1baa92
    
b1baa92
    <metric type="uint64" context="vm">
1279120
      <name>ResourceMemoryLimit</name>
dd2e205
      <action>
1279120
        virsh -r CONNECT dominfo NAME   \
1279120
          |awk -F ':' '
1279120
          function mkvarnam(s)  { # UPPER_CASE_UNDERSCORE
1279120
            sub("(^[[:space:]]+|[[:space:]]+$)", "", s);  # trim
1279120
            gsub("[[:space:]]+", "_", s); s = toupper(s);
1279120
            return s;
1279120
          }
1279120
          function filt_phys(s, sep,    num, unit) {  # 42.0 KM
1279120
            sub("(^[[:space:]]+|[[:space:]]+$)", "", s);  # trim
1279120
            if ( s ~ /^[0-9]*\.?[0-9]+[[:space:]]*[[:alpha:]]+$/ )
1279120
            {
1279120
              num = s; unit = s;
1279120
              sub("[[:space:]]*[[:alpha:]]+$", "", num);
1279120
              sub("^[0-9]*[.]?[0-9]+[[:space:]]*", "", unit);
1279120
              return num sep toupper(unit);
1279120
            }
1279120
            else
1279120
            {
1279120
              return s;
1279120
            }
1279120
          }
1279120
          /:/ {
1279120
            d1    = substr($0, 1, index($0, ":") - 1);
1279120
            rest  = substr($0, index($0, ":") + 1);
1279120
            printf("%s:%s\n", mkvarnam(d1), filt_phys(rest, ":"));
1279120
          }'                                  \
1279120
          | awk -F: '$1 == "MAX_MEMORY" { print int($2/1024); }'
dd2e205
      </action>
b1baa92
    </metric>
1279120
    
1279120
    <metric type="uint64" context="vm">
1279120
      <name>PhysicalMemoryAllocatedToVirtualSystem</name>
dd2e205
      <action>
1279120
        virsh -r CONNECT dominfo NAME   \
1279120
          |awk -F ':' '
1279120
          function mkvarnam(s)  { # UPPER_CASE_UNDERSCORE
1279120
            sub("(^[[:space:]]+|[[:space:]]+$)", "", s);  # trim
1279120
            gsub("[[:space:]]+", "_", s); s = toupper(s);
1279120
            return s;
1279120
          }
1279120
          function filt_phys(s, sep,    num, unit) {  # 42.0 KM
1279120
            sub("(^[[:space:]]+|[[:space:]]+$)", "", s);  # trim
1279120
            if ( s ~ /^[0-9]*\.?[0-9]+[[:space:]]*[[:alpha:]]+$/ )
1279120
            {
1279120
              num = s; unit = s;
1279120
              sub("[[:space:]]*[[:alpha:]]+$", "", num);
1279120
              sub("^[0-9]*[.]?[0-9]+[[:space:]]*", "", unit);
1279120
              return num sep toupper(unit);
1279120
            }
1279120
            else
1279120
            {
1279120
              return s;
1279120
            }
1279120
          }
1279120
          /:/ {
1279120
            d1    = substr($0, 1, index($0, ":") - 1);
1279120
            rest  = substr($0, index($0, ":") + 1);
1279120
            printf("%s:%s\n", mkvarnam(d1), filt_phys(rest, ":"));
1279120
          }'                                  \
1279120
          | awk -F: '$1 == "USED_MEMORY" { print int($2/1024); }'
dd2e205
      </action>
1279120
    </metric>
e2f0417
  </metrics>
e2f0417
</vhostmd>
b1baa92
dd2e205
  vi:ts=2:sw=2:expandtab:ignorecase:nu:ruler
b1baa92
-->
b1baa92