SwiftMetrics icon indicating copy to clipboard operation
SwiftMetrics copied to clipboard

Vapor Support

Open jdmcd opened this issue 8 years ago • 11 comments

Hello,

This project looks incredible. Is it possible to use it with a Vapor server? I saw in the article it said that it would automatically setup a Kitura server, but I'd like to use it with Vapor.

Thanks!

jdmcd avatar Jun 26 '17 17:06 jdmcd

@mcdappdev It should be easy to make it work with Vapor. Modifying SwiftMetricsDash.swift should be the place to make any changes. We don't have it in plan to do that right now but if you would like to have a go and submit a pull request, you would be more than welcome.

tobespc avatar Jun 27 '17 07:06 tobespc

@tanner0101 @LoganWright any views on doing this for Vapor?

seabaylea avatar Jun 27 '17 09:06 seabaylea

I'd love to give it a shot!

jdmcd avatar Jun 27 '17 12:06 jdmcd

I'm trying to figure out the best way to go about doing this, since the SwiftMetricsDash.swift file relies heavily on Kitura based imports currently. Should it be rewritten to be protocol-based?

jdmcd avatar Jun 27 '17 14:06 jdmcd

@mcdappdev I think the best way is make a fork, because this seems to be integrated to kitura

gperdomor avatar Jun 28 '17 23:06 gperdomor

@mcdappdev @gperdomor we're certainly not against refactoring and providing protocols to make it easier to plug into to other frameworks.

seabaylea avatar Jul 01 '17 08:07 seabaylea

@seabaylea would be awesome if the protocols and kitura implementation were in a separate package. We could then pull in just the protocols for the vapor implementation. lmk what I could do to help with that.

tanner0101 avatar Jul 20 '17 01:07 tanner0101

@tanner0101 I'll take a look at refactoring the protocols and Kitura implementation out into separate packages

tobespc avatar Jul 21 '17 11:07 tobespc

I'm sure you're plenty busy w/ a million other things, but I wanted to check in and see if you've had a chance to take a look yet @tobespc 👍

loganwright avatar Aug 09 '17 13:08 loganwright

I've created https://github.com/MrLotU/VaporMonitoring based off of SwiftMonitoring and the Kitura parts, but it's working with Vapor (as of posting this, it's still in it's early stages)

MrLotU avatar Jun 02 '18 11:06 MrLotU

Hello, if understand the Package.swift correctly, SwiftMetrics does not have a direct dependency on Kitura. This would make it very lightweight to integrate it into other projects. At the moment, you always have to build Kitura even when you are not using any of the Kitura features.

As a test I changed Package.swift slightly:

let package = Package(
  name: "SwiftMetrics",
  products: [
        .library(
            name: "SwiftMetrics",
            targets: ["SwiftMetrics"]),
        .library(
            name: "SwiftMetricsKitura",
            targets: ["SwiftMetricsKitura",
                "SwiftBAMDC",
                "SwiftMetricsBluemix",
                "SwiftMetricsDash",
                "SwiftMetricsREST",
                "SwiftMetricsPrometheus"]),

        .executable(name: "SwiftMetricsEmitSample", targets: ["SwiftMetricsEmitSample"]),
        .executable(name: "SwiftMetricsCommonSample", targets: ["SwiftMetricsCommonSample"]),
    ],
  dependencies: [
    .package(url: "https://github.com/IBM-Swift/Kitura.git", from: "2.3.0"),
    webSocketPackage,
    .package(url: "https://github.com/IBM-Swift/Swift-cfenv.git", from: "6.0.0"),
    .package(url: "https://github.com/RuntimeTools/omr-agentcore", .exact("3.2.4-swift4")),
  ],
  targets: [
      .target(name: "SwiftMetrics", dependencies: ["agentcore", "hcapiplugin", "envplugin", "cpuplugin", "memplugin", "CloudFoundryEnv"]),
      .target(name: "SwiftMetricsKitura", dependencies: ["SwiftMetrics", "Kitura"]),
      .target(name: "SwiftBAMDC", dependencies: ["SwiftMetricsKitura", "Kitura-WebSocket"]),
      .target(name: "SwiftMetricsBluemix", dependencies: ["SwiftMetricsKitura","SwiftBAMDC"]),
      .target(name: "SwiftMetricsDash", dependencies: ["SwiftMetricsBluemix"]),
      .target(name: "SwiftMetricsREST", dependencies: ["SwiftMetricsKitura"]),
      .target(name: "SwiftMetricsPrometheus", dependencies:["SwiftMetricsKitura"]),
      .target(name: "SwiftMetricsCommonSample", dependencies: ["SwiftMetrics"],
            path: "commonSample/Sources"),
      .target(name: "SwiftMetricsEmitSample", dependencies: ["SwiftMetrics"],
            path: "emitSample/Sources"),
      .testTarget(name: "CoreSwiftMetricsTests", dependencies: ["SwiftMetrics"]),
      .testTarget(name: "SwiftMetricsRESTTests", dependencies: ["SwiftMetricsREST"])
   ]
)

With this change I can use SwiftMetrics but no longer have to build Kitura as well. Would this be an option?

t089 avatar Nov 16 '18 20:11 t089