jmeter监控PerfMon之PTQL(sigar)

jmeter监控PerfMon之PTQL

1、sigar

1.1 sigar

Sigar(system information gather and report)是Hyperic-hq产品的基础包,是Hyperic HQ主要的数据收集组件。它用来从许多平台收集系统和处理信息。这些平台包括:Linux, Windows, Solaris, AIX, HP-UX, FreeBSD and Mac OSX。

Sigar有C,C#,Java和Perl API,java版的API为sigar.jar sigar.jar的底层是用C语言编写的,它通过本地方法来调用操作系统API来获取系统相关数据。

jmeter的PerfMon插件就是依赖这个包进行的数据采集。

Sigar下载地址

1.2 PTQL

1.2.1 PTQL语法

Hyperic SIGAR 提供一种定位进程的机制,叫做进程表查询语言-PTQL(process table query language)。所有的操作系统都会给运行的进程分配一个PID,但是这个进程号是一个随机数字,当你每次启动某个程序的时候,这个进程号是随机可变的。所以我们不能用进程号来定位程序, PTQL 使用的是进程的属性值来定位程序,这些属性值是一直不变的。

ptql的语法格式类是下面这样:

Class.Attribute.operator=value

如果查询条件中有空格,需要用双引号括起来。

sigar> ps "Exe.Name.ct=Program Files"
  • Class is the name is the sigar class minus the Proc prefix.
  • Attribute is an attribute of the given Class, index into an array or ker in a Map class.
  • operate in one of the folling for String values.
    • eq: Equal to values.
    • ne: Not Equal to value.
    • gt: Greater thab value.
    • ge: Great than or equal value.
    • lt: Less than value.
    • le: Less than or equal value.
    • ew: End with value.
    • sw: Starts with value.
    • ct: Contains value(subsring).
    • re: Regular expression value matches.

Mutiole queries must delimited by a comma.多个查询之间以逗号分隔连接。

1.2.2 PTQL属性

The attributes used in PTQL are directly from the sigar.Proc* classes. This document will outline the attributes most commonly used for identifying process. the complete set of Proc* classes and attributes can be found in the Sigar javadoc.

  • Pid.Pid: the process ID.
  • Pid.PidFile: file containing the process id.
  • Pid.Service: windows services name used to pid from the service manager.
  • State.Name: base name of the process executable.
  • CredName.User: user name of the process owner.
  • CredName.Group: group name of the process owner.
  • Cred.Uid: user id of the process owner.
  • Cred.Gid: group id of the process name.
  • Cred.Euid: effective user if of the process owner.
  • Cred.Egid: effective group id of the process owner.
  • Exe.name: full path name of the process executable.
  • Exe.Cwd: currnet working directory of the process.
  • Args.*: command line argument passed to the process.
  • Env.*: environment varibale within the process.
  • Module.*: shared library loaded within the process.

1.2.3 PTQL构建

The process of building a process query will vary depending on the application and the need to identify a unique peocess or group of processes. For these examples, we will use sigar shell. The sigar shell is started using the folling command.

第一节下载的包,拷贝其sigar-bin/lib目录下的sigar.jarlibsigar-amd64-linux.so文件,这个依赖文件根据自己的操作系统进行更换,然后保证自己已经安装好java环境就行了。

# 目录结构
[root@localhost sigar]# ls 
libsigar-amd64-linux.so  sigar.jar
# 启动命令
[root@localhost sigar]# java -jar sigar.jar 
sigar> 

The help command will show rhe complete list of top-level commands. We will focus on the handful that are useful for building PTQL queries:

  • ps: process status.
  • pargs: process arguments.
  • penv: process environment.
  • pfile: process file information.
  • pinfo: other process info.

Each of the commands listed above require an argument of rither a process id or PTQL query.** For certain commands like ps you can use tab completion in the shell to see the possilble values.**(按tab键补全)

2、服务端sigar的使用

2.1 Simple Process Identification

The simplest of queries can use 'State.Name', the basename of the process executable, to indetify a process. For example, the cron daemon on a linux system.

sigar> ps "State.Name.eq=crond"
15908   root    Sep6    123M    1.6M    964K    S   0:8 /usr/sbin/crond

This approach works to uniquely identify other daemons, such as 'syslogd', 'dhclient' and others where there should only be 1 process with the given name. However, in the case of a daemon such as sshd, there will likely be multiple instances:

sigar> ps "State.Name.eq=sshd" 
925 root    Aug22   104M    4.0M    3.1M    S   0:56    /usr/sbin/sshd
27275   root    Oct29   142M    5.1M    3.8M    S   0:0 sshd: root@pts/1

The easiest way to find the listening sshd server is to use the pid file:

sigar> ps "Pid.PidFile.eq=/var/run/sshd.pid"
925 root    Aug22   104M    4.0M    3.1M    S   0:56    /usr/sbin/sshd

2.2 Identifying a Unique Java Process

'State.Name' may be enough to identify certain processes, but this is almost never the case with java applications, where the executable basename is 'java' for all applications:

sigar> ps "State.Name.sw=java"              
1422    root    Sep21    21G    3.9G     16M    S   519:34  java:/opt/server/cynosure/cynosure-1.0.0-SNAPSHOT.jar
4251    root    09:35    11G     35M     12M    S   0:0 java:org.hyperic.sigar.cmd.Runner
25496   root    Sep11    11G    218M     12M    S   32:54   java:clojure.main
25683   root    Sep11    13G    407M     12M    S   46:30   java:clojure.main

To view the command line arguments for a specific process:

sigar> pargs 4251
pid=4251
exe=/home/qszhao2/jdk/bin/java
cwd=/home/qszhao2/sigar
   0=>java<=
   1=>-jar<=
   2=>sigar.jar<=

------------------------

For most java applications, the main class name can be used to uniquely identify the process, in this case argument 2 is the sigar main class name:

sigar> ps "State.Name.eq=java,Args.2.eq=sigar.jar" 
4251    root    09:35    11G     35M     12M    S   0:1 java:org.hyperic.sigar.cmd.Runner

3、jmeter的PTQL语句的编写

jmeter即将上述语法直接复制粘贴就好了,在服务端保证每次查询都只能查询出一条语句即可。

4、感谢

Sigar获取服务器内存、IP、CPU、IO、MAC地址、操作系统等信息

Sigar 命令的查询方法PTQL语法

你可能感兴趣的:(jmeter监控PerfMon之PTQL(sigar))