Thursday, October 29, 2015

Create a dashing.io dashboard on nitrous.io

Dashing.io is a simple ruby based dashboard creation tool with live updates and high quality graphics that look great on HD TVs.

Nitrous.io is a free cloud (browser based) Integrated Development Environment (IDE). I use the free package for this demo and that will work out to be adequate for what we are about to do.

We will walk through the steps of creating a new account on Nitrous.io, creating and running a sample dashing.io dashboard on Nitrous.io.

Step 1: Create an account or login with GitHub account



Step 2: Get Started:


Select 'Ruby on Rails' container

Give it a cool name

Step 3: Select a Plan

I would stick with the free one for this demo.

Step 4: Start the workspace

Step 5: Start the container

Step 6: Open the IDE


Step 7: Install dashing gem

Execute the following commands in the console section in the bottom of the IDE.

gem install dashing
gem install bundler




Step 8: Create a new dashboard

Execute the following commands to create a new dashboard.

#Create a dashboard named ai_dash
dashing new ai_dash


#Change to the dashboard directory
cd ai_dash

#Bundle
bundle install


Step 9: Start the dashboard

#Start the dashboard

dashing start 

Step 10: Configure preview port

Click on 'Preview' menu and 'Configure Ports'


Configure workspace port 3030 to forward to container port 3030. Clicking 'Apply Changes' will restart the container with port 3030 configured.

Step 11: Restart dashing from console. Click on 'Preview' -> Port 3030.

Ta da.


Have fun!


Tuesday, October 27, 2015

Redis cheatsheet



Redis is considered a NoSQL database. I see it as a great and efficient in memory cache on steroids. I use it for storing results of large calculations so I can quickly display the results on a web page. I actually use it as a cache for a production instance of dashing.io.

Here's a good article about creating a dashboard using dashing.io - https://gocardless.com/blog/raspberry-pi-metric-dashboards/. Towards the bottom of the article check out the 'Persistance' section where there are instructions for adding Redis as the cache for dashing.

Website: http://redis.io/
Official Docker container: https://hub.docker.com/_/redis/
Docker command: docker run -d -p 6379:6379 -v `pwd`:/data --name redis-server redis

To run redis commands on the container, execute:
docker exec -it redis-server /bin/bash

That should get you to the bash shell on the container. Execute 'redis-cli' and you are ready to start creating your keys in redis.



Cheatsheet

#Start redis
redis-server
#Execute commands
redis-cli <command>
#String:
set mykey somevalue
get mykey
#nx - fail if the key already exists
set mykey newval nx
#xx - set value if the key already exists
set mykey newval xx
#incr - increment
set counter 100
incr counter
incr counter
#incrby - increment by
incrby counter 50
#mset - set multiple values
mset a 10 b 20 c 30
#mget - get multiple values
mget a b c
#exists - 1 = yes, 0 = no
set mykey hello
exists mykey
#del - delete
del mykey
#type - Display data type of key
type mykey
#expire
set key some-value
expire key 5 (expires in 5 seconds)
get key
set key 100 ex 10
#ttl - time remaining before the key expires
ttl key
#List: rpush - bottom, lpush - top, lrange - extract a range of items in the list
rpush mylist A
rpush mylist B
lpush mylist first
lrange mylist 0 -1 (list from zero to last element)
lrange mylist 0 -2 (list from zero to penultimate element i.e. last element minus one)
lrange mylist 0 -3 (list from zero to last element minus two)
#rpop - pop from the right (bottom)
rpop mylist
#ltrim - sets the range of elements as the new list value
ltrim mylist 0 2 (sets the range 0 to 2 as the new value of mylist)
#ltrim - retains only the first 1000 newest elements on the list
ltrim mylist 0 999
##Blocking operations on list - Producer consumer model. Producers call lpush. Consumers call rpop.
##brpop, blpop - return to the caller only when a new element is added to the list or when a user specified timeout is reached.
#Wait for elements in the list 'tasks', but return after 5 seconds if no elements are present
brpop tasks 5
#zero timeout means wait forever
brpop tasks 0
##blocking pop on multiple lists with timeout.
#Wait for multiple lists at the same time and get notified when the first list receives an element.
brpop tasks schedules 10
#Safer queues or rotating queues
rpoplpush (try it)
brpoplpush (try it)
##Hashes
#Create or add to a hash
hmset user:1000 username antirez birthyear 1977 verified 1
#Get single value from hash
hget user:1000 username
#Get all values as a list from hash
hgetall user:1000
#Get multiple values from hash
hmget user:1000 username birthyear no-such-field
#Increment integer value stored in a hash
hincrby user:1000 birthyear 10


##Sets:
#Add new elements to a set
sadd myset 1 2 3

#Return all elements of a set
smembers myset

#Check if an element exists in the set: 0 - no, 1 - yes
sismember myset 2

#Intersection of sets: List all objects with specific tag values
sinter tag:1:news tag:2:news tag:5:news

#Extract a random element from the set
spop myset

#Extract multiple random elements from the set
spop myset 3

#Union of sets
sunionstore set1 set2 set3

#Cardinality of the set: Number of elements in the set
scard myset

#Random element without removing from the set
srandmember myset

#Multiple random elements without removing from the set
srandmember myset 3

##Sorted sets
#Add elements to the sorted set: zadd <score or sort-key> <element>
zadd fruit 50 apples
zadd fruit 20 oranges
zadd fruit 400 bananas
zadd fruit 10 guavas
zadd fruit 5 papayas
zadd fruit 500 berries

#Show all elements in the sorted set in ascending order of score
zrange fruit 0 -1

#Show all elements in the sorted set in descending order of score
zrevrange fruit 0 -1

#Show sorted elements of the set with scores
zrange fruit 0 -1 withscores

#Show sorted elements up to a certain score inclusive: Show all fruit with count up to 20. Should display papayas, guavas and oranges in the order listed.
zrangebyscore fruit -inf 20

#Remove range of elements from the sorted set: Removes papayas, guavas and oranges
zremrangebyscore fruit 5 20

#Rank: Position of an element in the sorted set
zrank fruit apples

#Lexicographical scores
#Show all elements lexicographically starting with specific characters: Shows bananas, berries and oranges
zrangebylex fruit [b [o

#Delete mutliple keys with the same prefix
redis-cli keys prefix:* | xargs redis-cli DEL

Saturday, October 17, 2015

Everything I know about Jenkins - Part 2 - Test drive

In this post, I will list simple steps to start Jenkins and play with it for the first time.

Prerequisites

1. Windows, Mac or Linux operating system or virtual machine
2. A recent version of JDK installed. Verify by executing 'java -version' on the command line.


Installation

Download the latest jenkins.war file from http://mirrors.jenkins-ci.org/war/latest/jenkins.war

Startup

1. Start Jenkins as a java app by executing 'java -jar jenkins.war' (In Windows, you may need to open command prompt as admin)
2. A message stating 'Jenkins is fully up and running' shows up eventually.





Access the front end

Open http://localhost:8080 in a browser and you should see the front page of Jenkins. Authentication is disabled by default.

Create your first Jenkins job

1. Click on 'New Item' on the list of links on the left.

2. Enter the job name, select 'Freestyle project' and click ok.

3. Scroll to the bottom of the job configuration page displayed, click 'Add build step' and select the step that applies to the operating system where the jenkins.war file is running.


4. echo "Hello World!" and click save


5. Build now - to run the job



6. First successful build - click on the blue icon next to #1 under 'Build History'


7. Verify the output


You've just built your first Jenkins job!




Saturday, October 10, 2015

Blue Angels in San Francisco on Columbus day 2015

Fleet week, Columbus Day and Blue Angels in San Francisco. These pictures are from Saturday, October 10, 2015. 





Friday, October 9, 2015

Everything I know about Jenkins - Part 1

I have been working with Jenkins for over an year as a user, developer, customization programmer and providing operations support for Jenkins at Blue Shield of California. I started playing with Jenkins by running it on my laptop as a standalone jar. I moved on to running it on Tomcat in a VirtualBox VM. Later, I created reusable a Vagrant box for the same. Then I got hooked on Docker and created a replica of a production Jenkins server as a Docker container.

1. What is Jenkins?
Jenkins is an open source tool that allows organizations to perform continuous integration and continuous delivery (CICD) of all their software applications through automated builds and deployments. The creator of Jenkins is Kohsuke Kawaguchi. I had the pleasure of meeting him at a Jenkins conference in San Francisco.

2. Are there other options?
Yes. Teamcity from JetBrains, Bamboo from Atlassian. There may be others and I have not tried them.

3. Do I need any other tools or software to perform CICD with Jenkins?
Yes. Jenkins is just one of the tools needed for CICD. Other tools include, source control, bug tracker, wiki, automated test execution suite, document or artifact storage tool, compilers, archiving software and in some cases infrastructure automation tools like Puppet.

4. What is under the hood?
Under the hood, the source code of Jenkins is written in Java. There is no database. Instead, configuration and build logs are stored on the hard drive. Whenever the Jenkins app is fired up, either as a standalone jar or as a web application deployed on a J2EE container based web server like Tomcat, the app reads configuration and build job information from the hard drive and does a good job of caching everything so there is no performance lag when a user needs to run a job. Also, under the hood, Jenkins was an offshoot of the popular build tool Hudson. Long story.

5. Which version should I use?
Irrespective of the level of experience with Jenkins, the latest or the second to latest LTS version (Long-Term Support) is recommended. LTS versions are most stable, with fewer bugs than the general release versions and as the name suggests, support is provided for a longer term than the general release versions.

6. Does Jenkins integrate with other software?
Yes and it integrates a little too well. There are Jenkins plug-ins for just about any software tool or API that one can install on the Jenkins instance and configure the integration on the Jenkins front end. If there is no plug-in for a particular tool or software that you currently use, building a Jenkins plug-in from scratch is a piece of cake.

7. What is the quickest way to get started with Jenkins?
Download the latest LTS release version from http://jenkins-ci.org/ for your operating system and follow the installation instructions. The really quick way of doing it is with Docker. Just execute "docker pull jenkins" on command line or follow instructions on Docker hub.

8. Why would I want to use Jenkins?
a. Automate builds and deployments of software applications
b. Orchestrate a complete cycle to compile code, run unit tests, perform static analysis of code, deploy the code to a test environment, execute automated smoke tests in the test environment and then deploy the code in production if all the prior steps are successful.
c. Or perform each of the above operations separately.
d. Get notified via email if any of the orchestration steps fail.

Jenkins is a Java based tool. The options for customization are limited to the available hardware resources. One can integrate just about any software product to work with Jenkins.

If you anticipate performing a task more than once, "automate it and get it right the first time". Jenkins provides the means to simplify the automation part.