Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

rzrbld/zabbix-exporter-3000

Open more actions menu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

zabbix-exporter-3000

just another zabbix exporter for Prometheus

like the other exporters it use Zabbix API and represent response as Prometheus metrics.

Docker hub stats GitHub License

Limitations:

Main limitation - one instance = one query.

Configuration

Variable Description Default
ZABBIX_API_ENDPOINT full url to Zabbix API http://zabbix/api_jsonrpc.php
ZABBIX_USER Zabbix user admin
ZABBIX_PASSWORD Zabbix password admin
ZABBIX_SKIP_SSL Skip Zabbix endpoint SSL check true
ZE3000_STRICT_METRIC_REG May be useful when you have an error about metric duplicate on registration - set this to false. On this case, you highly likely have a problem with query, but this may help you investigate. Don't set this to 'false' on real environment true
ZE3000_SINGLE_METRIC If you, for some reason, won't use Default mechanics with mapping metric name and field from Zabbix response. true
ZE3000_SINGLE_METRIC_HELP Hardcoded HELP field for Single metric mechanics single description
ZE3000_HOST_PORT which host and port exporter should listening. Supported notations - 0.0.0.0:9080 or :9080 localhost:8080
ZE3000_METRIC_NAMESPACE Metric namespace (part of metric name in Prometheus) zbx
ZE3000_METRIC_SUBSYSTEM Metric subsystem (part of metric name in Prometheus) subsystem
ZE3000_METRIC_NAME_PREFIX Metric name prefix prefix
ZE3000_METRIC_NAME_FIELD Mapping field. Which field form Zabbix response use as part of a name. Please note - this field will be trimmed, set to lower case and rid off of all symbols except A-z and 0-9. Only top level Zabbix response fields supported key_
ZE3000_METRIC_VALUE Mapping field. Which field form Zabbix response use as value of metric. Only top level Zabbix response fields supported lastvalue
ZE3000_METRIC_HELP Mapping field. Which field form Zabbix response use as help field of metric. Only top level Zabbix response fields supported description
ZE3000_ZABBIX_METRIC_LABELS Mapping field. Which field form Zabbix response use as labels. This field supported first level and second level fields name,
itemid,
key_,
hosts>host,
hosts>name,
interfaces>ip,
interface>dns
ZE3000_METRIC_URI_PATH uri path where prometheus can consume metrics /metrics
ZE3000_ZABBIX_REFRESH_DELAY_SEC How frequent Zabbix exporter will be query Zabbix. In seconds 10
ZE3000_ZABBIX_QUERY any Zabbix query, with field "auth" with value "%auth-token%" - yes, literally "%auth-token%" {"jsonrpc": "2.0",
"method": "item.get",
"params": {
"application":"My Valuable Application",
"output":["itemid","key_","description","lastvalue"],
"selectDependencies": "extend",
"selectHosts": ["name","status","host"],
"selectInterfaces": ["ip","dns"],
"sortfield":"key_" },
"auth": "%auth-token%",
"id": 1 }

How-to use

requirements

  • zabbix
  • prometheus
  • docker or k8s

description

Make some query to zabbix server over Insomnia, Postman, curl, you name it. Let's say this query is:

{
    "jsonrpc": "2.0",
    "method": "item.get",
    "params": {
    	"application":"My Super Application",
        "output": ["itemid","key_","description","lastvalue"],
        "selectDependencies": "extend",
        "selectHosts": ["name","status","host"],
        "selectInterfaces": ["ip","dns"],
        "sortfield":"key_"
    },
    "auth": "1234ml34kl3f4mk4gkl680klfmkl3fml",
    "id": 1
}

and response of this query is:

"jsonrpc": "2.0",
    "result": [
        {
            "itemid": "452345",
            "key_": "concurrencyConnections",
            "description": "The number of current concurrency connections.",
            "hosts": [
                {
                    "hostid": "54637",
                    "name": "Mighty Frontend",
                    "status": "2",
                    "host": "mighty.fronend"
                }
            ],
            "interfaces": [],
            "lastvalue": "9"
        },
        {
            "itemid": "902934",
            "key_": "numbeOfConnections",
            "description": "The number of currently active connections.",
            "hosts": [
                {
                    "hostid": "42092",
                    "name": "Mega Application",
                    "status": "0",
                    "host": "mega.application"
                }
            ],
            "interfaces": [
                {
                    "interfaceid": "1900",
                    "ip": "10.4.4.3",
                    "dns": ""
                }
            ],
            "lastvalue": "10987"
        },
      ],
  "id": 1
}

configure and run

Since we know the query and know what is return - let's configure and start Zabbix Exporter 3000: ZE3000_ZABBIX_METRIC_LABELS - supports second level fields over > operator.

docker run

docker run -d \
      -p 8080:8080 \
      -e ZABBIX_API_ENDPOINT=https://zabbix.example.com/zabbix/api_jsonrpc.php \
      -e ZABBIX_USER=someuser \
      -e ZABBIX_PASSWORD=str0nGpA5sw0rd \
      -e ZABBIX_SKIP_SSL=true \
      -e ZE3000_STRICT_METRIC_REG=true \
      -e ZE3000_METRIC_NAME_FIELD="key_" \
      -e ZE3000_SINGLE_METRIC=false \
      -e ZE3000_METRIC_NAMESPACE="megacompany" \
      -e ZE3000_METRIC_SUBSYSTEM="frontend" \
      -e ZE3000_METRIC_NAME_PREFIX="nginx" \
      -e ZE3000_METRIC_NAME_FIELD="key_" \
      -e ZE3000_METRIC_VALUE="lastvalue" \
      -e ZE3000_METRIC_HELP="description" \
      -e ZE3000_METRIC_URI_PATH="/my-metrics"
      -e ZE3000_ZABBIX_REFRESH_DELAY_SEC=20 \
      -e ZE3000_ZABBIX_METRIC_LABELS="itemid,key_,hosts>host,hosts>name,interfaces>ip,interface>dns" \
      -e ZE3000_HOST_PORT=localhost:8080 \
      -e ZE3000_ZABBIX_QUERY='{     "jsonrpc": "2.0",     "method": "item.get",     "params": {     	"application":"My Super Application",         "output": ["itemid","key_","description","lastvalue"],         "selectDependencies": "extend",         "selectHosts": ["name","status","host"],         "selectInterfaces": ["ip","dns"],         "sortfield":"key_"     },     "auth": "%auth-token%",     "id": 1 }' \
      rzrbld/ze3000:latest

💥 let's suppose everything running ok, and you don't have any error messages from ze3000

by default ze3000 brings up next endpoints:

  • /metrics - main and exported metrics (you can change it over ZE3000_METRIC_URI_PATH environment variable. In example above this env variable set to /my-metrics)
  • /ready - readiness probe for k8s monitoring
  • /live - liveness probe for k8s monitoring

Let's se at /my-metrics

$ curl http://localhost:8080/my-metrics
...
megacompany_frontend_nginx_concurrencyconnections{hosts_host="mighty.fronend",hosts_name="Mighty Frontend",interface_dns="NA",interfaces_ip="10.4.4.3",itemid="452345",key_="concurrencyConnections"} 9
...
megacompany_frontend_nginx_numbeofconnections{hosts_host="mega.application",hosts_name="Mega Application",interface_dns="NA",interfaces_ip="NA",itemid="902934",key_="numbeOfConnections"} 10987

kubernetes run

Look at example deployments at k8s folder in this repo.

How to build standalone binary

requirements

  • go 1.13+
  • git client
$ git clone https://github.com/rzrbld/zabbix-exporter-3000
$ cd zabbix-exporter-3000
$ go build main.go

after that you need to export environment variables - just like in docker stage above and run as average binary.

About

just another zabbix exporter for Prometheus

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Morty Proxy This is a proxified and sanitized view of the page, visit original site.