MagicMirror Forum
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • 3rd-Party-Modules
    • Donate
    • Discord
    • Register
    • Login
    A New Chapter for MagicMirror: The Community Takes the Lead
    Read the statement by Michael Teeuw here.

    ChatGpt developed Module MMM-Dockerstat

    Scheduled Pinned Locked Moved Development
    27 Posts 4 Posters 8.6k Views 4 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • S Offline
      sdetweil @Rags
      last edited by

      @Rags ssh via program is a tricky thing

      Sam

      How to add modules

      learning how to use browser developers window for css changes

      R 1 Reply Last reply Reply Quote 0
      • R Offline
        Rags @sdetweil
        last edited by

        @sdetweil Ok, is there any other method of achieving this?

        mumblebajM 1 Reply Last reply Reply Quote 0
        • mumblebajM Offline
          mumblebaj Module Developer @Rags
          last edited by

          @Rags Welcome to the forum and great start.

          Have you tried to run the module and found any issues?

          • Node_helper.js must be named node_helper.js

          • Your modules defines a bunch of dependent modules in node_helper.js but none of these were installed when you built the module so anybody who clones the module will not get of the dependent modules installed as they are not mentioned in package,js.

          • You declare ‘./Logger’ but it is never used. Do you need it?

          If you fix the above issues the module starts. I do not run a Docker anywhere but the modules seems to working with the above issues fixed or at least it should get you going.

          Always try and run the module first and check for issues and fix them if you can

          Check out my modules at: https://github.com/mumblebaj?tab=repositories
          Check my blog-post: https://mumblebaj.xyz/
          Check my MM Container: https://hub.docker.com/repository/docker/mumblebaj/magicmirror/general

          R 1 Reply Last reply Reply Quote 1
          • R Offline
            Rags @mumblebaj
            last edited by

            @mumblebaj Thanks for the encouragement. I made the changes as suggested and updated the files on github. I also did some debugging and tried to resolve issues. However, I guess i am reaching a dead end. So any help will be appreciated greatly.

            mumblebajM 1 Reply Last reply Reply Quote 0
            • mumblebajM Offline
              mumblebaj Module Developer @Rags
              last edited by sdetweil

              @Rags Need to be bit more specific with what issues you are experiencing. If you are running you mirror with npm start then list the output from npm. Also check the developer console (shift + ctrl+i) and see if there are any errors there.

              Check out my modules at: https://github.com/mumblebaj?tab=repositories
              Check my blog-post: https://mumblebaj.xyz/
              Check my MM Container: https://hub.docker.com/repository/docker/mumblebaj/magicmirror/general

              R 1 Reply Last reply Reply Quote 1
              • R Offline
                Rags @mumblebaj
                last edited by

                @mumblebaj
                Thanks for the help, i am running with npm start. The display does not show the status of the docker containers. Instead the rotating arrow is continuously displayed.
                I don’t know if the these error messages will indicate something, however here goes

                The error msg with npm start;
                02.04.2023 17:12.36.528] [LOG] Host 192.168.1.200 is offline.
                [02.04.2023 17:12.36.530] [ERROR] (node:11566) UnhandledPromiseRejectionWarning: TypeError: Cannot read properties of undefined (reading ‘info’)
                at /home/pi/MagicMirror/modules/MMM-Dockerstat/node_helper.js:59:21
                at /home/pi/MagicMirror/modules/MMM-Dockerstat/node_modules/ping/lib/ping-sys.js:40:9
                [02.04.2023 17:12.36.531] [ERROR] (node:11566) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 5)
                with developer console;

                Failed to load resource: the server responded with a status of 404 (Not Found)
                0.0.0.0/:1 Refused to execute script from ‘http://0.0.0.0:8088/modules/MMM-Dockerstat/fontawesome.js’ because its MIME type (‘text/html’) is not executable, and strict MIME type checking is enabled.
                loader.js:194 Error on loading script: modules/MMM-Dockerstat/fontawesome.js
                script.onerror @ loader.js:194

                mumblebajM 1 Reply Last reply Reply Quote 0
                • mumblebajM Offline
                  mumblebaj Module Developer @Rags
                  last edited by

                  @Rags Lots of issues in the code you had. I created a PR. Check it out.

                  Check out my modules at: https://github.com/mumblebaj?tab=repositories
                  Check my blog-post: https://mumblebaj.xyz/
                  Check my MM Container: https://hub.docker.com/repository/docker/mumblebaj/magicmirror/general

                  R 1 Reply Last reply Reply Quote 0
                  • R Offline
                    Rags @mumblebaj
                    last edited by

                    @mumblebaj
                    Yes Sir. I noticed the changes committed by you and I immediately approved the merge commit. Please understand this is my first attempt and I had ChatGPT to help me. I guess we both are still learning. Well, I cloned the fresh updated repository and installed it. Now when i run it the constantly rotating arrow is not displayed anymore, but even the status of the containers are not being displayed. The npm start logs do not have any error messages. The dev console is also not indicating any issue. So probably some more debug is required. Sincere request to keep assisting till it is resolved.
                    Thanks

                    mumblebajM 1 Reply Last reply Reply Quote 0
                    • mumblebajM Offline
                      mumblebaj Module Developer @Rags
                      last edited by

                      @Rags Unfortunately I don’t have a docker running here so cannot test that portion of your code. You need to supply the docker name as an input parameter to feed into .exec(`sudo docker ps -f name=${payload.container} --format "{{.Names}} {{.Status}}"`)

                      Have you added this into the config.js?

                      Check out my modules at: https://github.com/mumblebaj?tab=repositories
                      Check my blog-post: https://mumblebaj.xyz/
                      Check my MM Container: https://hub.docker.com/repository/docker/mumblebaj/magicmirror/general

                      S R 2 Replies Last reply Reply Quote 0
                      • S Offline
                        sdetweil @mumblebaj
                        last edited by

                        @mumblebaj can u see the container names from inside a container?

                        Sam

                        How to add modules

                        learning how to use browser developers window for css changes

                        mumblebajM R 2 Replies Last reply Reply Quote 0
                        • mumblebajM Offline
                          mumblebaj Module Developer @sdetweil
                          last edited by

                          @sdetweil No idea. Never worked with containers before. (Shocking I know :astonished_face: ) Just gave him a bit of code to get the module running correct up until the point he has to check the status of the container code.

                          Check out my modules at: https://github.com/mumblebaj?tab=repositories
                          Check my blog-post: https://mumblebaj.xyz/
                          Check my MM Container: https://hub.docker.com/repository/docker/mumblebaj/magicmirror/general

                          1 Reply Last reply Reply Quote 0
                          • R Offline
                            Rags @mumblebaj
                            last edited by

                            @mumblebaj {
                            module: ‘MMM-Dockerstat’,
                            header: ‘Docker Status’,
                            position: ‘top_right’,
                            config: {
                            host: ‘192.168.1.200’, // IP address of the second Pi running Docker
                            interval: 600000, //60 seconds
                            user:‘pi’,
                            password:‘mypass’,
                            container: ‘wireguard’, // just added to check
                            offlineIcon: ‘fa-times-circle’, // Font Awesome icon for offline status
                            onlineIcon: ‘fa-check-circle’ // Font Awesome icon for online status
                            }
                            },
                            Yes i added the name of the container. It is still not displaying the status. Anyways the idea was for the module to probe and display the status of all containers running in docker.

                            1 Reply Last reply Reply Quote 0
                            • R Offline
                              Rags @sdetweil
                              last edited by Rags

                              @sdetweil said in ChatGpt developed Module MMM-Dockerstat:

                              @mumblebaj can u see the container names from inside a container?

                              ‘Docker ps’ command list all the containers that are currently running. So i guess the command will execute and should be able to confirm the status with the command
                              " ‘.exec(sudo docker ps -f name=${payload.container} --format "{{.Names}} {{.Status}}")’"

                              This command uses the Docker CLI (Command Line Interface) to list the running Docker containers on a host, filtering the results by the name of the container specified in payload.container. The --format option specifies how to format the output of the docker ps command. In this case, {{.Names}} {{.Status}} is used to output only the names and statuses of the containers that match the specified filter. The output is then captured and processed by the SSH library used in the code.

                              anyways " work in progress ".

                              mumblebajM 1 Reply Last reply Reply Quote 0
                              • mumblebajM Offline
                                mumblebaj Module Developer @Rags
                                last edited by

                                @Rags The output from the query does not return a Status of “Online”

                                See below what it returns.

                                6ddea81e-8969-4d68-b3c3-62dfb470ab10-image.png

                                Check out my modules at: https://github.com/mumblebaj?tab=repositories
                                Check my blog-post: https://mumblebaj.xyz/
                                Check my MM Container: https://hub.docker.com/repository/docker/mumblebaj/magicmirror/general

                                R 1 Reply Last reply Reply Quote 0
                                • R Offline
                                  Rags @mumblebaj
                                  last edited by

                                  @mumblebaj said in ChatGpt developed Module MMM-Dockerstat:

                                  @Rags The output from the query does not return a Status of “Online”

                                  See below what it returns.

                                  6ddea81e-8969-4d68-b3c3-62dfb470ab10-image.png

                                  Yes you are right even i got a similar output when the command was run on the second pi directly. So at least we are getting somewhere. Good news.
                                  sudo docker ps -f name=wireguard --format “{{.Names}} {{.Status}}”
                                  wireguard Up 36 hours.
                                  so now i have to figure out a command line to get status of all containers in a table form with name of container and the uptime.

                                  S mumblebajM 2 Replies Last reply Reply Quote 0
                                  • S Offline
                                    sdetweil @Rags
                                    last edited by sdetweil

                                    @Rags but are you running this on the docker host? outside any container?

                                    if u run this from INSIDE the container (where MM is running) , does it work?

                                    as I recall, it does not.

                                    I think the command (on the host) is

                                    Usage:  docker exec [OPTIONS] CONTAINER COMMAND [ARG...]
                                    

                                    docker exec container_id “docker -ps … rest of parms”

                                    but you will have to use docker command to get the container_id from the name to use in the exec

                                    long time ago, 9 years now, I wrote a whole bunch of scripts to support using docker to deploy and manage a software api testing service…

                                    Sam

                                    How to add modules

                                    learning how to use browser developers window for css changes

                                    R 1 Reply Last reply Reply Quote 0
                                    • mumblebajM Offline
                                      mumblebaj Module Developer @Rags
                                      last edited by

                                      @Rags you can drop the -f name portion which will then list all containers running. Maybe change the query to something like the following which should give you some JSON type object which you can then work with.

                                      docker ps --format '{"ID":"{{ .ID }}", "Image": "{{ .Image }}", "Names":"{{ .Names }}, "Status": {{.Status}}"}'
                                      

                                      This will return something like the below:

                                      {"ID":"4c57d2ba3fd8", "Image": "getting-started", "Names":"silly_hodgkin, "Status": Up 44 minutes"}
                                      

                                      From this you can then extract the container you want and check the status. What I have seen the query only returns all running containers

                                      Check out my modules at: https://github.com/mumblebaj?tab=repositories
                                      Check my blog-post: https://mumblebaj.xyz/
                                      Check my MM Container: https://hub.docker.com/repository/docker/mumblebaj/magicmirror/general

                                      S 1 Reply Last reply Reply Quote 0
                                      • S Offline
                                        sdetweil @mumblebaj
                                        last edited by

                                        @mumblebaj but you don’t need to do all that fancy formatting if you are going to extract the info

                                        awk can do that

                                        11e836525b8d   jshridha/blueiris   "/usr/bin/supervisord"   2 years ago   Up 8 months   0.0.0.0:82->81/tcp, :::82->81/tcp, 0.0.0.0:5901->5900/tcp, :::5901->5900/tcp, 0.0.0.0:8280->8080/tcp, :::8280->8080/tcp   blueiris
                                        (base) sam@sams:~/MagicMirror/config$ 
                                        

                                        docker ps | awk ‘{print $1}’

                                        awk can split a string into parts (using some separator char (-F parm, space is default) and then u can print out just the parm u want

                                        also docker ps -q
                                        only displays the container ids.

                                        Sam

                                        How to add modules

                                        learning how to use browser developers window for css changes

                                        mumblebajM 1 Reply Last reply Reply Quote 0
                                        • mumblebajM Offline
                                          mumblebaj Module Developer @sdetweil
                                          last edited by

                                          @sdetweil Thanks Sam. I just installed Docker for the first time earlier and also learning. :-) Looks fun though. I was looking jq but can’t get that to work, How do i install jq on Docker? Or get it to work off the command line?

                                          Check out my modules at: https://github.com/mumblebaj?tab=repositories
                                          Check my blog-post: https://mumblebaj.xyz/
                                          Check my MM Container: https://hub.docker.com/repository/docker/mumblebaj/magicmirror/general

                                          S 1 Reply Last reply Reply Quote 0
                                          • S Offline
                                            sdetweil @mumblebaj
                                            last edited by

                                            @mumblebaj sorry, no idea on jq

                                            i use terminal commands all the time… jq only in nodejs

                                            when I have a terminal command i need output of, I use terminal command tools.

                                            the thing about docker is you can make an image of a ‘thing’ you want to run, and run it everywhere that supports that processor type. independent of OS and you can run multiple instance at the same time (scale up server?) without changing anything inside the image

                                            start up a web server with this content (mapped source folder)
                                            or that content , or both poof a docker command and up you go.

                                            getting the folders mapped to the right place for the ‘thing’ in the container takes a little (tiny amount) work

                                            Sam

                                            How to add modules

                                            learning how to use browser developers window for css changes

                                            1 Reply Last reply Reply Quote 0

                                            Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                                            Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                                            With your input, this post could be even better 💗

                                            Register Login
                                            • 1
                                            • 2
                                            • 1 / 2
                                            • First post
                                              Last post
                                            Enjoying MagicMirror? Please consider a donation!
                                            MagicMirror created by Michael Teeuw.
                                            Forum managed by Sam, technical setup by Karsten.
                                            This forum is using NodeBB as its core | Contributors
                                            Contact | Privacy Policy