Thursday, July 26, 2018

Script to start prometheus and grafana using docker

#!/bin/bash

# Start prometheus server
docker run -d -p 9090:9090 --restart unless-stopped \
  -v /home/ubuntu/graph/prometheus:/etc/prometheus \
  -v /home/ubuntu/graph/prometheus:/prometheus \
  --user $(id -u) --name prometheus prom/prometheus \
  --config.file=/etc/prometheus/prometheus.yml

# Start prometheus node exporter which collects node resource metrics
docker run -d -p 9100:9100 --restart unless-stopped \
  --user $(id -u) --name node-exporter prom/node-exporter

# Start grafana
docker run -d -p 3000:3000 --restart unless-stopped \
  -v /home/ubuntu/graph/grafana:/var/lib/grafana \
  --user $(id -u) --name grafana grafana/grafana


Assume that directories exists

    /home/ubuntu/graph/prometheus
    /home/ubuntu/graph/grafana

#Using graphite seems to be the better option since it allows posting data to it.
#Here is how to start it.

docker run -d   --name graphite   -p 8080:80   -p 2003:2003   sitespeedio/graphite:1.1.3

then access the web UI at 8080.

Run the following command to post some random data.

while true; do echo "fabric.tong.diceroll;nn=$((RANDOM%30));john=100 $((RANDOM % 100)) -1" | nc -q0 192.168.56.32 2003;sleep 3; done

The above command actually post metric named fabric.tong.diceroll with two tags, one is named nn, one is named john.

VirtuaBox host only network stops working

Once in awhile, virtualbox host only network will stop working. The host will not be able to ping the guest system. Even if the removal and recreate the host only network won't help. What it really helped me was to completely shutdown my macbook machine. do a cold restart, then network started working.

The route table of the host will look like this if the routing is working.

Use this command to show the current routing related to the VB host-only network
netstat -nr | grep 192.168

192.168.56         link#17            UC              3        0 vboxnet
192.168.56.1       a:0:27:0:0:0       UHLWIi          1        6     lo0
192.168.56.3       8:0:27:15:45:66    UHLWI           0        5 vboxnet   1171
192.168.56.255     ff:ff:ff:ff:ff:ff  UHLWbI          0        3 vboxnet

When it was not working, the netstat -nr shows no entries like the above.

Regardless the host network is working or not, from the host, you won't be able to ping the gateway of the host network, for example, ping 192.168.56.1 will fail.

If not wantting cold restart the machine, do the following.

sudo route delete 192.168.56.0/24

Then delete host only network and recreate host only network, then restart VM, it will work.

For some reasons, the mac host may not show any route to network 192.168.56.0/24. when that happens, use the following procedure to get it back.

1. Delete all host-only networks from virtualbox
2. Completely shut down the mac host, then reboot the host
3. Recreate the host-only network.

At this point, mac host should show at least the following (using netstat -nr command):

192.168.56         link#17            UC              2        0 vboxnet

After you start a VM which uses host-only network, you should see the following:

192.168.56         link#17            UC              2        0 vboxnet
192.168.56.255     ff:ff:ff:ff:ff:ff  UHLWbI          0        1 vboxnet

If you actually ping the guest VM with IP 192.168.56.32, and the ping is successful, then you should see the following:

192.168.56         link#17            UC              2        0 vboxnet
192.168.56.32      8:0:27:8f:d9:5e    UHLWIi          1        3 vboxnet   1195
192.168.56.255     ff:ff:ff:ff:ff:ff  UHLWbI          0        1 vboxnet

Monday, July 23, 2018

Fabric sdk-go usage

The flow to use go-sdk to create a new channel.

1. Get configuration from a configuration file using config.FromFile(path_to_config_file), this returns a ConfigProvider type.
2. Use ConfigProvider function and fabsdk.Option to create a sdk.
        sdk := fabsdk.New(configOpt, sdkOpts...)
3.  Use sdk.Context to create a client context.
clientContext := sdk.Context(fabsdk.WithUser(orgAdmin),
fabsdk.WithOrg(ordererOrgName))
4. Use resmgmt to create a new res management client
resMgmtClient, err := resmgmt.New(clientContext)
5. Use the resMgmtClient, orgName, and the sdk context to create a mspClient
mspClient, err := mspclient.New(sdk.Context(),
mspclient.WithOrg(orgName))
6. Get AdminIdentity using the orgAdmin string.
adminIdentity, err := mspClient.GetSigningIdentity(orgAdmin)
7. Use resmgmt.SaveChannelRequest.
    req := resmgmt.SaveChannelRequest{ChannelID: channelID,
             ChannelConfigPath: integration.GetChannelConfigPath(channelID + ".tx"),
             SigningIdentities: []msp.SigningIdentity{adminIdentity}}
8. Save the channel
    txID, err := resMgmtClient.SaveChannel(req,
resmgmt.WithRetry(retry.DefaultResMgmtOpts),
resmgmt.WithOrdererEndpoint("orderer.example.com"))
9. Make sure things went well.    
    require.Nil(t, err, "error should be nil")
    require.NotEmpty(t, txID, "transaction ID should be populated")







 

Friday, July 20, 2018

health vital info collection

we could create a block chain system which allow users to send data to a blockchain which de-identifies the user specific information such as name, location, etc. for example,

1. name or id will be replaced with something to prevent being used to identify a person. the ID may be replaced with something which can be used to correlate data set but can not be used to identify a user.
2. age can be mapped to an age group
3. location, optional
4. sex, optional
5. race, optional

The information posted onto the network if get confirmed, will receive points. transaction gets posted to the network once a day or every 6 hours. each transaction should contain a number of data points, for example, the vitals will be measured every 10 minutes, if post is done every 6 hours, then each transaction should contain 36 data points.

The data can be used to track population in a particular areas during a disaster. data can be correlated to some other statistics to predict the population.