-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
3,306 additions
and
1,064 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import {cache, rawQuery, applyFilter, applyFieldSelection} from '../k8slibs.js'; | ||
const metricMaxLength = 500; | ||
export const mutations = { | ||
}; | ||
export const lists = { | ||
coreNodeMetrics: async (parent, args: object) => { | ||
const ret:{name:string,data:{timestamp: string, window: string, cpu: string, memory: string}[]}[] = cache.get('coreNodeMetrics') || [] | ||
const lst:Array<object>|undefined = cache.get('coreNodeMetricsInternal') | ||
if (lst==undefined) { | ||
try { | ||
const parsed = await rawQuery('/apis/metrics.k8s.io/v1beta1/nodes') as {items:{metadata:{name:string}, window:string, timestamp:string, usage:{cpu:string,memory:string}}[]} | ||
if (!Array.isArray(parsed.items)) throw new Error(`No data`); | ||
parsed.items.forEach(i=>{ | ||
const line = { | ||
timestamp: i.timestamp, | ||
window: i.window, | ||
cpu: i.usage.cpu, | ||
memory: i.usage.memory | ||
} | ||
if (ret.filter(node=>node.name==i.metadata.name).length>0) { | ||
if (ret.filter(node=>node.name==i.metadata.name)[0].data.filter(d=>d.timestamp==i.timestamp).length<1) | ||
ret.filter(node=>node.name==i.metadata.name)[0].data.push(line) | ||
} else { | ||
ret.push({ | ||
name: i.metadata.name, | ||
data: [line] | ||
}) | ||
} | ||
if (ret.filter(node=>node.name==i.metadata.name)[0].data.length>500) | ||
ret.filter(node=>node.name==i.metadata.name)[0].data.pop(); | ||
}); | ||
cache.set('coreNodeMetricsInternal', [], 2); | ||
cache.set('coreNodeMetrics', ret, 2*metricMaxLength); | ||
return ret | ||
} catch (err) { | ||
if (typeof err === 'object' && (err as object)['body'] !=undefined) { | ||
if ((err as object)['body']['reason']!='Forbidden') { | ||
console.error('error', (err as object)['body']); | ||
} else { | ||
cache.set('coreNodeMetricsInternal', [], 2); | ||
} | ||
} else {console.error('error', err)} | ||
return [] | ||
} | ||
} | ||
if (lst===undefined) return [] | ||
return lst.filter(o=>applyFilter(o,args)).map(o=>applyFieldSelection(o,args)) | ||
} | ||
}; | ||
export const queries = { | ||
coreNodeMetrics: lists.coreNodeMetrics, | ||
}; | ||
export const resolvers = { | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import {cache, rawQuery, applyFilter, applyFieldSelection} from '../k8slibs.js'; | ||
const metricMaxLength = 500; | ||
export const mutations = { | ||
}; | ||
export const lists = { | ||
corePodMetrics: async (parent, args: object) => { | ||
const ret:{pod_name:string, name:string,namespace:string,data:{timestamp: string, window: string, cpu: string, memory:string}[]}[] = cache.get('corePodMetrics') || [] | ||
const lst:Array<object>|undefined = cache.get('corePodMetricsInternal') | ||
if (lst==undefined) { | ||
try { | ||
const parsed = await rawQuery('/apis/metrics.k8s.io/v1beta1/pods') as {items:{metadata:{name:string,namespace:string}, containers:object[],window:string, timestamp:string}[]} | ||
if (!Array.isArray(parsed.items)) throw new Error(`No data`); | ||
parsed.items.map(i=>i.containers.map(c=>{return {pod_name:i.metadata.name, namespace:i.metadata.namespace, name: c['name'], data: {timestamp: i.timestamp, window: i.window, cpu: c['usage']['cpu'], memory: c['usage']['memory']}}})).flat().forEach(i=>{ | ||
if (ret.filter(pod=>pod.pod_name==i.pod_name&&pod.name==i.name&&pod.namespace==i.namespace).length>0) { | ||
if (ret.filter(pod=>pod.pod_name==i.pod_name&&pod.name==i.name&&pod.namespace==i.namespace)[0].data.filter(d=>d.timestamp==i.data.timestamp).length<1) | ||
ret.filter(pod=>pod.pod_name==i.pod_name&&pod.name==i.name&&pod.namespace==i.namespace)[0].data.push(i.data) | ||
} else { | ||
ret.push({ | ||
name: i.name, | ||
pod_name: i.pod_name, | ||
namespace: i.namespace, | ||
data: [i.data] | ||
}) | ||
} | ||
if (ret.filter(pod=>pod.pod_name==i.pod_name&&pod.name==i.name&&pod.namespace==i.namespace)[0].data.length>500) | ||
ret.filter(pod=>pod.pod_name==i.pod_name&&pod.name==i.name&&pod.namespace==i.namespace)[0].data.pop(); | ||
}); | ||
cache.set('corePodMetricsInternal', [], 2); | ||
cache.set('corePodMetrics', ret, 2*metricMaxLength); | ||
return ret | ||
} catch (err) { | ||
if (typeof err === 'object' && (err as object)['body'] !=undefined) { | ||
if ((err as object)['body']['reason']!='Forbidden') { | ||
console.error('error', (err as object)['body']); | ||
} else { | ||
cache.set('corePodMetricsInternal', [], 2); | ||
} | ||
} else {console.error('error', err)} | ||
return [] | ||
} | ||
} | ||
if (lst===undefined) return [] | ||
return lst.filter(o=>applyFilter(o,args)).map(o=>applyFieldSelection(o,args)) | ||
} | ||
}; | ||
export const queries = { | ||
corePodMetrics: lists.corePodMetrics, | ||
}; | ||
export const resolvers = { | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.