3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

LibertyのDataSource使用量を見る

Posted at

目的

Libertyと、Dbで環境を構築してDataSource の使用量をJMXで確認します。

環境構築

環境は前に書いた

をもとにします。

テスト接続

にアクセスして DataSource 接続を使用するようにします。

JMXのオブジェクトを見つける

Key Value
ユーザー名 wsadmin
パスワード passw0rd

でアクセスして DataSource MBeanを見つけます。
jndiNameなど定義をキーにして探せるようにします。今回は以下が見つけられると良いです。

{"objectName":"WebSphere:type=com.ibm.ws.jca.cm.mbean.ConnectionManagerMBean,jndiName=jdbc/derbyEmbedded,name=dataSource[DefaultDetaSource]/connectionManager[default-0]","className":"com.ibm.ws.jca.cm.mbean.ConnectionManagerMBean","URL":"/IBMJMXConnectorREST/mbeans/WebSphere%3AjndiName%3Djdbc%2FderbyEmbedded%2Cname%3DdataSource%5BDefaultDetaSource%5D%2FconnectionManager%5Bdefault-0%5D%2Ctype%3Dcom.ibm.ws.jca.cm.mbean.ConnectionManagerMBean"}

curl でアクセスする場合には以下にサンプルがあります。ACCESS_HOST (libertyのホスト名) の指定が必要です。

git clone https://github.com/pdprof/db-connections
cd db-connections/derby-docker/mustgather-jmx-1
export ACCESS_HOST=localhost
./getMBeans.sh

MBeanのURLにアクセス

先に抜粋したJSONにURLが記載されているので、そこにアクセスします。

$ curl -s -k -u wsadmin:passw0rd https://localhost:9443/IBMJMXConnectorREST/mbeans/WebSphere%3AjndiName%3Djdbc%2FderbyEmbedded%2Cname%3DdataSource%5BDefaultDetaSource%5D%2FconnectionManager%5Bdefault-0%5D%2Ctype%3Dcom.ibm.ws.jca.cm.mbean.ConnectionManagerMBean | jq .
{
  "className": "com.ibm.ws.jca.cm.mbean.ConnectionManagerMBean",
  "description": "MBean for a Connection Manager",
  "descriptor": {
    "names": [],
    "values": []
  },
  "attributes": [],
  "attributes_URL": "/IBMJMXConnectorREST/mbeans/WebSphere%3AjndiName%3Djdbc%2FderbyEmbedded%2Cname%3DdataSource%5BDefaultDetaSource%5D%2FconnectionManager%5Bdefault-0%5D%2Ctype%3Dcom.ibm.ws.jca.cm.mbean.ConnectionManagerMBean/attributes",
  "constructors": [],
  "notifications": [],
  "operations": [
    {
      "name": "purgePoolContents",
      "description": "Purges the contents of the Connection Manager.",
      "descriptor": {
        "names": [],
        "values": []
      },
      "impact": "1",
      "returnType": "java.lang.Void",
      "signature": [
        {
          "name": "arg0",
          "type": "java.lang.String",
          "description": "Use 'abort' to abort all connections in the pool using Connection.abort(). Use 'immediate' to purge the pool contents immediately. Any other string value will purge the pool contents normally.",
          "descriptor": {
            "names": [],
            "values": []
          }
        }
      ],
      "URL": "/IBMJMXConnectorREST/mbeans/WebSphere%3AjndiName%3Djdbc%2FderbyEmbedded%2Cname%3DdataSource%5BDefaultDetaSource%5D%2FconnectionManager%5Bdefault-0%5D%2Ctype%3Dcom.ibm.ws.jca.cm.mbean.ConnectionManagerMBean/operations/purgePoolContents"
    },
    {
      "name": "showPoolContents",
      "description": "Displays the current contents of the Connection Manager in a human readable format.",
      "descriptor": {
        "names": [],
        "values": []
      },
      "impact": "0",
      "returnType": "java.lang.String",
      "signature": [],
      "URL": "/IBMJMXConnectorREST/mbeans/WebSphere%3AjndiName%3Djdbc%2FderbyEmbedded%2Cname%3DdataSource%5BDefaultDetaSource%5D%2FconnectionManager%5Bdefault-0%5D%2Ctype%3Dcom.ibm.ws.jca.cm.mbean.ConnectionManagerMBean/operations/showPoolContents"
    }
  ]
}

MBeanで使える operations などの情報が戻ります。

showPoolContents

接続プールの情報を取得します。

にアクセスしてどうやってMBeanにアクセスするかを確認します。
MBean operation invocation を選択して確認します。

image.png

showPoolContents の signature から 0 params と分かるので POSTする引数はなしで以下のようにできます。

curl -s -k -u wsadmin:passw0rd -H "Content-Type: application/json" -d "{}" https://localhost:9443/IBMJMXConnectorREST/mbeans/WebSphere%3AjndiName%3Djdbc%2FderbyEmbedded%2Cname%3DdataSource%5BDefaultDetaSource%5D%2FconnectionManager%5Bdefault-0%5D%2Ctype%3Dcom.ibm.ws.jca.cm.mbean.ConnectionManagerMBean/operations/showPoolContents | jq -r ".value"

PoolManager@d8ee2952
name=WebSphere:type=com.ibm.ws.jca.cm.mbean.ConnectionManagerMBean,jndiName=jdbc/derbyEmbedded,name=dataSource[DefaultDetaSource]/connectionManager[default-0]
jndiName=jdbc/derbyEmbedded
maxPoolSize=5
size=1
waiting=0
unshared=0
shared=0
available=1
 ManagedConnection@37c92820=Reusable

Extended ConnLeakLogic information
JNDI name:jdbc/derbyEmbedded
PoolManager object:-548673331
Total number of connections: 1 (max/min 5/2, reap/unused/aged/maxInUseTime 180/1800/-1/-1, connectiontimeout/purge 30/EntirePool)
Shared Connection information (shared partitions 200)
  No shared connections

Free Connection information (free distribution table 100)
  (1)MCWrapper id 37c92820  Managed connection WSRdbManagedConnectionImpl@254d13f9  State:STATE_ACTIVE_FREE

  Total number of connection in free pool: 1
UnShared Connection information
  No unshared connections

以下のようにすることで動作するスクリプトも用意しました。SHOWPOOL_URLは環境にあわせて設定します。

export SHOWPOOL_URL='/IBMJMXConnectorREST/mbeans/WebSphere%3AjndiName%3Djdbc%2FderbyEmbedded%2Cname%3DdataSource%5BDefaultDetaSource%5D%2FconnectionManager%5Bdefault-0%5D%2Ctype%3Dcom.ibm.ws.jca.cm.mbean.ConnectionManagerMBean/operations/showPoolContents'
./showPoolContents.sh

purgePoolContents

接続プールを破棄します。今回は abort.json を用意してあるので、それを使います。書き方は先の api のページを参考にします。

abort.json
{
  "params":[
      {
        "value" : "abort",
        "type" : "java.lang.String"
      }
   ],
  "signature":[
      "java.lang.String"
   ]
}
curl -s -k -u wsadmin:passw0rd -H "Content-Type: application/json" -d '@abort.json' https://localhost:9443/IBMJMXConnectorREST/mbeans/WebSphere%3AjndiName%3Djdbc%2FderbyEmbedded%2Cname%3DdataSource%5BDefaultDetaSource%5D%2FconnectionManager%5Bdefault-0%5D%2Ctype%3Dcom.ibm.ws.jca.cm.mbean.ConnectionManagerMBean/operations/purgePoolContents

以下のようにすることで動作するスクリプトも用意しました。PURGEPOOL_URLは環境にあわせて設定します。

export PURGEPOOL_URL='/IBMJMXConnectorREST/mbeans/WebSphere%3AjndiName%3Djdbc%2FderbyEmbedded%2Cname%3DdataSource%5BDefaultDetaSource%5D%2FconnectionManager%5Bdefault-0%5D%2Ctype%3Dcom.ibm.ws.jca.cm.mbean.ConnectionManagerMBean/operations/purgePoolContents'
./purgePoolContents.sh

まとめ

DataSourceの MBeanを参考に MBeanとAPIの確認と実行方法を紹介しました。
ここに書いたものだけでなく、ほかのMBeanにも使えるような情報になるといいと思って書いてみました。

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?