How to query MySQL DB and show the result in a graph using OBM policies

Hello All,

- I have OpenText OBM version 24.2 installed in a distributed windows environment (2 DPSs and 2 GWs).

- our customer need to run a query on a MySQL DB using Operations Agent and present the output as a graph in a dashboard. So, does any one know how to do it using OA as I know it can be done using SIteScope but, the requirement need to be done using OA.

Best Regards,

  • 0  

    Hello,

    Are you using Operations Bridge Unified Content for MySQL (https://docs.microfocus.com/doc/Content_for_MySQL/24.1/Home) or something else to monitor your database? 

    The documentation doesn't show any Porformance Perspective examples, but metrics are being created and these will be stored in coda which you can view.

    Thanks.

  • 0 in reply to   

    Thanks for your replay.

    we have the unified content for MySQL but, we need to run a custom query on the database like: SELECT count(*)
    FROM DEG_MULTISIM_DEVICE
    WHERE DEG_MD_STATUS='Active' AND DEG_MD_CREATETIME >=DATE_SUB(NOW(),INTERVAL 3 HOUR); and the output should be visualized on a graph

    So, we don't know how to do it using policies or something like that.

    regards, 

  • 0   in reply to 

    Hello,

    Please review https://easyengine.io/tutorials/mysql/mycnf-preference/ which describes how to setup  ~/.my.cnf to use a username and password.

    Then run your script:

    mysql -e "SELECT count(*) FROM DEG_MULTISIM_DEVICE WHERE DEG_MD_STATUS='Active' AND DEG_MD_CREATETIME >=DATE_SUB(NOW(),INTERVAL 3 HOUR);"

    Then you can use the OA12 perl APIs to store the value in coda which you can then graph.  This is a great resource:  Easily collect custom metrics using Perl and visualize in OBM .  Then you can use something like (this is just a sample, and I've not tested it but it will be something like).

    #!/path/to/perl
    use DBI; 
    use oaperlapi; 

    # Step 1: MySQL connection settings and querying
    my $dsn = "DBI:mysql:database=database;host=host;port=3306";
    my $user = "dbuser";
    my $password = "dbpassword";

    # Connect to MySQL
    my $dbh = DBI->connect($dsn, $user, $password, { RaiseError => 1, PrintError => 0 })
    or die "Could not connect to MySQL database: $DBI::errstr";

    my $sql = "SELECT count(*) FROM DEG_MULTISIM_DEVICE WHERE DEG_MD_STATUS='Active' AND DEG_MD_CREATETIME >=DATE_SUB(NOW(),INTERVAL 3 HOUR);";

    my $sth = $dbh->prepare($sql);
    $sth->execute();

    my ($active_count) = $sth->fetchrow_array(); # This retrieves the count value
    print "Active devices count: $active_count\n"; # Print the result for debugging

    $access = oaperlapi::OAAccess->new();

    $molist = oaperlapi::MetricObservationList->new();

    $obsTimestamp = time(); # Current time in seconds since epoch
    $mgbl = oaperlapi::MetricObservation->new($obsTimestamp);

    $mgbl->AddCounter("mySQL", "mySQL", "Active Devices Count", $active_count);

    $molist->AddMetricObservation($mgbl);

    $access->SubmitMetricObservationList($molist);

    $sth->finish();
    $dbh->disconnect();

    print "Data submitted to Oracle EBS datastore successfully.\n";

    I hope you get a better answer.

  • Suggested Answer

    0   in reply to   

    Setting status as suggested answer.