SPID = 1 BLOCKED = 0
i want to capture the above data, the above data is my querry result. please tell me the data point settings |
Collection the data metrics where there are unique keys
HI, now the block value is comming and Date is comming as null. i will try to create a block in DB and see weather iam getting date also. Thanks Bro
What does your raw collection script output look like? If blocked is 0, time_blocked should be null, right?
yes, time_blocked is comming as null


Thanks , bro
As of now , its ok . I need to go for TEST and see. Thanks soo much
The script failed, elapsed time: 0 seconds - No signature of method: java.lang.Integer.getAt() is applicable for argument types: (java.lang.Integer) values: [0]Possible solutions: getAt(java.lang.String), next(), putAt(java.lang.String, java.lang.Object), wait(), grep(), getClass()groovy.lang.MissingMethodException: No signature of method: java.lang.Integer.getAt() is applicable for argument types: (java.lang.Integer) values: [0]Possible solutions: getAt(java.lang.String), next(), putAt(java.lang.String, java.lang.Object), wait(), grep(), getClass() at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:71) at org.codehaus.groovy.runtime.callsite.PojoMetaClassSite.call(PojoMetaClassSite.java:48) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:128) at Script4977$_run_closure1$_closure2.doCall(Script4977.groovy:37) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:566) at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:98) at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325) at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:264) at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1034) at groovy.lang.Closure.call(Closure.java:418) at groovy.lang.Closure.call(Closure.java:434) at org.codehaus.groovy.runtime.DefaultGroovyMethods.each(DefaultGroovyMethods.java:2125) at org.codehaus.groovy.runtime.DefaultGroovyMethods.each(DefaultGroovyMethods.java:2110) at org.codehaus.groovy.runtime.DefaultGroovyMethods.each(DefaultGroovyMethods.java:2151) at org.codehaus.groovy.runtime.dgm$163.invoke(Unknown Source) at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoMetaMethodSiteNoUnwrapNoCoerce.invoke(PojoMetaMethodSite.java:274) at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:56) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:128) at Script4977$_run_closure1.doCall(Script4977.groovy:33) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:566) at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:98) at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325) at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:264) at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1034) at groovy.lang.Closure.call(Closure.java:418) at groovy.lang.Closure.call(Closure.java:434) at groovy.sql.Sql.callClosurePossiblyWithConnection(Sql.java:4396) at groovy.sql.Sql.withTransaction(Sql.java:3586) at groovy.sql.Sql$withTransaction.call(Unknown Source) at Script4977.run(Script4977.groovy:24)
hi, iam getting error related to time blocked, can you please check
This is the important part of the error:
No signature of method: java.lang.Integer.getAt() is applicable for argument types: (java.lang.Integer) values: [0]Possible solutions: getAt(java.lang.String)
This means that the .toInteger() method (of which java.lang.Integer.getAt() is a sub-method) requires input of an object of a certain type. You passed in an object that could not be converted to an integer. This means that either h or m doesn’t contain a string that can be converted to an integer. .toInteger() needs a string to convert to an integer. It looks like you’re passing in either a “0” (integer) or [0] (list). I can’t tell which one because java debugging requires a higher state of consciousness to decipher.
If you’re still using the script from here, the issue is in the “toInteger()” method, which is happening at this point in your script. Here are some suggestions on how to troubleshoot it.
// get the values of hours and minutes from time_blocked. time_blocked will be something like 18:53
// so h should end up being 18 (in this case)
// and m should end up being 53 (in this case)
(h,m) = row.time_blocked.split(":")
// put a println statement here to see what h and m are to make sure they are convertable to integers
println("h=${h}\nm=${m}")
// if h and m look like integers here, then you shouldn't have any problems converting them to integers.
// if this line still doesn't work, it may be that there are extra spaces. In that case, use .trim() to remove any extra spaces
time_blocked = h.trim().toInteger()*60 + m.trim().toInteger()
// You can also split these lines up into their individual steps to see which one is failing
intHours = h.toInteger()
intMinutes = m.toInteger()
time_blocked = intHours * 60 + intMinutes
// if h and m look like this:
// h=[18]
// m=[53]
// then you don't have strings, you have a list of strings. You'd need to extract the elements from the list:
time_blocked = h[0].toInteger()*60 + m[0].toInteger()
Give some of these suggestions a try and see what you get. Check the output of the println statement to see if you’re getting valid values from the .split() method.
There are other ways to parse a string into an integer, but your first order of business is to find out what h and m contain after the .split() happens.


hi please find the above codes and output. here i want to make segments as my instances. please tell me how to do.
You should make this a “script”, since your collection script is designed to only poll one instance’s worth of data.
In your collection script, your datapoint keys should not have spaces in them, so I’d update line 28 in your collection script to this:
def result = sql.rows("select s.name Segment, cast(sum((size*$alloc)/1048576) as decimal(38,10)) 'size_in_MB', cast(sum((size*$alloc)/1048576)-sum((curunreservedpgs(db_id('${wildvalue}'),lstart, unreservedpgs)* $alloc)/1048576) as decimal(38,10)) 'Used_in_MB', cast(sum((curunreservedpgs(db_id('${wildvalue}'),lstart, unreservedpgs)* $alloc)/1048576) as decimal(38,10)) 'Free_in_MB' from master..sysusages u, syssegments s where u.dbid=db_id('${wildvalue}') and (segmap & power(2, segment))=power(2,segment) group by s.name")
You’ll also need to figure out a way to transform the “Segment” into a number since the collection script can only provide numbers to the DataSource. You could modify your discovery script to add the segment as part of the instance definition, either the description or an instance level property. I’d work on getting your collection working before attempting that.
actually, Iam think of to add segment as discovery. any idea of that
Do you want to add it as the display name of the instance, the description of the instance, or an instance level property of the instance?
Either way, you’ll need to add a section of code to your discovery script to make the query that returns the segment for each if the sysdatabases you’re discovering. Is there a single query you can run that will return the names of the databases along with the segment for each one (I’m assuming each database only has one segment)?
So, instead of running this query in your discovery:
select name from master..sysdatabases
Is there a query you can run that would return the sysdatabase name in the first column and the segment in the second?
each database has 3 segments
please check my dicovery script. it is running sucessfully but instances are not discovering.please make some changes
import groovy.sql.Sql
import java.sql.*
// Get basic info to connect
def hostname = hostProps.get("system.hostname")
def user = hostProps.get("sybase.user")
def pass = hostProps.get("sybase.pass")
def port = 21000
// Construct an SQL instance with a url and a driver
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()
// Retrieve database names and IDs
def dbRs = stmt.executeQuery("select name, dbid from sysdatabases")
while (dbRs.next()) {
def dbName = dbRs.getString("name")
def dbId = dbRs.getInt("dbid")
// Retrieve segment information for each database
def segmentRs = stmt.executeQuery("select name from '${dbName}'..syssegments where dbid = ${dbId}")
while (segmentRs.next()) {
def segmentName = segmentRs.getString("segment_name")
def segment = segmentRs.getBytes("segment")
// Process segment information and create instance
def instanceName = "${dbName}_${segmentName}_segment"
def instanceConfig = [segment: segment]
createInstance(instanceName, instanceConfig)
}
segmentRs.close()
}
dbRs.close()
stmt.close()
} catch (SQLException e) {
// Handle SQL exception
e.printStackTrace()
} finally {
if (conn != null) {
conn.close()
}
}
// Function to create instance
def createInstance(name, config) {
println("Creating instance ${name} with config ${config}")
// Implementation of instance creation logic here
}
Ok, each db has three segments.
You want your discovery output to have one line per instance you want discovered. You need to provide at least two terms for each instance: unique identifier and display name. You can include other terms as well.
Based on your script, it looks like you probably need the dbName and segmentName combined to form the unique identifier for the segment. Ok. Your function should at minimum look like this:
// Function to create instance
def createInstance(name, config) {
println("${name}##${name}")
}
The first time `name` is in your println statement defines the unique id that will match up in the collection script (if BATCHSCRIPT) is used. It’s referred to as the WILDVALUE.
The second time `name` is in your println statement defines the display name of the instance.
You should be checking the Use Wildvalue as Unique Identifier checkbox (it should be the default, the reasons to have it unchecked are few). Having it checked means that you can make the display name anything you want as long as the wildvalue is unique.
If you wanted to add a description or instance level properties (for grouping), your function would look something like this:
// Function to create instance
def createInstance(name, config) {
description = config.something
prop1 = config.something_else
prop2 = config.something_else_entirely
println("${name}##${name}##${description}####prop1name=${prop1value}&prop2name=${prop2value}")
}
I would also recommend making your display name something a little more readable. You don’t even have to have the db name in the display name. You could put the display name in one of the instance level properties and group by that property.
i have changed the code as mentioned below
import groovy.sql.Sql
// Get basic info to connect
def hostname = hostProps.get("system.hostname")
def user = hostProps.get("sybase.user")
def pass = hostProps.get("sybase.pass")
def port = 21000
// Construct an SQL instance with a URL and a driver
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()
// Retrieve database names and IDs
def dbRs = stmt.executeQuery("select name, dbid from sysdatabases")
while (dbRs.next()) {
def dbName = dbRs.getString("name")
def dbId = dbRs.getInt("dbid")
// Retrieve segment information for each database
def segmentRs = stmt.executeQuery("select name from '${dbName}'..syssegments where dbid = ${dbId}")
while (segmentRs.next()) {
def segmentName = segmentRs.getString("name")
// Process segment information and create instance
def instanceName = "${dbName}_${segmentName}_segment"
def instanceConfig = [segment: segmentName]
createInstance(instanceName, instanceConfig)
}
segmentRs.close()
}
dbRs.close()
stmt.close()
} catch (e) {
// Handle SQL exception
e.printStackTrace()
} finally {
if (conn != null) {
conn.close()
}
}
def createInstance(name, config) {
def description = config.description
def prop1 = config.prop1
def prop2 = config.prop2
println("${name}##${name}##${description}####prop1name=${prop1}&prop2name=${prop2}")
}
i am getting the following output

import groovy.sql.Sql
import java.sql.SQLException
// Get basic info to connect
def hostname = hostProps.get("system.hostname")
def user = hostProps.get("sybase.user")
def pass = hostProps.get("sybase.pass")
def port = 21000
// Construct an SQL instance with a URL and a driver
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()
// Retrieve database names
def dbRs = stmt.executeQuery("select name from master..sysdatabases")
while (dbRs.next()) {
def dbName = dbRs.getString("name")
// Construct a new SQL instance for each database
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()
// Retrieve segment names for the current database
def segmentRs = dbStmt.executeQuery("select name from syssegments")
while (segmentRs.next()) {
def segmentName = segmentRs.getString("name")
// Process segment information and create instance
def instanceName = "${dbName}_${segmentName}_segment"
def instanceConfig = [
"segment": segmentName,
"description": "Instance for segment: ${segmentName}",
"prop1name": "prop1value",
"prop2name": "prop2value"
]
createInstance(instanceName, instanceConfig)
}
segmentRs.close()
dbStmt.close()
} catch (SQLException e) {
// Handle SQL exception
e.printStackTrace()
} finally {
if (dbConn != null) {
dbConn.close()
}
}
}
dbRs.close()
stmt.close()
} catch (SQLException e) {
// Handle SQL exception
e.printStackTrace()
} finally {
if (conn != null) {
conn.close()
}
}
def createInstance(name, config) {
def description = config.description
def prop1 = config.prop1name
def prop2 = config.prop2name
println("${name}##${name}##${description}####prop1name=${prop1}&prop2name=${prop2}")
}
i got the out put as desired

the problem here is how to pass this instance as wild value in the second script. say if my second script is below
import groovy.sql.Sql
//@Grab('org.hsqldb:hsqldb:2.7.1:jdk8')
//@GrabConfig(systemClassLoader=true)
Class.forName("com.sybase.jdbc4.jdbc.SybDriver")
// Get basic info to connect
def hostname = hostProps.get("system.hostname")
def user = hostProps.get("sybase.user")
def pass = hostProps.get("sybase.pass")
def port = 21000
def wildvalue = instanceProps.get("wildvalue")
def segmentWildcard = "${wildvalue}"
// Construct an SQL instance with a url and a driver
def url = "jdbc:sybase:Tds:${hostname}:${port}"
def sql = Sql.newInstance(url, user, pass, "com.sybase.jdbc4.jdbc.SybDriver")
sql.eachRow("sp_helpsegment '${segmentWildcard}'") { row ->
println row
}
sql.close()


please check the above as data is not polling
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.
As i got my out put as required, cant’ i poll data with the old one?
As my team already ok , with the out put we recived earlier

can you please tell me how to capture data in data poll
i have tried different option

please look into it
Thanks
Reply
Sign up
Already have an account? Login
Login to the community
No account yet? Create an account
LogicMonitor Employee? Click here:
LogicMonitor Employee LoginEnter your username or e-mail address. We'll send you an e-mail with instructions to reset your password.