RuntimeTools / SwiftMetrics

Swift Application Metrics instruments the Swift runtime for performance monitoring, providing the monitoring data programatically via an API or visually with an Eclipse Client.
https://developer.ibm.com/swift/monitoring-diagnostics/application-metrics-for-swift/
Other
156 stars 50 forks source link

Vapor Support #130

Open jdmcd opened 7 years ago

jdmcd commented 7 years ago

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!

tobespc commented 7 years ago

@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.

seabaylea commented 7 years ago

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

jdmcd commented 7 years ago

I'd love to give it a shot!

jdmcd commented 7 years ago

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?

gperdomor commented 7 years ago

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

seabaylea commented 7 years ago

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

tanner0101 commented 7 years ago

@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.

tobespc commented 7 years ago

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

loganwright commented 7 years ago

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 👍

MrLotU commented 6 years ago

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)

t089 commented 6 years ago

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?