Skip to content

Commit

Permalink
Merge pull request #7 from belavina/issues/4-app-release
Browse files Browse the repository at this point in the history
Release pipeline and App Bundling
  • Loading branch information
manekenpix authored Jun 14, 2019
2 parents 837adb8 + 79d0f2a commit 7508fe1
Show file tree
Hide file tree
Showing 9 changed files with 147 additions and 26 deletions.
41 changes: 41 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Golang CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-go/ for more details
version: 2
jobs:
deploy:
docker:
- image: circleci/golang:1.9

working_directory: /go/src/github.com/Seneca-CDOT/StatUtils

steps:
- checkout

- run:
name: "Get Utility Libraries"
command: |
go get -u github.com/tcnksm/ghr
- run:
name: "Build executables and package"
command: |
mkdir dist
mkdir pkg
GOOS=windows GOARCH=amd64 go build -o dist/perfmonitor.exe
GOOS=linux GOARCH=amd64 go build -o dist/perfmonitor
zip -r -j pkg/perfmonitor_win_amd64.zip dist/perfmonitor.exe ./INSTALL_WIN.md ./SysStats.ps1 ./Perfmonitor.xml
zip -r -j pkg/perfmonitor_linux_amd64.zip dist/perfmonitor ./INSTALL_LINUX.md ./perfmonitor.service
- run:
name: "Deploy on github releases"
command: |
VERSION="v$(dist/perfmonitor -version)"
ghr -t ${GITHUB_TOKEN} -u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} -c ${CIRCLE_SHA1} -soft ${VERSION} pkg/
workflows:
version: 2
build-deploy:
jobs:
- deploy:
filters:
branches:
only:
- master
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
/*.exe
/*.out
.vscode
pkg
dist
17 changes: 17 additions & 0 deletions INSTALL_LINUX.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
**Linux Installation**

Steps to install `perfmonitor` release on a linux system;

1) Install binary:

`cp ./perfmonitor /usr/bin/`

2) Install service:

```
cp perfmonitor.service /etc/systemd/system
systemctl start perfmonitor
systemctl enable perfmonitor
```
3) Data is accessible at `:9159/sysstats`
24 changes: 24 additions & 0 deletions INSTALL_WIN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
**Windows Installation**

Steps to install `perfmonitor` release on a win system;


1) Extract the release bundle as `C:\Program Files\perfmonitor_win_amd64`

2) Open `Task Scheduler` as `Administrator`

3) Import pre-defined task by picking `Import Task` on action tab

a) select `Perfmonitor` xml file in `C:\Program Files\perfmonitor_win_amd64`

b) Click `Ok`, select `Task Scheduler Library` on the left, right click on `Perfmonitor` & select `Enable` and then `Run` in the dropdown menu

4) Alternatively, you can create a new task by choosing `Create task` option

a) On tab `General`, set name as `Perfmonitor`, tick `Run whether user is logged on or not` and `Run with highest privileges`

b) On tab `Triggers`, set `At startup` as task trigger

c) On tab `Action`, point `Program/script` to `cmd`, set `Add arguments` as `/c perfmonitor.exe > log.txt` and `Start in` as `C:\Program Files\perfmonitor_win_amd64`

d) Click `Ok`, select `Task Scheduler Library` on the left, right click on `Perfmonitor` & select `Run` in the dropdown menu
Binary file added Perfmonitor.xml
Binary file not shown.
71 changes: 48 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,37 +1,28 @@
# StatUtils
# StatUtils [![CircleCI](https://circleci.com/gh/Seneca-CDOT/StatUtils/tree/master.svg?style=svg)](https://circleci.com/gh/Seneca-CDOT/StatUtils/tree/master)

Collection of utilities for querying hardware statistics and information for Anvil! systems;

## perfmonitor

Perfomonitor is a server returning system performance data upon a request;

### Running Windows

Open `PowerShell` as `Administrator` and run the following command:

`Set-ExecutionPolicy RemoteSigned`

Start perfmonitor by running:
### Release

`./perfmonitor.exe`

### Running Linux
Navigate to [releases page](https://github.com/Seneca-CDOT/StatUtils/releases) to grab the latest version of perfmonitor. Platform-specific bundles contain ready-to-use executables as well as instructions on how to install it on the target system.

Start perfmonitor by running:

`./perfmonitor`


### HTTP Interface
**HTTP Interface**

Current performance stats can be accessed at HTTP port `:9159` & route `/sysstats`:

`$ curl -i "http://{{vm_host}}:9159/sysstats"`
```bash
$ curl -i "http://{{vm_host}}:9159/sysstats"
```

data is returned in the following JSON format (this is windows example, Keys won't match the linux output):

```
```javascript
[
{
"Date":"6/9/2019 10:16:39 PM",
Expand All @@ -54,19 +45,37 @@ data is returned in the following JSON format (this is windows example, Keys won

You can find os of the vm `perfmonitor` is running on by querying:

`$ curl -i "http://{{vm_host}}:9159/platform"`

```bash
$ curl -i "http://{{vm_host}}:9159/platform"
```

```javascript
{
"machine":"my.hostname",
"platform":"linux" // or "windows"
}
```

### Compilation
### Development

Building & development requires golang binary release present on your system, navigate to the [official "Getting Started" page](https://golang.org/doc/install) to grab the latest version.

Note that it can be installed on fedora systems as:

```bash
$ dnf install golang -y
```

Building step requires golang binary release present on your system, navigate to the [official downlad page](https://golang.org/dl/) to grab the latest
version.
**Package Installation**

Grab the latest `perfmonitor` by running:

```bash
# installs in ~/go/src/github.com/Seneca-CDOT/StatUtils
go get github.com/Seneca-CDOT/StatUtils
```

**Compilation**

The .exe can be built for windows (on linux) as:

Expand All @@ -78,4 +87,20 @@ Or it can be compiled on windows as:

Linux executable can be created with the following command:

`GOOS=linux GOARCH=amd64 go build -o perfmonitor`
`GOOS=linux GOARCH=amd64 go build -o perfmonitor`

**Running Windows**

Open `PowerShell` as `Administrator` and run the following command:

`Set-ExecutionPolicy RemoteSigned`

Start perfmonitor by running:

`./perfmonitor.exe`

**Running Linux**

Start perfmonitor by running:

`./perfmonitor`
4 changes: 2 additions & 2 deletions perfmonitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import (
"net/http"
"os"

"./perfstats"
"github.com/Seneca-CDOT/StatUtils/perfstats"
)

// AppVersion - current app version
const AppVersion = "1.1.0"
const AppVersion = "0.0.1"

// Processes http request for latest system performance statistics
func sysStatsHandler(w http.ResponseWriter, r *http.Request) {
Expand Down
11 changes: 11 additions & 0 deletions perfmonitor.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[Unit]
Description=Perfmonitor tool collecting system performance

[Service]
Type=idle
Restart=always
RestartSec=3
ExecStart=/usr/bin/perfmonitor

[Install]
WantedBy=multi-user.target
2 changes: 1 addition & 1 deletion perfstats/perfstats_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func sysStatCSVToJSON(cmdOut []byte) []byte {
// Query performance stats on windows platform
func queryWindowsSysStats() []byte {

cmdResult := exec.Command("powershell.exe", "./SysStats.ps1")
cmdResult := exec.Command("powershell.exe", "-executionpolicy", "bypass", "-file", "./SysStats.ps1")

out, err := cmdResult.Output()
if err != nil {
Expand Down

0 comments on commit 7508fe1

Please sign in to comment.