How to do nginx request monitoring - nginx

I have gone through some tools like nagios, collectd but they din't find best as we need to monitor no_of_req/sec for each virtual host with all response status, with response time also.

I'm Using ELK Stack:
Separate access logs for each server block for better visibility or you can separate charts via URLs.
Then Use ELK stack:
Feed the logs to logstash via filebeat.
Create grok pattern for your log model.
Create charts via kibana and monitor in real time.
For realtime monitoring:
Try netdata, Its amazing. Please note its not a replacement for nagios or zabbix.

After some quick research, I found this: check_nginx_status.pl. I think defining something like:
define command {
command_name check-nginx
command_line $USER1$/check_nginx_status.pl -H $HOSTADDRESS$ -s $ARG1$ -u $ARG2$ $ARG3$ $ARG4$ $ARG5$ $ARG6$
}
is probably just what you're looking for.
The -s flag ($ARG1$) would be the hostname of the virtual host
The -u flag ($ARG2$) would be the specific url (/something/status)
And then the rest of the args would be used if you needed to add any additional flags.
Hope this helps!

Related

Getting started with Sony Audio Control API

Trying to use the new Sony Audio Control API with my STR-DN1080 (firmware M41.R.0377), but having a lot of trouble following the guide on https://developer.sony.com/develop/audio-control-api/. It's certainly pretty looking, but the Tutorials are not very helpful.
So based on that portal, it sounds like I need to discover the receiver's port via SSDP/UPNP. There's not much guidance on how to do this, so I used an Android app "UPNP Browser" and found 3 separate URLs. Within http://str.dn.1080.ip:52323/dmr.xml, I find the base URL:port and available services:
<av:X_ScalarWebAPI_DeviceInfo>
<av:X_ScalarWebAPI_Version>1.0</av:X_ScalarWebAPI_Version>
<av:X_ScalarWebAPI_BaseURL>http://str.dn.1080.ip:10000/sony</av:X_ScalarWebAPI_BaseURL>
<av:X_ScalarWebAPI_ServiceList>
<av:X_ScalarWebAPI_ServiceType>guide</av:X_ScalarWebAPI_ServiceType>
<av:X_ScalarWebAPI_ServiceType>system</av:X_ScalarWebAPI_ServiceType>
<av:X_ScalarWebAPI_ServiceType>audio</av:X_ScalarWebAPI_ServiceType>
<av:X_ScalarWebAPI_ServiceType>avContent</av:X_ScalarWebAPI_ServiceType>
</av:X_ScalarWebAPI_ServiceList>
</av:X_ScalarWebAPI_DeviceInfo>
Then, following the API reference for getSystemInformation (v1.4), I issue a GET to http://str.dn.1080.ip:10000/sony/system/getSystemInformation, but all I get back is {"error":[404,"Not Found"]}
I'm stumped now, and looking for help from Sony Developer Support. What am I missing? Is there something I need to enable on my receiver? Is there a hidden firmware that the Auto Updater won't apply?
Thanks!
For those searching on how to use the Sony API in Windows with curl, and to add onto the accepted answer, you'll need to replace the single quotes with double quotes and then escape the double quotes in the JSON:
curl -i -d "{\"method\": \"getSystemInformation\",\"id\": 1,\"params\":
[],\"version\": \"1.4\"}" http://str.dn.1080.ip:10000/sony/system
For postman, set type to POST, URL to: http://str.dn.1080.ip:10000/sony/system, and specify Body as raw/JSON, and paste the JSON:
{
"method":"getSystemInformation",
"id":1,
"params":[],
"version":"1.4"
}
The Sony Audio Control API is based on POST request.
So you have to use some program that can generate a POST request like curl to send requests
curl -i -d '{"method": "getSystemInformation","id": 1,"params": [],"version": "1.4"}' http://str.dn.1080.ip:10000/sony/system
You can also use programs like postman to send test requests if you want something with a GUI.

How can I remove the Server header in Payara Micro 172?

I'd like to remove the server header from Payara Micro's output.
For example, it reports this:
HTTP/1.1 200 OK
Server: Payara Micro #badassfish
I'd like to get rid of that Server line.
I see that issue 32 provided the capability in theory to disable this. The associated pull request certainly seems to show that there is some sort of property being consulted to disable this. And I can infer from this that I could presumably go into the administration GUI if this were a full-fledged server and click a checkbox somewhere.
But I'm running Payara Micro which needs to be fully configured from the command line at startup.
What I'm lacking is a simple "put this on the command line"-type of instruction and I can't seem to locate that anywhere. Is there a setting in, say, glassfish-web.xml-as-modified-by-Payara I could use? Or a command line switch? Or a specific asadmin attribute I could set in a pre-boot script?
Ideas?
The change that you referenced linked to a pull request which added a boolean server-header property to the http-listener which would disable the header.
There is no native asadmin command to set this property, so you will need to use an asadmin set command with the correct dotted name for the listener you want to modify. To find out what this is, you can use the get command with a wildcard and grep for the value you want, as shown below with Payara Server:
➜ ~ /opt/payara/server/171.1/bin/asadmin get "*" | grep server-header
configs.config.default-config.network-config.protocols.protocol.http-listener-2.http.server-header=true
configs.config.default-config.network-config.protocols.protocol.http-listener-1.http.server-header=true
configs.config.default-config.network-config.protocols.protocol.admin-listener.http.server-header=true
configs.config.server-config.network-config.protocols.protocol.admin-listener.http.server-header=true
configs.config.default-config.network-config.protocols.protocol.sec-admin-listener.http.server-header=true
configs.config.server-config.network-config.protocols.protocol.http-listener-1.http.server-header=true
configs.config.server-config.network-config.protocols.protocol.http-listener-2.http.server-header=true
Since the default-config is just a template and not used, we want the listeners from server-config. http-listener-1 is for HTTP by default and http-listener-2 is for HTTPS by default. To modify the server-header property in Payara Micro, you would need to create a file with the following command in (note that Payara Micro only has a single listener by default called http-listener):
set configs.config.server-config.network-config.protocols.protocol.http-listener.http.server-header=false
You can then apply these with a prebootcommandfile as follows:
java -jar /opt/payara/micro/173/payara-micro.jar --prebootcommandfile myCommands.txt
You may also wish to disable the xpowered-by property via the same method.

Datapower SSH login ignores username

When I ssh to my Datapower node like so: ssh user#192.168.0.1 I receive this response:
ssh user#192.168.0.1
(unknown)
Unauthorized access prohibited.
login:
I then enter in the same username, and am also prompted for a password. I type in my credentials and it works! Why didn't it just read my username the first time?
This is hampering my ability to automate a few basic tasks with shell scripts such as fetching logs for processing.
I agree with #Ken and #Stefan that a XML Management is a more appropriate tool for long term automations, howerver, sometimes we need something quick or temporary (or both) ... and for that a CLI automation is easier and faster to develop.
An easy way to push commands to CLI from a shell script is directing the input and output, like this quick sample:
#!/bin/ksh
DPHOST=datapower.device.company.com
DP_USER_ID="myuser"
DP_PASSWORD="mypasword"
TMPFILE=/tmp/tempfile.dp
OUTFILE=/tmp/outfile.dp
TS=`date +%Y%m%d%H%M%S`
cat << EOF > $TMPFILE
DP_USER_ID
DP_PASSWORD
default
echo show cpu
show cpu
echo show memory
show memory
EOF
ssh -T $DPHOST < $TMPFILE > $OUTFILE.$TS
rm $TMPFILE
Note that if you do not have any application domains defined, you may suppress the "default" after the password
And of course, for security reasons you may request the user and password at run time, rather then have it saved on a plain text file, but that is up to you ... the relevant piece here is that you can redirect the file with the commands to an regular ssh session
If you prefer, something like cat $TMPFILE | ssh -T $DPHOST > $OUTFILE.$TS would also works.
That is because DataPower really isn't a SSH server only using the protocol.
What I do in my scripts is that I do the connection, wait for the response and then send the username as the second command and password as third:
ssh [datapower ip]
(unknown)
Unauthorized access prohibited.
login:
your-username
password:
your-password
'#xi52:
DataPower ignores the passed-in username.
Will using the XML Management interface meet your needs? I probably have some scripts laying around.
Ken

Postfix: how to block incoming emails to a specific recipient?

I have Postfix set up to deliver all incoming email to 〈any_random_address〉#mydomain.com to myname#mydomain.com. I've recently noticed that a large percentage of spam is going to the same non-existent username, and I'd like to block incoming email to that username, while still sending all other emails to my inbox. What is the best way to accomplish that?
Aside from the fact that catch-all doesn't really make sense:
In your virtual aliases map (e.g. /etc/postfix/virtual_alias_maps), add the following line:
john.doe#example.com devnull
In /etc/aliases, add the following line:
devnull: /dev/null
This defines a mailbox named devnull and stores its contents in /dev/null.
Don't forget to update the alias caches and restart Postfix, for example like
sudo postmap /etc/postfix/virtual_alias_maps
sudo newaliases
sudo service postfix restart
Now you should be fine.

cURL and ActiveMQ

I need an example on how to read/write to an ActiveMQ queue over HTTP in C or C++ using cURL (or something else, I'm open to anything at this point).
I have working code in C#, but it doesn't help.
Any help is appreciated,
Thank you.
First I assume:
You are running activemq 5.5.0
You are using the default activemq configuration that enables the web-console
Test it by pointing a browser to http://localhost:8161/admin
By cURL you mean libcurl and a command line example is sufficient
Example:
Create a queue named test, set the body to hello world.
Note: [clientId] this a unique string to identify your subscribe otherwise a new consumer will be created for each request see REST
$ curl -d 'body="Hello World"' "http://localhost:8161/demo/message/test?type=queue&clientId=consumerA"
Pop the message of the queue
$ curl -X delete "http://localhost:8161/demo/message/test?type=queue&clientId=consumerA"
You should see "Hello World"
Finally unsubscribe from the queue
$ curl -d 'action=unsubscribe' "http://localhost:8161/demo/message/test?type=queue&clientId=consumerA"
You should be able to monitor all of the above operations from the admin interface
Until version 5.8, REST API was part of the Web Samples and was mapped
to http://localhost:8161/demo/message url. From 5.8 onwards, the API
is available by default at http://localhost:8161/api/message url
http://activemq.apache.org/rest.html

Resources