From 2674535c7db9ce7d18600f5f082f875c09310cdd Mon Sep 17 00:00:00 2001 From: Bradley Taunt Date: Mon, 12 May 2025 15:26:13 -0400 Subject: New post for NFS status page --- posts/nfs-status.md | 149 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 149 insertions(+) create mode 100644 posts/nfs-status.md (limited to 'posts/nfs-status.md') diff --git a/posts/nfs-status.md b/posts/nfs-status.md new file mode 100644 index 0000000..bc85b17 --- /dev/null +++ b/posts/nfs-status.md @@ -0,0 +1,149 @@ +# Creating a Basic Status Page on NearlyFreeSpeech + +2025-05-12 + +Since I talked about [hosting multiple websites through NearlyFreeSpeech](https://btxx.org/posts/nfs-multiple-websites/) in the past, I thought it would be nice to walkthrough setting up a barebones "status" page that runs automatically on your existing NFS server. This post isn't going to be mind blowing, but it will give you a solid overview of some weekly stats, such as: + +- basic system info (FreeBSD stats, etc) +- weekly visitor stats +- weekly traffic by browser type + +You can obviously build off of this "skeleton", but I find this works well +enough for my own needs. + +## Live Example + +You can see a live example of my own status page +[here](https://btxx.org/status.html). + +The stats on this page are skewed though, since they take into account all +websites I host through NFS. If you happen to host only a single site on your +account, the data will be much more specific. + +## The Status Script + +The script that generates this status page is very basic shell. You could use +any language really, but I like to keep things as simple as possible (most +times). Here is the code in all of its glory: + +~~~sh +OUTPUT="/home/public//status.html" +ACCESS_LOG="/home/logs/access_log" +VISITOR_COUNT=$(awk '{print $1}' "$ACCESS_LOG" | sort | uniq | wc -l) + +# Capture system data +OS=$(uname -s) +RELEASE=$(uname -r) +ARCH=$(uname -m) +SHELL=$SHELL +RAM=$(top -b | awk '/Mem:/ {print $2 " used, " $4 " free"}' || echo 'N/A') +UPTIME=$(uptime | sed 's/.*up \([^,]*\),.*/\1/') +LOADAVG=$(uptime | sed 's/.*load averages: //') + +{ +cat < + + + + + + Status - NearlyFreeSpeech + + + +

NearlyFreeSpeech.NET Server Info

+

Generated on: $(date)
+Stats updated hourly.

+ +
+/\\,-'''''-,/\\
+\\_)       (_/
+|           |
+|           |
+ ;         ;
+  '-_____-'
+
+ +

System Info

+ + + + + + + + +
OS$OS
Release$RELEASE
Architecture$ARCH
Shell$SHELL
RAM$RAM
Uptime$UPTIME
Load Average$LOADAVG
+ +

Visitor Stats (Reset Weekly)

+ + + +
MetricValue
Unique Visitors$VISITOR_COUNT
+ +

Browser Traffic (Reset Weekly)

+ + +EOF + +# Output each browser row +awk -F\" '{print $6}' "$ACCESS_LOG" | grep -v '^-$' | \ +awk ' + /Edg/ { browsers["Edge"]++ } + /Chrome/ && !/Edg/ { browsers["Chrome"]++ } + /Safari/ && !/Chrome/ { browsers["Safari"]++ } + /Firefox/ { browsers["Firefox"]++ } + /MSIE/ || /Trident/ { browsers["Internet Explorer"]++ } + /curl/ { browsers["curl"]++ } + /wget/ { browsers["wget"]++ } + END { + for (b in browsers) { + printf "\n", b, browsers[b] + } + } +' + +cat < + + +EOF + +} > "$OUTPUT" +~~~ + +Be sure to change the main variables with your own info (file path, etc.) and +you should be good to go. Now save this script and place it on your main NFS +server under the `/home/public` directory. + +
+Important! +Before you setup your automated script, make sure you have enabled Access +Logs under your NFS site panel (found under Log Settings) +
+ + +Our next step is to setup our cronjob. + +## Automating Our Script + +Setting up a `cronjob` through NearlyFreeSpeech is handled through the main +admin site settings. Login and navigate to your **Sites** panel and select your +desired website. Under the sidebar heading **Actions** select **Manage +Scheduled Tasks**. Next, click **Add Scheduled Task**. + +On the following page you will want to enter the following: + +- **Tag**: Whatever name you want +- **URL or Shell Command**: `/bin/sh /home/public/.sh` +- **Enabled**: Yes +- **User**: me +- **Hour**: `*` (run every hour) +- **Day of Week**: Every +- **Date**: `*` (every day of the month) + +Now click Save and you're done! Since your script won't run right away, feel +free to run it directly from the command line for the first time. + +Happy status page building! -- cgit v1.2.3-70-g09d2
BrowserCount
%s%d