Example #1
0
    def testUnMonitorMetric(self, requestsMock):

        requestsMock.delete.return_value = Mock(status_code=200)

        metric_utils.unmonitorMetric("localhost", "taurus", "foo")

        requestsMock.delete.assert_called_once_with(
            "https://localhost/_models/foo", verify=ANY, auth=("taurus", ""))
  def testUnMonitorMetric(self, requestsMock):

    requestsMock.delete.return_value = Mock(status_code=200)

    metric_utils.unmonitorMetric("localhost", "taurus", "foo")

    requestsMock.delete.assert_called_once_with(
      "https://localhost/_models/foo",
      verify=ANY, auth=("taurus", ""))
Example #3
0
def main():
  logging_support.LoggingSupport.initTool()

  try:
    options = _parseArgs()
    g_log.info("Running %s with options=%r", sys.argv[0], options)

    if options["unmonitorAll"]:
      models = metric_utils.getAllModels(
        host=options["htmServer"],
        apiKey=options["apiKey"])
    else:
      models = tuple(
        metric_utils.getOneModel(
          host=options["htmServer"],
          apiKey=options["apiKey"],
          modelId=modelId)
        for modelId in options["modelIds"]
      )

    # Save model objects to file for use by monitor_metrics
    with open(options["modelsFilePath"], "w") as outFile:
      json.dump(models, outFile, indent=4)

    if not models:
      g_log.info("No models to unmonitor")
      return

    g_log.info("Unmonitoring %d models", len(models))

    for i, model in enumerate(models, 1):
      modelId = model["uid"]
      metric_utils.unmonitorMetric(
        host=options["htmServer"],
        apiKey=options["apiKey"],
        modelId=modelId)
      g_log.info("Unmonitored metric=%s (%d of %d)",
                 modelId, i, len(models))

    g_log.info("Unmonitored %d models", len(models))
  except SystemExit as e:
    if e.code != 0:
      g_log.exception("unmonitor_metrics failed")
    raise
  except Exception:
    g_log.exception("unmonitor_metrics failed")
    raise