List users all instances

john_fhm
john_fhm Registered Posts: 3
edited July 16 in Using Dataiku

Hi,

I'm have 3 instances running in parallel (PRE, PROD and an Event server). I want to make a dashboard about the users activity across all the instances. I want to list all the users in each instance and when was the last activity of each user.

I tried this code:

import dataiku
client = dataiku.api_client()
dss_users = client.list_users()

user_list = []
# Grab list of users where they have active web socket sessions
for user in dss_users:
    if user['activeWebSocketSesssions'] != 0:
        user_list.append(user['displayName'])
print(user_list)


but there's only info about an instance in that instance and i want to locate all the info on the Event server.

How can a get the list of the users acroos all the instances and send to the Event server to make the dashboard?

Thanks

BR


Operating system used: Windows

Best Answer

  • Ignacio_Toledo
    Ignacio_Toledo Dataiku DSS Core Designer, Dataiku DSS Core Concepts, Neuron 2020, Neuron, Registered, Dataiku Frontrunner Awards 2021 Finalist, Neuron 2021, Neuron 2022, Frontrunner 2022 Finalist, Frontrunner 2022 Winner, Dataiku Frontrunner Awards 2021 Participant, Frontrunner 2022 Participant, Neuron 2023 Posts: 415 Neuron
    edited July 17 Answer ✓

    Then you need to use the method:

     client.list_users_activity()

    to extract the information.

    import dataiku
    import pandas as pd
    
    client = dataiku.api_client()
    for user in client.list_users_activity():
        print(f"User {user.activity['login']} last activity was on {pd.Timestamp(user.activity['lastSessionActivity'], unit='ms')}")

    Then you can use the client from other instances, to check instance by instance.

Answers

  • Ignacio_Toledo
    Ignacio_Toledo Dataiku DSS Core Designer, Dataiku DSS Core Concepts, Neuron 2020, Neuron, Registered, Dataiku Frontrunner Awards 2021 Finalist, Neuron 2021, Neuron 2022, Frontrunner 2022 Finalist, Frontrunner 2022 Winner, Dataiku Frontrunner Awards 2021 Participant, Frontrunner 2022 Participant, Neuron 2023 Posts: 415 Neuron
    edited July 17

    Hello @john_fhm
    ,

    we use the dataikuapi library to check users (and other things) in different instances, and then you can iterate over the clients. Using your script:

    import dataikuapi
    client_02 = dataikuapi.DSSClient('http://instance02.url.dom:port', api_key='instance02APIKeyadm')
    client_03 = dataikuapi.DSSClient('http://instance02.url.dom:port', api_key='instance03APIKeyadm')
    
    dss_users02 = client02.list_users()
    dss_users03 = client03.list_users()
    
    # Grab list of users where they have active web socket sessions
    for li_users in [dss_users02, dss_users03]:
        user_list = []
        for user in li_users:
            if user['activeWebSocketSesssions'] != 0:
                user_list.append(user['displayName'])
        print(user_list)

    Of course, you have to provide your own instance URLs and API keys.

    I hope this helps!

  • john_fhm
    john_fhm Registered Posts: 3
    edited July 17

    Hi @Ignacio_Toledo
    ,

    Thanks for the reply.

    If I put the condition:

    user['activeWebSocketSesssions'] != 0

    Checks if the user has active WebSocket sessions. What I need is to check not only the online users but all users and when was their last connection.

    Many thanks!

  • john_fhm
    john_fhm Registered Posts: 3

    This works perfectly!

Setup Info
    Tags
      Help me…