brooklyn-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Richard Downer <rich...@apache.org>
Subject Re: SshCommandSensor
Date Mon, 20 Oct 2014 16:25:29 GMT
I've located the cause of this problem. It was a strange one, and the
answer is so bizarre yet obvious that everyone should know about it
and keep it in their "toolkit" for the future.

The problem is that the LANG environment variable is different between
me running SSH in a terminal to test out potential commands, and when
Brooklyn is opening SSH sessions to run its commands.

When I was experimenting with finding the right command to run, I
would SSH to a Linux box and run variations on my command until I came
up with a working version. This SSH session would inherit my
workstation's LANG of en_GB.UTF-8. When I ran mpstat, here is a
typical line of output:

16:13:15     all    5.40    0.05    2.18    0.52    0.09    0.03
0.00    0.00   91.74

Having got a working command, I plugged it into my blueprint and let
Brooklyn run the command. Unfortunately, Brooklyn (probably) does not
set the LANG environment variable, and this particular Linux machine
chose a default of en_US.UTF-8. When it ran mpstat, here is the
equivalent line of output:

04:13:11 PM  all    5.40    0.05    2.18    0.52    0.09    0.03
0.00    0.00   91.74

Notice that the date has changed from 24-hour form, to 12-hour with
AM/PM suffix. Also note that there is a space before the "PM" suffix -
causing all of my awk field numbers to now be off-by-one. D'oh!

So the moral of the story is: if the output of your command includes
potentially locale-specific items, explicitly set LANG.

In my specific case, I modified my command to expect the en_US.UTF-8
form, and explicitly set that LANG in my blueprint:

  brooklyn.initializers:
  - type: brooklyn.entity.software.ssh.SshCommandSensor
    brooklyn.config:
      name: cpu.load
      command: LANG=en_US.UTF-8 mpstat | awk '$3=="all"{print
$4+$5+$6+$7+$8+$9+$10+$11}'


Richard.


On 17 October 2014 19:19, Richard Downer <richard@apache.org> wrote:
> All,
>
> I've been trying to add additional sensors to an entity using the
> SshCommandSensor. I'm seeing some problems - some commands don't work
> (the sensor content is always blank), while others do. In particular,
> commands involving a bit of processing with awk don't seem to work.
>
> I can see in brooklyn.debug.log that the commands are being executed
> as expected, and they are coming back with a successful status.
> Sticking a debugger onto Brooklyn, I can see that Brooklyn thinks that
> the command had no stdout.
>
> Here's a blueprint which illustrates the problem I'm seeing:
>
> name: Test
> services:
> - serviceType: brooklyn.entity.webapp.tomcat.TomcatServer
>   name: Tomcat
>   location: AWS_eu-west-1_SUSE
>   brooklyn.initializers:
>   - type: brooklyn.entity.software.ssh.SshCommandSensor
>     brooklyn.config:
>       name: this.works
>       command: mpstat | grep all
>   - type: brooklyn.entity.software.ssh.SshCommandSensor
>     brooklyn.config:
>       name: this.also.works
>       command: mpstat > cpustats && grep -F all cpustats
>   - type: brooklyn.entity.software.ssh.SshCommandSensor
>     brooklyn.config:
>       name: this.doesnt.work
>       command: mpstat | awk '$2=="all"{print $3+$4+$5+$6+$7+$8+$9+$10}'
>   - type: brooklyn.entity.software.ssh.SshCommandSensor
>     brooklyn.config:
>       name: this.doesnt.work.either
>       command: mpstat | awk $$2==\"all\"{print $$3+$$4+$$5+$$6+$$7+$$8+$$9+$$10}
>   - type: brooklyn.entity.software.ssh.SshCommandSensor
>     brooklyn.config:
>       name: neither.does.this.one
>       command: mpstat | awk '$$2=="all"{print $$3+$$4+$$5+$$6+$$7+$$8+$$9+$$10}'
>   - type: brooklyn.entity.software.ssh.SshCommandSensor
>     brooklyn.config:
>       name: nor.this.one
>       command: mpstat | awk '\$2=="all"{print \$3+\$4+\$5+\$6+\$7+\$8+\$9+\$10}'
>   brooklyn.config:
>     pre.install.command: sudo zypper -n install sysstat
>
> In summary, these commands work:
>
> mpstat | grep all
> mpstat > cpustats && grep -F all cpustats
>
> But these commands always leave the sensor empty:
>
> mpstat | awk '$2=="all"{print $3+$4+$5+$6+$7+$8+$9+$10}'
> mpstat | awk $$2==\"all\"{print $$3+$$4+$$5+$$6+$$7+$$8+$$9+$$10}
> mpstat | awk '$$2=="all"{print $$3+$$4+$$5+$$6+$$7+$$8+$$9+$$10}'
> mpstat | awk '\$2=="all"{print \$3+\$4+\$5+\$6+\$7+\$8+\$9+\$10}'
>
> Any ideas what is going wrong?
>
> Thanks
> Richard.

Mime
View raw message