NIFI system configuration


In [ ]:
import json
import requests

In [ ]:
example = '{"systemDiagnostics":{"aggregateSnapshot":{"totalNonHeap":"135.34 MB","totalNonHeapBytes":141910016,"usedNonHeap":"127.37 MB","usedNonHeapBytes":133558728,"freeNonHeap":"7.96 MB","freeNonHeapBytes":8351288,"maxNonHeap":"-1 bytes","maxNonHeapBytes":-1,"totalHeap":"512 MB","totalHeapBytes":536870912,"usedHeap":"413 MB","usedHeapBytes":433062392,"freeHeap":"99 MB","freeHeapBytes":103808520,"maxHeap":"512 MB","maxHeapBytes":536870912,"heapUtilization":"81.0%","availableProcessors":4,"processorLoadAverage":2.1474609375,"totalThreads":80,"daemonThreads":30,"uptime":"00:22:06.609","flowFileRepositoryStorageUsage":{"freeSpace":"384.06 GB","totalSpace":"464.77 GB","usedSpace":"80.71 GB","freeSpaceBytes":412386148352,"totalSpaceBytes":499046809600,"usedSpaceBytes":86660661248,"utilization":"17.0%"},"contentRepositoryStorageUsage":[{"identifier":"default","freeSpace":"384.06 GB","totalSpace":"464.77 GB","usedSpace":"80.71 GB","freeSpaceBytes":412386148352,"totalSpaceBytes":499046809600,"usedSpaceBytes":86660661248,"utilization":"17.0%"}],"garbageCollection":[{"name":"G1 Young Generation","collectionCount":35,"collectionTime":"00:00:01.607","collectionMillis":1607},{"name":"G1 Old Generation","collectionCount":0,"collectionTime":"00:00:00.000","collectionMillis":0}],"statsLastRefreshed":"08:51:56 PDT","versionInfo":{"niFiVersion":"1.3.0","javaVendor":"Oracle Corporation","javaVersion":"1.8.0_60","osName":"Mac OS X","osVersion":"10.12.3","osArchitecture":"x86_64","buildTag":"nifi-1.3.0-RC1","buildTimestamp":"06/05/2017 12:31:48 PDT"}}}}'

In [ ]:
js = json.loads(example)

In [ ]:
js

Can't run this against local nifi instance because of container stuff.. grumble'


In [ ]:
url_system_diags = 'http://localhost:8080/nifi-api/system-diagnostics'

In [ ]:
url_system_diags

In [ ]:
system_diags = requests.get(url_system_diags)

In [ ]:
system_diags

In [ ]:
js = json.loads(system_diags.content)

In [ ]:
system_diags.close()

In [ ]:
js['systemDiagnostics']['aggregateSnapshot']['freeHeapBytes']

In [ ]:
#build up keys to hash...
##input: 
##d: data structure to decompose.
##pre: optional key prefix
##
def rollup(pre="", d={} ):
    if isinstance (d, dict):
        for k,v in d.items():
            yield from rollup(pre + ":" + k, v)
    elif isinstance (d, list):
        for i,v in enumerate(d):
            yield from rollup(pre + '_' + str(i), v)
    else:
        yield (pre,d)

In [ ]:
arh = js['systemDiagnostics']['aggregateSnapshot']['contentRepositoryStorageUsage'][0]

In [ ]:
arh

In [ ]:
print("\n".join([str(k)+ " " + str(v) for k,v in rollup('nifi',arh)
               if isinstance(v,int)]))

In [ ]:
type(55.0) in [int]

In [ ]:
nifiDataList = [str(k)+ " " + str(v) for k,v in rollup('nifi',js)
               if type(v) in [int,float]]

In [ ]:
print("\n".join(nifiDataList))

In [ ]: