Update Progress from mender client

Description

So we report our progress in % to our UI. We do this by getting the progress from “mender” i.e. mender client. We piped the output from mender indirectly to the UI

we did use mender client 1.x (in sumo) the output went to stout.
I think since the upgrade to mender client 2.x (dunfell) the progress is not going to sdout.
It display it on the terminal but it doesn’t seemed to get piped anymore.

I have tired various logging options. No joy
What is the correct way of getting the progress from mender client.

Example use-cases:
sudo mender -rootfs image.mender (worked)
sudo mender install image.mender (doesn’t)

Hi @tactmaster,

In modern versions of mender, the progress for standalone install is written interactively to stdout. I think it might be hard to parse and update your GUI from that, though.

You’ll get something like:

INFO[0003] Opening device "/dev/hda3" for writing       
INFO[0003] Native sector size of block device /dev/hda3 is 512 bytes. Mender will write in chunks of 1048576 bytes 
.............                                                  -  21 %

and eventually:

......................................................................
time="2022-09-21T08:56:14Z" level=info msg="All bytes were successfully written to the new partition"

Ed, if the percentage is written we should be able to capture that via a regex or something.

I have successfully parsed numeric output for projects, however, something to be aware of, early versions had an incrementing percentage numeric in the output, then at some point it was removed, this required me to create a custom patch for progress.go on my Yocto mender recipe to replace the new progress renderer with the old one. I had been meaning to create a ticket for this, as there should really be an option to change the type of progress renderer rather than replace it, as this was a breaking change for me.

If it helps or serves as a starting point, the patch for my projects is below and may or may not apply cleanly depending on your version being used.

From 83cc8154732da938a63c2fe87198685b71abed5b Mon Sep 17 00:00:00 2001
From: Dell Green <dell.green@ideaworks.co.uk>
Date: Thu, 25 Feb 2021 14:29:35 +0000
Subject: [PATCH] add our own custom notty progress writer

---
 .../mendersoftware/progressbar/progress.go    | 40 ++++++++++++++++++-
 1 file changed, 39 insertions(+), 1 deletion(-)

diff --git a/vendor/github.com/mendersoftware/progressbar/progress.go b/vendor/github.com/mendersoftware/progressbar/progress.go
index 8c1841a..6baf9ef 100644
--- a/vendor/github.com/mendersoftware/progressbar/progress.go
+++ b/vendor/github.com/mendersoftware/progressbar/progress.go
@@ -48,7 +48,7 @@ func New(size int64) *Bar {
 		}
 	} else {
 		return &Bar{
-			Renderer: &NoTTYRenderer{
+			Renderer: &IwNoTTYRenderer{
 				Out:            os.Stderr,
 				ProgressMarker: ".",
 				terminalWidth:  80,
@@ -134,3 +134,41 @@ func (p *NoTTYRenderer) Render(percentage int) {
 		fmt.Fprintf(p.Out, str)
 	}
 }
+
+type IwNoTTYRenderer struct {
+	Out            io.Writer // Output device
+	ProgressMarker string
+	lastPercentage int
+	terminalWidth  int
+}
+
+func (p *IwNoTTYRenderer) Render(percentage int) {
+	if percentage <= p.lastPercentage {
+		return
+	}
+	suffix := fmt.Sprintf(" %3d%%", percentage)
+	widthAvailable := p.terminalWidth - len(suffix)
+	number_of_dots := int((float64(widthAvailable) * float64(percentage)) / 100)
+	number_of_fillers := widthAvailable - number_of_dots
+	if percentage > 100 {
+		number_of_dots = widthAvailable
+		number_of_fillers = 0
+	}
+	if percentage < 0 {
+		return
+	}
+	if number_of_dots < 0 {
+		return
+	}
+	if number_of_fillers < 0 {
+		return
+	}
+	p.lastPercentage = percentage
+	fmt.Fprintf(p.Out, "%s%s%s\n",
+		strings.Repeat(p.ProgressMarker, number_of_dots),
+		strings.Repeat(" ", number_of_fillers),
+		suffix)
+	if percentage == 100 {
+		fmt.Fprintln(p.Out)
+	}
+}
-- 
2.25.1
3 Likes

Sorry for the late reply. Yes thank very much this worked. We updated mender client to match yours in dunfell but all is fine.

1 Like

I have finally got around to putting up a ticket for this, will probably need discussion.

https://tracker.mender.io/browse/MEN-6318

Issue has now been migrated to: [MEN-6318] - Mender and CFEngine (by Northern.tech) Jira

Percentage based progress is scheduled to be added into the new C++ implementation of the client, and not the GO implementation.

https://northerntech.atlassian.net/browse/MEN-6318

https://northerntech.atlassian.net/browse/MEN-6670

1 Like