I was using the following instructions to install and configure StatsD on a Graphite server:
https://www.digitalocean.com/community/tutorials/how-to-configure-statsd-to-collect-arbitrary-stats-for-graphite-on-ubuntu-14-04
Now that I have a server with StatsD running, I do not see the metrics being logged under /var/log/statsd/statsd.log when I am testing sending them from the command line. Here is what I see:
29 Oct 02:30:39 - server is up
29 Oct 02:47:49 - reading config file: /etc/statsd/localConfig.js
29 Oct 02:47:49 - server is up
29 Oct 14:16:45 - reading config file: /etc/statsd/localConfig.js
29 Oct 14:16:45 - server is up
29 Oct 15:36:47 - reading config file: /etc/statsd/localConfig.js
29 Oct 15:36:47 - DEBUG: Loading server: ./servers/udp
29 Oct 15:36:47 - server is up
29 Oct 15:36:47 - DEBUG: Loading backend: ./backends/graphite
29 Oct 15:36:47 - DEBUG: numStats: 3
The log stays at the last entry of 'numStats: 3', even though I keep entering different metrics at the command line.
Here are a sample of the metrics I entered:
echo "sample.gauge:14|g" | nc -u -w0 127.0.0.1 8125
echo "sample.gauge:10|g" | nc -u -w0 127.0.0.1 8125
echo "sample.count:1|c" | nc -u -w0 127.0.0.1 8125
echo "sample.set:50|s" | nc -u -w0 127.0.0.1 8125
Of interest, I see this under /var/log/statsd/stderr.log:
events.js:72
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE
at errnoException (net.js:901:11)
at Server._listen2 (net.js:1039:14)
at listen (net.js:1061:10)
at Server.listen (net.js:1135:5)
at /usr/share/statsd/stats.js:383:16
at null.<anonymous> (/usr/share/statsd/lib/config.js:40:5)
at EventEmitter.emit (events.js:95:17)
at /usr/share/statsd/lib/config.js:20:12
at fs.js:268:14
at Object.oncomplete (fs.js:107:15)
Here is what my localConfig.js file looks like:
{
graphitePort: 2003
, graphiteHost: "localhost"
, port: 8125
, graphite: {
legacyNamespace: false
},
debug: true,
dumpMessages: true
}
Would anybody be able to shed some light as to where the problem lies?
Thanks!
There is a management interface available by default on port 8126: https://github.com/etsy/statsd/blob/master/docs/admin_interface.md
You likely have another service listening on that port in the same system.
Try this:
# localConfig.js
{
graphitePort: 2003
, graphiteHost: "localhost"
, port: 8125
, mgmt_port: 8127
, graphite: {
legacyNamespace: false
},
debug: true,
dumpMessages: true
}
See https://github.com/etsy/statsd/blob/master/exampleConfig.js#L28
Related
It seems the Redis container hostname is being converted to localhost by NodeJS.
Here are my files:
.env
REDIS_HOST=redis-eventsystem
REDIS_PORT=6379
REDIS_SECRET=secret
index.ts
// there are things above this
let Redis = require('redis');
let client : any = Redis.createClient({
host: process.env.REDIS_HOST,
port: process.env.REDIS_PORT,
legacyMode: true
});
client.on('error', (err : Error) : void => {
console.error(
`Redis connection error: ${err}`
);
});
client.on('connect', (err : Error) : void => {
console.info(
`Redis connection success.`
);
});
client.connect();
// there are things bellow this
docker-compose.yml
version: '3.8'
services:
eventsystem:
image: eventsystem
restart: always
depends_on:
- "redis-eventsystem"
ports:
- "80:3000"
networks:
- eventsystem
redis-eventsystem:
image: redis
command: ["redis-server", "--bind", "redis-eventsystem", "--port", "6379", "--protected-mode", "no"]
restart: always
networks:
- eventsystem
networks:
eventsystem:
driver: bridge
docker log
2022-11-21 17:50:41 eventsystem-redis-eventsystem-1 | 1:C 21 Nov 2022 20:50:41.106 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
2022-11-21 17:50:41 eventsystem-redis-eventsystem-1 | 1:C 21 Nov 2022 20:50:41.106 # Redis version=7.0.5, bits=64, commit=00000000, modified=0, pid=1, just started
2022-11-21 17:50:41 eventsystem-redis-eventsystem-1 | 1:C 21 Nov 2022 20:50:41.106 # Configuration loaded
2022-11-21 17:50:41 eventsystem-redis-eventsystem-1 | 1:M 21 Nov 2022 20:50:41.106 * monotonic clock: POSIX clock_gettime
2022-11-21 17:50:41 eventsystem-redis-eventsystem-1 | 1:M 21 Nov 2022 20:50:41.108 * Running mode=standalone, port=6379.
2022-11-21 17:50:41 eventsystem-redis-eventsystem-1 | 1:M 21 Nov 2022 20:50:41.108 # Server initialized
2022-11-21 17:50:41 eventsystem-redis-eventsystem-1 | 1:M 21 Nov 2022 20:50:41.108 * Ready to accept connections
2022-11-21 17:50:41 eventsystem-eventsystem-1 |
2022-11-21 17:50:41 eventsystem-eventsystem-1 | > eventsystem#1.0.0 start
2022-11-21 17:50:41 eventsystem-eventsystem-1 | > node index.js serve
2022-11-21 17:50:41 eventsystem-eventsystem-1 |
2022-11-21 17:50:42 eventsystem-eventsystem-1 | Application is listening at http://localhost:3000
2022-11-21 17:50:42 eventsystem-eventsystem-1 | Mon Nov 21 2022 20:50:42 GMT+0000 (Coordinated Universal Time) - Redis connection error: Error: connect ECONNREFUSED 127.0.0.1:6379
As you all can see the connection is refused for the IP 127.0.0.1 but on my application the redis is set to work on the hostname for the container which holds the redis server. I can't think of anything that may be causing this problem.
So to answer my own question, basically the problem was related to the variables passed on createClient at my code.
It seems that for some unknown reason the host and port variables need to be passed inside a variable called socket inside the createClient argument object.
So, instead of doing the usual and passing the host and port inside the argument object, you must do the following:
let client : any = Redis.createClient({
host: process.env.REDIS_HOST,
port: process.env.REDIS_PORT,
socket: {
host: process.env.REDIS_HOST,
port: process.env.REDIS_PORT
},
legacyMode: true
});
Hope to have helped someone else besides me.
Cheers!
This question already has answers here:
Error: Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED 127.0.0.1:6379
(7 answers)
Closed 9 months ago.
i have this docker compose that connects my redis server with my socket server that has redis client
version: "3.8"
services:
redis-server:
image: "redis"
volumes:
- express-chat-vol:/express-chat/
networks:
- express-chat-net
ports:
- 6379:6379
socket-server:
build:
context: ./server/
dockerfile: Dockerfile.socketServer
ports:
- 5000:5000
networks:
- express-chat-net
volumes:
express-chat-vol:
networks:
express-chat-net:
but socket server can't access the redis server and bring up this error and i'm stuck for 2 days now , how can i solve it ?
Starting token2_socket-server_1 ... done
Starting token2_redis-server_1 ... done
Attaching to token2_socket-server_1, token2_redis-server_1
redis-server_1 | 1:C 29 May 2022 01:07:22.191 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
redis-server_1 | 1:C 29 May 2022 01:07:22.191 # Redis version=7.0.0, bits=64, commit=00000000, modified=0, pid=1, just started
redis-server_1 | 1:C 29 May 2022 01:07:22.191 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
//some logs
redis-server_1 | 1:M 29 May 2022 01:07:22.195 * Ready to accept connections
socket-server_1 | socket server is listening on port 5000
socket-server_1 | node:internal/process/promises:288
socket-server_1 | triggerUncaughtException(err, true /* fromPromise */);
socket-server_1 | ^
socket-server_1 |
socket-server_1 | Error: connect ECONNREFUSED 127.0.0.1:6379
socket-server_1 | at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1195:16)
socket-server_1 | Emitted 'error' event on Commander instance at:
socket-server_1 | at RedisSocket.<anonymous> (/socketServer/node_modules/#redis/client/dist/lib/client/index.js:339:14)
socket-server_1 | at RedisSocket.emit (node:events:527:28)
socket-server_1 | at RedisSocket._RedisSocket_connect (/socketServer/node_modules/#redis/client/dist/lib/client/socket.js:127:14)
socket-server_1 | at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
socket-server_1 | at async Commander.connect (/socketServer/node_modules/#redis/client/dist/lib/client/index.js:163:9)
socket-server_1 | at async connectRedisClient (/socketServer/socketServer.js:19:3) {
socket-server_1 | errno: -111,
socket-server_1 | code: 'ECONNREFUSED',
socket-server_1 | syscall: 'connect',
socket-server_1 | address: '127.0.0.1',
socket-server_1 | port: 6379
socket-server_1 | }
socket-server_1 |
socket-server_1 | Node.js v18.0.0
token2_socket-server_1 exited with code 1```
Try using redis-server as the hostname and not 127.0.0.1.
I'm trying to run a very simple docker-compose.yml, but am getting a "ReferenceError: server is not defined" from index.js in the client container.
| /app/index.js:6
node-app_1 | host: redis-server,
node-app_1 | ^
Here's the code:
index.js
const express = require('express');
const redis = require('redis');
const app = express();
const client = redis.createClient({
host: redis-server,
port: 6379
});
client.set('visits', 0);
app.get('/', (req,res) => {
client.get('visits', (err,visits) => {
res.send('Number of visit is: ' + visits);
client.set('visits', parseInt(visits) + 1);
})
})
app.listen(8081, () =>{
console.log('Listening on port 8081');
})
docker-compose.yml
version: '3'
services:
redis-server:
image: 'redis'
node-app:
build: .
ports:
- '4001:8081'
Output of docker-compose up
redis-server_1 | 1:C 07 Nov 2020 16:52:30.899 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
redis-server_1 | 1:C 07 Nov 2020 16:52:30.900 # Redis version=6.0.9, bits=64, commit=00000000, modified=0, pid=1, just started
redis-server_1 | 1:C 07 Nov 2020 16:52:30.900 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
redis-server_1 | 1:M 07 Nov 2020 16:52:30.901 * Running mode=standalone, port=6379.
redis-server_1 | 1:M 07 Nov 2020 16:52:30.902 # Server initialized
redis-server_1 | 1:M 07 Nov 2020 16:52:30.902 * Loading RDB produced by version 6.0.9
redis-server_1 | 1:M 07 Nov 2020 16:52:30.902 * RDB age 180 seconds
redis-server_1 | 1:M 07 Nov 2020 16:52:30.902 * RDB memory usage when created 0.77 Mb
redis-server_1 | 1:M 07 Nov 2020 16:52:30.903 * DB loaded from disk: 0.000 seconds
redis-server_1 | 1:M 07 Nov 2020 16:52:30.903 * Ready to accept connections
node-app_1 |
node-app_1 | > start
node-app_1 | > node index.js
node-app_1 |
node-app_1 | /app/index.js:6
node-app_1 | host: redis-server,
node-app_1 | ^
node-app_1 |
node-app_1 | ReferenceError: server is not defined
node-app_1 | at Object.<anonymous> (/app/index.js:6:17)
node-app_1 | at Module._compile (node:internal/modules/cjs/loader:1083:30)
node-app_1 | at Object.Module._extensions..js (node:internal/modules/cjs/loader:1112:10)
node-app_1 | at Module.load (node:internal/modules/cjs/loader:948:32)
node-app_1 | at Function.Module._load (node:internal/modules/cjs/loader:789:14)
node-app_1 | at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:72:12)
node-app_1 | at node:internal/main/run_main_module:17:47
node-app_1 | npm ERR! code 1
node-app_1 | npm ERR! path /app
node-app_1 | npm ERR! command failed
node-app_1 | npm ERR! command sh -c node index.js
node-app_1 |
node-app_1 | npm ERR! A complete log of this run can be found in:
node-app_1 | npm ERR! /root/.npm/_logs/2020-11-07T16_52_31_324Z-debug.log
visits_node-app_1 exited with code 1
It doesn't find "redis-server", but according to the udemy course, it should find it because that's how it's identified in the composer.
What's the problem?
"redis-server" should be a string, and denoted by quotes:
const client = redis.createClient({
host: 'redis-server',
port: 6379
});
I get the following error when running 'pm2 start project.json' in my project.
port: 3000 }
0|serv | Tue, 08 Sep 2020 03:14:18 GMT app LoadSettingFromRedis: loaded
0|serv | { Error: listen EADDRINUSE 127.0.0.1:3000
0|serv | at Server.setupListenHandle [as _listen2] (net.js:1360:14)
0|serv | at listenInCluster (net.js:1401:12)
0|serv | at doListen (net.js:1510:7)
0|serv | at _combinedTickCallback (internal/process/next_tick.js:142:11)
0|serv | at process._tickCallback (internal/process/next_tick.js:181:9)
0|serv | errno: 'EADDRINUSE',
0|serv | code: 'EADDRINUSE',
0|serv | syscall: 'listen',
0|serv | address: '127.0.0.1',
0|serv | port: 3000 }
0|serv | Tue, 08 Sep 2020 03:15:08 GMT app LoadSettingFromRedis: loaded
0|serv | Tue, 08 Sep 2020 03:20:43 GMT app LoadSettingFromRedis: loaded
When I check what process is listening on port 3000, I get node. I kill this process, but it still doesn't solve the issue. Does anyone know what is the problem here?
It means your port is already in use. Try killing port with following command
sudo kill -9 $(sudo lsof -t -i:3000)
if that not works try following
sudo lsof -i tcp:3000 // this will return some PIDs
sudo kill -9 [your pid to remove]
Then run pm2 start command again
with this code on nodeJS :
var MongoClient = require('mongodb').MongoClient;
...
MongoClient.connect('mongodb://127.0.0.1:27017', { useUnifiedTopology: true }, (error, db) => {
if (error) {
obs.error(this.throwExceptionError(error));
} else {
this.dbConnect = db.db(dbb);
obs.next(true);
}
});
i can connect to MongoDB on windows and it works well.
I try to execute this code on my raspberry Pi but the code didn't work.
I installed mongodb, launch :
service mongodb start
When i execute mongo in a console, it works and i see my dbs and my collections.
The log of the mongoDb are :
Sun Jun 28 13:43:51.566 [initandlisten]
Sun Jun 28 13:43:51.566 [initandlisten] db version v2.4.14
Sun Jun 28 13:43:51.566 [initandlisten] git version: nogitversion
Sun Jun 28 13:43:51.566 [initandlisten] build info: Linux bm-wb-03 3.19.0-trunk-armmp #1 SMP Debian 3.19.1-1~exp1+plugwash1 (2015-03-28) armv7l BOOST_LIB_VERSION=1_58
Sun Jun 28 13:43:51.566 [initandlisten] allocator: system
Sun Jun 28 13:43:51.566 [initandlisten] options: { bind_ip: "127.0.0.1", config: "/etc/mongodb.conf", dbpath: "/var/lib/mongodb", journal: "true", logappend: "true", logpath: "/var/log/mongodb/mongodb.log", port: 27017 }
Sun Jun 28 13:43:51.578 [initandlisten] journal dir=/var/lib/mongodb/journal
Sun Jun 28 13:43:51.578 [initandlisten] recover : no journal files present, no recovery needed
Sun Jun 28 13:43:51.606 [websvr] admin web console waiting for connections on port 28017
Sun Jun 28 13:43:51.606 [initandlisten] waiting for connections on port 27017
And the command "netstat -tulpn"
pi#raspberrypi:~ $ sudo netstat -tulpn
Connexions Internet actives (seulement serveurs)
Proto Recv-Q Send-Q Adresse locale Adresse distante Etat PID/Program name
tcp 0 0 127.0.0.1:27017 0.0.0.0:* LISTEN 3407/mongod
tcp 0 0 0.0.0.0:5900 0.0.0.0:* LISTEN 486/vncserver-x11-c
tcp 0 0 127.0.0.1:28017 0.0.0.0:* LISTEN 3407/mongod
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 495/sshd
So i think the server is running...
I don't understand why i can't connect to mongoDB on my raspberry pi.
help plz ^^