@@ -10,6 +10,7 @@ const {
10
10
GraphQLList,
11
11
GraphQLInt,
12
12
GraphQLNonNull,
13
+ GraphQLBoolean,
13
14
} = require ( 'graphql' ) ;
14
15
15
16
//---------------Internal Module Imports----------------
@@ -48,14 +49,82 @@ const RootQueryType = new GraphQLObjectType({
48
49
metric : { type : GraphQLNonNull ( GraphQLString ) } ,
49
50
start : { type : GraphQLNonNull ( GraphQLInt ) } ,
50
51
end : { type : GraphQLNonNull ( GraphQLInt ) } ,
51
- resolution : { type : GraphQLNonNull ( GraphQLInt ) }
52
+ resolution : { type : GraphQLNonNull ( GraphQLInt ) } ,
53
+ prometheusURL : { type : GraphQLNonNull ( GraphQLString ) }
52
54
} ,
53
- resolve : ( parent , { start, end, resolution, metric} ) => {
54
- return axios . get ( `http://localhost:9090/api/v1/query_range?step=${ resolution } s&end=${ end } &start=${ start } &query=${ queryTypes [ metric ] } ` )
55
- . then ( res => res . data . data . result [ 0 ] . values )
55
+ resolve : ( parent , { start, end, resolution, metric, prometheusURL} ) => {
56
+ if ( prometheusURL [ prometheusURL . length ] === '/' ) prometheusURL = prometheusURL . slice ( 0 , prometheusURL . length ) ;
57
+
58
+ return axios . get ( `${ prometheusURL } /api/v1/query_range?step=${ resolution } s&end=${ end } &start=${ start } &query=${ queryTypes [ metric ] } ` )
59
+ . then ( res => {
60
+ return res . data . data . result [ 0 ] . values } )
56
61
. catch ( error => error ) ;
57
62
}
58
- }
63
+ } ,
64
+ livenessIndicator : {
65
+ type : GraphQLBoolean ,
66
+ description : 'Boolean value representing whether the ksqlDB server up and emitting metrics.' ,
67
+ args : {
68
+ prometheusURL : { type : GraphQLNonNull ( GraphQLString ) }
69
+ } ,
70
+ resolve : async ( parent , { prometheusURL } ) => {
71
+ try {
72
+ return await axios . get ( `${ prometheusURL } /api/v1/query?query=ksql_ksql_engine_query_stats_liveness_indicator` )
73
+ . then ( res => res . data . data . result [ 0 ] . value [ 1 ] === "1" )
74
+ . catch ( error => { throw error } ) ;
75
+ } catch ( error ) {
76
+ return error ;
77
+ }
78
+ }
79
+ } ,
80
+ errorRate : {
81
+ type : GraphQLInt ,
82
+ description : 'The number of messages that were consumed but not processed.' ,
83
+ args : {
84
+ prometheusURL : { type : GraphQLNonNull ( GraphQLString ) }
85
+ } ,
86
+ resolve : async ( parent , { prometheusURL } ) => {
87
+ try {
88
+ return await axios . get ( `${ prometheusURL } /api/v1/query?query=ksql_ksql_engine_query_stats_error_rate` )
89
+ . then ( res => Number ( res . data . data . result [ 0 ] . value [ 1 ] ) )
90
+ . catch ( error => { throw error } ) ;
91
+ } catch ( error ) {
92
+ return error ;
93
+ }
94
+ }
95
+ } ,
96
+ errorQueries : {
97
+ type : GraphQLInt ,
98
+ description : 'The count of queries in ERROR state.' ,
99
+ args : {
100
+ prometheusURL : { type : GraphQLNonNull ( GraphQLString ) }
101
+ } ,
102
+ resolve : async ( parent , { prometheusURL } ) => {
103
+ try {
104
+ return await axios . get ( `${ prometheusURL } /api/v1/query?query=ksql_ksql_engine_query_stats_error_queries` )
105
+ . then ( res => Number ( res . data . data . result [ 0 ] . value [ 1 ] ) )
106
+ . catch ( error => { throw error } ) ;
107
+ } catch ( error ) {
108
+ return error ;
109
+ }
110
+ }
111
+ } ,
112
+ bytesConsumed : {
113
+ type : GraphQLInt ,
114
+ description : 'The total number of bytes consumed across all queries.' ,
115
+ args : {
116
+ prometheusURL : { type : GraphQLNonNull ( GraphQLString ) }
117
+ } ,
118
+ resolve : async ( parent , { prometheusURL } ) => {
119
+ try {
120
+ return await axios . get ( `${ prometheusURL } /api/v1/query?query=ksql_ksql_engine_query_stats_bytes_consumed_total` )
121
+ . then ( res => Number ( res . data . data . result [ 0 ] . value [ 1 ] ) )
122
+ . catch ( error => { throw error } ) ;
123
+ } catch ( error ) {
124
+ return error ;
125
+ }
126
+ }
127
+ } ,
59
128
} )
60
129
} ) ;
61
130
@@ -68,4 +137,4 @@ app.use('/graphql', graphqlHTTP({
68
137
graphiql : true
69
138
} ) ) ;
70
139
71
- app . listen ( 5000 , ( ) => console . log ( 'Server Running...' ) ) ;
140
+ app . listen ( 5001 , ( ) => console . log ( 'Server Running...' ) ) ;
0 commit comments