diff options
author | Ted Ross <tross@apache.org> | 2009-02-24 14:15:28 +0000 |
---|---|---|
committer | Ted Ross <tross@apache.org> | 2009-02-24 14:15:28 +0000 |
commit | 043cfb51401c11dbe9a9db7c07580f3ff84efb3b (patch) | |
tree | bf265ab71177abf6184750bb610cb5009fe12671 | |
parent | 37d3f0675c0b7f6052c14d104a6b03e78b86965a (diff) | |
download | qpid-python-043cfb51401c11dbe9a9db7c07580f3ff84efb3b.tar.gz |
QPID-1676 - Added client process name and pid to connection object for management.
Supported in C++, Python, and Ruby clients.
Still needs to be added to the Java clients.
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@747389 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | qpid/cpp/src/qpid/broker/Connection.h | 2 | ||||
-rw-r--r-- | qpid/cpp/src/qpid/broker/ConnectionHandler.cpp | 18 | ||||
-rw-r--r-- | qpid/cpp/src/qpid/client/ConnectionHandler.cpp | 7 | ||||
-rw-r--r-- | qpid/cpp/src/qpid/sys/SystemInfo.h | 5 | ||||
-rwxr-xr-x | qpid/cpp/src/qpid/sys/posix/SystemInfo.cpp | 24 | ||||
-rwxr-xr-x | qpid/cpp/src/qpid/sys/windows/SystemInfo.cpp | 19 | ||||
-rw-r--r-- | qpid/python/qpid/delegates.py | 6 | ||||
-rw-r--r-- | qpid/ruby/lib/qpid/delegates.rb | 5 | ||||
-rw-r--r-- | qpid/specs/management-schema.xml | 3 |
9 files changed, 86 insertions, 3 deletions
diff --git a/qpid/cpp/src/qpid/broker/Connection.h b/qpid/cpp/src/qpid/broker/Connection.h index 71e03d76d4..b1e1cda973 100644 --- a/qpid/cpp/src/qpid/broker/Connection.h +++ b/qpid/cpp/src/qpid/broker/Connection.h @@ -125,6 +125,8 @@ class Connection : public sys::ConnectionInputHandler, management::ManagementAgent* agent; Timer& timer; boost::intrusive_ptr<TimerTask> heartbeatTimer; + public: + qmf::org::apache::qpid::broker::Connection* getMgmtObject() { return mgmtObject; } }; }} diff --git a/qpid/cpp/src/qpid/broker/ConnectionHandler.cpp b/qpid/cpp/src/qpid/broker/ConnectionHandler.cpp index f136d61462..b79342b86c 100644 --- a/qpid/cpp/src/qpid/broker/ConnectionHandler.cpp +++ b/qpid/cpp/src/qpid/broker/ConnectionHandler.cpp @@ -46,6 +46,9 @@ const std::string en_US = "en_US"; const std::string QPID_FED_LINK = "qpid.fed_link"; const std::string QPID_FED_TAG = "qpid.federation_tag"; const std::string SESSION_FLOW_CONTROL("qpid.session_flow"); +const std::string CLIENT_PROCESS_NAME("qpid.client_process"); +const std::string CLIENT_PID("qpid.client_pid"); +const std::string CLIENT_PPID("qpid.client_ppid"); const int SESSION_FLOW_CONTROL_VER = 1; } @@ -141,9 +144,22 @@ void ConnectionHandler::Handler::startOk(const framing::FieldTable& clientProper } QPID_LOG(info, "Connection is a federation link"); } - if ( clientProperties.getAsInt(SESSION_FLOW_CONTROL) == SESSION_FLOW_CONTROL_VER ) { + if (clientProperties.getAsInt(SESSION_FLOW_CONTROL) == SESSION_FLOW_CONTROL_VER) { connection.setClientThrottling(); } + + if (connection.getMgmtObject() != 0) { + string procName = clientProperties.getAsString(CLIENT_PROCESS_NAME); + uint32_t pid = clientProperties.getAsInt(CLIENT_PID); + uint32_t ppid = clientProperties.getAsInt(CLIENT_PPID); + + if (!procName.empty()) + connection.getMgmtObject()->set_remoteProcessName(procName); + if (pid != 0) + connection.getMgmtObject()->set_remotePid(pid); + if (ppid != 0) + connection.getMgmtObject()->set_remoteParentPid(ppid); + } } void ConnectionHandler::Handler::secureOk(const string& response) diff --git a/qpid/cpp/src/qpid/client/ConnectionHandler.cpp b/qpid/cpp/src/qpid/client/ConnectionHandler.cpp index 377b84c019..6efdb91e96 100644 --- a/qpid/cpp/src/qpid/client/ConnectionHandler.cpp +++ b/qpid/cpp/src/qpid/client/ConnectionHandler.cpp @@ -28,6 +28,7 @@ #include "qpid/framing/reply_exceptions.h" #include "qpid/log/Helpers.h" #include "qpid/log/Statement.h" +#include "qpid/sys/SystemInfo.h" using namespace qpid::client; using namespace qpid::framing; @@ -52,6 +53,9 @@ const std::string INVALID_STATE_OPEN_OK("open-ok received in invalid state"); const std::string INVALID_STATE_CLOSE_OK("close-ok received in invalid state"); const std::string SESSION_FLOW_CONTROL("qpid.session_flow"); +const std::string CLIENT_PROCESS_NAME("qpid.client_process"); +const std::string CLIENT_PID("qpid.client_pid"); +const std::string CLIENT_PPID("qpid.client_ppid"); const int SESSION_FLOW_CONTROL_VER = 1; } @@ -80,6 +84,9 @@ ConnectionHandler::ConnectionHandler(const ConnectionSettings& s, ProtocolVersio FINISHED.insert(CLOSED); properties.setInt(SESSION_FLOW_CONTROL, SESSION_FLOW_CONTROL_VER); + properties.setString(CLIENT_PROCESS_NAME, sys::SystemInfo::getProcessName()); + properties.setInt(CLIENT_PID, sys::SystemInfo::getProcessId()); + properties.setInt(CLIENT_PPID, sys::SystemInfo::getParentProcessId()); } void ConnectionHandler::incoming(AMQFrame& frame) diff --git a/qpid/cpp/src/qpid/sys/SystemInfo.h b/qpid/cpp/src/qpid/sys/SystemInfo.h index d43fe34b04..017a05e2c5 100644 --- a/qpid/cpp/src/qpid/sys/SystemInfo.h +++ b/qpid/cpp/src/qpid/sys/SystemInfo.h @@ -73,6 +73,11 @@ namespace SystemInfo { */ uint32_t getParentProcessId(); + /** + * Get the name of the current process (i.e. the name of the executable) + */ + std::string getProcessName(); + }}} // namespace qpid::sys::SystemInfo diff --git a/qpid/cpp/src/qpid/sys/posix/SystemInfo.cpp b/qpid/cpp/src/qpid/sys/posix/SystemInfo.cpp index 938d4861c4..5d9eda605d 100755 --- a/qpid/cpp/src/qpid/sys/posix/SystemInfo.cpp +++ b/qpid/cpp/src/qpid/sys/posix/SystemInfo.cpp @@ -27,6 +27,9 @@ #include <arpa/inet.h> #include <stdio.h> #include <unistd.h> +#include <iostream> +#include <fstream> +#include <sstream> #ifndef HOST_NAME_MAX # define HOST_NAME_MAX 256 @@ -104,6 +107,27 @@ uint32_t SystemInfo::getParentProcessId() return (uint32_t) ::getppid(); } +string SystemInfo::getProcessName() +{ + uint32_t pid = getProcessId(); + string value; + + stringstream pathStream; + pathStream << "/proc/" << pid << "/status"; + ifstream input(pathStream.str().c_str()); + if (input.good()) { + while (!input.eof()) { + string key; + input >> key; + if (key == "Name:") { + input >> value; + break; + } + } + input.close(); + } + return value; +} }} // namespace qpid::sys diff --git a/qpid/cpp/src/qpid/sys/windows/SystemInfo.cpp b/qpid/cpp/src/qpid/sys/windows/SystemInfo.cpp index b887cac58b..dc5c56b6fb 100755 --- a/qpid/cpp/src/qpid/sys/windows/SystemInfo.cpp +++ b/qpid/cpp/src/qpid/sys/windows/SystemInfo.cpp @@ -155,6 +155,25 @@ void SystemInfo::getSystemId (std::string &osName, machine = "unknown"; break; } + +uint32_t SystemInfo::getProcessId() +{ + // TODO: Provide Windows implementation + return 0; +} + +uint32_t SystemInfo::getParentProcessId() +{ + // TODO: Provide Windows implementation + return 0; +} + +std::string SystemInfo::getProcessName() +{ + // TODO: Provide Windows implementation + return std::string(); +} + } }} // namespace qpid::sys diff --git a/qpid/python/qpid/delegates.py b/qpid/python/qpid/delegates.py index 7cfd9b11db..a720e2e1c7 100644 --- a/qpid/python/qpid/delegates.py +++ b/qpid/python/qpid/delegates.py @@ -21,6 +21,7 @@ import os, connection, session from util import notify from datatypes import RangedSet from logging import getLogger +import sys log = getLogger("qpid.io.ctl") @@ -141,7 +142,10 @@ class Client(Delegate): PROPERTIES = {"product": "qpid python client", "version": "development", - "platform": os.name} + "platform": os.name, + "qpid.client_process": os.path.basename(sys.argv[0]), + "qpid.client_pid": os.getpid(), + "qpid.client_ppid": os.getppid()} def __init__(self, connection, username="guest", password="guest", mechanism="PLAIN", heartbeat=None): diff --git a/qpid/ruby/lib/qpid/delegates.rb b/qpid/ruby/lib/qpid/delegates.rb index 9707cdbc76..171f310e48 100644 --- a/qpid/ruby/lib/qpid/delegates.rb +++ b/qpid/ruby/lib/qpid/delegates.rb @@ -168,7 +168,10 @@ module Qpid # analog in Ruby PROPERTIES = {"product" => "qpid python client", "version" => "development", - "platform" => Config::CONFIG["build_os"]} + "platform" => Config::CONFIG["build_os"], + "qpid.client_process" => File.basename($0), + "qpid.client_pid" => Process.pid, + "qpid.client_ppid" => Process.ppid} def initialize(connection, args) diff --git a/qpid/specs/management-schema.xml b/qpid/specs/management-schema.xml index 307ced1245..67c90a1fbe 100644 --- a/qpid/specs/management-schema.xml +++ b/qpid/specs/management-schema.xml @@ -206,6 +206,9 @@ <property name="SystemConnection" type="bool" access="RC" desc="Infrastucture/ Inter-system connection (Cluster, Federation, ...)"/> <property name="federationLink" type="bool" access="RO" desc="Is this a federation link"/> <property name="authIdentity" type="sstr" access="RO" desc="authId of connection if authentication enabled"/> + <property name="remoteProcessName" type="sstr" access="RO" optional="y" desc="Name of executable running as remote client"/> + <property name="remotePid" type="uint32" access="RO" optional="y" desc="Process ID of remote client"/> + <property name="remoteParentPid" type="uint32" access="RO" optional="y" desc="Parent Process ID of remote client"/> <statistic name="closing" type="bool" desc="This client is closing by management request"/> <statistic name="framesFromClient" type="count64"/> <statistic name="framesToClient" type="count64"/> |