1.6. Get entities domain view graph

Fast DDS Statistics Backend allows to retrieve the entire graph of active entities for which the singleton holds statistics data. The result of this query is a Graph tree structure that contains the info of each entity. To be able to understand and interpret this tree, it is required to know about all the available entities and the inner relations between them. Following, there is a diagram of the relation between the Fast DDS Statistics Backend entities, and how are they divided into physical and domain related. For more information about the different EntityKind please refer to EntityKind.

../../_images/internal_db.svg

Fast DDS Statistics Backend entity relations and their division into physical and domain related.

1.6.1. Example

The on_domain_view_graph_update() DomainListener callback notifies when a domain has updated its graph. Alternatively, the graph can be regenerated manually by calling regenerate_domain_graph():

StatisticsBackend::regenerate_domain_graph(domain_id);

For the following example, a simple scenario is considered, where there is one process running two participants on the same domain; one with a data reader and the other one with a data writer (both in the same topic). This means that there is only one USER within a single HOST. The application can retrieve the network graph by:

Graph domain_view_graph = StatisticsBackend::get_domain_view_graph(domain_id);

In this example, the previous call would return a Graph object similar to the following:

{
    "kind": "domain",
    "domain": "0",
    "topics":
    {
        "5":
        {
            "kind": "topic",
            "metatraffic": false,
            "alias": "Square"
        }
    },
    "hosts":
    {
        "2":
        {
            "kind": "host",
            "metatraffic": false,
            "alias": "example_host_alias",
            "status": "OK",
            "users":
            {
                "3":
                {
                    "kind": "user",
                    "metatraffic": false,
                    "alias": "example_user_alias",
                    "status": "OK",
                    "processes":
                    {
                        "4":
                        {
                            "kind": "process",
                            "metatraffic": false,
                            "alias": "example_process1_alias",
                            "pid": "1234",
                            "status": "OK",
                            "participants":
                            {
                                "1":
                                {
                                    "kind": "participant",
                                    "metatraffic": false,
                                    "alias": "shapes_demo_participant_1_alias",
                                    "status": "OK",
                                    "app_id": "SHAPES_DEMO",
                                    "endpoints":
                                    {
                                        "6":
                                        {
                                            "kind": "datawriter",
                                            "app_id": "SHAPES_DEMO",
                                            "metatraffic": false,
                                            "alias": "shapes_demo_datawriter_alias",
                                            "status": "OK",
                                            "topic": "5"
                                        }
                                    }
                                }
                            }
                        },
                        "8":
                        {
                            "kind": "process",
                            "metatraffic": false,
                            "alias": "example_process2_alias",
                            "pid": "1235",
                            "status": "OK",
                            "participants":
                            {
                                "7":
                                {
                                    "kind": "participant",
                                    "metatraffic": false,
                                    "alias": "shapes_demo_participant_2_alias",
                                    "status": "OK",
                                    "app_id": "SHAPES_DEMO",
                                    "endpoints":
                                    {
                                        "9":
                                        {
                                            "kind": "datareader",
                                            "app_id": "SHAPES_DEMO",
                                            "metatraffic": false,
                                            "alias": "shapes_demo_datareader_alias",
                                            "status": "OK",
                                            "topic": "5"
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}

Then, the application can extract information about the entities from the graph as shown below:

std::cout << "Domain: " << domain_view_graph[DOMAIN_ENTITY_TAG] << std::endl;
// Iterate
for (const auto& host : domain_view_graph[HOST_CONTAINER_TAG])
{
    std::cout << "\tHost alias: " << host[ALIAS_TAG] << std::endl;
    std::cout << "\tHost status: " << host[STATUS_TAG] << std::endl;
    for (const auto& user : host[USER_CONTAINER_TAG])
    {
        std::cout << "\t\tUser alias: " << user[ALIAS_TAG] << std::endl;
        std::cout << "\t\tUser status: " << user[STATUS_TAG] << std::endl;
        for (const auto& process : user[PROCESS_CONTAINER_TAG])
        {
            std::cout << "\t\t\tProcess alias: " << process[ALIAS_TAG] << std::endl;
            std::cout << "\t\t\tProcess PID:  " << process[PID_TAG] << std::endl;
            std::cout << "\t\t\tProcess status: " << process[STATUS_TAG] << std::endl;
            for (const auto& participant : process[PARTICIPANT_CONTAINER_TAG])
            {
                std::cout << "\t\t\t\tParticipant alias: " << participant[ALIAS_TAG] << std::endl;
                std::cout << "\t\t\t\tParticipant app_id:  " << participant[APP_ID_TAG] << std::endl;
                std::cout << "\t\t\t\tParticipant status: " << participant[STATUS_TAG] << std::endl;
                for (const auto& endpoint : participant[ENDPOINT_CONTAINER_TAG])
                {
                    std::cout << "\t\t\t\t\tEndpoint alias: " << endpoint[ALIAS_TAG] << std::endl;
                    std::cout << "\t\t\t\t\tEndpoint kind:  " << endpoint[KIND_TAG] << std::endl;
                    std::cout << "\t\t\t\t\tEndpoint app_id:  " << endpoint[APP_ID_TAG] << std::endl;
                    std::cout << "\t\t\t\t\tEndpoint status: " << endpoint[STATUS_TAG] << std::endl;
                }
            }
        }
    }
}
for (const auto& topic : domain_view_graph[TOPIC_CONTAINER_TAG])
{
    std::cout << "\tTopic alias: " << topic[ALIAS_TAG] << std::endl;
    std::cout << "\tTopic metatraffic: " << topic[METATRAFFIC_TAG] << std::endl;
}

Running the previous snippet on the given example should output:

Domain: 0
    Host alias: "example_host_alias"
    Host status: "OK"
        User alias: "example_user_alias"
        User status: "OK"
            Process alias: "example_process1_alias"
            Process PID:  "1234"
            Process status: "OK"
                Participant alias: "shapes_demo_participant_1_alias"
                Participant app_id:  "SHAPES_DEMO"
                Participant status: "OK"
                    Endpoint alias: "shapes_demo_datawriter_alias"
                    Endpoint kind:  "datawriter"
                    Endpoint app_id:  "SHAPES_DEMO"
                    Endpoint status: "OK"
            Process alias: "example_process2_alias"
            Process PID:  "1235"
            Process status: "OK"
                Participant alias: "shapes_demo_participant_2_alias"
                Participant app_id:  "SHAPES_DEMO"
                Participant status: "OK"
                    Endpoint alias: "shapes_demo_datareader_alias"
                    Endpoint kind:  "datareader"
                    Endpoint app_id:  "SHAPES_DEMO"
                    Endpoint status: "OK"
    Topic alias: "Square"
    Topic metatraffic: false

For more information about the operations available with Graph objects, please refer to Graph.