Monitoring services & more with monit

Intro

Monit is a tool we can use to monitor any number of things on the Linux installations in AWS — from CPU usage to Internet connectivity.
* Website: https://mmonit.com/monit/
* Lots of configuration help can be found here and google. https://mmonit.com/wiki/Monit/ConfigurationExamples

We’re going to use it to monitor solr. Solr is a search database `systemd` service that occasionally fails without warning, possibly rendering your  application useless. Having at least a notification email sent out will help you  proactively address an issue before users/customers notice it.

Setup
Setup is fairly straightforward.
1. Install monit
`sudo apt-get install monit`
2. Edit (with sudo) the `/etc/monit/monitrc` file. This file contains all the rules and configurations. Copy/paste the file below *(`/etc/monit/monitrc`), completely overwriting the existing one. Make these changes as needed

  • Alert email format
  • desired alert recipient list
  • Desired action on service anomaly. The provided file has solr set up for passive mode, so a solr failure will simply be logged in /var/log/monit.log` and an email will be sent. Change the mode from passive to active, and monit will persistently try to restart the service on its own.
  • Desired services to monitor. You can add add’l service besides solr, just following the example. Nginx, mongod, etc.
  • Desired frequency (in seconds) of status checking

3. Once the `monitrc` file is edited, you must restart monit for changes to take effect. `sudo service monit restart`. If it complains, do `journalctl -xe` to see where the syntax error is, likely it’s due to a typo in the `monitrc` config file.
That’s it! Install monit, copy/paste the config making the needed format changes, and restart monit. You can test the notifications by stopping solr, waiting for the periodic polling to register the downed service, and checking the specified alert email address for an email.
***

Here’s an example monitrc file.

How to create beautiful API documentation with apiDoc.js

apidoc_sample

 

This is some explanation for making any changes, how to create the API Doc, etc. ApiDoc website: http://www.apidocjs.com

1. install node.js, node packagemanager, and nodejs-legacy: https://www.digitalocean.com/community/tutorials/how-to-install-node-js-on-ubuntu-16-04

2.Install nodejs-legacy: `sudo apt-get install nodejs-legacy` (for explanation of *why* this step is necessary, see here: http://stackoverflow.com/questions/21168141/cannot-install-packages-using-node-package-manager-in-ubuntu)

3.Install apidoc : `sudo npm install apidoc -g` 4. Annotate according to apidoc instructions and following the example of `BionewsRssResource.java` in the BPN repo. Sample annotation:


/**
@api {get} /bpn/rest/bionewsRss Get Bionews Search Results
@apiName bionewsRss
@apiGroup Search
@apiVersion 1.0.0
@apiParamExample Example: https://example.com/rest/bionewsRss?source=mySource&count=7
@apiParam {String} searchId id of a previous search (Optional)
@apiParam {String[]} source type of Bionews source: companies, syndicated, twitter, other (Optional -- default = all)
@apiParam {Integer} count maximum # of items to return (Optional -- default = 10)
*/
@GET @Produces({ "text/xml" })
public String get(@QueryParam("searchId") String searchId, @QueryParam("source") List source, @QueryParam("count") @DefaultValue("10") int count) {

//function body goes here….
}

How to generate the docs:  once the apiDoc node package is installed, run this command from the root directory of : apidoc  -o /path/to/doc/output. Alternatively, the `-i` flag allows you to specify the input directory. For a full list of features, see `apidoc –help`. Screenshot: Lastly, review the end result, and you may want to grep search & replace if you still see junk in the final product, perhaps due to misconfigured annotation.

Changing Keyboard shortcuts in Cinnamon (Linux Mint)

A quick note about changing keyboard shortcuts. I was trying to delete a keyboard shortcut, because it was getting in the way of one of my applications. In particular: ALT+F7 moves the window in the OS, but I want Intelli-J’s binding to take over (for IntelliJ, ALT+F7 finds all usages of the selected variable). Deleting the keyboard was easy enough, but getting them to register is another story.

Preferences -> Keyboard -> Keyboard Shortcuts
And make whatever add/delete/updates that you want.

But once I did this, the keyboard shortcut wasn’t deleted! So after restarting the machine, everything worked as expected. If restarting the machine is too much for your liking, perhaps you can get away with just logging off and logging back on. Underneath the hood, it’s probably some settings file being sourced. But a restart definitely does the trick.

Nifty way of Switching JDK versions on OSX

This SuperUser post details a nice way to easily and quickly switch JDK versions on OSX. Just add the function to your ~/.bash_profile, and switching from Java 7 to Java 8 is a simple as this:

derrick:~ derrick$ setjdk 1.8
JAVA_HOME set to /Library/Java/JavaVirtualMachines/jdk1.8.0_31.jdk/Contents/Home
java version "1.8.0_31"
Java(TM) SE Runtime Environment (build 1.8.0_31-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.31-b07, mixed mode)
derrick:~ derrick$

Credit to Neeme Praks.

Spring XML: Invoking setter methods with multiple arguments

In the JavaBeans idea of a perfect world, every mutable field of an object should be mutated with a single-argument setter method. I find this overly restrictive. At any rate, it is a convention that is not universally followed.

When configuring Java beans with Spring XML files, there isn’t an obvious way to deal with setters that take more than one argument. Consider the following method:

public void setTitles(String... titles)
{
for (String s : titles)
titleSet.add(s);
}

The standard single-arg approach we’re familiar with is:

<bean id="Paul_McCartney" class="com.example.Person">
<propety id="titles" value="Sir"/>
</bean>

But someone with two titles, like “Rev. Dr. Martin Luther King” isn’t easily handled. This is because the XML attribute “value“, like all XML attributes, cannot be multivalued. Here is the workaround:

<bean id="MLK_JR" class="com.example.Person" />

<bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
    <property name="targetObject">
        <ref local="MLK_JR"/>
    </property>
    <property name="targetMethod">
        <value>setTitles</value>
    </property>
    <property name="arguments">
        <list>
            <value>"Reverend"</value>
            <value>"Doctor"</value>
        </list>
    </property>
</bean>

Credit for this fix due to this question on StackOverflow.

The End of History Illusion

If you think you’re done changing as a person, then consider reading this.

Almost everyone anticipates some measure of vertical growth for themselves (whether it be spiritual, financial, or career). But not as widely expected is horizontal growth: total overhauls of how we act w.r.t. things like personality, attitude, mannerisms, etc.

From the original article published in Science:

People, it seems, regard the present as a watershed moment at which they have finally become the person they will be for the rest of their lives. This “end of history illusion” had practical consequences, leading people to overpay for future opportunities to indulge their current preferences.

E-books have room for improvement

Despite how rapidly technology changes, I want this blog to be useful to people today, and five years from now. The blog format is not (yet) optimized for archived information retrieval, but what is? The book, with table of contents and index, comes close.  But there’s one major flaw: information changes, books don’t.

I don’t care if you can fit more books onto your iPad/Kindle/Nook/tablet than the Library of Congress. E-books are still a largely static product. They are written, published, sold, shipped, and then they die. They just sit there on your reader.

In a recent book announcement, Reg Braithwaite explains his unorthodox publishing approach:

Dead tree books remind me of shrink-wrapped software. Today we love Github and software-as-a-service and continuous deployment and running a business in real time on tight feedback circles. That’s how Linux works, that’s how the web works, that’s how I wanted to publish[…]

So his ebook (it’s a JavaScript functions book) is a living thing, which readers can expect to change. I think it’s a fresh approach.