monitoringartist / zabbix-docker-monitoring

:whale: Docker/Kubernetes/Mesos/Marathon/Chronos/LXC/LXD/Swarm container monitoring - Docker image, Zabbix template and C module
https://hub.docker.com/r/monitoringartist/zabbix-agent-xxl-limited/
GNU General Public License v2.0
1.19k stars 268 forks source link

Allow HCONTAINERID to be taken from different container property #13

Closed demelziraptor closed 9 years ago

demelziraptor commented 9 years ago

When running docker with mesos and marathon, the Name ends up like mesos-018bcb1a-5511-44a3-bbb5-6d79c1f13c95, however it's possible to get a more useful name:

root@server:/$ docker inspect mesos-018bcb1a-5511-44a3-bbb5-6d79c1f13c95
    "Name": "/mesos-018bcb1a-5511-44a3-bbb5-6d79c1f13c95",
    "Config": {
        "Env": [
            "MARATHON_APP_ID=/useful-app/name",

Is it possible to get the HCONTAINERID from this property if it exists? I had a quick go myself but my C is not great.

jangaraj commented 9 years ago

Yes, I agree, it'll be useful. Could you provide full output from your mesos docker inspect command please? Code from docker.inspect[fci,par1,par2] can be used here eventually and discovery can have optional parameters e.g. docker.discovery[Config,Env,some selector]

demelziraptor commented 9 years ago

Yeh that sounds good. Here's the output:

[
{
    "Id": "dfa1cdb596986f65848791c8c5c069d93b4e2951dad4058cc4a70996ae4008d9",
    "Created": "2015-07-20T19:07:03.661946452Z",
    "Path": "/app/docker/entry",
    "Args": [
        "scheduler"
    ],
    "State": {
        "Running": true,
        "Paused": false,
        "Restarting": false,
        "OOMKilled": false,
        "Dead": false,
        "Pid": 363,
        "ExitCode": 0,
        "Error": "",
        "StartedAt": "2015-07-20T19:07:03.743434948Z",
        "FinishedAt": "0001-01-01T00:00:00Z"
    },
    "Image": "c21d0709262991ac59fe6105c6c460e4e9e4613e37e752da6d7eaf555bdcbc83",
    "NetworkSettings": {
        "Bridge": "",
        "EndpointID": "64e410501de768305d5d1d64900ab905d5d9f90cd254a16ed0bf22839d97fb77",
        "Gateway": "\u003cnil\u003e",
        "GlobalIPv6Address": "",
        "GlobalIPv6PrefixLen": 0,
        "HairpinMode": false,
        "IPAddress": "",
        "IPPrefixLen": 0,
        "IPv6Gateway": "",
        "LinkLocalIPv6Address": "",
        "LinkLocalIPv6PrefixLen": 0,
        "MacAddress": "",
        "NetworkID": "a88c0892d9ccac31c5e93104df1e63cf481a364cfb2b98994dafbd89d8dcd8a5",
        "PortMapping": null,
        "Ports": {},
        "SandboxKey": "/var/run/docker/netns/default",
        "SecondaryIPAddresses": null,
        "SecondaryIPv6Addresses": null
    },
    "ResolvConfPath": "/var/lib/docker/containers/dfa1cdb596986f65848791c8c5c069d93b4e2951dad4058cc4a70996ae4008d9/resolv.conf",
    "HostnamePath": "/var/lib/docker/containers/dfa1cdb596986f65848791c8c5c069d93b4e2951dad4058cc4a70996ae4008d9/hostname",
    "HostsPath": "/var/lib/docker/containers/dfa1cdb596986f65848791c8c5c069d93b4e2951dad4058cc4a70996ae4008d9/hosts",
    "LogPath": "/var/lib/docker/containers/dfa1cdb596986f65848791c8c5c069d93b4e2951dad4058cc4a70996ae4008d9/dfa1cdb596986f65848791c8c5c069d93b4e2951dad4058cc4a70996ae4008d9-json.log",
    "Name": "/mesos-3a132267-9971-47a2-bea2-f02a8977a02a",
    "RestartCount": 0,
    "Driver": "aufs",
    "ExecDriver": "native-0.2",
    "MountLabel": "",
    "ProcessLabel": "",
    "Volumes": {
        "/mnt/mesos/sandbox": "/tmp/mesos/slaves/20150713-160509-1779102600-5050-11858-S0/frameworks/20150625-180546-1745548168-5050-18182-0001/executors/useful-app_name.794a7ec3-2f12-11e5-91bd-0cc47a48879a/runs/3a132267-9971-47a2-bea2-f02a8977a02a"
    },
    "VolumesRW": {
        "/mnt/mesos/sandbox": true
    },
    "AppArmorProfile": "",
    "ExecIDs": null,
    "HostConfig": {
        "Binds": [
            "/tmp/mesos/slaves/20150713-160509-1779102600-5050-11858-S0/frameworks/20150625-180546-1745548168-5050-18182-0001/executors/useful-app_name.794a7ec3-2f12-11e5-91bd-0cc47a48879a/runs/3a132267-9971-47a2-bea2-f02a8977a02a:/mnt/mesos/sandbox"
        ],
        "ContainerIDFile": "",
        "LxcConf": [],
        "Memory": 1107296256,
        "MemorySwap": 0,
        "CpuShares": 614,
        "CpuPeriod": 0,
        "CpusetCpus": "",
        "CpusetMems": "",
        "CpuQuota": 0,
        "BlkioWeight": 0,
        "OomKillDisable": false,
        "Privileged": false,
        "PortBindings": {},
        "Links": null,
        "PublishAllPorts": false,
        "Dns": null,
        "DnsSearch": null,
        "ExtraHosts": null,
        "VolumesFrom": null,
        "Devices": [],
        "NetworkMode": "host",
        "IpcMode": "",
        "PidMode": "",
        "UTSMode": "",
        "CapAdd": null,
        "CapDrop": null,
        "RestartPolicy": {
            "Name": "no",
            "MaximumRetryCount": 0
        },
        "SecurityOpt": null,
        "ReadonlyRootfs": false,
        "Ulimits": null,
        "LogConfig": {
            "Type": "json-file",
            "Config": {}
        },
        "CgroupParent": ""
    },
    "Config": {
        "Hostname": "node1",
        "Domainname": "domainname.com",
        "User": "",
        "AttachStdin": false,
        "AttachStdout": false,
        "AttachStderr": false,
        "PortSpecs": null,
        "ExposedPorts": null,
        "Tty": false,
        "OpenStdin": false,
        "StdinOnce": false,
        "Env": [
            "MARATHON_APP_VERSION=2015-07-16T11:03:35.870Z",
            "HOST=node1.domainname.com",
            "PYTHONPATH=/mnt/mesos/sandbox",
            "PORT_10000=31038",
            "MESOS_TASK_ID=useful-app_name.794a7ec3-2f12-11e5-91bd-0cc47a48879a",
            "PORT=31038",
            "PORTS=31038",
            "__FORCE_REDEPLOY_MARKER=b2ff9f4fc67c42a4803d0831b2da51a7",
            "MARATHON_APP_ID=/useful-app/name",
            "PORT0=31038",
            "MESOS_SANDBOX=/mnt/mesos/sandbox",
            "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
            "DEBIAN_FRONTEND=noninteractive",
            "LANG=en_US.UTF-8",
            "PIP_TIMEOUT=180",
            "PYTHONUNBUFFERED=yes"
        ],
        "Cmd": [
            "scheduler"
        ],
        "Image": "i.domainname.com/app/useful-app:e823cf8",
        "Volumes": null,
        "VolumeDriver": "",
        "WorkingDir": "/app",
        "Entrypoint": [
            "/app/docker/entry"
        ],
        "NetworkDisabled": false,
        "MacAddress": "",
        "OnBuild": null,
        "Labels": {}
    }
}
]
jangaraj commented 9 years ago

Please compile mesos branch https://github.com/jangaraj/Zabbix-Docker-Monitoring/tree/mesos and edit template discovery key:

docker.discovery[Config,Env,MARATHON_APP_ID=]

It will generate:

"{#HCONTAINERID}":"/useful-app/name"

for

root@server:/$ docker inspect mesos-018bcb1a-5511-44a3-bbb5-6d79c1f13c95
    "Name": "/mesos-018bcb1a-5511-44a3-bbb5-6d79c1f13c95",
    "Config": {
        "Env": [
            "MARATHON_APP_ID=/useful-app/name",

Please test it and drop me email. I would like to know how do you (we) solve problem, when many instances of /useful-app/name are running ;-)

Probably better discovery key:

docker.discovery[Config,Env,MESOS_TASK_ID=]
jangaraj commented 9 years ago

@demelziraptor

Did you test mesos branch?

jangaraj commented 9 years ago

Feature is available in master branch.