from cbagent.collectors.libstats.remotestats import RemoteStats, parallel_task


class TPStats(RemoteStats):

    METRICS = (
        ("rss", 1),    # already in bytes
    )

    def __init__(self, hosts, workers, user, password):
        super().__init__(hosts, workers, user, password)
        self.typeperf_cmd = "typeperf \"\\Process(*{}*)\\Working Set\" -sc 1|sed '3q;d'"

    @parallel_task(server_side=True)
    def get_samples(self, process):
        samples = {}
        if process == "beam.smp":
            stdout = self.run(self.typeperf_cmd.format("erl"))
            values = stdout.split(',')[1:5]
        elif process == "memcached":
            stdout = self.run(self.typeperf_cmd.format(process))
            values = stdout.split(',')[1:2]
        else:
            return samples
        sum_rss = 0
        if stdout:
            for v in values:
                v = float(v.replace('"', ''))
                sum_rss += v
            metric, multiplier = self.METRICS[0]
            title = "{}_{}".format(process, metric)
            samples[title] = float(sum_rss) * multiplier
            return samples

from cbagent.collectors.libstats.remotestats import RemoteStats, parallel_task


class TPStats(RemoteStats):

    METRICS = (
        ("rss", 1),    # already in bytes
    )

    def __init__(self, hosts, workers, user, password):
        super().__init__(hosts, workers, user, password)
        self.typeperf_cmd = "typeperf \"\\Process(*{}*)\\Working Set\" -sc 1|sed '3q;d'"

    @parallel_task(server_side=True)
    def get_server_samples(self, process):
        samples = {}
        if process == "beam.smp":
            stdout = self.run(self.typeperf_cmd.format("erl"))
            values = stdout.split(',')[1:5]
        elif process == "memcached":
            stdout = self.run(self.typeperf_cmd.format(process))
            values = stdout.split(',')[1:2]
        else:
            return samples
        sum_rss = 0
        if stdout:
            for v in values:
                v = float(v.replace('"', ''))
                sum_rss += v
            metric, multiplier = self.METRICS[0]
            title = "{}_{}".format(process, metric)
            samples[title] = float(sum_rss) * multiplier
            return samples

    def get_client_samples(self, process):
        pass

Add missing methods to TPStats
Add missing methods to TPStats

Change-Id: I332a83f3816ee30597288180ed344da3161861f8
Reviewed-on: http://review.couchbase.org/79675
Tested-by: Build Bot <80754af91bfb6d1073585b046fe0a474ce868509@couchbase.com>
Reviewed-by: Pavel Paulau <dd88eded64e90046a680e3a6c0828ceb8fe8a0e7@gmail.com>

  from cbagent.collectors.libstats.remotestats import RemoteStats, parallel_task
  
  
  class TPStats(RemoteStats):
  
      METRICS = (
          ("rss", 1),    # already in bytes
      )
  
      def __init__(self, hosts, workers, user, password):
          super().__init__(hosts, workers, user, password)
          self.typeperf_cmd = "typeperf \"\\Process(*{}*)\\Working Set\" -sc 1|sed '3q;d'"
  
      @parallel_task(server_side=True)
-     def get_samples(self, process):
+     def get_server_samples(self, process):
          samples = {}
          if process == "beam.smp":
              stdout = self.run(self.typeperf_cmd.format("erl"))
              values = stdout.split(',')[1:5]
          elif process == "memcached":
              stdout = self.run(self.typeperf_cmd.format(process))
              values = stdout.split(',')[1:2]
          else:
              return samples
          sum_rss = 0
          if stdout:
              for v in values:
                  v = float(v.replace('"', ''))
                  sum_rss += v
              metric, multiplier = self.METRICS[0]
              title = "{}_{}".format(process, metric)
              samples[title] = float(sum_rss) * multiplier
              return samples
  
+     def get_client_samples(self, process):
+         pass
+ 
Add missing methods to TPStats
## Code Before:
from cbagent.collectors.libstats.remotestats import RemoteStats, parallel_task


class TPStats(RemoteStats):

    METRICS = (
        ("rss", 1),    # already in bytes
    )

    def __init__(self, hosts, workers, user, password):
        super().__init__(hosts, workers, user, password)
        self.typeperf_cmd = "typeperf \"\\Process(*{}*)\\Working Set\" -sc 1|sed '3q;d'"

    @parallel_task(server_side=True)
    def get_samples(self, process):
        samples = {}
        if process == "beam.smp":
            stdout = self.run(self.typeperf_cmd.format("erl"))
            values = stdout.split(',')[1:5]
        elif process == "memcached":
            stdout = self.run(self.typeperf_cmd.format(process))
            values = stdout.split(',')[1:2]
        else:
            return samples
        sum_rss = 0
        if stdout:
            for v in values:
                v = float(v.replace('"', ''))
                sum_rss += v
            metric, multiplier = self.METRICS[0]
            title = "{}_{}".format(process, metric)
            samples[title] = float(sum_rss) * multiplier
            return samples

## Instruction:
Add missing methods to TPStats
## Code After:
from cbagent.collectors.libstats.remotestats import RemoteStats, parallel_task


class TPStats(RemoteStats):

    METRICS = (
        ("rss", 1),    # already in bytes
    )

    def __init__(self, hosts, workers, user, password):
        super().__init__(hosts, workers, user, password)
        self.typeperf_cmd = "typeperf \"\\Process(*{}*)\\Working Set\" -sc 1|sed '3q;d'"

    @parallel_task(server_side=True)
    def get_server_samples(self, process):
        samples = {}
        if process == "beam.smp":
            stdout = self.run(self.typeperf_cmd.format("erl"))
            values = stdout.split(',')[1:5]
        elif process == "memcached":
            stdout = self.run(self.typeperf_cmd.format(process))
            values = stdout.split(',')[1:2]
        else:
            return samples
        sum_rss = 0
        if stdout:
            for v in values:
                v = float(v.replace('"', ''))
                sum_rss += v
            metric, multiplier = self.METRICS[0]
            title = "{}_{}".format(process, metric)
            samples[title] = float(sum_rss) * multiplier
            return samples

    def get_client_samples(self, process):
        pass
