Hello,
You can read the mxd or mapx file in the service's directory with arcpy in Python too. You will find database / file source and the layer's ID with which you can make the connection between database and service.
You can find the path to the mxd file in the service properties. Do a loop on all services to have all files of all services.
Managing GIS Servers with Python
Work with arcpy and ArcGIS Project
# Create temporary ArcGIS Projec to import service file
aprx = arcpy.mp.ArcGISProject(r"C:\projectArcGISPRO.aprx")
# Import service file with file path in service's properties
aprx.importDocument(filepath)
#List all maps in ArcGIS PRO
mapList = aprx.listMaps()
for m in mapList:
#List layers in map
layerList = m.listLayers()
for l in layerList:
if not l.isGroupLayer:
if l.supports("DATASOURCE"):
#Find datasource
datasource = l.dataSource
#Find layerID used in service
layerID = l.getDefinition('V2').serviceLayerID
GaetanPRU