21 lines
482 B
Python
21 lines
482 B
Python
import asyncio
|
|
|
|
from google.protobuf.json_format import MessageToJson
|
|
import systemd
|
|
|
|
async def main() -> None:
|
|
services = ["docker.service", "sshd.service"]
|
|
monitor = systemd.Monitor(services)
|
|
await monitor.initialize()
|
|
|
|
resp = await monitor.poll()
|
|
|
|
for unit in resp:
|
|
json = MessageToJson(unit, including_default_value_fields=True)
|
|
print(json)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
loop = asyncio.new_event_loop()
|
|
loop.run_until_complete(main())
|