Repository navigation
Feature/Http-Routes #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
15fd42b
feat(WindowsMetrics.fs): Added Processor Metrics
MathusanP 73c11c1
feat(WindowsMetrics.fs): Added disk information
MathusanP 72eb47b
feat(WindowsMetrics.fs): Added metrics for graphical processors
MathusanP 995ebfc
fea(DeviceMetrics.fs): Added uptime metric
MathusanP dd1a6e5
feat(tests): Added unit tests and pipeline runs for tests
MathusanP 7f99dab
fix(tests.yml): Switched build os to windows
MathusanP 045d09e
feat(NetworkMetrics.fs): Added network metrics
MathusanP 6c5add7
chore(test.yml): Changed dotnet version to 9.0.x
MathusanP 0395ac3
feat(DeviceMetrics.fs): Added architecture information and error hand…
MathusanP faddb71
Merge branch 'feature/metrics-endpoint' of https://github.com/Mathusa…
MathusanP 1998e0a
feat: Made Http endpoints
MathusanP 87644a0
fix(Pryde.Api/Handlers.fs): Changed content handler to explicit
MathusanP c355b9e
Merge branch 'master' into feature/metrics-endpoint
MathusanP 9654833
chore(tests.fs): changed type(args) to new type(args)
MathusanP 8e47db1
Merge branch 'feature/metrics-endpoint' of https://github.com/Mathusa…
MathusanP 25f007a
chore(NetworkMetrics.fs): Changed network metrics from let to use Sea…
MathusanP 392a2e1
refactor(Handlers.fs): Improved status code handling
MathusanP 46283dd
feat(RouteTests.fs): Added routes testing
MathusanP File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| module Pryde.Api.Handlers | ||
|
|
||
| open Giraffe | ||
| open Pryde.Data | ||
|
|
||
| let getCpuHandler : HttpHandler = | ||
| fun next ctx -> | ||
| json (DeviceMetrics.getCpuInfo ()) next ctx | ||
|
|
||
| let getDiskHandler : HttpHandler = | ||
| fun next ctx -> | ||
| json (DeviceMetrics.getDiskInfo ()) next ctx | ||
|
|
||
| let getGraphicsHandler : HttpHandler = | ||
| fun next ctx -> | ||
| json (DeviceMetrics.getGraphicsInfo ()) next ctx | ||
|
|
||
| let getUptimeHandler : HttpHandler = | ||
| fun next ctx -> | ||
| json (DeviceMetrics.getUptime ()) next ctx | ||
|
|
||
| let getNetworkThroughputHandler : HttpHandler = | ||
| fun next ctx -> | ||
| json (NetworkMetrics.getNetworkThroughput ()) next ctx | ||
|
|
||
| let getPortHandler (port: int) : HttpHandler = | ||
| fun next ctx -> | ||
| if port < 1 || port > 65535 then | ||
| (setStatusCode 400 >=> json {| message = "Invalid port number" |}) next ctx | ||
| else | ||
| match NetworkMetrics.getPortInfo port with | ||
| | Some info -> json info next ctx | ||
| | None -> (setStatusCode 404 >=> json {| message = "Port not listening" |}) next ctx | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,24 +1,22 @@ | ||
| open System | ||
| namespace Pryde.Api | ||
|
|
||
| open Giraffe | ||
| open Pryde.Api.Routes | ||
| open Microsoft.AspNetCore.Builder | ||
| open Microsoft.Extensions.Hosting | ||
| open Pryde.Data | ||
| open Pryde.Data.NetworkMetrics | ||
| open Microsoft.Extensions.DependencyInjection | ||
|
|
||
| [<EntryPoint>] | ||
| let main args = | ||
| let cpu = DeviceMetrics.getCpuInfo () | ||
| let disk = DeviceMetrics.getDiskInfo () | ||
| let gpu = DeviceMetrics.getGraphicsInfo() | ||
| let networkThroughput = NetworkMetrics.getNetworkThroughput() | ||
|
|
||
| printfn "%A" cpu | ||
| printfn "%A" disk | ||
| printfn "%A" gpu | ||
| printfn "%A" networkThroughput | ||
|
|
||
| let builder = WebApplication.CreateBuilder(args) | ||
| let app = builder.Build() | ||
|
|
||
| app.Run() | ||
| type Program() = | ||
| class end | ||
|
|
||
| 0 // Exit code | ||
| module Program = | ||
| [<EntryPoint>] | ||
| let main args = | ||
| let builder = WebApplication.CreateBuilder(args) | ||
| builder.Services.AddGiraffe() |> ignore | ||
|
|
||
| let app = builder.Build() | ||
| app.UseGiraffe(webApp) | ||
|
|
||
| app.Run() | ||
| 0 // Exit code |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| module Pryde.Api.Routes | ||
|
|
||
| open Giraffe | ||
| open Pryde.Api.Handlers | ||
| let webApp : HttpHandler = | ||
| choose [ | ||
| GET >=> choose [ | ||
| route "/system/cpu" >=> getCpuHandler | ||
| route "/system/disk" >=> getDiskHandler | ||
|
MathusanP marked this conversation as resolved.
|
||
| route "/system/graphics" >=> getGraphicsHandler | ||
| route "/system/uptime" >=> getUptimeHandler | ||
| route "/network/throughput" >=> getNetworkThroughputHandler | ||
| routef "/network/port/%i" getPortHandler | ||
| ] | ||
| ] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| module Pryde.Tests | ||
|
|
||
| open Microsoft.AspNetCore.Mvc.Testing | ||
| open Xunit | ||
| open System.Net | ||
| open Pryde.Api | ||
|
|
||
| type RouteTests() = | ||
| let factory = new WebApplicationFactory<Program>() | ||
| let client = factory.CreateClient() | ||
|
|
||
| [<Fact>] | ||
| member _.``GET system cpu returns 200`` () = task { | ||
| let! response = client.GetAsync("/system/cpu") | ||
| Assert.Equal(HttpStatusCode.OK, response.StatusCode) | ||
| } | ||
|
|
||
| [<Fact>] | ||
| member _. ``GET system disk returns 200`` () = task { | ||
| let! response = client.GetAsync("/system/disk") | ||
| Assert.Equal(HttpStatusCode.OK, response.StatusCode) | ||
| } | ||
|
|
||
| [<Fact>] | ||
| member _.``Get network port with invalid port returns 400`` () = task { | ||
| let! response = client.GetAsync("/network/port/-1") | ||
| Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode) | ||
| } | ||
|
|
||
| [<Fact>] | ||
| member _.``Get network port with unused port returns 404`` () = task { | ||
| let! response = client.GetAsync("/network/port/59999") | ||
| Assert.Equal(HttpStatusCode.NotFound, response.StatusCode) | ||
| } | ||
|
|
||
| interface System.IDisposable with | ||
| member _.Dispose() = factory.Dispose() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.