Ad Widget

Collapse

How to get metric from python script

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • scav
    Junior Member
    • Aug 2022
    • 4

    #1

    How to get metric from python script

    Hi, I'm working on a python script to send logging details to zabbix. The machine where I'm working (linux Ubuntu) is already monitored through the agent installed and it is sending everything to the server with no issues.

    After some research i found that i can send to my server logging details from python script using this:



    from pyzabbix import ZabbixMetric, ZabbixSender

    # Send metrics to zabbix trapper
    packet = [
    ZabbixMetric('hostname1', 'test[cpu_usage]', 2),
    ZabbixMetric('hostname1', 'test[system_status]', "OK"),
    ZabbixMetric('hostname1', 'test[disk_io]', '0.1'),
    ZabbixMetric('hostname1', 'test[cpu_usage]', 20, 1411598020),
    ]

    result = ZabbixSender(use_config=True).send(packet)




    source: https://github.com/adubkov/py-zabbix#readme

    If I'm not wrong this should work without inserting any information, given that the python library is taking all the details from my config file: /etc/zabbix/zabbix_agentd.conf (source: https://py-zabbix.readthedocs.io/en/...art_guide.html), is this correct?

    If i run the script no errors are showed up so i assume that my script is sending something?

    Last and most important question how can i map this from the server side, i have already been inserting new items under "configuration" -> "Templates" -> items but i don't know how to instruct the server to look for that specific key, Type and so on...


    Thanks
    Attached Files
  • tim.mooney
    Senior Member
    • Dec 2012
    • 1427

    #2
    Originally posted by scav
    i have already been inserting new items under "configuration" -> "Templates" -> items but i don't know how to instruct the server to look for that specific key, Type and so on...
    When you assign a template to a host, all the items, triggers, graphs, etc. that are part of that template are applied to that host.



    Comment

    • scav
      Junior Member
      • Aug 2022
      • 4

      #3
      hi tim.mooney , I'm adding an item to an existing template. this link is usefull: https://www.zabbix.com/documentation...items/item/key thanks, but given the code posted above what would you suggest to change on the screenshot below?

      if this is the metric ZabbixMetric('hostname1', 'test[cpu_usage]', 2),

      key=test ?
      type?




      Click image for larger version

Name:	image.png
Views:	843
Size:	88.8 KB
ID:	449948


      Comment

      • cyber
        Senior Member
        Zabbix Certified SpecialistZabbix Certified Professional
        • Dec 2006
        • 4807

        #4
        Originally posted by scav
        if this is the metric ZabbixMetric('hostname1', 'test[cpu_usage]', 2),

        key=test ?
        type?
        No... Key is "test[cpu_usage]"
        type is "Zabbix trapper". (your script even says "Send metrics to zabbix trapper".. )

        Comment

        • scav
          Junior Member
          • Aug 2022
          • 4

          #5
          Hi cyber thank you very much! It is now working pefectly!!

          Comment

          Working...