Forum Discussion
I suggest the following simpler version of your discovery script:
import groovy.sql.Sql
import java.sql.SQLException
def hostname = hostProps.get("system.hostname")
def user = hostProps.get("sybase.user")
def pass = hostProps.get("sybase.pass")
def port = 21000
def url = "jdbc:sybase:Tds:$hostname:$port"
def driver = "com.sybase.jdbc4.jdbc.SybDriver"
def sql = Sql.newInstance(url, user, pass, driver)
def conn = sql.getConnection()
try {
def stmt = conn.createStatement()
def dbRs = stmt.executeQuery("select name from master..sysdatabases") // get the databases on the host
while (dbRs.next()) { // loop through each database on the host
def dbName = dbRs.getString("name")
// connect to the service
def dbUrl = "jdbc:sybase:Tds:$hostname:$port?ServiceName=$dbName"
def dbSql = Sql.newInstance(dbUrl, user, pass, driver)
def dbConn = dbSql.getConnection()
try {
def dbStmt = dbConn.createStatement()
def segmentRs = dbStmt.executeQuery("select name from syssegments") // Retrieve segment names for the current database
while (segmentRs.next()) { // loop through each segment
def segmentName = segmentRs.getString("name")
println("${dbName}_${segmentName}") // output the instance
}
}
segmentRs.close()
dbStmt.close()
}
catch (SQLException e) {e.printStackTrace()}
finally {
if (dbConn) {dbConn.close()}}
if (dbRs) {dbRs.close()}
if (stmt) {stmt.close()}
}
catch (SQLException e) {e.printStackTrace()}
finally {if (conn != null) {conn.close()}}
To get the same names into your collection script, you’d just repeat what you’ve already done in your discovery script, just output the data instead of just the names. This requires changing back to BATCHSCRIPT, since you’d be outputting all the data with one run of your collection script. I’m making a lot of guesses here since I don’t really understand your data. You may need to adjust this so that things match up.
import groovy.sql.Sql
import java.sql.SQLException
def hostname = hostProps.get("system.hostname")
def user = hostProps.get("sybase.user")
def pass = hostProps.get("sybase.pass")
def port = 21000
def url = "jdbc:sybase:Tds:$hostname:$port"
def driver = "com.sybase.jdbc4.jdbc.SybDriver"
def sql = Sql.newInstance(url, user, pass, driver)
def conn = sql.getConnection()
try {
def stmt = conn.createStatement()
def dbRs = stmt.executeQuery("select name from master..sysdatabases") // get the databases on the host
while (dbRs.next()) { // loop through each database on the host
def dbName = dbRs.getString("name")
// connect to the service
def dbUrl = "jdbc:sybase:Tds:$hostname:$port?ServiceName=$dbName"
def dbSql = Sql.newInstance(dbUrl, user, pass, driver)
def dbConn = dbSql.getConnection()
try {
def dbStmt = dbConn.createStatement()
def segmentRs = dbStmt.executeQuery("select name from syssegments") // Retrieve segment names for the current database
while (segmentRs.next()) { // loop through each segment
def segmentName = segmentRs.getString("name")
// println("${dbName}_${segmentName}") // output the instance
dbSql.eachRow("sp_helpsegment '${segmentName}'") { row -> //not sure how this query needs to be contructed, this is a guess (did you create a function?)
datapoint = row.tokenize(":. ")[2] // take the row "master:system.Size: 50.0", split it wherever there is a `:`, a `.`, or a ` ` (space) and grab the third item from that set "Size"
value = row.tokenize(":. ")[3] // take the row "master:system.Size: 50.0", split it wherever there is a `:`, a `.`, or a ` ` (space) and grab the fourth item from that set "50"
println("${dbName}_${segmentName}.${datapoint}: ${value}") // print out the data: `BTS_PROD_system_segment.Size: 50`
}
}
}
segmentRs.close()
dbStmt.close()
}
catch (SQLException e) {e.printStackTrace()}
finally {
if (dbConn) {dbConn.close()}}
if (dbRs) {dbRs.close()}
if (stmt) {stmt.close()}
}
catch (SQLException e) {e.printStackTrace()}
finally {if (conn != null) {conn.close()}}
Notice how the only real difference between the two is what gets output for each segment in the `while (segmentRs.next()) loop. In discovery, you output the instance naming details. In collection you output the wildvalue, plus the datapoint name, plus the value.
Related Content
- 2 years ago
- 3 days ago
- 2 years ago