Ad Widget

Collapse

Using zabbix to monitor output from a cron job

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • luvdablus
    Junior Member
    • Sep 2018
    • 1

    #1

    Using zabbix to monitor output from a cron job

    I am new to zabbix. I have a cronjob that runs on a redhat linux server that shows me the % of tablespace of an oracle db, but still takes into account autosizing. I want to make zabbix agent aware of this cron output and report it.
    Is this possible?
  • kloczek
    Senior Member
    • Jun 2006
    • 1771

    #2
    http://uk.linkedin.com/pub/tomasz-k%...zko/6/940/430/
    https://kloczek.wordpress.com/
    zapish - Zabbix API SHell binding https://github.com/kloczek/zapish
    My zabbix templates https://github.com/kloczek/zabbix-templates

    Comment

    • bbrendon
      Senior Member
      • Sep 2005
      • 870

      #3
      I don't see how that link is relevant...
      Unofficial Zabbix Expert
      Blog, Corporate Site

      Comment

      • kloczek
        Senior Member
        • Jun 2006
        • 1771

        #4
        Originally posted by bbrendon

        I don't see how that link is relevant...
        Trust me it is, because in case of cronjob you may know when job starts (less likely but still some people may be interested when it started) and when cronjob ends, and with what kind of the status.
        Because how cronjobs are working (as a bit asynchronous events) you will never know when exactly it started and finished.
        To monitor async things trapper items are the proper type of the zabbix items.
        In other words to monitor exact type of the cronjob you may need 1 to 3 metrics:
        - status of the cronjob
        and optionally:
        - start time
        - end time
        Using above you may organise for example backups monitoring because end_time-start_time will give you how long backup have been running (to monitor is this time does not exceeds your backup window) and first metric will give you possibility to define second trigger about status of the backup.
        All what you need is adding zabbix_send command into your backup script.

        In you case you want to monitor only output of the cronjobs. This as well asyns metric. You need to organize just one text item which content will be delivered over trapper item as well.
        Last edited by kloczek; 24-09-2018, 10:48.
        http://uk.linkedin.com/pub/tomasz-k%...zko/6/940/430/
        https://kloczek.wordpress.com/
        zapish - Zabbix API SHell binding https://github.com/kloczek/zapish
        My zabbix templates https://github.com/kloczek/zabbix-templates

        Comment

        • Markku
          Senior Member
          Zabbix Certified SpecialistZabbix Certified ProfessionalZabbix Certified Expert
          • Sep 2018
          • 1781

          #5
          I have a Perl script that is run daily in cron to do the MySQL database partition maintenance. In the Perl script I added quick’n dirty Zabbix trapper:

          Code:
          printf("Sending Zabbix trap to server\n");
          my $dt = DateTime->now;
          $dt->set_time_zone($curr_tz);
          my $dtstr = $dt->ymd . " " . $dt->hms;
          system("/usr/bin/zabbix_sender -z zabbix.server.address -s hostname.of.this.server -k mysql.partition_maintenance -o \"Run at $dtstr\"");
          Then, in the Zabbix server I added that mysql.partition_maintenance item (type of character if I remember correctly), and I created a ”nodata” trigger for that item. Thus, if the maintenance script is not executed for some specific amount of time, the trigger will notify the admins. In this example the contents of the trapper item data is not relevant (because just ”nodata” is used) but you could also include some status message in the data to check that in the trigger if needed.

          Markku

          Comment

          • kloczek
            Senior Member
            • Jun 2006
            • 1771

            #6
            Originally posted by Markku
            I have a Perl script that is run daily in cron to do the MySQL database partition maintenance. In the Perl script I added quick’n dirty Zabbix trapper:
            BTW patritioning.
            Your way of maintaining partitions has some embedded issue.
            If you DB backend will be used on master/slave and time to time yoy willl be moving master DB you must always remember about move your script to new location.
            It is solution which has no this issue which is using SQL event.
            SQL event is SQL engine internal like cron job manager and on define it yu can specify even does it needs to be executed on master or slave DB,
            As event executed on master is perfect for maintaining partitioning similar event executed on slave can be used to schedule make backup (lock DB -> flush-> create snapshot and copy it off site or even execute mysqldump -> unlock database)
            Good thing about that way is everything is in database, Making database dump you can specyfy dump as well database events. Importing such dump will automatically initiate scheduling database events.
            Only thing which is necessary to take care is make sure that MySQL engine event scheduler is switched ON, and this is why in my MySQL monitoring template is metric about checking
            "SELECT variable_value FROM performance_schema.global_variables WHERE variable_name='event_scheduler';" and activated trigger SVC::MySQL::event_scheduler=OFF if this query des not return "ON"

            Code:
            mysql> show events\G;
            *************************** 1. row ***************************
                              Db: zabbix
                            Name: e_part_history_manage
                         Definer: root@localhost
                       Time zone: SYSTEM
                            Type: RECURRING
                      Execute at: NULL
                  Interval value: 1
                  Interval field: DAY
                          Starts: 2017-12-14 00:02:00
                            Ends: NULL
                          Status: ENABLED
                      Originator: 0
            character_set_client: utf8
            collation_connection: utf8_general_ci
              Database Collation: utf8_bin
            *************************** 2. row ***************************
                              Db: zabbix
                            Name: e_part_trends_manage
                         Definer: root@localhost
                       Time zone: SYSTEM
                            Type: RECURRING
                      Execute at: NULL
                  Interval value: 2
                  Interval field: WEEK
                          Starts: 2017-12-14 00:02:00
                            Ends: NULL
                          Status: ENABLED
                      Originator: 0
            character_set_client: utf8
            collation_connection: utf8_general_ci
              Database Collation: utf8_bin
            2 rows in set (0.00 sec)
            
            
            mysql> SHOW CREATE EVENT e_part_history_manage\G; SHOW CREATE EVENT e_part_trends_manage\G;
            *************************** 1. row ***************************
                           Event: e_part_history_manage
                        sql_mode: ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
                       time_zone: SYSTEM
                    Create Event: CREATE DEFINER=`root`@`localhost` EVENT `e_part_history_manage` ON SCHEDULE EVERY 1 DAY STARTS '2017-12-14 00:02:00' ON COMPLETION PRESERVE ENABLE COMMENT 'Zabbix history tables partitioning.' DO BEGIN
                    CALL partition_maintenance('zabbix', 'history',        28,    24,    7);
                    CALL partition_maintenance('zabbix', 'history_log',    28,    24,    7);
                    CALL partition_maintenance('zabbix', 'history_str',    28,    24,    7);
                    CALL partition_maintenance('zabbix', 'history_text',    28,    24,    7);
                    CALL partition_maintenance('zabbix', 'history_uint',    28,    24,    7);
                END
            character_set_client: utf8
            collation_connection: utf8_general_ci
              Database Collation: utf8_bin
            1 row in set (0.00 sec)
            
            ERROR:
            No query specified
            
            *************************** 1. row ***************************
                           Event: e_part_trends_manage
                        sql_mode: ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
                       time_zone: SYSTEM
                    Create Event: CREATE DEFINER=`root`@`localhost` EVENT `e_part_trends_manage` ON SCHEDULE EVERY 2 WEEK STARTS '2017-12-14 00:02:00' ON COMPLETION PRESERVE ENABLE COMMENT 'Zabbix trends tables partitioning.' DO BEGIN
                    CALL partition_maintenance('zabbix', 'trends',        730,    336,    2);
                    CALL partition_maintenance('zabbix', 'trends_uint',    730,    336,    2);
                END
            character_set_client: utf8
            collation_connection: utf8_general_ci
              Database Collation: utf8_bin
            1 row in set (0.00 sec)
            https://dev.mysql.com/doc/refman/5.7...ow-events.html
            Last edited by kloczek; 05-10-2018, 00:10.
            http://uk.linkedin.com/pub/tomasz-k%...zko/6/940/430/
            https://kloczek.wordpress.com/
            zapish - Zabbix API SHell binding https://github.com/kloczek/zapish
            My zabbix templates https://github.com/kloczek/zabbix-templates

            Comment

            • Markku
              Senior Member
              Zabbix Certified SpecialistZabbix Certified ProfessionalZabbix Certified Expert
              • Sep 2018
              • 1781

              #7
              Hi, thanks for the note, I have recognized the situation and will look into it. In the wiki there were good instructions for that as well I believe.

              Markku

              Comment

              • kloczek
                Senior Member
                • Jun 2006
                • 1771

                #8
                Originally posted by Markku
                Hi, thanks for the note, I have recognized the situation and will look into it. In the wiki there were good instructions for that as well I believe.
                Last small detail about partitioning monitoring.
                Instead monitoring status of the execution partitioning procedure which needs to be done using trapper item(s) it is easier to check does exist next day/week/month partition on exact table and than on top of this create trigger to warn that something is wrong with partitioning.
                http://uk.linkedin.com/pub/tomasz-k%...zko/6/940/430/
                https://kloczek.wordpress.com/
                zapish - Zabbix API SHell binding https://github.com/kloczek/zapish
                My zabbix templates https://github.com/kloczek/zabbix-templates

                Comment

                Working...