Search code examples
pythonboto3minio

How to get MinIO metrics (/minio/v2/metrics/cluster)?


Bases on the MinIO documentation at page 14 following API is mentioned /minio/v2/metrics/cluster and /minio/v2/metrics/node.
But looks like these API available only for "Prometheus". And I have no clue to get those using python.

Of course if I try send request to http://<host>:<port>/minio/v2/metrics/cluster I get 403 error:

<?xml version="1.0" encoding="UTF-8"?>
<Error><Code>AllAccessDisabled</Code><Message>All access to this bucket has been disabled.</Message><Resource>/minio/v2/metrics/cluster</Resource><RequestId></RequestId><HostId><uuid-here></HostId></Error>

I've tried to generate presigned URL (like for GET object from bucket) but even with signature result is same as above.

Maybe someone know to reach that API(s)?
And how to do proper authentication for these endpoint without "Prometheus"?


Solution

  • Solution:

    import jwt  # pyJWT
    import requests
    import datetime
    
    expired_at = (datetime.datetime.now() + datetime.timedelta(days=1)).timestamp()
    
    token = jwt.encode(
        payload={
            "exp": expired_at,
            "sub": "<AccessKey>",
            "iss": "prometheus",
        },
        key="<SecretKey>",
        algorithm="HS512"
    )
    
    headers = {
        "Authorization": f"Bearer {token.decode()}"
    }
    response = requests.get(
        url="<schema>://<host>:<port>/minio/prometheus/metrics",
        headers=headers
    )
    

    How mc utility generates bearer token I found at https://github.com/minio/mc/blob/master/cmd/admin-prometheus-generate.go

    URL /minio/prometheus/metrics was found during call to utility mc admin prometheus generate test-minio