Jobs Monitoring

1. Job count

Use the GraphQL API to check the number of jobs and apps existing per platform or project. Use the following URL, replacing <saagie_host> with your Saagie host and <platform_id> with the platform identifier for the platform from which you would like to retrieve information.

https://<saagie_host>/api/v1/projects/platform/<platform_id>/graphql
For more information on GraphQL, refer to the GraphQL documentation.

1.1. cURL commands

1.1.1. Authentication

When requesting a GraphQL API, you must authenticate. Use this command line to retrieve a Bearer connection token via cURL with the following replacements:

  • <realm> is your Saagie realm, which is the prefix that was determined during Saagie installation.

  • <user> is your Saagie username.

  • <pwd> is your Saagie password.

  • <saagie_host> is your Saagie host.

TOKEN_SAAGIE_API=$( \
      curl \
        -s \
        -X POST \
        -H "Content-Type:application/json" \
        -H 'Saagie-Realm: '<realm> \
         --data '{"login":"<user>", "password":"<pwd>"}' \
        https://<saagie_host>/authentication/api/open/authenticate \
    )

1.1.2. GraphQL API query

Once authenticated, you can retrieve information about jobs and apps from a single platform.

For example, use the following command to retrieve the count of jobs and apps per project with the following replacements:

  • <token_saagie_api> is your Saagie Realm.

  • <saagie_host> is your Saagie host.

  • <platform_id> is platform identifier for the platform on which you would like to retrieve information.

curl \
    -H 'Accept: application/json' \
    -H "Authorization: Bearer <token_saagie_api>" \
    --request POST \
    --header "Content-Type:application/json" \
    --data '{"query":"{\n  projects {\n    jobsCount\n  }\n}\n","variables":null}' \
    https://<saagie_host>/api/v1/projects/platform/<platform_id>/graphql

This request will provide the jobs and apps count per project. The sum of the field jobsCount reveals the total count per platform.

{
  "data": {
    "projects": [
      {
        "id": "cea7be12-462f-4000-b8bb-666c1eb63d95",
        "name": "test port",
        "jobsCount": 6
      },
      {
        "id": "17236c69-88f9-4124-bf2f-6e90aef48640",
        "name": "test-reporter",
        "jobsCount": 0
      },
      {
        "id": "f3062b55-4802-40d1-a957-d3ae8331ad2b",
        "name": "test ux",
        "jobsCount": 1
      },
      {
        "id": "154008e6-2f68-4046-80e8-949edf8157f0",
        "name": "test b",
        "jobsCount": 2
      }
    ]
  }
}

1.2. Example script for the sum of the count of jobs

Using the data from the previous GraphQL response, you can obtain the total count of jobs and apps for one platform using the jq command.

The script below will allow you to retrieve the total count of jobs and apps on a platform by filling in the necessary variables with your values.

#!/bin/bash

PLATFORM_SAAGIE=1
SAAGIE_HOST=saagie1-beta.a42.saagie.cloud
REALM=saagie1
user=user
pwd=password

TOKEN_SAAGIE_API=$( \
      curl \
        -s \
        -X POST \
        -H "Content-Type:application/json" \
        -H 'Saagie-Realm: '$REALM \
         --data '{"login":"'$user'", "password":"'$pwd'"}' \
        https://$SAAGIE_HOST/authentication/api/open/authenticate \
    )

responseGraphql=$( \
    curl \
      -s \
      -H 'Accept: application/json' \
      -H "Authorization: Bearer $TOKEN_SAAGIE_API" \
      -H "Content-Type:application/json" \
      -X POST \
      --data '{"query":"{\n  projects {\n    jobsCount\n  }\n}\n","variables":null}' \
      https://$SAAGIE_HOST/api/v1/projects/platform/$PLATFORM_SAAGIE/graphql \
    )

echo $responseGraphql | jq -n '[inputs | .data.projects[].jobsCount] | reduce .[] as $num (0; .+$num)'