Using a Surface Pro as a Network Monitor with Grafana

This is the first of my new ‘project blogs’, where I complete a project and write as I go. I hope you find it interesting and enjoyable, but I must stress that it is not a guide or tutorial, as you shall soon find out…

I have a Surface Pro that I got for free. It’s the first Surface Pro that originally shipped with Windows 8 as far as I am aware, and now has Windows 10. It runs pretty well, although I’ve only used it for about fifteen minutes.

It has a dead battery and doesn’t work unless connected to power, so my idea is to set it up and mount it somewhere as a Grafana dashboard for my network. It seems like a good use for something like this.

I also have a Surface RT that does hold a charge, so I’m trying to decide what to do with that or sell it.

Step 1: Install Ubuntu Server

Creating the USB

This should be pretty easy. Ubuntu Server is a standard x86 OS just as Windows, nothing fancy going on here. The Surface is just a regular PC that happens to be made by Microsoft. It’s not like Apple and Mac, where things are locked down more (however, my home server is a 2012 Mac mini Server that I’ve upgraded and installed Ubuntu on).

I have an Ubuntu Server ISO lying around on my server because it’s just a useful thing to have, so let’s scp that across to my Mac and create a bootable USB with Etcher…

Booting & installing Ubuntu

Again, the Surface is just a standard PC. To boot from a USB, you just have to go into the Windows recovery screen and select the USB drive:

This booted into a standard Ubuntu Server installer…after a funky red boot screen (which my capture card wouldn’t pick up):

There’s not much that’s exciting here. It’s a standard Ubuntu install. Notably, however, the setup natively picked up the Surface’s WiFi card:

I don’t know if I should be surprised at that or not. Obviously Microsoft don’t use some fancy proprietary WiFi cards (even my Mac mini Server has WiFi natively on Ubuntu, as do most Macs before the T-series security chips & Apple Silicon chips) but I was pleased that it worked straight away. Wherever and however I decide to mount this, I don’t intend to run Ethernet cables because the Surface only has one USB port that I’d rather keep free for debugging purposes. WiFi will be fine for simple Grafana.

The setup connected to my WiFi network and obtained an IPv4 address from my DHCP server as expected. I’m glad networking didn’t become an issue (it usually does for me!) I later assigned a static lease on my DHCP server to ensure I could reliably remote into the Surface.

Ubuntu then began to install as usual, and fetched any updates automatically. So far, so good!

Once Ubuntu was installed, the Surface kept the red boot screen so I’m thinking it’s a sort of warning to do with Secure Boot or something. I haven’t changed any settings in the BIOS etc but it’s only showed up since I’ve been messing with non-Windows things!

Step 2: Network Configuration

Ethernet connection

At this point, I connected a USB Ethernet adapter to do some updates and get things running a bit quicker. To start, it didn’t immediately connect (but showed up under lsusb ) so I had to manually configure it with netplan and NetworkManager, as I do on my server:

…and it broke everything. Obviously, this is me.

NetworkManager is not installed, so netplan is unable to apply the changes. But I deleted all other netplan configs so there was now no WiFi either. Fun! And no, I didn’t back up the files. That’s too logical and makes too much sense for my brain. Eventually, the Ethernet adapter and the WiFi appeared in ip a again so I manually created the config file for WiFi only first…including the interface name wlx281878388b0f. Typing that exactly on a Surface keyboard with nano running at 1920x1080 resolution with no zoom.

As I was waiting on dhclient to obtain an IP address, I realised that I’ve configured the WiFi interface as Ethernet (see above screenshot) and also hadn’t supplied an SSID and password. Classic me! Let’s try again…

And….there we go! It works! Please ignore my disastrously high LAN pings — I’m getting new access points this week…

Anyway, adding Ethernet should just be another item in that file. So here we go. Let’s break it again! I did this over SSH this time as I had WiFi working.

netplan took a moment to apply, but after that, hurrah! I have both interfaces working and configured with DHCP. My pings were now down to an average of 0.4 seconds, so it’s definitely using my direct Ethernet connection rather than WiFi. And if I unplug the USB Ethernet adapter….they did not shoot up because I lost my SSH connection, to the WiFi IP address. Fun. Pings from my Mac immediately timed out, so maybe I should plug the Ethernet back in, delete its config, and get on with WiFi working.

And now pings are working to the WiFi IP with Ethernet plugged in. Whaaaat?!

IPv4 address for enx7cc2c6356015: 10.45.1.137
IPv4 address for wlx281878388b0f: 10.45.1.153

So the WiFi IP is 153 and the Ethernet IP is 137. If I ping both of those at once from my Mac, I get terrible, WiFi-like response times. My Mac and the Surface are connected to the same Ethernet switch below my desk. Wonderful!

I’m giving up on Ethernet now. WiFi works which is what matters. I only needed Ethernet to make updates go faster…time to do those updates then remove all traces of the Ethernet config! I have commented out the WiFi config whilst I do this. After restarting my SSH session to the correct IP address, I was properly connected over Ethernet and can get the updates done. I won’t bore you with this — standard apt procedure.

Step 3: The Desktop GUI

Installing xfce

My initial idea for this was an Ubuntu Desktop install with Firefox in full screen mode. However, I thought it would be better for both an older device, stability, and reliability if I built on top of basic, stripped-down Ubuntu Server. Hence, xfce. It’s the GUI I use on my server over VNC and it’s very stable and just works. All I need it to do is display a web browser, and then write a quick script to launch that on reboot through cron. The rest of this project should be fairly simple.

Xfce install is very simple. It’s just sudo apt install xfce4 xfce4-goodies. I’ll also install Firefox. It’s not the most lightweight browser, but it’s overall very stable and this Surface will absolutely have no troubles running it. I’ll set up VNC later to ensure I can access the GUI on the Surface as well, which is especially important for managing Firefox and Grafana, as well as Webmin - which I put on all my Linux boxes for general observation and management. It’s one of the coolest things I use day-to-day.

Okay, Xfce is now installed, and to launch, it’s just startxfce4 on the Surface (not SSH) and it should all work. Should.

And it did! I launched Firefox fine after Xfce launched, but unfortunately I couldn’t capture this as it set the HDMI output to a secondary display.

Unfortunately, the trackpad doesn’t work and the touchscreen works as a poorly calibrated mouse. I could probably fix this, but I’m not too worried for now. I’ve disconnected the Ethernet adapter and reconfigured the WiFi connection, so I can connect a wireless mouse for the final setup.

Getting Xfce to work (not)

Either way, after booting up, I was faced with an Ubuntu login screen that logged into this:

This is not Xfce. It’s a weird Ubuntu Desktop (GNOME?) sort of empty desktop. It’s not what I want, so I need to figure that out now. I can SSH in, even though the Settings here seems to indicate no WiFi networks detected.

I can select Xfce on the login screen, which is good, but I’m not sure if that’s a permanent choice. I also want autologin so may have to create another, passwordless user, but that’s not my worry for now.

Selecting Xfce results in a login screen loop…so I logged back into Ubuntu and uninstalled gnome-shell as well as an apt autoremove command for good measure. I then ran dpkg-reconfigure for the lightdm desktop manager, and rebooted.

I now have a different login screen, which has my account name and a password box. It’s reminiscent of older Ubuntu versions. However, entering my password results in Failed to start session in red text. Yay, more problems!

I rebooted and used Ctrl+Alt+F3 to enter a command line, and now my plan is to purge uninstall everything and start again. This is so fun! I’m waiting for the comments of the one million and three things I’ve done wrong at every step.

With everything uninstalled now, the Surface is back to where I was before I started messing with Xfce. There is also no Gnome or Ubuntu packages installed, so installing Xfce should just work…famous last words! Here we go… and I’ve re-enabled Ethernet so I don’t suffer in the pains of my terrible WiFi.

I was asked which display manager to select again, but this time lightdm was highlighted by default so I figured that’s the best option. Perhaps gdm3 was the cause of some of the previous issues, along with the Ubuntu/GNOME desktop weird stuff being installed. Either way, it’s almost done installing so let’s see what happens when I run the glorious startxfce4...

And it works! And it doesn’t! After a reboot I get the below and then the same Gnome desktop or whatever from before. The grey-blue-ish one.

At this point, I might give up on Xfce. This desktop environment works fine for what I need, and although it’s not what I wanted it should be fine. At least it lets me mirror displays, which Xfce didn’t for some reason. Apparently it’s a long-standing bug, and I wasn’t in the mood to edit XML files anyway…who ever is?!

Onto Grafana!

Step 4: Grafana

I don’t yet have the Grafana dashboard I want to use designed. It’s something I’ve been working on and am waiting for my new ISP in a couple of days so I can update a few scripts that check my broadband health, as well as hopefully getting access to the API of my new access points. So for the purposes of getting this done now, I’m going to use my Pi-hole dashboard.

Creating the account

Firstly, though, I want a new Grafana account that isn’t the admin. I have never done this before and do not know how dashboard access works, so let’s find out.

The mention of organisations and permissions makes me believe that all Grafana dashboards are stored in an organisation, and this new account has permission to access them as part of that org. Seems very logical and expected from a tool like Grafana.

Logging into Grafana

Let’s try and sign into Grafana in Firefox on the Surface and see what happens…

And…this is not fast. Took a good 20 seconds to load. I hope it’s a WiFi thing rather than a Surface or Ubuntu or Firefox thing.

I’m finally logged into Grafana on the Surface and all of my dashboards are there — perfect!

The dashboard

Although my Pi-hole dashboard is suddenly massively broken, here is what it looks like in Grafana’s built in kiosk mode:

And here is it in person, ready to be mounted somewhere (once I actually fix the dashboard!)

Step 5: Finishing Touches

Auto-login user account

At the moment, when the Surface boots, it asks for a password and logs in like any other computer. I need to create a second, deployment user account to auto-login and launch Firefox. I say this, laughing at the last few hours…but this should be easy!

First thing to do is actually create the account.

New account created. It forced me to set a password or allow a password to be set on login, so I’m not convinced it’ll work. Then again, this is Linux so it will work somehow eventually…(spoiler alert: I was correct)

Ah. Again I can’t capture this because it defaults to the display output as an extended (secondary) display when not logged in, but it’s forcing me to set a password to log in. Maybe I can delete it afterwards?

We’re in and mirroring, so let’s take a look at account settings…I’ve enabled automatic login and let’s see if it bypasses the need for a password on boot.

Reboot time, this usually breaks everything!

Somehow, surprisingly, it worked! Automatically logged into the new Grafana account. Wonderful! I don’t know why I’m surprised that the ‘Auto-login’ option did what it should’ve, but after tonight I have no trust in anything anymore.

Automatically loading Grafana

Firstly, I need to sign into Grafana in Firefox and get it set to the startpage.

Very simple, all done. It does take a while to load, but that won’t be an issue in deployment as the Grafana page won’t fully reload regularly. It’ll just do it’s own data refresh every 5 seconds which is almost unnoticeable.

Now for auto-full screen, but I think that’ll be part of the autolaunch script perhaps.

Automatically launching Firefox in full screen on login

There’s an addon. That was easy. Nothing exciting here.

Launch on login

I installed gnome-tweaks. It was very simple. No script that I presumed I’d have to write.

There’s some cool things in there but nothing to worry about now.

Almost there! I think this has gone very well overall, so far. I’m about due to massively break something now.

VNC access

As this machine is primarily a GUI, I want to be able to access it through VNC as well as SSH. This is very simple. I hope. I’ve installed TigerVNC and set a password…

And, oh, it’s not the same desktop as on the Surface screen. This behaviour both very useful and very annoying, depending on the circumstances. It’s currently the second for me. Maybe I just do TeamViewer?!

Back into my main user account, installed vino which should enable native ‘Screen Sharing’ in Settings.

And the ‘on’ switch doesn’t work because Ubuntu doesn’t detect the network because it’s managed through NetworkManager or netplan or something or I don’t even know anymore.

Apparently x11vnc could help but I have no faith in anything anymore!

And…there we go. Perfect! Next thing is to sort out a password.

I now have SSH tunnelling enabled in Screens, and it connects the same but securely through SSH — which is great. Still no VNC password though, so I need to work out how to set that for x11vnc . I’m also unsure of how to start it on login, so the VNC server is always running. Running it over SSH results in a new Xfce desktop being created, which isn’t the intention.

Ummm, I just installed tigervnc and its Xorg extension, and started gdm as the guide I’m following dictated (hindsight: I read the guide wrong; this step was only if I had no display manager running already) - however the screen on the Surface is now black. I cannot remember back to last night and I think I’m using lightdm instead! Rebooted, and back into my Grafana account - which, has automatically launched Firefox in full screen to the Pi-hole dashboard. So a good accidental test run!?

Either way, I need VNC working. Password now configured, vncserver run on the Surface directly, let’s see what happens…

Well, I couldn’t get it to connect from my Mac and when running the xtigervncviewer command it specifies, I end up with a brand new desktop. Lovely. How hard can it be?!

So apparently gnome-remote-desktop is designed for exactly this - so I’ve installed it. If this doesn’t work, I’m just going to use TeamViewer because I am sure that works!

And, no, I just got kicked out of my user session. Lovely.

It seems that the reason why Screen Sharing won’t work is because it can’t detect any network connections — the same as the actual network pane in Settings — and it seems that my netplan config is wrong for this. This is what I suspected before trying the last two (three?) solutions, but whatever. In theory, I can just edit it to say this and it’ll work:

network:
version: 2
renderer: NetworkManager

Unfortunately, Settings won’t detect any WiFi networks now. How fun. Perhaps a reboot, but I’m not convinced. I’m also not convinced that I even have NetworkManager installed. I think that was an issue in an earlier stage, and why I used networkd.

Reboot done, WiFi working! Wonderful, let’s try Screen Sharing now. It would be hilarious(ly painful) if I spent this long when it was just a simple network config change.

Interestingly, Screens has automatically detected it on the network so I think it should work straight away…

It took a second to connect, but that’s my WiFi more than anything. And there we go, VNC access to the same desktop!

I now need to run a complete test run, powering off and checking it logs into the Grafana account with functional VNC.

Display and sleep

Now this will absolutely be simple. It’s built into the GNOME Settings tool. The Surface will now no longer sleep or dim the screen after no user interaction, exactly what I need to ensure for a kiosk-style device.

…and it didn’t work! I hadn’t disabled the ‘Automatic Suspend’. Simple fix thankfully.

Webmin

The last management thing I want to install is Webmin. As I’ve mentioned earlier, it’s a really useful and powerful web-based monitoring and management system for Linux. I absolutely love it and it saves me so much time doing basic tasks on my server, including making automatic updates easy and simple.

Installation is simple, unsurprisingly. I just need to add the apt repo and install it. Then again, this is me so it’ll probably not be that easy.

It’s hardly speedy, running over WiFi, but again that’s something that will be fixed with my new access points. It’s not a Surface issue. Nevertheless, it’s a nice way to keep an eye on the stats of this once it’s fully deployed and mounted.

Enabling automatic updates, or ‘Scheduled Upgrades’, is as easy as most things in Webmin.

Final testing and conclusion

Checking it all works

Now, I’m sure everything works because I’ve done it stage by stage but I want to test that I can power off the Surface, plug it in, power it on, and everything boots up as it should. Welp, here we go! (video speed increased)

I’m very happy at this. It automatically boots up and launches Grafana, just as it should. I would like a custom boot screen instead of the verbose boot, but this is something I’ve never done before and therefore I wouldn’t try it on a working, deployable device. I don’t want to risk breaking something that could require a reinstall to repair.

Conclusion

Aside from fixing Pi-hole stuff in Grafana, and building the main network overview Grafana dashboard, I think the project I aimed to complete has been completed — repurposing an old Surface Pro with a dead battery as a lightweight, self-sufficient network dashboard.

This is clearly not a tutorial, but I hope you’ve learnt a couple of things along the way (even if you’ve only learnt about my disastrous luck). If you have any questions, leave a comment or Tweet me.

Also, this has been the first in my ‘Project Blogs’. It’s something I want to do more often, as I enjoy writing it; it helps me to keep track of what I’ve done; and it’s (hopefully) interesting with limited educational value for you!

If there’s any projects you think I’d like to do, then send me a Tweet or DM. I’m open to doing anything cool if I have the equipment, or it’s not too expensive!

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store