| SPID = 1 BLOCKED = 0 SPID = 3 BLOCKED = 0 SPID = 4 BLOCKED = 0 SPID = 5 BLOCKED = 0 SPID = 6 BLOCKED = 0 SPID = 7 BLOCKED = 0 SPID = 8 BLOCKED = 0 SPID = 9 BLOCKED = 0 SPID = 10 BLOCKED = 0 SPID = 11 BLOCKED = 0 SPID = 12 BLOCKED = 0 SPID = 13 BLOCKED = 0 SPID = 14 BLOCKED = 0 SPID = 17 BLOCKED = 0 SPID = 37 BLOCKED = 0 SPID = 60 BLOCKED = 0 SPID = 107 BLOCKED = 0 SPID = 147 BLOCKED = 0 SPID = 165 BLOCKED = 0 SPID = 183 BLOCKED = 0 SPID = 251 BLOCKED = 0 SPID = 273 BLOCKED = 0 SPID = 319 BLOCKED = 0 SPID = 430 BLOCKED = 0 SPID = 435 BLOCKED = 0 SPID = 466 BLOCKED = 0 SPID = 470 BLOCKED = 0 SPID = 494 BLOCKED = 0 SPID = 522 BLOCKED = 0 SPID = 539 BLOCKED = 0 SPID = 555 BLOCKED = 0 SPID = 584 BLOCKED = 0 SPID = 596 BLOCKED = 0 SPID = 600 BLOCKED = 0 SPID = 651 BLOCKED = 0 SPID = 673 BLOCKED = 0 i want to capture the above data, the above data is my querry result. please tell me the data point settings |
LM User
·3 years agoPlease start a new thread with this question.
manthena2020
OP3 years agohi , i have the follwing path
To read log file using event source can you please tell me how to fill the logfielpath using above path
LM User
·3 years agoYeah, you should avoid the space. You can do a .replaceAll(“ “,””) on that portion of the string to make sure it doesn’t have any spaces in it.
manthena2020
OP3 years agoi am have space in one of the output ( recv sleep). i have issue to capture that datapoint. when i give space its not pulling data
can you please tell me . Thanks
manthena2020
OP3 years agoThanks bro problem solved. I have used ‘-’ instead of : . problem solved
Thanks
Bye bro
LM User
·3 years agohttps://www.logicmonitor.com/support/logicmodules/datasources/active-discovery/script-active-discovery#:~:text=Wildvalue%20cannot%20contain%20the%20following%20characters%3A%20%3D%2C%20%3A%2C%20%5C%2C%20%23%2C%20space
manthena2020
OP3 years agoJust for clarification can we use ‘-’ instead of _ As i have split issues with _.
LM User
·3 years agoYour output must change since `:` is not allowed in the wildvalue. This is why I suggested the script updates.
If your wildvalue were “BTS_PROD_system” your output would be “BTS_PROD_system.Size: 21260” so your datapoint key for Size would be `##WILDVALUE##.Size`.
manthena2020
OP3 years agoAs 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
LM User
·3 years agoOh, I misunderstood. I thought you said the data was not polling.
manthena2020
OP3 years agoAs i got my out put as required, cant’ i poll data with the old one?
LM User
·3 years agoI suggest the following simpler version of your discovery script:
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.
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.
manthena2020
OP3 years agoplease check the above as data is not polling
manthena2020
OP3 years agoimport 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()
manthena2020
OP3 years agoi 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
LM User
·3 years agoOk, 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:
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:
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.
manthena2020
OP3 years agoplease 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
}
manthena2020
OP3 years agoeach database has 3 segments
LM User
·3 years agoDo 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:
Is there a query you can run that would return the sysdatabase name in the first column and the segment in the second?
manthena2020
OP3 years agoactually, Iam think of to add segment as discovery. any idea of that
LM User
·3 years agoYou 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:
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.
manthena2020
OP3 years agohi please find the above codes and output. here i want to make segments as my instances. please tell me how to do.
manthena2020
OP3 years agomanthena2020
OP3 years agoLM User
·3 years agoThis is the important part of the error:
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.
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.
manthena2020
OP3 years agohi, iam getting error related to time blocked, can you please check
manthena2020
OP3 years agomanthena2020
OP3 years agoAs of now , its ok . I need to go for TEST and see. Thanks soo much
LM User
·3 years agoSo, you’re good? All working as expected?
manthena2020
OP3 years agoThanks , bro
manthena2020
OP3 years agoyes, time_blocked is comming as null
LM User
·3 years agoWhat does your raw collection script output look like? If blocked is 0, time_blocked should be null, right?
manthena2020
OP3 years agoHI, 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
manthena2020
OP3 years agomanthena2020
OP3 years agosure i will try to workout and get back to you
manthena2020
OP3 years agomanthena2020
OP3 years agomanthena2020
OP3 years agoyes, null value as it will give time when it gets blocked only
LM User
·3 years agoIs row.time_blocked in the output of your query?
manthena2020
OP3 years agoThe script failed, elapsed time: 0 seconds - Cannot invoke method tokenize() on null object
java.lang.NullPointerException: Cannot invoke method tokenize() on null object
at org.codehaus.groovy.runtime.NullObject.invokeMethod(NullObject.java:91)
at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:47)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
at org.codehaus.groovy.runtime.callsite.NullCallSite.call(NullCallSite.java:34)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:128)
at Script1309$_run_closure2.doCall(Script1309.groovy:36)
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(DelegatingMethodAccessorIm
LM User
·3 years agoYou do not need to have the SPID in the WHERE statement of your sql query. You could, but you’d have to change from BATCHSCRIPT to SCRIPT, which would spawn an individual task on the collector for each SPID and you don’t want to do that.
BATCHSCRIPT lets you execute one query and return all the data at once, for all the instances. I assumed you needed the database name in your SQL query to return the right SPIDs. If you don’t need that, don’t have a where statement at all. Just query all the SPIDs and return all the data for all the SPIDs.
You don’t need a different datasource for cmd and time_blocked. If they were both numerical, you’d have separate datapoints. So you’d have a datapoint for blocked, a datapoint for cmd, and a datapoint for time_blocked.
manthena2020
OP3 years agoresults = sql.rows("select spid, time_blocked, blocked from master..sysprocesses WHERE db_name(dbid)=${dbname}") }. our instance here is spid , can i change to spid ie.. as mentioned below
results = sql.rows("select spid, time_blocked, blocked from master..sysprocesses WHERE spid =${wildvalue}")
do i need to create datasource for CMD & TIME_bloked? if what are the properties for them
LM User
·3 years agoOk, non-numeric data can’t be fetched as part of collection. However, you could add the cmd string to the instance level properties. so that you have that information available in LM. You’d do that by making your discovery output look like this:
Where cmdofSPID1, cmdofSPID3, etc. is just the string from the cmd column.
As for the time_blocked, you’d need to convert that to an integer or floating point decimal (HH:MM is not a number, it’s a string). So, your collection script would look like this:
I added time_blocked to your SQL statement as you probably have already done.
I changed your each loop to just a basic for..each loop and used simple print statements.
I added 3 lines to the for..each loop to grab the hours and minutes from the time_blocked string, convert to an integer and put it all together as an integer. Then I printed out the line that gives the data to LM to put in the time_blocked datapoint.
Also, since you’re discovering the SPIDs as instances, the wildvalue isn’t the name of the database anymore. I assume there’s just one db name. If there’s more, we can discuss it. Instead of pulling the db name from the wildvalue (which doesn’t contain it anymore), i added it as a host property. You’ll need to add the dbname as a host property to the host (and probably apply it to the appliesto since the DS won’t work without it).
manthena2020
OP3 years agoyes cmd is not numeric but time_blocked is time format
LM User
·3 years agoAre cmd and time_blocked additional numeric datapoints about SPID1 (and each other SPID)?
manthena2020
OP3 years agook, what if i am querrying select spid, cmd, blocked, time_blocked from master..sysprocesses
Then i will get my collection script would be
SPID1.BLOCKED: 0.CMD:tunning.time_blocked:18:52 ?
is it right
LM User
·3 years agoPiecing together what you’re trying to do here. You want to know how many blocked there are per SPID, right? Then yes, your discovery should be outputting something like this:
Your collection script is pretty close to what you eventually want. Instead of
You would have this:
Your datapoint would be defined as a multi-line key-value pair and the key would be:
When your collection script outputs this:
LM will automatically take care of matching up the lines in your collection output with the lines in your discovery output based on your datapoint key. The key dictates that LM should look for lines in your collection output that have the WILDVALUE, then a dot, then the word “BLOCKED”, then a colon, then a number. If the WILDVALUE of your collection script output line matches the WILDVALUE of a line in the discovery script, then the data will be matched up and added to that instance.
manthena2020
OP3 years agoAs per my i understanding i shall the discovery method as SPID instead of Database name.?
manthena2020
OP3 years agoimport 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
// Construct an SQL instance with a url and a driver
def url = "jdbc:sybase:Tds:${hostname}:${port}", username=user, password=pass
// Sybase SQL Driver
def driver = "com.sybase.jdbc4.jdbc.SybDriver"
// Create a connection to the SQL server
def sql = Sql.newInstance(url, user, pass, driver)
def results = []
sql.withTransaction {
// Iterate over query results and list the databases
def wildvalue = instanceProps.get("wildvalue")
results = sql.rows("select spid, blocked from master..sysprocesses WHERE db_name(dbid)=${wildvalue}")
}
sql.close()
// Format the results as key-value pairs
def resultParsed = results.collect { row ->
"SPID = ${row.spid}\nBLOCKED = ${row.blocked}\n"
}
// Join the results with newlines and print the output
println resultParsed.join("\n")
return 0
manthena2020
OP3 years agoimport groovy.sql.Sql
//@Grab('org.hsqldb:hsqldb:2.7.1:jdk8')
//@GrabConfig(systemClassLoader=true)
//@Grab("com.sybase.jdbc4.jdbc.SybDriver")
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
// Construct an SQL instance with a url and a driver
def url = "jdbc:sybase:Tds:##hostname##:21000", username=user, password=pass
//def url = "jdbc:sybase:Tds:hostname:port", "user", "pass"
// sybase SQL Driver
def driver = "com.sybase.jdbc4.jdbc.SybDriver"
// Create a connection to the SQL server
sql = Sql.newInstance(url,user,pass,driver)
sql.withTransaction {
// Iterate over query results and list the databases
sql.eachRow("select name from master..sysdatabases")
{
name= it.toString().split(":")[1].replace("]","")
// Create an instance for each database
println name+"##"+name
}
}
sql.close()
return 0
LM User
·3 years agoYou still didn’t answer any of the questions. Batchscript? What discovery are you doing?
At any rate, you’re thinking about it wrong. SPID651 is not data. It’s the identifier. So you should have a discovery script that creates the instances based on the identifiers, then your collection script outputs the data with the identifier and datapoint name before the colon and the data after the colon.
manthena2020
OP3 years agoif i go like this
SPID651.blocked: 0
SPID673.blocked: 0
i cant predifne SPID651 in datapoints , as there was no gaurantee that this is going to be in the table
manthena2020
OP3 years agoi just wanted to store all spid and blocked info
manthena2020
OP3 years agomanthena2020
OP3 years agoLM User
·3 years agoYou’re going to need to provide more information. Is this a batchscript datasource? What does your discovery look like?
Your output will need to change if it’s batchscript.
It’ll probably need to look something like:
SPID651.blocked: 0
SPID673.blocked: 0
This makes assumptions since you didn’t provide any of the required details. Assuming you want separate instances for each line in your output and assuming blocked is the single datapoint you want to store for each of these instances.
manthena2020
OP3 years agoplease help