I'm trying to get some basic performance data (such as CPU and Memory Usage) from the IBM i every minute or so. Then I'm creating a Web App, which will display all of this in a centralized dashboard and also notify the user for any unusual values/events.
All I need is some kind of parsable data output from IBM i; could be JSON, CSV, perhaps even ODBC,...
I already tried running commands to get spool output, but that's not consistent so it can't really be parsed. The latest thing I found is collecting CSV files, but that is not automatic.
Inside the "IBM i Navigator -> Performance -> Investigate Data" there is an option to show a graph with my required data and it's even possible to export it as CSV.
However, I was wondering if it's possible to GET this data via a HTTP Request as JSON? I was searching around and found mentions of "Integrated Web Services" and "CICS Transactions Server HTTP Requests", but nothing specific on getting existing data, only on creating your own.
https://www.ibm.com/docs/en/cics-ts/5.3?topic=protocol-http-requests https://www.ibm.com/docs/en/i/7.3?topic=tasks-integrated-web-application-server
Thank you!
CodePudding user response:
I don't know if the data you search for available through a web request. What is the greater goal you want to achieve? Just curiosity? Centralized Monitoring for erratic values?
Usually, the requested class of data is exposed in more or less real time via SNMP and easily accessible by existing monitoring applications. It uses UDP and is much more efficient in terms of processor overhead than web requests.
The graphs you mention might be derived from the Performance Tools, something akin to sar & friends on Linux/Unix. However, this data is also not exported via web request. I think there are API calls within the OS to access this data. See Performance Tools for an overview.
Of course, this data is saved in tables and can be accessed via ODBC from outside IBM i, but I question the effort resulting from the probable lack of documentation about the table structure to be beneficial.
CodePudding user response:
the system exposes all sorts of performance info as SQL table functions. here is the active job info table function
PHP can be used to write a web service which first calls the table function, then returns the resulting data as a JSON data stream.
<?php
$showColNameArr = array("JOB_NAME", "SUBSYSTEM", "JOB_TYPE", "FUNCTION", "FUNCTION_TYPE",
"JOB_STATUS", "CPU_TIME" ) ;
header("Content-type: text/javascript; charset=utf-8;");
// access an input, posted json object.
$postContents = file_get_contents('php://input') ;
$postObject = json_decode( $postContents ) ;
$action = isset($postObject->action) ? $postObject->action : '' ;
{
$conn = as400Connect('qgpl qtemp') ;
$sql = "SELECT *
from TABLE(QSYS2.ACTIVE_JOB_INFO( ))" ;
$stmt = db2_prepare($conn, $sql) ;
$result = db2_execute($stmt) ;
$colNames = db2Stmt_GetColNames( $stmt ) ;
$finalArr = array( ) ;
while( $row = db2_fetch_array($stmt))
{
$assocArr = array( ) ;
for( $jx = 0 ; $jx < sizeof($row) ; $jx )
{
$colName = $colNames[$jx] ;
if ( in_array( $colName, $showColNameArr ))
{
$vlu = $row[$jx] ;
$assocArr[$colName] = $vlu ;
}
}
$finalArr[] = $assocArr ;
}
echo json_encode( $finalArr ) ;
}
// ---------------------------- as400Connect ------------------------
function as400Connect( $libl )
{
$options = array('i5_naming' => DB2_I5_NAMING_ON);
if (strlen($libl) > 0)
{
$options['i5_libl'] = $libl ;
}
$conn = db2_connect("*LOCAL","","", $options);
if (!$conn) {
echo "Connection failed" ;
echo "<br>" ;
echo db2_conn_errormsg( ) ;
exit( ) ;
}
return $conn ;
}
// --------------------- db2Stmt_GetColNames ----------------
// build and return array of column names from a db2_execute
// executed $stmt.
function db2Stmt_GetColNames( $stmt )
{
$colCx = db2_num_fields($stmt);
$colNames = array( ) ;
for( $ix=0; $ix < $colCx; $ix )
{
array_push( $colNames, db2_field_name( $stmt, $ix )) ;
}
return $colNames ;
}
?>