perl script not working

Asked by cnsmith

This script is not updating in graphite. Any ideas?

OUTPUT:
weather.temperature 35 1263766247
weather.humidity 64 1263766247
weather.wind_speed 6 1263766247

SCHEMAS:
/usr/local/graphite/storage/storage-schemas.conf
[everything_1min_1day]
priority = 100
pattern = .*
retentions = 60:1440

[weather_data]
priority = 100
pattern = .*
retentions = 60:1440

CODE:
#!/usr/bin/perl -w

use IO::Socket;
use strict;
use Weather::Google;

# init host and port
my $host = '127.0.0.1';
my $port = 2003;

my $gw;

my $date = `date +%s`;

## Initialize the module
$gw = new Weather::Google(60657); # Zip code

my $temp = $gw->current_conditions('temp_f');

my $humidity = $gw->current_conditions('humidity');
$humidity =~ m#Humidity:(.*)%#;
$humidity = $1;

my $wind = $gw->current_conditions('wind_condition');
$wind =~ m#at (.*) mph#;
$wind = $1;

my $line1 = "weather.temperature $temp $date";
my $line2 = "weather.humidity$humidity $date";
my $line3 = "weather.wind_speed $wind $date";

my $line = "$line1$line2$line3";

my $sock = new IO::Socket::INET( PeerAddr => $host, PeerPort => $port, Proto => 'tcp');
$sock or die "no socket: $!";

$sock->send($line);
print $line;
close($sock);

LOGS:
/opt/graphite/carbon/storage/log/carbon-cache/log/
18/01/2010 01:01:01 :: Unhandled Error
Traceback (most recent call last):
  File "/usr/lib/python2.6/threading.py", line 477, in run
    self.__target(*self.__args, **self.__kwargs)
  File "/usr/lib/python2.6/dist-packages/twisted/python/threadpool.py", line 210, in _worker
    result = context.call(ctx, function, *args, **kwargs)
  File "/usr/lib/python2.6/dist-packages/twisted/python/context.py", line 59, in callWithContext
    return self.currentContext().callWithContext(ctx, func, *args, **kw)
  File "/usr/lib/python2.6/dist-packages/twisted/python/context.py", line 37, in callWithContext
    return func(*args,**kw)
--- <exception caught here> ---
  File "/opt/graphite/carbon/lib/carbon/writer.py", line 144, in writeForever
    writeCachedDataPoints()
  File "/opt/graphite/carbon/lib/carbon/writer.py", line 83, in writeCachedDataPoints
    for schema in schemas:
exceptions.NameError: global name 'schemas' is not defined

Question information

Language:
English Edit question
Status:
Solved
For:
Graphite Edit question
Assignee:
No assignee Edit question
Solved by:
cnsmith
Solved:
Last query:
Last reply:

This question was reopened

Revision history for this message
chrismd (chrismd) said :
#1

Which version of graphite are you using? The latest version is 0.9.5 and it installs by default into /opt/graphite/ instead of /usr/local/graphite/. I bring that up in case you may have upgraded but assumed it would have overwritten a previous installation in /usr/local/. The "global name schemas is not defined" error usually indicates a problem parsing the storage-schemas.conf file. The sample you included looks fine so maybe the file is not in the expected location (/opt/graphite/conf/storage-schemas.conf if you're using 0.9.5). Also, the perl code looks good so the problem is more than likely with carbon not reading the storage-schemas.conf file.

If you are not using 0.9.5, my advice would be to upgrade simply because so much has changed and been fixed since 0.9.4 was released a year or so ago.

Revision history for this message
cnsmith (cnsmith21) said :
#2

i am using the latest version. /usr/local/graphite is a sym link to /opt/graphite.

I also think its a problem with my schemas.

No such file or directory: 'conf/storage-schemas.conf'

18/01/2010 11:13:03 :: Unhandled Error
Traceback (most recent call last):
  File "/usr/lib/python2.6/threading.py", line 477, in run
    self.__target(*self.__args, **self.__kwargs)
  File "/usr/lib/python2.6/dist-packages/twisted/python/threadpool.py", line 210, in _worker
    result = context.call(ctx, function, *args, **kwargs)
  File "/usr/lib/python2.6/dist-packages/twisted/python/context.py", line 59, in callWithContext
    return self.currentContext().callWithContext(ctx, func, *args, **kw)
  File "/usr/lib/python2.6/dist-packages/twisted/python/context.py", line 37, in callWithContext
    return func(*args,**kw)
--- <exception caught here> ---
  File "/opt/graphite/carbon/lib/carbon/writer.py", line 144, in writeForever
    writeCachedDataPoints()
  File "/opt/graphite/carbon/lib/carbon/writer.py", line 83, in writeCachedDataPoints
    for schema in schemas:
exceptions.NameError: global name 'schemas' is not defined

18/01/2010 11:13:18 :: Failed to reload storage schemas
18/01/2010 11:13:18 :: Unhandled Error
Traceback (most recent call last):
  File "/usr/lib/python2.6/dist-packages/twisted/internet/base.py", line 1137, in mainLoop
    self.runUntilCurrent()
  File "/usr/lib/python2.6/dist-packages/twisted/internet/base.py", line 757, in runUntilCurrent
    call.func(*call.args, **call.kw)
  File "/usr/lib/python2.6/dist-packages/twisted/internet/task.py", line 114, in __call__
    d = defer.maybeDeferred(self.f, *self.a, **self.kw)
  File "/usr/lib/python2.6/dist-packages/twisted/internet/defer.py", line 106, in maybeDeferred
    result = f(*args, **kw)
--- <exception caught here> ---
  File "/opt/graphite/carbon/lib/carbon/writer.py", line 154, in reloadStorageSchemas
    schemas = loadStorageSchemas()
  File "/opt/graphite/carbon/lib/carbon/storage.py", line 109, in loadStorageSchemas
    config.read(STORAGE_SCHEMAS_CONFIG)
  File "/opt/graphite/carbon/lib/carbon/conf.py", line 45, in read
    for line in open(path):
exceptions.IOError: [Errno 2] No such file or directory: 'conf/storage-schemas.conf'

18/01/2010 11:13:19 :: Sorted 11 cache queues in 0.000029 seconds

Revision history for this message
cnsmith (cnsmith21) said :
#3

Webapp graphite-0.9.5.tar.gz
Storage Service carbon-0.9.5.tar.gz
Database Library whisper-0.9.5.tar.gz

Revision history for this message
cnsmith (cnsmith21) said :
#4

I resolved this issue by making the directory /opt/graphite/storage/conf and then adding the schemas.conf file. It was a lot of guess and check because I dont know python. :-)

/opt/graphite/storage/conf/storage-schemas.conf

Revision history for this message
cnsmith (cnsmith21) said :
#5

For some reason I started getting this error again.

21/01/2010 14:41:54 :: Failed to reload storage schemas
21/01/2010 14:41:54 :: Unhandled Error
Traceback (most recent call last):
  File "/usr/lib/python2.6/dist-packages/twisted/internet/base.py", line 1137, in mainLoop
    self.runUntilCurrent()
  File "/usr/lib/python2.6/dist-packages/twisted/internet/base.py", line 757, in runUntilCurrent
    call.func(*call.args, **call.kw)
  File "/usr/lib/python2.6/dist-packages/twisted/internet/task.py", line 114, in __call__
    d = defer.maybeDeferred(self.f, *self.a, **self.kw)
  File "/usr/lib/python2.6/dist-packages/twisted/internet/defer.py", line 106, in maybeDeferred
    result = f(*args, **kw)
--- <exception caught here> ---
  File "/opt/graphite/carbon/lib/carbon/writer.py", line 154, in reloadStorageSchemas
    schemas = loadStorageSchemas()
  File "/opt/graphite/carbon/lib/carbon/storage.py", line 109, in loadStorageSchemas
    config.read(STORAGE_SCHEMAS_CONFIG)
  File "/opt/graphite/carbon/lib/carbon/conf.py", line 45, in read
    for line in open(path):
exceptions.IOError: [Errno 2] No such file or directory: 'conf/storage-schemas.conf'

Revision history for this message
cnsmith (cnsmith21) said :
#6

I rresolved this by restarting graphite.

Revision history for this message
chrismd (chrismd) said :
#7

This is because carbon uses a relative path to find its config file so it is intended to be started from the installation directory (/opt/graphite/ in your case). So if you cd to /opt/graphite/ before starting carbon you should not have this problem.