Forum Discussion

Tom's avatar
8 years ago

Measure, Alert on Ulimit level

Greeting LM community,

 

Is it possible to alert on the Linux ulimit level?

 

Cheers,

Tom

  • Jon_Blake's avatar
    Jon_Blake
    Former Employee

    Hi Tom, 

    You could create a script datasource to get the ulimit value, here is an example below.  You would need to create a datapoint in the datasource using a key value pair *Key set to "Ulimit".  You can set a threshold in the datapoint for alerting.  You will need to set "ssh.user" and "ssh.pass" properties on the device.

    The output from the script will look like this --> Ulimit:1024

    -Jon

    /* Ulimit script */

    import com.santaba.agent.groovyapi.expect.Expect

    def hostname = hostProps.get("system.hostname");
    def username = hostProps.get("ssh.user");
    def pass = hostProps.get("ssh.pass");

    // default timeout for Expect SSH
    def timeout = 15;

    // Command to get load average data
    def ulimit_cmd = "ulimit -n\n";

    // Expected shell prompt character, may have to be changed
    // Linux generally uses "#" for root shells
    def prompt = '\\$'

    /*
     * Ulimit Pattern Key
     */
    ulimit_pattern = ~/^(\d+)$/


    // Connect to the device and wait for the prompt
    ssh_conn = Expect.open(hostname, username, pass, timeout);
    ssh_conn.expect(prompt);

    // Send the ulimit command and wait for the prompt
    ssh_conn.send(ulimit_cmd);
    ssh_conn.expect(prompt);

    // Iterate over output
    ssh_conn.before().eachLine
    { line ->
    //println line
        // Run the match
        matcher = ulimit_pattern.matcher(line);

        // Did we match?
        if (matcher.getCount() > 0)
        {
            // Yes, print data
            println "ulimit:" + matcher[0][1];
        }

    }

    // Exit the shell!
    ssh_conn.send("exit\n");
    ssh_conn.expectClose();

    return 0;

  • Thanks for your time and effort on this :)/emoticons/smile@2x.png 2x" title=":)" width="20">

     

    Regards,

    Tom